6.1.2 Methods for adding a time of day to a time offset
These methods implement addition between a time offset and a time of day:
// Method on <time-offset>, <time-of-day>
define method \+
(offset :: <time-offset>, time-of-day :: <time-of-day>)
=> (sum :: <time-of-day>)
make(<time-of-day>,
total-seconds: offset.total-seconds + time-of-day.total-seconds);
end method \+;
The method on <time-offset>, <time-of-day> is invoked when the first argument is a time offset and the second argument is a time of day. It does the work of creating a new <time-of-day> instance with the total-seconds slot initialized to the sum of the total-seconds slots of the two arguments.
// Method on <time-of-day>, <time-offset>
define method \+
(time-of-day :: <time-of-day>, offset :: <time-offset>)
=> (sum :: <time-of-day>)
offset + time-of-day;
end method \+;
The method on <time-of-day>, <time-offset> is invoked when the first argument is a time of day and the second argument is a time offset. It simply calls + with the order of the arguments switched — this call invokes the method on <time-offset>, <time-of-day>.
To test these methods, we can use one of the time offsets created in Section 6.1.1, and define the *8-30-59* variable, which contains a <time-of-day> instance, which we define as follows:
define variable *8-30-59* = make(<time-of-day>, total-seconds: encode-total-seconds(8, 30, 59));
We add the time offset and the time of day:
? decode-total-seconds(*minus-2-hours* + *8-30-59*); 6 30 59
We add the time of day and the time offset:
? decode-total-seconds(*8-30-59* + *minus-2-hours*); 6 30 59




