[squeak-dev] About the new Date

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Feb 10 21:51:00 UTC 2012


2012/2/10 David T. Lewis <lewis at mail.msen.com>:
> On Fri, Feb 10, 2012 at 08:22:34AM +0200, Brent Pinkney wrote:
>> Hi,
>>
>> One thing we can consider is a DynamicBinding that specifies the offset. If no binding, then use the global default.
>>
>> This is how lisp/scheme would solve it.
>
> Hi Brent,
>
> That might be a good approach. I did something like that with the
> TimeZoneDatabase tables, such that the current time zone is a proxy
> that points to the Olsen time zone tables, and "DateAndTime
> localTimeZone offset" finds the proper offset in the tables. This
> works well.
>
> Having said that, I think that Chris' original idea was to use only
> the UTC-based (#globalize) style, and to rely on idioms like
> "DateAndTime now asDate" to create an instance of Date with an
> offset for local time zone. Having played around with the inbox changes
> a bit now, I have to say that I think Chris was right, it's is probably
> better to keep things simple and consistent, and not try to have a
> #localize variant.
>
> Do you (Brent) have a preference on this? For myself, I'm happy
> with Chris' proposal (minus the #localize feature, which I suspect
> that Chris will be more than happy to remove ;)
>

+1 again, I like DateAndTime>>midnight to use receiver offset, and
consequently asDate too, it's the least surprising...
Well, it won't perfectly handle those legal days when DST change and
which are not 24h long, but it's already better than what we have.

Now, if you don't have a local zero offset, you'll get
(Date newDay: 10 month: 2 year: 2012) = Date today = false

So maybe we need to have this kind of method on instance side:

Date>>withoutOffset "Note: it's makeUTC without statefull side effects"
    "Answer the same day without any time zone offset."
    ^self withOffset: 0 hours

Date>>localize "or local or localTime or ?"
    "Answer the same day starting at midnight local time"
    ^self withOffset: DateAndTime localOffset

Date>>withOffset: aDuration
    "Answer the same day in a different time zone"
    ^self starting: (start copy primOffset: aDuration asDuration)

Nicolas

> Dave
>
>


More information about the Squeak-dev mailing list