Converting dates to epoch times
App Development4 posts238 viewsLast activity Nov 2022
AS
asarpeshkarOP
Oct 2022Is there a more concise way to convert a Date to epoch time than:
toEpochTime d = convertRelTimeToMicroseconds $ subTime (dateToTime d) epoch
epoch = dateToTime $ date 1970 Jan 1
dateToTime d = time d 0 0 0
ST
Stephen
Nov 2022The Unix epoch is deemphasized in the Daml-LF primitive date/time model, which is defined in terms of RFC 3339 instead. That is, your bounds are not some power of 2 offset from Unix epoch; they are defined as dates that are intuitive to read based on the RFC 3339 textual representation.
That said, timeToMicrosecondsSinceEpoch currently exists from DA.Internal.Time, but as the module name suggests, if you use it and your program breaks, you get to keep both pieces.
AS
asarpeshkar
Nov 2022Is it problematic to add timeToMicrosecondsSinceEpoch to the public API?
ST
Stephen
Nov 2022I think it’s problematic. Maybe someone else feels differently.