0

I would like to verify if my understanding of JSR310 classes use-cases are correct, below a diagram with classes, and how i see them fit:

   Database (UTC)
       ||
       \/
  OffsetDateTime      (used in persistence or transmission, databases and XML)
       ||
       \/
    Instant            (used in business logic, for date time calculations)
       ||
       \/
   ZonedDateTime  <-- ZoneId  (used in presentation layer, requiring the client zoneId)
       ||
       \/
    LocalDateTime (used in presentation layer, obtained from ZonedDateTime)
       ||
       \/
     Front-end

My uncertainity its related with ZonedDateTime and LocalDateTime, since as far as i understand are both suitable for presentation layer, altough LocalDatetime does not have time-zone or offset.

Its the LocalDateTime what i should send to front-end, after ZonedDateTime has handled all DST conversions and anomalies?

Do i not send a ZonedDateTime to front-end since it has extra information like time-zone?

thanks in advance

dotmindlabs
  • 778
  • 1
  • 12
  • 35
  • For most purposes I would still send `ZonedDateTime` to the presentation layer and leave to that layer whether to format it with or without UTC offset and/or time zone (e.g., time zone abbreviation). If you know the user’s time zone you may argue that it is not necessary. – Ole V.V. Jan 18 '23 at 16:19
  • @OleV.V. Yes in this case we know the users time-zone. But its a good point. – dotmindlabs Jan 19 '23 at 14:31

1 Answers1

1

JSR310 is the Java specification for the java.time package, which provides classes for date and time manipulation in Java. The main classes in the package are:

  • LocalDate: Represents a date without a time (year, month, and day)
  • LocalTime: Represents a time without a date (hours, minutes, seconds, and nanoseconds)
  • LocalDateTime: Represents a date and time without a time zone (combines LocalDate and LocalTime)
  • ZonedDateTime: Represents a date and time with a time zone
  • Instant: Represents a point in time (similar to java.util.Date)

You should use LocalDate when you only need to represent a date, LocalTime when you only need to represent a time, LocalDateTime when you need to represent both date and time but without timezone, ZonedDateTime when you need to represent both date and time with timezone and Instant when you need to represent a point in time.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • Yes usually clients dont require to see UTC offset or Timezone in front-end. So it hink Locals are more suitable for this layer. – dotmindlabs Jan 18 '23 at 11:55