Note: This is a work in progress, but will give insight into how I am thinking about this.
The timelanguage code supports a set of operations and transformations that are logical outgrowths of this model of time. The simple notation below indicates a derivation with an arrow, and any necessary parameter for the operation as a word in the middle of the arrow, so
CalendarDate ---zone---> TimeInterval
means "A TimeInterval can be derived from a CalendarDate given a zone (TimeZone)."
This "algebra" is slightly different than assigning responsibilities to classes. The goal here is to have a consistent system of logical statements and computations that are expressive and convenient. Although responsibility for each computation will be assigned to some object, that may not be the receiver. To make the language more fluid, and to make a more complete algebra, many "convenience" methods will be added, which simply delegate some computation to the class that does have responsibility.
For example, TimeInterval class is responsible for creating TimeIntervals, but TimePoint has an operation "until" that delegates to TimeInterval. This is to support an expression of an interval like
fiveOClock.until(tenOClock)
which should be the same as
TimeInterval.over(fiveOClock, tenOClock)
Note: all transformations between Time and Calendar also have the implicit argument of a calendar, but the GregorianCalendar is the (currently hard-coded) default. No such default seems prudent for TimeZone (zone), so it is always required.
Calendar Date ---zone-----> TimeInterval
CalendarInterval ---zone----> TimeInterval
TimePoint ---zone---> CalendarDate
TimePoint <---zone & format---> String representation
The following conversions are not possible:
CalendarDate ---X--- TimePoint
Duration of months (calendar) ---X--- Duration of milliseconds (time)
Calendar Duration (Months) --- TimePoint of either endpoint---> TimeInterval
TimeInterval and CalendarInterval are both derived from ComparableInterval, which could be used for any set of objects which implement Comparable interface. Any such extention of ComparableInterval supports the following operations.
interval includes element ---> boolean
interval intersects interval ---> boolean
interval intersection interval ---> interval
Some of the theoretical considerations of intervals are discussed here.
Note: TimeInterval creation methods default to half open, [a, b), which is typical of most time applications. This can be overriden by explicitly specifying the inclusion of the end points.
Note: Some of these operations are not available in the current version.
TimePoint + Duration ---> TimePoint
TimePoint until Duration ---> TimeInterval
TimePoint until TimePoint ---> TimeInterval
TimeInterval start ---> TimePoint
TimeInterval end ---> TimePoint
TimeInterval length ---> Duration
Duration + Duration ---> Duration
Duration - Duration ---> Duration
TimeInterval iterate Duration ---> sub TimeIntervals (count or iterate)
TimeInterval appended by Duration ---> TimeInterval
TimeInterval prepended by Duration ---> TimeInterval
Calendar Date until Calendar Date ---> Date Interval
Calendar Date until Calendar Duration ---calendar---> Date Interval
Calendar Duration from Calendar Date ---calendar---> Date Interval
*TimePoint until Calendar Duration ---calendar---> Time Interval (*mapping Calendar/Physical)
Calendar Date + Calendar Duration (Months) ---calendar---> Calendar Date
Calendar Interval length---> Calendar Duration
Calendar Duration + Calendar Duration ---> Calendar Duration
DateInterval ---CalendarDuration---> sub DateIntervals (count or iterate)
Business Calendar is a Time Line of non-overlapping Intervals, either DateIntervals or TimeIntervals.
DateInterval --bus calendar---> Duration
CalendarDate until CalendarDuration ---bus calendar---> Duration
????
Weeks, Days, Hours, Minutes, Seconds, Milliseconds
Duration ---physical units---> Representation
Months, Quarters, Years
Calendar Duration ---calendar units---> Representation