-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Representing time - moments in time, durations, calendar calculations, etc - should always be done with strongly-typed classes where possible, rather than simple integer types (which are a bad choice because they don't include units - eg. 5 could represent 5 minutes, seconds, or even milliseconds).
Joda-Time recommends moving to java.time.* - and has for a long time!
Java has had an excellent built-in time-representation library in the java.time.* package since Java 8, released in 2014. Prior to that, the best available option was Joda-Time (written by the same person who went on to advise on java.time, Stephen Colebourne) - and at the Guardian we still have active production code that still uses Joda-Time - but where we're updating code, we should aim to migrate to java.time.*.
Equivalent classes in java.time
org.joda.time.Instant→java.time.Instantorg.joda.time.DateTime→java.time.ZonedDateTime- assuming that you need to have localised date - if not, you may want to be usingjava.time.Instantinstead.
See https://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html for a full list.
Examples
- https://github.com/guardian/ophan/pull/3988
- https://github.com/guardian/ophan/issues/4202
- Use strongly-typed
Durations for time riff-raff#1348 - https://github.com/guardian/janus/pull/4688
- Drop Scala 2.12, drop Joda-Time -
maxAuthAgebecomes ajava.time.Durationplay-googleauth#201 - Mss 339/remove joda time pa-football-client#42