Chronos is one of the many Smalltalk-related blogs syndicated on Planet Smalltalk
χρόνος

Discussion of the Essence# programming language, and related issues and technologies.

Blog Timezone: America/Los_Angeles [Winter: -0800 hhmm | Summer: -0700 hhmm] 
Your local time:  

2006-01-09

Event Times in Multiple Time Zones--A Chronos Example

A "Squeak Chat" is a discussion about Squeak Smalltalk hosted on an IRC channel. It's hosted on Freenode with the channel ID #squeak.

Squeak Chats are scheduled every 100 hours, so that the time-of-day at which they occur in any given time zone varies by +4 hours each time the event occurs (assuming no DST transitions intervene.)

The next Squeak Chat is scheduled for 2006-01-14T04:00:00+0000 (UT: Universal Time). What time is that where you live?

Using Chronos, the answer can be obtained by doing a "print it" of the following expression:

DateAndTime utYear: 2006 month: January day: 14 hour: 4 minute: 0 second: 0

The expression above creates an instance of DateAndTime (actually, Timepoint--DateAndTime is simply a global alias for Timepoint) that represents the same point-in-time as 2006-01-14T04:00:00+0000, but whose local time is set to be the same as Chronos' current default time zone (which would normally be your local time zone.) When a DateAndTime (Timepoint) instance prints itself, it displays the local time in the time zone to which it was bound when it was created. So, if your local time zone offset is -8 hours, then the result of doing a "print it" of the Timepoint created by the foregoing expression would be 2006-01-13T20:00:00-08:00 (13 Jan 2006, 8pm.)

When will Squeak Chats occur during the next year? When will they occur in a representative sample of world time zones? The code to compute the schedule of Squeak Chats for the next year in selected world time zones is given below:

| base interval timePeriod stream timeZones printPolicy |
interval := 100 hours.
base := DateAndTime year: 2006 month: January day: 14 hour: 4 minute: 0 second: 0 timeZone: 'Universal'.
timePeriod := Timeperiod yearStartingAt: base.
timeZones := #(UT 'Pacific/Auckland' 'Australia/Sydney' 'Asia/Tokyo' 'Asia/Hong_Kong' 'Asia/Calcutta' 'Europe/Moscow' 'Asia/Jerusalem' 'Europe/Amsterdam' 'Europe/London' 'America/Sao_Paulo' 'America/Argentina/Buenos_Aires' 'America/New_York' 'America/Chicago' 'America/Denver' 'America/Los_Angeles' 'Pacific/Honolulu').
printPolicy :=
     ChronosPrintPolicy applying:
         #(useMonthAbbreviation
         showDayOfWeekAbbreviation
         dateAndTimeSeparator: ' '
         use12HourFormat
         showTimeZoneVerbosely
         timeZoneSeparator: $
         timeZoneElementSeparator: nil).
[stream := (ResourcePath fromString: 'schedule.txt') newWriteStream.
timePeriod every: interval do: [:tp |
    stream nextPutAll: '== Squeak Chat Times in selected time zones =============================='; cr.
    timeZones do: [:tz |
        | timepoint |
        timepoint := tp start in: tz.
        stream cr; tab.
        timepoint printOn: stream using: printPolicy].
        stream cr; cr]] ensure: [stream close].

The ouptut shows that the next two Squeak Chats will occur at the following times in the selected set of time zones:

== Squeak Chat Times in selected time zones ==============================

Sat, 2006-Jan-14 04:00:00 am +0000 (UT: Universal Time)
Sat, 2006-Jan-14 05:00:00 pm +1300 (NZDT: Pacific/Auckland)
Sat, 2006-Jan-14 03:00:00 pm +1100 (EST: Australia/Sydney)
Sat, 2006-Jan-14 01:00:00 pm +0900 (JST: Asia/Tokyo)
Sat, 2006-Jan-14 12:00:00 pm +0800 (HKT: Asia/Hong_Kong)
Sat, 2006-Jan-14 09:30:00 am +0530 (IST: Asia/Calcutta)
Sat, 2006-Jan-14 07:00:00 am +0300 (MSK: Europe/Moscow)
Sat, 2006-Jan-14 06:00:00 am +0200 (IST: Asia/Jerusalem)
Sat, 2006-Jan-14 05:00:00 am +0100 (CET: Europe/Amsterdam)
Sat, 2006-Jan-14 04:00:00 am +0000 (GMT: Europe/London)
Sat, 2006-Jan-14 02:00:00 am -0200 (BRST: America/Sao_Paulo)
Sat, 2006-Jan-14 01:00:00 am -0300 (ART: America/Argentina/Buenos_Aires)
Fri, 2006-Jan-13 11:00:00 pm -0500 (EST: America/New_York)
Fri, 2006-Jan-13 10:00:00 pm -0600 (CST: America/Chicago)
Fri, 2006-Jan-13 09:00:00 pm -0700 (MST: America/Denver)
Fri, 2006-Jan-13 08:00:00 pm -0800 (PST: America/Los_Angeles)
Fri, 2006-Jan-13 06:00:00 pm -1000 (HST: Pacific/Honolulu)

== Squeak Chat Times in selected time zones ==============================

Wed, 2006-Jan-18 08:00:00 am +0000 (UT: Universal Time)
Wed, 2006-Jan-18 09:00:00 pm +1300 (NZDT: Pacific/Auckland)
Wed, 2006-Jan-18 07:00:00 pm +1100 (EST: Australia/Sydney)
Wed, 2006-Jan-18 05:00:00 pm +0900 (JST: Asia/Tokyo)
Wed, 2006-Jan-18 04:00:00 pm +0800 (HKT: Asia/Hong_Kong)
Wed, 2006-Jan-18 01:30:00 pm +0530 (IST: Asia/Calcutta)
Wed, 2006-Jan-18 11:00:00 am +0300 (MSK: Europe/Moscow)
Wed, 2006-Jan-18 10:00:00 am +0200 (IST: Asia/Jerusalem)
Wed, 2006-Jan-18 09:00:00 am +0100 (CET: Europe/Amsterdam)
Wed, 2006-Jan-18 08:00:00 am +0000 (GMT: Europe/London)
Wed, 2006-Jan-18 06:00:00 am -0200 (BRST: America/Sao_Paulo)
Wed, 2006-Jan-18 05:00:00 am -0300 (ART: America/Argentina/Buenos_Aires)
Wed, 2006-Jan-18 03:00:00 am -0500 (EST: America/New_York)
Wed, 2006-Jan-18 02:00:00 am -0600 (CST: America/Chicago)
Wed, 2006-Jan-18 01:00:00 am -0700 (MST: America/Denver)
Wed, 2006-Jan-18 12:00:00 am -0800 (PST: America/Los_Angeles)
Tue, 2006-Jan-17 10:00:00 pm -1000 (HST: Pacific/Honolulu)






No comments: