Giter Site home page Giter Site logo

Comments (3)

brendanlong avatar brendanlong commented on July 29, 2024

This should be easy for someone else to do by looking at the code and tests in Pgx_value_core and basically just doing the same thing for Ptime. Let me know if you're interested and run into any issues.

from pgx.

jsthomas avatar jsthomas commented on July 29, 2024

I'm interested in working on this issue. I was hoping to get some feedback about whether I'm on the right track, since I'm a bit of a beginner with OCaml.

Currently my pgx_value_ptime.mli file looks like this:

type v = Pgx.Value.v [@@deriving compare, sexp_of]
type t = Pgx.Value.t [@@deriving compare, sexp_of]

include module type of Pgx.Value with type v := v and type t := t

val of_date : Ptime.date -> t
val to_date_exn : t -> Ptime.date
val to_date : t -> Ptime.date option

val of_time : ?tz_offset_s:Ptime.tz_offset_s -> Ptime.t -> t
val to_time_exn : t -> Ptime.t * Ptime.tz_offset_s
val to_time : t -> (Ptime.t * Ptime.tz_offset_s) option

val time_of_string : string -> Ptime.t * Ptime.tz_offset_s

Does the use of Ptime.t * Ptime.tz_offset_s tuples make sense? In the core version, it looks like Time contains a date, time of day, and timezone. However, Ptime.t describes a POSIX timestamp in UTC, so there needs to be some additional way of storing the timezone information.

I thought about using Ptime.date * Ptime.time instead; Ptime.time does carry timezone information. I ruled this out because Ptime.time has integer-valued seconds, which would mean a loss of precision.

from pgx.

brendanlong avatar brendanlong commented on July 29, 2024

@jsthomas Sorry, for some reason I didn't see the comment on here. One thing to consider is if it's necessary to pass the offset around at all. Another possible interface is to just always accept and return UTC timestamps. Although if Postgres stores offsets for some reason then having that be available in the interface is probably valuable for someone.

from pgx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.