• GTG3000@programming.dev
    link
    fedilink
    arrow-up
    21
    arrow-down
    1
    ·
    25 days ago

    Anything an API returns should just look like 1720533944.963659 .

    There’s no reason to store dates as anything other than UTC. User-side, sure, timezones are useful. Server doesn’t have to know.

    • Zagorath@aussie.zone
      link
      fedilink
      English
      arrow-up
      17
      ·
      edit-2
      24 days ago

      This is absolutely fundamentally wrong. What you’ve described is what Nodatime calls an Instant, and it’s a very important data class, but there are valid reasons to use other classes.

      A LocalDateTime cares about the date and time locally. An event scheduled for 8am every Monday might use this. It would update accordingly if you move locations to a new locale.

      A ZonedDateTime can almost be directly translated into an Instant, except that one time zone might change. If you go into or out of daylight saving time, or your region decides to change its time offset. Oslo time is still Oslo time. You use this if your event occurs at a specific time in a specific location.

      An OffsetDateTime is like a ZonedDateTime, but instead of being tied to a specific time zone (e.g. “Oslo time”) it’s tied to a specific UTC offset (e.g. UTC+1).

      You don’t have to use Nodatime, but you should at least think deeply about what your time objects actually represent and what is the best way to represent them.

      See the creator of Nodatime’s presentation about thinking deeply about time for more.