indexing
description: "Durations of time"
status: "See notice at end of class"
date: "$Date$"
revision: "$Revision$"
access: time
class interface
TIME_DURATION
create
make (h, m, s: INTEGER)
hourminutesecondhms
ensure
hour_set: hour = h
minute_set: minute = m
second_set: second = s
make_fine (h, m: INTEGER; s: DOUBLE)
minutesecondhm
s
fractional_seconds
ensure
hour_set: hour = h
minute_set: minute = m
fine_second_set: fine_second = s
make_by_seconds (s: INTEGER)
s
ensure
seconds_count_set: seconds_count = s
make_by_fine_seconds (s: DOUBLE)
s
ensure
minute_large_enough: minute >= 0
minute_small_enough: minute < minutes_in_hour
second_large_enough: second >= 0
second_small_enough: second < seconds_in_minute
fine_seconds_set: dabs (fine_seconds_count - s) <= tolerance
feature
make (h, m, s: INTEGER)
hourminutesecondhms
ensure
hour_set: hour = h
minute_set: minute = m
second_set: second = s
make_by_fine_seconds (s: DOUBLE)
s
ensure
minute_large_enough: minute >= 0
minute_small_enough: minute < minutes_in_hour
second_large_enough: second >= 0
second_small_enough: second < seconds_in_minute
fine_seconds_set: dabs (fine_seconds_count - s) <= tolerance
make_by_seconds (s: INTEGER)
s
ensure
seconds_count_set: seconds_count = s
make_fine (h, m: INTEGER; s: DOUBLE)
minutesecondhm
s
fractional_seconds
ensure
hour_set: hour = h
minute_set: minute = m
fine_second_set: fine_second = s
feature
fine_seconds_count: DOUBLE
Hours_in_day: INTEGER is 24
TIME_CONSTANTS
Minutes_in_hour: INTEGER is 60
TIME_CONSTANTS
seconds_count: INTEGER
ensure
same_count: Result = fine_seconds_count.truncated_to_integer
Seconds_in_day: INTEGER is 86400
TIME_CONSTANTS
Seconds_in_hour: INTEGER is 3600
TIME_CONSTANTS
Seconds_in_minute: INTEGER is 60
TIME_CONSTANTS
time_default_format_string: STRING
TIME_CONSTANTS
zero: TIME_DURATION
ensure GROUP_ELEMENT
result_exists: Result /= void
feature
infix "<=" (other: like Current): BOOLEAN
other
PART_COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
infix ">" (other: like Current): BOOLEAN
other
PART_COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
infix ">=" (other: like Current): BOOLEAN
other
PART_COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
feature
canonical: BOOLEAN
hour
minutesecond
fractional_second
hour
minutesecond
fractional_second
is_negative: BOOLEAN
DURATION
is_positive: BOOLEAN
is_zero: BOOLEAN
DURATION
feature
prefix "+": like Current
DURATION
ensure GROUP_ELEMENT
result_exists: Result /= void
result_definition: Result.is_equal (Current)
infix "-" (other: like Current): like Current
other
DURATION
require GROUP_ELEMENT
other_exists: other /= void
ensure GROUP_ELEMENT
result_exists: Result /= void
feature
time_modulo_day: like Current
ensure
result_smaller_than_day: Result.seconds_count < seconds_in_day
result_positive: Result >= zero
to_canonical: like Current
ensure
result_canonical: Result.canonical
to_days: INTEGER
feature
fine_second_add (s: DOUBLE)
s
sfractional_second
hour_add (h: INTEGER)
h
ensure
hour_set: hour = old hour + h
minute_add (m: INTEGER)
m
ensure
minute_set: minute = old minute + m
second_add (s: INTEGER)
s
ensure
second_set: second = old second + s
infix "+" (other: like Current): like Current
other
require GROUP_ELEMENT
other_exists: other /= void
ensure GROUP_ELEMENT
result_exists: Result /= void
commutative: Result.is_equal (other + Current)
prefix "-": like Current
ensure GROUP_ELEMENT
result_exists: Result /= void
result_definition: (Result + Current).is_equal (zero)
feature
fine_second: DOUBLE
fractional_second: DOUBLE
hour: INTEGER
minute: INTEGER
second: INTEGER
feature
is_equal (other: like Current): BOOLEAN
other
require ANY
other_not_void: other /= void
ensure ANY
symmetric: Result implies other.is_equal (Current)
consistent: standard_is_equal (other) implies Result
infix "<" (other: like Current): BOOLEAN
other
require PART_COMPARABLE
other_exists: other /= void
feature
set_fine_second (s: DOUBLE)
fine_seconds
require TIME_MEASUREMENT
s_large_enough: s >= 0
s_small_enough: s < seconds_in_minute
ensure TIME_MEASUREMENT
fine_second_set: fine_second = s
set_fractionals (f: DOUBLE)
fractional_secondf
fsecond
require TIME_MEASUREMENT
f_large_enough: f >= 0
f_small_enough: f < 1
ensure TIME_MEASUREMENT
second_same: second = old second
set_hour (h: INTEGER)
hourh
require TIME_MEASUREMENT
h_large_enough: h >= 0
h_small_enough: h < hours_in_day
ensure TIME_MEASUREMENT
hour_set: hour = h
set_minute (m: INTEGER)
minutem
require TIME_MEASUREMENT
m_large_enough: m >= 0
m_small_enough: m < minutes_in_hour
ensure TIME_MEASUREMENT
minute_set: minute = m
set_second (s: INTEGER)
seconds
fractional_second
require TIME_MEASUREMENT
s_large_enough: s >= 0
s_small_enough: s < seconds_in_minute
ensure TIME_MEASUREMENT
second_set: second = s
invariant
fractionals_large_enough: fractional_second > - 1
fractionals_small_enough: fractional_second < 1
fractional_and_second_same_sign: second * fractional_second >= 0
equal_signs: canonical implies (hour >= 0 and minute >= 0 and fine_second >= 0) or (hour <= 0 and minute <= 0 and fine_second <= 0)
ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)
DURATION
sign_correctness: is_positive xor is_negative xor is_zero
GROUP_ELEMENT
neutral_addition: Current.is_equal (Current + zero)
self_subtraction: zero.is_equal (Current - Current)
end -- TIME_DURATION