Why does Joda Time allow a Period constructor to take two LocalTimes but there is no Duration constructor like that?
I want to know because it may aid in my understanding of the best use of Joda Time.
Here’s my thinking: Duration is good for social convention unaware applications and the lack of awareness is what makes it different from Period. LocalTime is good for convention unaware use because it has no timezone. This suggests Duration should be used with LocalTime and vice-versa.
A
Durationis the amount of time between two preciseInstants in time (which are completely independent of human concepts like years, days, and seconds).LocalTimes, however, represent ambiguous points in time (they require a date and time zone to define anInstant).It makes sense to say there’s a “standard duration” (the duration of the period assuming no DST, no leap years, no leap seconds (which Joda chronologies don’t support, admittedly)) between two
LocalTimes, but there’s not enough information to compute a “true duration”. I suspect this is whyDurationdoesn’t have that constructor.For example, let’s suppose we have two
LocalTimes: one representing 1:00 AM and 4:00 AM. 99% of the time, it’d make sense to say that’s a duration of 3 hours. But, if they represent times on the day of a Daylight Saving Time switch, the duration would be 2 hours or 4 hours.Periodis defined more broadly, where it make senses to have a period between two partially-defined times likeLocalTimes (just “3 hours” in the example).Periods correspond easily to standard durations, so one can just callperiod.toStandardDuration().