From: Alistair Grant <akgrant0...@gmail.com>

I think that there's still use for representing a date as a timespan,
i.e. a 24 hour period that we can use to find the intersection of
times, etc (in addition to adding a timezone offset to a DateTime to
figure out the date in a different country).  Whether it needs to be a
separate class from Timespan I'm not so sure.

From my Smalltalk library:

Date
  methods:
    asMidnightDateAndTime
      ^DateAndTime year: self year  month: self month day: self dayOfMonth
                   hour: 0 minute: 0 second: 0
    pvtSpanFrom: start to: end
      ^Timespan starting: start asMidnightDateAndTime
                  ending: end   asMidnightDateAndTime
    daySpan
      ^self pvtSpanFrom: self to: self next
    monthSpan
      ^self pvtSpanFrom: self thisMonth to: self nextMonth
    quarterSpan
      ^self pvtSpanFrom: self thisQuarter to: self nextQuarter
    yearSpan
      ^self pvtSpanFrom: self thisYear to: self nextYear

One of the tricky things here is that the result of #daySpan
may be 23, 24, or 25 hours, plus or minus a second depending
where the leap seconds fall.  It is *usually* a 24-hour
period, but definitely not always.

And of course you can't go *back* from a #daySpan to a Date
without reference to a particular time zone (not zone offset,
because of course the zone offset can change during a "day").




Reply via email to