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:  
Showing posts with label TimePeriod. Show all posts
Showing posts with label TimePeriod. Show all posts

2007-01-22

Version B1.196 of the Chronos Date/Time Library Published

Chronos Version B1.196 has been published. Chronos B1.196 is available for VisualWorks, Squeak and Dolphin.

Chronos Version B1.196 can be obtained from the Chronos Web Site. The VisualWorks version can also be obtained from the Cincom Public StORE Repository, and the Squeak version can also be obtained from SqueakMap (as a .sar archive.) The Monticello-based version of B1.196 will be available on SqueakSource within a few days (the previous version, B1.190, is on SqueakSource now.)

NOTE: The SqueakMapPackageLoader tool does not work with the Chronos.sar archive, although Chronos.sar can be dowloaded to your local machine over HTTP and then installed using the Squeak FileList. (This problem has been reported, and a fix has been identified. See: [SM][BUG] Error: can't find EOCD position.)

You may also use the direct download link for VisualWorks, the direct download link for Squeak or the direct download link for Dolphin.

The Chronos Time Zone Repository is included in the download archive. Be sure to follow the Chronos Installation Instructions--especially if you have not already done so for a previous version of Chronos.

If you are reinstalling Chronos into an image in which an earlier version is already resident, and do not install the new version from the Cincom Public StORE Repository using StORE, it is necessary to first remove the earlier version. StORE has been able to correctly install the new version on top of every earlier version I have tried--but I haven't tried them all.

About Chronos Version B1.196



The following enhancements (or fixes) were made:

1. Enhanced both parsing and printing of Timeperiods, Timepoints and YearMonthDay values:

a) Full support was added for parsing ISO 8601 truncated date/time representations. Truncated date/time values are parsed into instances of Timeperiod. For example, "2007" is parsed into a Timeperiod with a duration of 1 year whose starting value is the YearMonthDay value for 2007-01-01.

b) The print behavior of Timeperiods was changed so that when the Timeperiod's starting value is at the start of a time unit (e.g, start of year, start of month, start of day, start of hour, start of minute, start of second,) and the extent of the Timeperiod's duration corresponds to that time unit, the Timeperiod is printed truncated to that unit, and no "/duration" is appended. This means that both the parsing and printing of date/time values conform to the behavior and semantics required by ISO 8601. For example, the printString for "Timeperiod from: YearMonthDay today duration: CalendarDayDuration" would be "2007-01-22" (if that is today's date.)

c) Since a YearMonthDay can't be bound to a time zone, support for date-valued points-in-time that are bound to a time zone was added by simply using a Timeperiod whose starting value is a Timepoint bound to the time zone, and whose duration is 1 day. So "YearMonthDay today >> (Timezone at: ''Pacific/Honolulu'')" now results in a Timeperiod with a duration of 1 day whose staring value is a Timepoint representing the initial moment of today, bound to the 'Pacific/Honolulu' time zone. The printString would be "2007-01-22-10:00" (if today's date were 2007-01-22.)

2. Added the following convenience methods to Timeperiod class (instance creation methods):

Timeperiod class>>nowIn:as:duration:
Timeperiod class>>nowIn:duration:
Timeperiod class>>nowWithDuration:

3. Changed the semantics of both Timeperiod class>>todayIn:as: and Timeperiod class>>todayIn:, so that the start value of the answered Timeperiod will now be a Timepoint bound to the specified time zone, and not a YearMonthDay (which cannot be bound to a time zone,) UNLESS the specified time zone is "ChronosTimezone nominal," in which case a YearMonthDay will be used as the starting value (as would have been the case all the time, previously.)

4. Fixed problem loading a new version of Chronos using StORE that only is an issue when a previous version of Chronos is already in the image. Not relevant otherwise (loading into a clean image worked as expected when installing versions prior to B1.196.)

5. Fixed bug in ChronosPrintPolicy class>>newANSIStandard, which in some cases would not answer an instance of ChronosPrintPolicy itself, but instead answer an instance of some subclass. Fixed it so that it always answers an instance of ChronosPrintPolicy itself, even when invoked as "self newANSIStandard" in a subclass.


2007-01-15

Chronos 101: Intervals of Time

This is the third article in a series of articles that conceptually discuss the Chronos model of time. The first one, Chronos 101: "Points" in Time, explains the way Chronos models "points" in time. The second one, Chronos 101: Durational Values, explains the way Chronos models durations of time.

Time Intervals in Chronos



An interval of time has a beginning, and end, and a duration. Unlike a duration, a time interval has a specific location on the timeline: It starts at a specific moment, and it ends at a specific moment.

The duration of a time interval is the amount of elapsed time from the beginning of the interval up to its end. For example, the first quarter of 2007 is a 3-month time interval starting at the first moment of January 1, 2007 and ending as of the last moment of March 31, 2007. The temporal extent (size, length, duration) of the interval is 3 months. The interval begins as of the first moment of January 1, 2007, and ends as of the last moment of March 31, 2007.

Mathematical Analogy



As used in mathematics, an interval is an ordered set of values on a number line, all of which are greater than one value but less than another. Ignoring advanced mathematics and/or degenerate cases, there are four types of interval:
  • Closed: A closed interval contains both its endpoints, one of which is the starting point and the other the ending point. Example: All the numbers between 3 and 4, including both 3 and 4. More formally: [3, 4] is the set of all x such that 3 <= x <= 4.

  • Open: An open interval contains neither its leftmost (starting) point nor its rightmost (ending) point. Example: All the numbers between 3 and 4, including neither 3 nor 4. More formally: (3, 4) is the set of all x such that 3 < x < 4.

  • Left-closed, right-open: A left-closed, right-open interval contains its leftmost (starting) point, but does not contain its rightmost (ending) point. Example: All the numbers between 3 and 4, including 3 but not including 4. More formally: [3, 4) is the set of all x such that 3 <= x < 4.

  • Left-open, right-closed: A left-open, right-closed interval does not contain its leftmost (starting) point, but does contain its rightmost (ending) point. Example: All the numbers between 3 and 4, excluding 3 but including 4. More formally: (3, 4] is the set of all x such that 3 < x <= 4.


Time intervals in Chronos are always left-closed, right-open intervals. A Chronos interval contains its starting/leftmost point in time, but does not contain its ending/rightmost point in time. In Chronos, a time interval of three months duration that starts as of the first moment of January contains every moment of January 1, and contains every moment of March 31, but does not contain any moments of April 1--not even the very first moment.

Time Intervals with Negative Durations



However, a Chronos time interval may have a negative duration. Example: The interval starting on the initial moment of 2007 and extending backwards in time one calendar year (more formally, the set of moments in time such that, for all x that are members of the set, 2006-01-01T00:00:00 < x <= 2007-01-01T00:00:00.) In the case of Chronos time intervals whose duration is negative, the starting moment occurs temporally later than the ending moment, because a negative duration involves traveling backwards in time. In other words, Chronos time intervals have temporal directionality (forwards or backwards.) Why? Because an algorithm might traverse the timeline either forwards or backwards, even though physical objects can only traverse the timeline in the forward direction. This behavior for Chronos time intervals was chosen so that the semantics of a Chronos time interval depends only on the interval itself, with the effect that algorithms that use a Chronos interval can be independent of whether the interval's directionality is forwards or backwards.

So Chronos intervals with positive duration are "earliest-endpoint-closed, latest-endpoint-open" intervals, but Chronos intervals with negative duration are "earliest-endpoint-open, latest-endpoint-closed" intervals. Consequently, Chronos time intervals preserve the invariant that the starting endpoint (from the perspective of the direction in which the timeline is being traversed) are always included in the interval, but the last endpoint (from the perspective of the direction in which the timeline is being traversed) are never included in the interval. Also, from the perspective of real-world objects that traverse the timeline going forward, this means that earliest-open, latest-closed intervals can be represented by simply making the duration negative (and specifying the temporally-latest point-in-time, instead of the temporally-first point-in-time, as the interval's starting/left-most endpoint.)

It should also be noted that ISO 86O1 does not allow time intervals with negative durations (so "2007-01-01T00:00:00/P-1Y" is not legal ISO 86O1--although Chronos supports it anyway.) But ISO 86O1 does allow the first element of a time interval to be a duration. For example, P1Y/2007-01-01T00:00:00 is a legal IS0 86O1 designation of a time interval, where the starting/rightmost moment is computed by subtracting the duration from the rightmost/ending moment. So P1Y/2007-01-01T00:00:00 designates the time interval containing all moments of the year 2006, but not containing any moments of any other year (more formally, P1Y/2007-01-01T00:00:00 specifies the set of moments in time such that, for all x that are members of the set, 2006-01-01T00:00:00 <= x < 2007-01-01T00:00:00.)

Points-in-Time as Special-Case Time Intervals



Even the Chronos "point-in-time" values (instances of YearMonthDay, Timepoint or InfiniteTimepoint) are implemented as time intervals in Chronos. However, the duration of YearMonthDay, Timepoint and InfiniteTimepoint instances is static, is the same for all instances, and no instance variable is used to specify the duration of a YearMonthDay, Timepoint or InfiniteTimepoint (as discussed in the first essay of this series, Chronos 101: "Points" in Time.)

The duration of a YearMonthDay is one calendar day. The duration of a Timepoint is one nanosecond. The duration of an InfiniteTimepoint is "InfiniteDuration positive."

Time Intervals: The General Case



The Chronos class Timeperiod implements time intervals that can have any duration representable using any of the Chronos durational classes (ScientificDuration, CalendarDuration, CivilDuration, InfiniteDuration--as discussed in the essay Chronos 101: Durational Values.)

Timeperiod is not an abstract class, and has no subclasses. By unifying "points-in-time" with time intervals, by delegating as much responsibility as possible to the Chronos durational values, and by leveraging Smalltalk's dynamic typing, a Timeperiod instance can be composed of any combination of one Chronos "point-in-time" value and one Chronos durational value. So there is no need for time-interval classes such as Year, Month or Week, as can be found in Squeak's Chronology date/time library.