The Timing of Time

Alan Lovejoy squeak-dev.sourcery at forum-mail.net
Fri Apr 14 16:11:14 UTC 2006


Garau wrote:
"I succesfully loaded:
    1- Passport-Kernel
    2- Passport-Squeak
    3- Chronos-System-Squeak
    4- Chronos-System-Squeak-PostV3.6"

There's a file missing from your list: Chronos.st.  That needs to be filed
in third. Chronos.st defines ChronosEnvironment, among many other things.

"- Starting on the 31Mar2006 generate a schedule of payments every month
until 31Mar2007.
That should return 30Apr06 31May06 30Jun06 ... 28Feb07 31Mar07"

| schedule |
schedule := OrderedCollection new.
(Timeperiod from: (YearMonthDay year: 2006 month: 4 day: 1) duration:
(CalendarDuration years: 1 months: 0 days: 0))
	monthsDo: [:month | schedule add: month last].
schedule => OrderedCollection (2006-04-30 2006-05-31 2006-06-30 2006-07-31
2006-08-31 2006-09-30 2006-10-31 2006-11-30 2006-12-31 2007-01-31 2007-02-28
2007-03-31)

"- Adjust the previous schedule to the british and japanese calendar, making
sure all dates are 'good business days'. So, for example, if 30Apr06 falls
on Sunday or a british bank holiday, change it according to some rule.
Examples of such rules are:
next business day, next calendar day, etc.

It gets more complicated when you think about DCC (day count conventions).
In the first example we were dealing with actual months. But under the
30/360 DCC, every month has 30 days."

Chronos doesn't currently support the Japanese Imperial Calendar. I haven't
actually looked at that one, so I don't know how easy or hard it may be to
implement.  However, once implemented, adding new calendars to Chronos is
quite easy.

SemanticDatePolicy instances can be used to define holiday schedules using
any combination of supported calendars.  Extensible observance rules are
supported.  US Holidays (including all rule-based and
one-time-only-historical NYSE holidays) are predefined; others must be added
by the programmer.

So, modifying the first example to handle US banking holidays would look
like this:

| sdp holidays schedule dateSelector |
sdp := SemanticDatePolicy unitedStates.
holidays := SemanticDatePolicy usFederalHolidaySemanticKeys.
schedule := OrderedCollection new.
dateSelector :=
	[:date |
	date dayOfWeekKey == #Sunday
		ifTrue: [dateSelector value: (date addingDays: 1)]
		ifFalse:
			[(date annualDateSemanticKeyFrom: sdp satisfies:
[:semanticKey | holidays includes: semanticKey])
				ifTrue: [dateSelector value: (date
addingDays: 1)]
				ifFalse: [date]]].
(Timeperiod from: (YearMonthDay year: 2006 month: 4 day: 1) duration:
(CalendarDuration years: 1 months: 0 days: 0))
	monthsDo: [:month | schedule add: (dateSelector value: month last)].
schedule => OrderedCollection (2006-05-01 2006-05-31 2006-06-30 2006-07-31
2006-08-31 2006-09-30 2006-10-31 2006-11-30 2007-01-02 2007-01-31 2007-02-28
2007-03-31)

The 30/360 DCC is trivial to implement, using CalendarDurations and
Timeperiods.

"Dates can be seen from many different points of view. In a financial system
we are certainly not interested in the duration of a date. Not in
nanoseconds, not in milliseconds or even hours. A date is a business date."

The class Chronos YearMonthDay is implemented just that way, for just that
reason.

Thanks for your questions. I'll be adding the second example to the website.

--Alan

-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of
Francisco Garau
Sent: Friday, April 14, 2006 3:31 AM
To: The general-purpose Squeak developers list; Alan Lovejoy
Subject: Re: The Timing of Time

Hi Alan,

As yourself, I am also interested in date and times. I tried loading the
Chronos package following the instructions from your website [1], but
something went awry.

I succesfully loaded:
    1- Passport-Kernel
    2- Passport-Squeak
    3- Chronos-System-Squeak
    4- Chronos-System-Squeak-PostV3.6

The problem happens on step 3. The last two lines of that fileOut says:

    ChronosSqueakEnvironment initialize !
    ChronosEnvironment canonical install !

I guess that ChronosEnvironment should be a class and canonical a message.
But neither of them are in the image.

My interest on dates is more biased towards dates than towards times. Dates,
months, years and calendars are central objects in financial systems.
Amongst the many problems that arises in such systems, here a couple of
examples:

- Starting on the 31Mar2006 generate a schedule of payments every month
until 31Mar2007.
That should return 30Apr06 31May06 30Jun06 ... 28Feb07 31Mar07

- Adjust the previous schedule to the british and japanese calendar, making
sure all dates are 'good business days'. So, for example, if 30Apr06 falls
on Sunday or a british bank holiday, change it according to some rule.
Examples of such rules are:
next business day, next calendar day, etc.

It gets more complicated when you think about DCC (day count conventions).
In the first example we were dealing with actual months. But under the
30/360 DCC, every month has 30 days.

Dates can be seen from many different points of view. In a financial system
we are certainly not interested in the duration of a date. Not in
nanoseconds, not in milliseconds or even hours. A date is a business date.

I agree with the Mercap guys that dates, months and years are views of the
same time-line at different levels of granularity. In financial systems we
don't need to go further down that date. For other type of systems requiring
global syncronization, you probably need to go down to the millisecond
level. Furthermore, you need every time to be expressed as an offset from a
central location (Greenwich?).

That is my poor understanding of time-zones and the reason why I want to
play with the Chronos package.

Cheers,
Francisco

[1] http://chronos-st.org/frames/Squeak-Downloads.html
[2] http://article.gmane.org/gmane.comp.lang.smalltalk.squeak.general/100148






More information about the Squeak-dev mailing list