The Timing of Time

Jeffrey J. Hallman m1jjh00 at frb.gov
Wed Apr 19 16:09:59 UTC 2006


I'm enjoying the discussion about calendars and times, but I'd like to
direct some attention to the idea of a TimeIndex.  I came at this from
another direction, thinking of a TimeSeries as data indexed by time,
which leads to the idea of a TimeIndex.  

In my current implementation, a TimeIndex has two instance variables: a
freq symbol (such as #weeklyMonday, #monthly, #hourly, etc.) and an
integer period, which represents the number of periods elapsed since the
base period for that freq. TimeIndex understands '+' and '-', so if 'z'
is the weeklyMonday time index for April 17 2006, then (z - 4) asYmd
yields 20060320, and so on. 

My TimeSeries class is a subclass of Matrix with an additional instance
variable called 'start' which is a TimeIndex, and has accessors like

TimeSeries>>atTimeIndex:
TimeSeries>>atTimeIndex:put: 
TimeSeries>>atTimeIndex:column:
TimeSeries>>atTimeIndex:column:put: 

I've found this scheme works pretty well, and will probably generalize
it a bit more by making TimeIndex an abstract class with subclasses for
different kinds of sequences. 

I think a package that wants to handle date and time issues should
have something like a TimeIndex in it that allows sequences of various
frequencies to be defined.  At the same time, the implementation should
be simple enough to be easily understood, and indexing into a TimeSeries
should be very fast.  If indexing isn't fast, we'll end up with ugly
code in every TimeSeries method that that converts TimeIndex'es to
row numbers and back.  Trust me, you really don't want that.

So how do these various packages handle indexing data by time?

A second issue is how to handle date arithmetic.  Some durations are
based on linear time (e.g., weeks, seconds, hours, etc.) and others are
based on the calendar (months, years, etc.).  The distinction between
these two leads to questions like: What should happen if you start at
January 28'th and advance by a month and then go back by a month?
Jan28 --> Feb28 --> (Jan 28 or Jan 31?)   Can we agree on some
conventions? 

Jeff Hallman



More information about the Squeak-dev mailing list