Time Arithmetic

The PITimeServer provides the AddIntervals method and the InputString property to do time arithmetic. AddIntervals is available for ITimeInterval, PITimeFormat, and DynamicTime objects. InputString is available for PITimeFormat and DynamicTime objects. Arithmetic with time may be done in UTC time or in local time depending on the interval chosen for addition or subtraction. Due to some regions using daylight savings time, calendars with leap years and interval members that vary in length (for example, month), arithmetic increments in local time may not change uniformly. Arithmetic in UTC time increases in uniform step sizes.

UTC arithmetic

UTC time as used in the PITimeServer increases monotonically. Thus, the term "UTC time" as used in the PITimeServer is actually TAI time (Temps Atomique International, or atomic clock time). True UTC time includes leap seconds. Leap seconds introduce variable interval durations for all intervals greater than seconds. For time arithmetic in the PITimeServer, adding or subtracting time in UTC units may be done by converting all intervals to seconds. For example, adding 24 hours is equivalent to adding 86400 seconds. Additionally, only UTC arithmetic is capable of fractional interval steps. Adding 1.5 hours is equivalent to adding 5400 seconds. Intervals such as year, month and local time days usually do not allow fractions. For example, adding a fraction of a month would require choosing between a month containing 28, 29, 30 or 31 days.

Local time arithmetic

Local time is also known as wall clock time. Daylight savings time may cause a discontinuity in time and is observed by many regions. This may cause intervals and durations to vary during the daylight savings changes. Depending on the desired result, calculations based on such durations may be done in UTC or local time by using the PITimeServer objects. The PITime, PITimeFormat and DynamicTime objects can provide UTC seconds for calculating durations or local date (in units of days).

Local time addition of days may cover 24 hours or, using US rules, sometimes 23 or 25 hours. If a local time calculation causes the resultant local time to fall within the spring standard to daylight transition, the time is illegal. Rather than return an error, the PITimeServer returns the time in the previous hour. Specifying a time or a time calculation that produces a local time in the ambiguous hour in the fall will result in using the current system's daylight or standard setting.

The addition of months to a given day may cause the day to be out of range for the next month. For instance, March 31 + 1 month would result in April 30 if the AddIntervals method is used. The assumption is that the end of the month is desired. Thus, if a sequence of times of the end of the month is desired, a start time of January 31 + # months should be used for each time in the sequence. A cumulative addition will result in January 31, February 28, March 28, etc. (unless it is a leap year, in which case the 29th of all months after january would result).  If the C run time library routines were used and the month was incremented for March 31, the result would be May 1.

Adding years will typically result in the same day of the resultant year. However, adding to the leap year day, Feb 29, will result in March 1.

Enabling Operational Intelligence