On Github rskonnord-plos / time-sucks
It causes bugs!
The Internet offers a two-part list of 113 ways that time screws up software.
There are many contenders for the biggest cause of time-related bugs...
but today I'll be focusing on my personal pet peeve...
false precision.
A joke!
A teacher takes an elementary class to the science museum. They look at a dinosaur fossil. The tour guide says, "This fossil is from a dinosaur that died sixty-five million and two years ago." The teacher asks, "How can you know that?" The tour guide says, "Well, when they hired and trained me, they said it was sixty-five million years old. And I've worked here for two years."The year 1996 and the Date class.
An annoyingly one-size-fits-all approach to storing and representing time values, riddled with early-OOP antipatterns.
Or, as it is known in Java 8, the java.time.* package.
A library of improved classes for representing time.
Java, pre-8 Few classes Overloaded and complex Joda-Time Larger and more complex selection of classes Each class is simpleThe remainder of the talk will be a brief tour of Joda-Time's basic classes.
If you are not a Java coder, I hope it will provide a good philosophical example.
Example: Neil Armstrong first stepped onto the Moon at July 21, 1969, 02:56 UTC.
Example: The release date of the movie Primer was October 8, 2004.
Example: WiFri begins at 4:30 PM.
Example: Bastille Day is celebrated on July 14.
Example: The next Game of Thrones season premiere episode will air April 24, 2016 at 9:00 PM.
ZonedDateTime and OffsetDateTime represent date-and-timestamps in particular time zones.
Both can be translated into Instant objects.
An offest is just a number of hours offset from UTC.
A time zone defines an offset, with complicated baggage about stuff like Daylight Saving Time.
Example: The Pacific Time Zone's offset is equal to UTC minus eight hours in the winter and UTC minus seven hours in the summer.
Example: Regulation time in a game of soccer is 90 minutes.
Example: A warranty lasts for 90 days.
To avoid false precision!
Days, as measured on a calendar, don't neatly translate into 24-hour intervals.
What if Daylight Saving Time begins or ends during the period? What if you travel between time zones?
Representing a 90-day warranty as 2,160 hours is silly.
The java.time.temporal.* package provides nice enums for every time unit and calendar field you can think of.
Fear magic numbers no longer.
But I thought the whole point of the Calendar class was to avoid ethnocentric preference for the Gregorian calendar?
It's not Gregorian; it's ISO-8601.
Can't be ethnocentric with "International" right in the name.
The java.time.chrono.* package has got you covered with library classes for Islamic, Japanese, Chinese, and Thai calendars.
Time left for questions?