Skip to content
CCPEDIAby Unity Nodes
App Development

Converting dates to epoch times

4 posts272 viewsLast activity Nov 2022

  1. asarpeshkarOP

    Is 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
    
  2. Stephen

    The 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.

  3. asarpeshkar

    Is it problematic to add timeToMicrosecondsSinceEpoch to the public API?

  4. Stephen

    I think it’s problematic. Maybe someone else feels differently.