OffsetDate represents a date with a zone offset. I don't understand the purpose this class serves, what are the main use cases justifying its existence?
Asked
Active
Viewed 1,029 times
1 Answers
7
When analysing the basic components of dates and times there are four basic elements:
- date
- time
- offset (hours plus/minus from Greenwich)
- time-zone
These naturaly form seven classes:
- LocalDate - date only
- LocalTime - time only
- LocalDateTime - date + time
- OffsetDate - date + offset
- OffsetTime - time + offset
- OffsetDateTime - date + time + offset
- ZonedDateTime - date + time + offset + zone
(a time-zone can only be used if you know the date and the time, so there is no ZonedDate or ZonedTime class)
The first six forms directly match XML schema definitions, which in effect justifies their existence. In application design terms I suspect that OffsetDate
will be the least used of the seven classes.
Update: 2013-01-24: OffsetDate won't be in JDK 1.8.

JodaStephen
- 60,927
- 15
- 95
- 117
-
"These naturally form seven classes" -- Does not seem natural to me. This explains why you added it but doesn't answer my question about use cases. – Brian Harris Oct 21 '11 at 14:15
-
The use case is that XML schema needs the Offset* classes, and ISO-8601 also parses to the Local* or Offset* classes, not ZonedDateTime – JodaStephen Dec 06 '11 at 17:39
-
3May be today I am a bit sleepy but why a time-zone can only be used if you know the date and the time? For example, 23 April 1999 at America/NewYork. Seems that this is a concrete period of time enclosed from 23 April 1999 00:00:00 to 23 April 1999 23:59:59 at America/NewYork – borjab Mar 04 '16 at 16:43
-
@borjab because while an `OffsetDate` would always be 24 hours, a `ZonedDate` would not be. Neither are particularly useful though. – OrangeDog Mar 26 '19 at 17:19
-
@borjab Here's what I'm guessing is an example off the top of my head. Say you're in the Eastern U.S. The time zone shift happens at 3:00 AM. So if you're Eastern time on the date of the switchover, whether you're Eastern Standard Time or Eastern Daylight time depends on whether it's before or after the time zone switch happens in the morning. I'm guessing "America/New York" isn't a time zone, but rather a zone ID for figuring out the time zone based on the current date & time. Hopefully someone knowledgeable can confirm/refute my guess. – M. Justin Jul 21 '20 at 23:05
-
For those following along at home, [`OffsetDate`](https://www.threeten.org/threeten-extra/apidocs/org.threeten.extra/org/threeten/extra/OffsetDate.html) was just added to the [ThreeTen-Extra](https://www.threeten.org/threeten-extra) library in its 1.6.0 release. – M. Justin Feb 19 '21 at 23:07
-
Setting aside how often it would be useful in practice, isn't there a reasonable conceptual argument to be made for a `ZonedDate`? Like, if I were living in New York and I were talking about something happening locally on May 1, I'd be expecting it between midnight May 1 (inclusive) & midnight May 2 (exclusive) in New York time. This would be a different time range than someone in California talking about something happening locally on May 1. – M. Justin Mar 09 '21 at 21:19
-
1Yes, `ZonedDate` is essentially a range of time from one midnight to the next. It would make a fine addition to ThreeTen-Extra – JodaStephen Mar 11 '21 at 00:18
-
@JodaStephen Thanks for the confirmation! With (of course) the standard caveat that not all time zones have midnights for every date. :-) – M. Justin Mar 11 '21 at 00:27