[squeak-dev] [ANN] Chalten 2.0

Maximiliano Taborda mtaborda at gmail.com
Tue Aug 26 20:20:25 UTC 2008


Hi.

We uploaded to SqueakSource (for Squeak) and to the Cincom Public
Repository (for Visualworks) a new release of the project called
"Chalten" (2.0) that is our implementation of the Time Domain (not
only of the Gregorian Calendar now).

This model was born as a representation of the Gregorian Calendar,
and, in this last version, the model support the Gregorian, Julian,
Islamic an Hebrew Calendars.
Many refactorings was done from the original model to get this last
version wich reifyes many concepts of the Time Domain that
Smalltalk-80 does not; for example: day, day of month, month of year,
month, year, calendars, time zones, filters over the timeline, etc..

The main objective of this model is to easily, and in a "SDL way",
solve problems of the Time Domain that are not easy (or impossible) to
do with the Smalltalk-80 abstractions.
t provides also some concepts that are useful for financial
application, among others, like relative dates and time line filters.

This model also uses the units models (Aconcagua). Because it uses the
units model, there are some concepts that are not useful anymore, like
Duration, because a Duration is a Measure of time.
The model covers many concepts of the Time Domain, but lacks of some
abstractions; for example, the representation of the leap second.

It comes with more than 1600 tests (all green).

Here are some examples:

"Create some time entities"
       August twentieth, 2008          -->     Creates an instance of
the gregorian Date for 20/08/2008
       August twentieth                -->     Creates an instance of
the gregorian DayOfMonth for 20/08
       August, 2008                    -->     Creates an instance of
the gregorian MonthOfYear for August of 2008

"But, not only gregorian entities"
       Shaban seventeenth, 1429        -->     Creates an instance of
the islamic Date for 17/08/1429
       Shaban seventeenth              -->     Creates an instance of
the islamic DayOfMonth for 17/08
       Shaban, 1429                    -->     Creates an instance of
the islamic MonthOfYear for Shaban of 1429

       JulianAugust seventh, 2008      -->     Creates an instance of
the julian Date for 07/08/2008
       JulianAugust seventh            -->     Creates an instance of
the julian DayOfMonth for 07/08
       JulianAugust, 2008              -->     Creates an instance of
the julian MonthOfYear for August of 2008

       Av nineteenth, 5768             -->     Creates an instance of
the hebrew Date for 19/05/2008
       Av nineteenth                   -->     Creates an instance of
the hebrew DayOfMonth for 19/05
       Av, 5768                        -->     Creates an instance of
the hebrew MonthOfYear for Av of 5768

"Converting dates between diferents calendars"
       (August twentieth, 2008) asIslamic      -->     Return Sha'ban 17, 1429
       (August twentieth, 2008) asHebrew       -->     Return Av 19, 5768
       (August twentieth, 2008) asJulian       -->     August 7, 2008 (julian)

       (Shaban seventeenth, 1429) asHebrew     -->     Return Av 19, 5768
       (JulianAugust seventh, 2008) asIslamic  -->     Return Sha'ban 17, 1429
       (Av nineteenth, 5768) asGregorian       -->     August 20, 2008
(gregorian)

"Measuring distances"
       August twentieth, 2008 distanceTo: December thirtieth, 2008
-->     Return an instance of Measure <132 days>
       Shaban seventeenth, 1429 distanceTo: Muharram second, 1430
-->     Return an instance of Measure <132 days>
       Av nineteenth, 5768 distanceTo: Tevet third, 5769
-->     Return an instance of Measure <132 days>

"Also, measuring distance expressed in diferents way (calendars)"
       August twentieth, 2008 distanceTo: Tevet third, 5769
-->     Return an instance of Measure <132 days>
       Shaban seventeenth, 1429 distanceTo: December thirtieth, 2008
 -->     Return an instance of Measure <132 days>
       Av nineteenth, 5768 distanceTo: Muharram second, 1430
-->     Return an instance of Measure <132 days>

"Collect some entities"
	(ChaltenYear number: 2008 calendar: GregorianCalendar) months
		collect: [:monthOfYear | monthOfYear lastDate]  -->     Returns all
the last dates of the 2008 months.
	(ChaltenYear number: 2008 calendar: GregorianCalendar) dates select:
		[:date | date is: Monday]       -->     Returns all Mondays of 2008
	(ChaltenYear number: 5768 calendar: HebrewCalendar) dates select:
		[:date | date is: YomShabbat]   -->     Returns all yom shabbats of 5768

"Let's create a filter for all dates..."
       nonWorkingDays := TimeLineFilter named: 'Non Working Days'

"Now, we want Saturdays to be on that filter"
       nonWorkingDays addDayRule: Saturday

"Now we want Sundays from January 1st of year 1000 to the end of time..."
       nonWorkingDays
               addRule: (nonWorkingDays dayRule: Sunday)
               from: (January first, 1000)
               to: TheEndOfTime

"Now we want all July 9th since 1816 because is the Independence Day
in Argentina".
       nonWorkingDays
               addRule: (nonWorkingDays dayOfMonthRule: July ninth)
               from: (July ninth, 1816)
               to: TheEndOfTime

"Testing some dates..."
       nonWorkingDays includes: (July ninth, 2008)     -->     Returns true
       nonWorkingDays includes: (July eighth, 2008)    -->     Returns false
       nonWorkingDays includes: (July twelfth, 2008)   -->     Returns
true, it is Saturday

"But, how about to filter some like the hebrew new year day"
       nonWorkingDays addDayOfMonthRule: Tishri first
       nonWorkingDays includes: (Tishri first, 5769)           -->
Return true, it is the next hebrew new year
       nonWorkingDays includes: (September thirtieth, 2008)    -->
Return true, it is the next hebrew new year (in gregorian)

"21/08/2008 is a Thursday"
       timespan := TimeSpan from: (August twentyfirst, 2008) duration:
(48 * TimeUnits hour)
       settleDate := RelativeDate timespan: timespan using:
nonWorkingDays negated

       nonWorkingDays includes: (August twentyfifth, 2008)     -->
Returns false because 25/08/2008, a Monday, is a working day
       settleDate absoluteDate                                 -->
Returns 25/08/2008

"Now a new non working day is added to the filter"
       nonWorkingDays addDateRule: (August twentyfifth, 2008)

       nonWorkingDays includes: (August twentyfifth, 2008)	-->     Return true.
"Now 25/08/2008, is a not working day"
	settleDate absoluteDate					-->     Now it returns 26/08/2008 because
the filter has changed

"Working with time zones"
       buenosAiresDateTime := TimeZonedDateTime
               dateTime: (DateTime
                       date: August twentieth, 2008
                       timeOfDay: (TimeOfDay hours: 19 minutes: 35))
               zone: TimeZones buenosAires

       greenwichDateTime := TimeZonedDateTime
               dateTime: (DateTime
                       date: August twentieth, 2008
                       timeOfDay: (TimeOfDay hours: 22 minutes: 35))
               zone: TimeZones greenwich

       buenosAiresDateTime = greenwichDateTime			-->     Return true,
it is the same instant but measure in diferent zone
       buenosAiresDateTime distanceTo: greenwichDateTime	-->
Return a measure <0 days>, because it is the same instant

       buenosAiresDateTime  := buenosAiresDateTime next: (TimeUnits hour * 3)

       buenosAiresDateTime = greenwichDateTime			-->     Return false,
the hour is the same but the zone is different
       (buenosAiresDateTime distanceTo: greenwichDateTime)
		convertTo: TimeUnits hour  			-->     Return a measure <-3 hours>,
just the offset between zones



Regards.-
Maximiliano



More information about the Squeak-dev mailing list