Upload
esug
View
217
Download
3
Embed Size (px)
Citation preview
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) [email protected]
Máximo Prieto** Lifia œ Facultad de Informática
Universidad Nacional de La Plata cc11, 1900, La Plata, Argentina
+54 221 422-8252 (ext. 215) [email protected]
Luciano Romeo Mercap Software Architect
Tacuarí 202, 7mo Piso C1071AAF, Buenos Aires, Argentina
54-11-4878-1118 [email protected]
* Also Universidad de Buenos Aires, UBA, Argentina ** Also Universidad Nacional de la Patagonia Austral, Unidad Académica Caleta Olivia (UNPA-UACO)
Problem Presentation
n Time Domain is pervasive n Cross Cutting n Related with Financial Domain n Related with almost every Domain…
n We concentrated our work on the Gregorian Calendar
Gregorian Calendar n Main Design Challenges
n Irregularity n Months have 28,29, 30 or 31 days n Leap years n Associated with natural events (i.e. day/nigth, seasons, earth
movement, etc.) n Comparing
n January < July n January first < February twentyninth n 3 months < 1 year or 5 days < 1 week
n Distance n (January distanceTo: July) = (January, 2005 distanceTo: July, 2005)
n Time line filtering n workingDays includes: (January first, 2005) n workingDays from: (April first, 2005) to: (April thirty, 2005) n 14 days from: (April first, 2005) counting: workingDays
Current Models’ Limitations n Lack of abstractions
n Smalltalk-80: #Monday < #Friday (It returns false) n Abstractions not matching reality
n Squeak: Date dates (There are no days in a date time…) n Some models have one, or a few, general purpose abstractions
n aCalendar.set ( Calendar.MONTH, 1) (Does this mean January?) n Calendar.getInstance () (Are calendar a singleton?)
n These problems show lack of understanding, they provide a poor domain language, therefore: n It is difficult to express common situations with them n They are difficult to learn n They offer different possible interpretations
n These problems imply: n Ad-hoc implementations n Code duplication n Error prone situations
Matching Reality R M
April first
01/01/2005
April 2005
01/01/2005
?
? Smalltalk-80
R M
April first
01/01/2005
April 2005
Java / .Net
aCalendar
R M
01/01/2005
April 2005
01/01/2005
Squeak
April 2005
R M
April first
01/01/2005
April 2005
01/01/2005
The Best Solution
April first
April 2005
Our Metaphor
Year 2005
Year 2007
Year 2003 Year Granularity
Jan. 2005 Dec.
2005
Zoom in
July 2005 Month of Year
Granularity
15/07/05 00:00:00
15/07/05 23:59:59
Zoom in
15/07/05 12:00:00 Date Time
Granularity
01/07/05 31/07/05
Zoom in
Date Granularity 15/07/05
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
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
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
April Y2005
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
1 April2005
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
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
Recurrent Time Entities
n 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
February January April
Recurrent Time Entities
n Day of Month n January first n December twentyFifth
n Day of Week n Monday n Tuesday
n Time of Day n TimeOfDay noon n TimeOfDay hours: 10 minutes: 11
Time measurements and Their Relevance
+nameBaseUnit
+name+baseUnit
DerivedUnit
-sameDomainAs:aUnitUnitBehavior
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
Measurements
n Generic Model n Will be presented at OOPSLA 2005 n Examples:
n 1 year + 6 months à 18 months n 3 months + 5 days à 3 months + 5 days (A “Bag”) n 5 days + 3 weeks à 26 days n 1 day + 1 hour à 25 hours n 0.10 / 1 year à Yearly Interest Rate of 10 % n 40 km / 1 hour à Speed n 40 km / 1 hour * 2 hours à 80 km
Time Units
year
month
century decade week
day
minute hour
second millisec.
Base Units
Derived Units
n Gregorian calendar irregularity
Intervals
anInterval
Jan2005
January, 2005 to: November, 2006 by: 2 months
Nov2006
2 month
Collection
SequenceableCollection
+from+to+size+...
MeasurementIntervalInterval
Segments
01/01/2005
15 days
theEndOfTime theBeginningOfTime
-15 days
aTimespan
n Absolute and Relative
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
Conclusions n Object model of the Gregorian calendar n Metaphor: Different resolution points of the time line
n Total order between time points n Distance n Move from one point to another n Move between points of different resolution
n Representation of time line segments and intervals n Generic Measurement Model to reify Time Measurements n Time line filtering allows Relative points in time n Abstractions for time entities such as a day, a day of a
month and months.
Future Work
n Time zone support n Expand Timespan protocol n New abstractions like Hour, Minute, etc.
(not units) n Reify time lines n Allow relative points of any granularity
Questions