a new object-oriented model of the gregorian calender

23
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)

Upload: esug

Post on 15-Jul-2015

218 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: A new Object-Oriented Model of the Gregorian Calender

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)

Page 2: A new Object-Oriented Model of the Gregorian Calender

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

Page 3: A new Object-Oriented Model of the Gregorian Calender

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

Page 4: A new Object-Oriented Model of the Gregorian Calender

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

Page 5: A new Object-Oriented Model of the Gregorian Calender

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

Page 6: A new Object-Oriented Model of the Gregorian Calender

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

Page 7: A new Object-Oriented Model of the Gregorian Calender

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 Calender

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 Calender

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

Page 10: A new Object-Oriented Model of the Gregorian Calender

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

Page 11: A new Object-Oriented Model of the Gregorian Calender

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 Calender

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 Calender

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

Page 14: A new Object-Oriented Model of the Gregorian Calender

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

Page 15: A new Object-Oriented Model of the Gregorian Calender

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

Page 16: A new Object-Oriented Model of the Gregorian Calender

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

Page 17: A new Object-Oriented Model of the Gregorian Calender

Time Units

year

month

century decade week

day

minute hour

second millisec.

Base Units

Derived Units

n  Gregorian calendar irregularity

Page 18: A new Object-Oriented Model of the Gregorian Calender

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 Calender

Segments

01/01/2005

15 days

theEndOfTime theBeginningOfTime

-15 days

aTimespan

n  Absolute and Relative

Page 20: A new Object-Oriented Model of the Gregorian Calender

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 Calender

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.

Page 22: A new Object-Oriented Model of the Gregorian Calender

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

Page 23: A new Object-Oriented Model of the Gregorian Calender

Questions