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-02-26

Preliminary Port of Chronos To Squeak Published

Avi Bryant has published a very preliminay (and only partially functional) port of Chronos to Squeak. It's available from SqueakSource or from Squeak Map. It is very much a "work in progress." When Avi is satisfied that the port is sufficiently functional and stable, he will make a general announcement to that effect. No promises have been made with respect to when a version suitable for general use may become available, nor is there any commitment to provide all the same functionality as is available from the VisualWorks version. Of course, nothing prevents others from contributing improvements/enhancements in addition to whatever Avi publishes (hint, hint.)

I am very appreciative of the contributution Avi is making towards porting Chronos to Squeak.

Fair warning: As of Mon, 27 Feb 2006 01:39:04 +0000 (Universal Time,) the version on SqueakMap will not work "as is" in versions of Squeak from 3.7 onward (you can load it, but if you execute the initialization/installation "do it" that the pop-up Transcript window suggests, you will then be unable to either save the image or compile any methods.) The problem is caused by the fact that the installation procedure (as implemented in the version currently available from SqueakMap) redefines both DateAndTime and Duration so that they are aliases for the Chronos classes Timepoint and ScientificDuration (respectively,) in place of the native Chronology classes named DateAndTime and Duration (and this issue is precisely why I chose not to use the names "DateAndTime" and "Duration" as class names.) This problem can be fixed if you install Chronos according to the following procedure:

  1. Download the Chronos Update for Squeak (based on Chronos Version B1.64).

  2. Extract the files Chronos-B1.64.1.cs and Chronos-Squeak.cs from the zip archive downloaded in step 1.
  3. File in both of the changeset (*.cs) files extracted in step 2 (this assumes you have already installed Chronos from the version on SqueakSource/SqueakMap.) The file Chronos-B1.64.1.cs contains all the platform-independent Chronos code, less some of the initialization/installation logic. The file Chronos-Squeak.cs contains deltas to the Squeak-specific code provided by Avi that substantially improve the functionality of Chronos on Squeak (but it does not enable accessing any time zones from the Chronos Time Zone Repository.)
  4. Evaluate the following expression in a workspace:

    Chronos
    at: #Duration put: ScientificDuration;
    at: #DateAndTime put: Timepoint.

    If this is not done, many of the code examples in the method comments won't work, because they expect DateAndTime and Duration to be references to Chronos.Timepoint and Chronos.ScientificDuration. Since all the Chronos classes have the global Chronos as a shared pool Dictionary, the above code makes the Browsers bind #DateAndTime and #Duration to their Chronos implementations when browsing a Chronos class. If you'd also like to achieve the same effect in any of your own classes, just add #Chronos and #ChronosConstants as pool Dictionaries.

  5. Now evaluate "ChronosEnvironment install." (But dont't do so until until the above steps have been completed.)

Avi is using Squeak 3.6 to do the porting work. The Chronology library did not become part of standard Squeak until version 3.7, and so there is no issue raised by (re)defining the globals DateAndTime and Duration as global aliases for Timepoint and ScientificDuration (respectively) in versions of Squeak prior to 3.7. That may well be why Avi is using Squeak 3.6 to do the port. (Squeak badly needs a mechanism to more elegantly handle issues such as this one.)

Note that the version currently available from SqueakMap has not been given the ability to access files--so it can't retrieve any time zones from the Chronos Time Zone Repository, and therefore Olson time zone keys such as 'Americal/Los_Angeles', 'Europe/Paris' and 'Asia/Tokyo' cannot be used to identify a time zone. Nor is there any code that makes any attempt to determine the local time zone from the host operating system, nor any code that provides any locale information.



Consequently, the Chronos system time zone simply defaults to Universal Time (which is what the native Chronology library does also, so at least you're no worse off than you were before.) Nevertheless, you can still do quite a bit. For example, after loading and properly initializing Chronos, you can evaluate the following expression to set the Chronos system time zone so that it matches the zone rules that have been in effect since 1996 for CET/CEST (Central European Time):

(ChronosTimezone
key: #'Europe/Berlin' name: #'Central European Time'
initialOffset: (ScientificDuration hours: 1) withAbbreviation: #CET
until: (WeekOfMonthDayOfWeek month: 3 week: 0 dayOfWeek: 1)
"The 'zeroeth week' means the last week of the month"
at: (TimeOfDay hour: 1 minute: 0 second: 0) relativity: #universal
thenOffset: (ScientificDuration hours: 2) withAbbreviation: #CEST
until: (WeekOfMonthDayOfWeek month: 10 week: 0 dayOfWeek: 1)
at: (TimeOfDay hour: 1 minute: 0 second: 0) relativity: #universal)
beSystem

Then, you can evaluate "Timepoint now" to see the current time. And if you find yourself in Madrid, Paris, Berlin or Amsterdam, the answer will even be correct. However, due to the fact that the Squeak system clock reports local time, setting the Chronos system time zone has no effect on what is displayed when "Timepoint now" is evaluated. It only changes the results of evaluating "Timepoint utNow." On a system whose clock reported Universal Time, the situation would be reversed.




No comments: