Timestamps in the Standard Gleam Time Package #4095
Replies: 5 comments 32 replies
-
These two functions are also being considered, but we may want to keep functionality light so we don't over commit to anything. External packages can also provide additional functions. pub fn to_seconds(timestamp: Timestamp) -> Int {
timestamp.milliseconds / 1000
}
// Maybe, for use in pipelines mostly I assume
pub fn to_milliseconds(timestamp: Timestamp) -> Int {
timestamp.milliseconds
} |
Beta Was this translation helpful? Give feedback.
-
I think it's better to have an approach that is flexible while at the same time provides the safeguards around units which I think phantom types provide: pub type Unit {
MicroSecond
MilliSecond
Second
Minute
Hour
Day
Week
Month
Year
}
pub type Timestamp(unit) {
Timestamp(Int)
} We may even omit the |
Beta Was this translation helpful? Give feedback.
-
The Elm time library has some other functions that make use of zones. Would we want to adapt those too? https://package.elm-lang.org/packages/elm/time/latest/Time If we do not provide anything along these lines how would the programmer be expected to work with these timestamps? Being able to convert them to a textual representation seems like it would be one of the most common needs. |
Beta Was this translation helpful? Give feedback.
-
I appreciate being included in the initial message but |
Beta Was this translation helpful? Give feedback.
-
I have started on a time library here: gleam-lang/time#1 |
Beta Was this translation helpful? Give feedback.
-
Hello all!
A standard gleam time package is in the works, and I would like to invite community involvement in its development. Its immediate goal is to provide interop between time packages in the ecosystem.
As a first step, the Timestamp type is being explored. Timestamps are just
Int
s, but by giving it a standard type we can help assure that a second denominated timestamp is not accidentally compared to a millisecond denominated timestamp.The current design is this:
For now, we would like to focus on providing types in the standard package with minimal functionality, relying on the ecosystem to deliver richer functionality. If just core types are provided, then less can be committed to in the standard package. Gleam's type system is unique (and fantastic), and as such we may want to take some novel approaches to dealing with time. The less we commit to the standard library, the more experimentation we can do as a community, and the more cool things we might discover!
Do any of you amazing community members have any additional points we should take into consideration before canonicalizing this design?
After timestamps are settled, we could move on to probably the next simplest type which really isn't all that simple: dates. Some big questions are: 1. how should they be represented? 2. should the constructor be opaque?
I am the author of
tempo
(gtempo on hex), but I would like to make sure @massivefermion (author ofbirl
), @maxdeviant (author ofbigben
), and @michaeljones (author ofrada
) are aware of this thread. I am not part of the Gleam core team, so while I have had prior conversations with Louis, nothing I say should be taken as official.Beta Was this translation helpful? Give feedback.
All reactions