| Dates in Smalltalk MT
use the Windows date and time API. This means that dates and
times are correctly localized and time zone corrected. This
functionality is wrapped in the Time class so there is no Date
class.
Let go through the basics. There are two times in Windows,
system time and local time.
System time is expressed in UTC (Coordinated Universal Time).
Local time is the time for the localized system. For example
right now in a workspace:
Time getSystemTime
shows: 5:42:38 PM - 3/6/2005
Time getLocalTime
shows: 10:42:38 AM - 3/6/2005
This is because I am currently at UTC - 7 hours (I am in
Colorado).
UTC is used in several places in Smalltalk MT, for example
the timestamp in the change log is UTC. This allows change logs
to be correctly timed regardless of where and what system it was
created on. Otherwise imagine if I created a method in one time
zone and sent it to another time zone.
A windows date time structure (called a SYSTEMTIME) holds
year, month, day of week, day, hour, seconds, milliseconds.
Time zone information can be obtained by using
Time getTimeZoneInformation
If you inspect the result you will be looking at a
TIME_ZONE_INFORMATION structure.
To manipulate time, the easiest was is to first convert the
SYSTEMTIME to a FILETIME. The FILETIME structure is a 64-bit
value representing the number of 100-nanosecond intervals since
January 1, 1601 (UTC).
This means that 10000000 (1 with 7 zeros) represents 1 second
(since a nanosecond is 10^9, 100 nanoseconds is 10^7).
For example, to take the current local time and add 1 hour,
you would use the following (1 hour is = 1 hour * 60 minutes *
60 seconds * 10000000).
initialTime := Time getLocalTime.
fileTime := initialTime asFileTime.
fileTime := fileTime + (1*60*60*10000000).
newTime := Time fromFileTime: fileTime.
Inspect initialTime and newTime and they will be 1 hour
apart.
|