![Page 1: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/1.jpg)
A New Object-Oriented Model of the Gregorian
Calendar
Hernán Wilkinson* Mercap Development Manager
Tacuarí 202, 7mo Piso C1071AAF, Buenos Aires, Argentina
54-11-4878-1118 (ext. 120)
Máximo Prieto** Lifia – Facultad de Informática
Universidad Nacional de La Plata cc11, 1900, La Plata, Argentina
+54 221 422-8252 (ext. 215)
Luciano Romeo Mercap Software Architect
Tacuarí 202, 7mo Piso C1071AAF, Buenos Aires, Argentina
54-11-4878-1118
* Also Universidad de Buenos Aires, UBA, Argentina ** Also Universidad Nacional de la Patagonia Austral, Unidad Académica Caleta Olivia (UNPA-UACO)
![Page 2: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/2.jpg)
Problem Presentation
Time Domain is pervasive Cross Cutting Related with Financial Domain Related with almost every Domain…
We concentrated our work on the Gregorian Calendar
![Page 3: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/3.jpg)
Gregorian Calendar Main Design Challenges
Irregularity Months have 28,29, 30 or 31 days Leap years Associated with natural events (i.e. day/nigth, seasons, earth
movement, etc.) Comparing
January < July January first < February twentyninth 3 months < 1 year or 5 days < 1 week
Distance (January distanceTo: July) = (January, 2005 distanceTo: July,
2005) Time line filtering
workingDays includes: (January first, 2005) workingDays from: (April first, 2005) to: (April thirty, 2005) 14 days from: (April first, 2005) counting: workingDays
![Page 4: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/4.jpg)
Current Models’ Limitations
Lack of abstractions Smalltalk-80: #Monday < #Friday (It returns false)
Abstractions not matching reality Squeak: Date dates (There are no days in a date time…)
Some models have one, or a few, general purpose abstractions
aCalendar.set ( Calendar.MONTH, 1) (Does this mean January?) Calendar.getInstance () (Are calendar a singleton?)
These problems show lack of understanding, they provide a poor domain language, therefore:
It is difficult to express common situations with them They are difficult to learn They offer different possible interpretations
These problems imply: Ad-hoc implementations Code duplication Error prone situations
![Page 5: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/5.jpg)
Matching RealityRRMM
April first
01/01/2005
April 2005
01/01/2005
?
?Smalltalk-80
RRMM
April first
01/01/2005
April 2005
Java / .Net
aCalendar
RRMM
01/01/2005
April 2005
01/01/2005
Squeak
April 2005
RRMM
April first
01/01/2005
April 2005
01/01/2005
The Best Solution
April first
April 2005
![Page 6: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/6.jpg)
Our Metaphor
Year2005
Year2007
Year2003Year Granularity
Jan. 2005
Dec.2005
Zoom in
July 2005
Month of Year Granularity
15/07/05
00:00:0015/07/0523:59:59
Zoom in
15/07/05
12:00:00Date Time Granularity
01/07/05 31/07/05
Zoom in
Date Granularity 15/07/05
![Page 7: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/7.jpg)
Main Abstraction
+< aMagnitude(A)
Magnitude
+to:aMagnitude+to:aMagnitude by: aMeasurement+...
IntervalAwareMagnitude
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTimeprevious: aMeasurement ^self next: aMeasurement negated
distanceFrom: aPointInTime ^aPointInTime distanceTo: self
![Page 8: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/8.jpg)
Year Granularity
+numberOfDays+numberOfDaysInFebruary(A)+isLeap (A)+number+...
GregorianYear
+numberOfDays+numberOfDaysInFebruary+isLeap+...
GregorianLeapYear
+numberOfDays+numberOfDaysInFebruary+isLeap+...
GregorianNonLeapYearnumberOfDaysInFebruary ^28 days
isLeap ^false
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime
The programmer should not careabout this implementation desicion
numberOfDays ^366 days
GregorianYear number: 2005.
Y2005
GregorianYear number: 2004.
Y2004
![Page 9: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/9.jpg)
Month of Year Granularity
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime
+month+year+next:aMeasurement+distanceTo:aGregorianMonthOfYear+< aGregorianMonthOfYear+...
GregorianMonthOfYear
y2005 april April, 2005 April of: 2005
April2005
AprilY2005
![Page 10: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/10.jpg)
Date Granularity
+year+monthOfYear+day+distanceTo: aGregorianDate+< aGregorianDate+...
GregorianDateBehavior
+next:aMeasurement+...
GregorianDate
+calendar-timespan+absoluteDate+next:aMeasurement+...
RelativeGregorianDate
absoluteDate ^calendar next: timespan
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime
April first, 2005
01/04/2005
1April2005
![Page 11: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/11.jpg)
Date Granularity
+year+monthOfYear+day+distanceTo: aGregorianDate+< aGregorianDate+...
GregorianDateBehavior
+next:aMeasurement+...
GregorianDate
+calendar-timespan+absoluteDate+next:aMeasurement+...
RelativeGregorianDate
absoluteDate ^calendar next: timespan
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime 14 days from: (April first, 2005) counting: workingDays
aRelDate
workingDays
01/04/2005
aTimespan
14 days
![Page 12: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/12.jpg)
Date Time Granularity
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime
+date+time+...
GregorianDateTime
(April first, 2005) atNoon
01/04/2005 12:00:00
aDateTime
![Page 13: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/13.jpg)
Recurrent Time Entities
Month
+name(A)+numberOfDaysIn: aGregorianYear (A)+...
GregorianMonth
+numberOfDaysIn: aGregorianYear+numberOfDaysFromJanuaryFirst+...
JanuaryGregorianMonth
+numberOfDaysIn:aGregorianYear+numberOfDaysFromJanuaryFirst+...
FebruaryGregorianMonth
+numberOfDaysIn:aGregorianYear+numberOfDayFromJanuaryFirst+...
NonSpecificGregorianMonth
numberOfDayFromJanuaryFirst ^self zeroDays
numberOfDayIn: aGregorianYear ^aGregorianYear numberOfDaysInFebruary
+previous: aMeasurement+next: aMeasurement (A)+distanceTo: aPointInTime (A)+distanceFrom: aPointInTime
PointInTime
Programmer should not care aboutthis implementation decision
FebruaryJanuary April
![Page 14: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/14.jpg)
Recurrent Time Entities Day of Month
January first December twentyFifth
Day of Week Monday Tuesday
Time of Day TimeOfDay noon TimeOfDay hours: 10 minutes: 11
![Page 15: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/15.jpg)
Time measurements and Their Relevance
+name
BaseUnit
+name+baseUnit
DerivedUnit
-sameDomainAs:aUnit
UnitBehavior
January distanceTo: February January, 2005 distanceTo: February, 2005
(GregorianYear number: 2000) distanceTo: (GregorianYear number: 2005)
1 month
5 years year
month
1
5
+amount+unit++ aMeasurement+- aMeasurement+* aMeasurment+/ aMeasurement
Measurement
![Page 16: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/16.jpg)
Measurements Generic Model Will be presented at OOPSLA 2005 Examples:
1 year + 6 months 18 months 3 months + 5 days 3 months + 5 days (A
“Bag”) 5 days + 3 weeks 26 days 1 day + 1 hour 25 hours 0.10 / 1 year Yearly Interest Rate of 10 % 40 km / 1 hour Speed 40 km / 1 hour * 2 hours 80 km
![Page 17: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/17.jpg)
Time Units
year
month
centurydecade week
day
minutehour
second millisec.
Base Units
Derived Units
Gregorian calendar irregularity
![Page 18: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/18.jpg)
Intervals
anInterval
Jan2005
January, 2005 to: November, 2006 by: 2 months
Nov2006
2 month
Collection
SequenceableCollection
+from+to+size+...
MeasurementIntervalInterval
![Page 19: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/19.jpg)
Segments
01/01/2005
15 days
theEndOfTimetheBeginningOfTime
-15 days
aTimespan
Absolute and Relative
![Page 20: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/20.jpg)
Time Line Filtering
Object
+from+duration+to+...
Timespan
+setDefinedByRules+includes: aTimepoint (A)+between:and:+negated (A)
TimelineViewBehavior
+includes:anObject+negated
TimelineView
+includes:anObject+negated
NegatedTinelineView
14 days from: (April first, 2005) counting: workingDays
aRelDate
workingDays
01/04/2005
aTimespan
14 days
nonWorkDys
![Page 21: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/21.jpg)
Conclusions Object model of the Gregorian calendar Metaphor: Different resolution points of the time line
Total order between time points Distance Move from one point to another Move between points of different resolution
Representation of time line segments and intervals Generic Measurement Model to reify Time
Measurements Time line filtering allows Relative points in time Abstractions for time entities such as a day, a day of
a month and months.
![Page 22: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/22.jpg)
Future Work
Time zone support Expand Timespan protocol New abstractions like Hour, Minute,
etc. (not units) Reify time lines Allow relative points of any granularity
![Page 23: A New Object-Oriented Model of the Gregorian Calendar](https://reader036.vdocument.in/reader036/viewer/2022062517/56649f335503460f94c4f366/html5/thumbnails/23.jpg)
Questions