Class DT_TIME_DURATION PreviousNext

note
description:

    "Time durations"

remark:       "Do not take leap seconds into account"
library:    "Gobo Eiffel Time Library"
author:     "Eric Bezault <ericb@gobosoft.com>"
copyright:  "Copyright (c) 2000-2001, Eric Bezault and others"
license:    "MIT License"
class interface
DT_TIME_DURATION
inherit
DT_DURATION
    KL_PART_COMPARABLE
    HASHABLE
    KL_CLONABLE
DT_TIME_VALUE
DT_GREGORIAN_CALENDAR
create
make (h, m, s: INTEGER)
        -- Create a new time duration.
    ensure
        hour_set: hour = h
        minute_set: minute = m
        second_set: second = s
        millisecond_set: millisecond = 0
make_precise (h, m, s, ms: INTEGER)
        -- Create a new time duration with millisecond precision.
    ensure
        hour_set: hour = h
        minute_set: minute = m
        second_set: second = s
        millisecond_set: millisecond = ms
make_canonical (s: INTEGER)
        -- Create a canonical time duration.
    ensure
        is_canonical: is_canonical
        second_count_set: second_count = s
        millisecond_set: millisecond = 0
make_precise_canonical (ms: INTEGER)
        -- Create a canonical time duration
        -- with millisecond precision.
    ensure
        is_canonical: is_canonical
        millisecond_count_set: millisecond_count = ms
feature -- Access
hour: INTEGER
        -- Hour
        -- (From DT_TIME_VALUE.)
minute: INTEGER
        -- Minute
        -- (From DT_TIME_VALUE.)
second: INTEGER
        -- Second
        -- (From DT_TIME_VALUE.)
millisecond: INTEGER
        -- Millisecond
        -- (From DT_TIME_VALUE.)
second_count: INTEGER
        -- Total number of seconds
    ensure
        definition: Result = ((hour * Minutes_in_hour + minute) *
            Seconds_in_minute + second + millisecond // 1000)
millisecond_count: INTEGER
        -- Total number of milliseconds
    ensure
        definition: Result = (((hour * Minutes_in_hour + minute) *
            Seconds_in_minute + second) * 1000 + millisecond)
time (a_time: DT_TIME): DT_TIME
        -- Addition of current duration to a_time
        -- (Create a new object at each call.)
        -- (From absolute_time in DT_DURATION.)
    require
        a_time_not_void: a_time /= Void
    ensure
        time_not_void: Result /= Void
        definition: Result.is_equal (a_time + Current)
hash_code: INTEGER
        -- Hash code value
        -- (From HASHABLE.)
    ensure
        good_hash_value: Result >= 0
feature -- Status report
is_canonical: BOOLEAN
        -- Has current duration a canonical form?
    ensure
        positive_definition: Result implies
            (millisecond_count >= 0 implies (hour >= 0 and
                minute >= 0 and minute < Minutes_in_hour and
                second >= 0 and second < Seconds_in_minute and
                millisecond >= 0 and millisecond < 1000))
        negative_definition: Result implies
            (millisecond_count <= 0 implies (hour <= 0 and
                minute <= 0 and minute > -Minutes_in_hour and
                second <= 0 and second > -Seconds_in_minute and
                millisecond <= 0 and millisecond > -1000))
feature -- Status setting
set_canonical
        -- Set time duration to be canonical.
    ensure
        is_canonical: is_canonical
        same_duration: is_equal (old cloned_object)
feature -- Setting
set_hour_minute_second (h, m, s: INTEGER)
        -- Set hour to h, minute to m and second to s.
    ensure
        hour_set: hour = h
        minute_set: minute = m
        second_set: second = s
        millisecond_set: millisecond = 0
set_precise_hour_minute_second (h, m, s, ms: INTEGER)
        -- Set hour to h, minute to m, second
        -- to s, and millisecond to ms.
    ensure
        hour_set: hour = h
        minute_set: minute = m
        second_set: second = s
        millisecond_set: millisecond = ms
set_hour (h: INTEGER)
        -- Set hour to h.
    ensure
        hour_set: hour = h
        same_minute: minute = old minute
        same_second: second = old second
        same_millisecond: millisecond = old millisecond
set_minute (m: INTEGER)
        -- Set minute to m.
    ensure
        minute_set: minute = m
        same_hour: hour = old hour
        same_second: second = old second
        same_millisecond: millisecond = old millisecond
set_second (s: INTEGER)
        -- Set second to s.
    ensure
        second_set: second = s
        same_hour: hour = old hour
        same_minute: minute = old minute
        same_millisecond: millisecond = old millisecond
set_millisecond (ms: INTEGER)
        -- Set millisecond to ms.
    ensure
        millisecond_set: millisecond = ms
        same_hour: hour = old hour
        same_minute: minute = old minute
        same_second: second = old second
feature -- Element change
add_hours_minutes_seconds (h, m, s: INTEGER)
        -- Add h hours, m minutes and
        -- s seconds to current duration.
    ensure
        hour_added: hour = old hour + h
        minute_added: minute = old minute + m
        second_added: second = old second + s
add_precise_hours_minutes_seconds (h, m, s, ms: INTEGER)
        -- Add h hours, m minutes, s seconds
        -- and ms milliseconds to current duration.
    ensure
        hour_added: hour = old hour + h
        minute_added: minute = old minute + m
        second_added: second = old second + s
        millisecond_added: millisecond = old millisecond + ms
add_hours (h: INTEGER)
        -- Add h hours to current duration.
    ensure
        hour_added: hour = old hour + h
add_minutes (m: INTEGER)
        -- Add m minutes to current duration.
    ensure
        minute_added: minute = old minute + m
add_seconds (s: INTEGER)
        -- Add s seconds to current duration.
    ensure
        second_added: second = old second + s
add_milliseconds (ms: INTEGER)
        -- Add ms milliseconds to current duration.
    ensure
        millisecond_added: millisecond = old millisecond + ms
feature -- Basic operations
infix "+" (other: like Current): like Current
        -- Sum of current duration with other
        -- (From DT_DURATION.)
    require
        other_not_void: other /= Void
    ensure
        addition_not_void: Result /= Void
infix "-" (other: like Current): like Current
        -- Difference with other
        -- (From DT_DURATION.)
    require
        other_not_void: other /= Void
    ensure
        subtraction_not_void: Result /= Void
prefix "+": like Current
        -- Unary plus
        -- (From DT_DURATION.)
    ensure
        unary_plus_not_void: Result /= Void
        same_object: Result = Current
prefix "-": like Current
        -- Unary minus
        -- (From DT_DURATION.)
    ensure
        unary_minus_not_void: Result /= Void
feature -- Comparison
infix "<" (other: like Current): BOOLEAN
        -- Is current time duration less than other?
        -- (From KL_PART_COMPARABLE.)
    require
        other_not_void: other /= Void
infix "<=" (other: like Current): BOOLEAN
        -- Is current object less than or equal to other?
        -- (From KL_PART_COMPARABLE.)
    require
        other_not_void: other /= Void
    ensure
        definition: Result = ((Current < other) or is_equal (other))
infix ">=" (other: like Current): BOOLEAN
        -- Is current object greater than or equal to other?
        -- (From KL_PART_COMPARABLE.)
    require
        other_not_void: other /= Void
    ensure
        definition: Result = (other <= Current)
infix ">" (other: like Current): BOOLEAN
        -- Is current object greater than other?
        -- (From KL_PART_COMPARABLE.)
    require
        other_not_void: other /= Void
    ensure
        definition: Result = ((other < Current) or is_equal (other))
is_equal (other: like Current): BOOLEAN
        -- Is current time duration equal to other?
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
    ensure
        symmetric: Result implies other.is_equal (Current)
        consistent: standard_is_equal (other) implies Result
same_time_duration (other: DT_TIME_DURATION): BOOLEAN
        -- Is current time duration equal to other?
    require
        other_not_void: other /= Void
    ensure
        definition: Result = (millisecond_count = other.millisecond_count)
feature -- Duplication
copy (other: like Current)
        -- Copy other to current duration.
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
        type_identity: same_type (other)
    ensure
        is_equal: is_equal (other)
feature -- Conversion
to_date_time_duration: DT_DATE_TIME_DURATION
        -- Date time duration equivalent to current time duration
    ensure
        date_time_duration_not_void: Result /= Void
        year_set: Result.year = 0
        month_set: Result.month = 0
        day_set: Result.day = 0
        hour_set: Result.hour = hour
        minute_set: Result.minute = minute
        second_set: Result.second = second
        millisecond_set: Result.millisecond = millisecond
to_canonical : like Current
        -- Canonical version of current time duration
    ensure
        canonical_duration_not_void: Result /= Void
        is_canonical: Result.is_canonical
        same_duration: Result.is_equal (Current)
feature -- Output
out: STRING
        -- Printable representation (hour:minute:second[.millisecond])
        -- (The millisecond part appears only when not zero.)
        -- (From GENERAL.)
    ensure
        out_not_void: Result /= Void
precise_out: STRING
        -- Printable representation (hour:minute:second.millisecond)
        -- (From DT_TIME_VALUE.)
    ensure
        precise_out_not_void: Result /= Void
time_out: STRING
        -- Printable representation (hour:minute:second[.millisecond])
        -- (The millisecond part appears only when not zero.)
        -- (From DT_TIME_VALUE.)
    ensure
        time_out_not_void: Result /= Void
precise_time_out: STRING
        -- Printable representation (hour:minute:second.millisecond)
        -- (From DT_TIME_VALUE.)
    ensure
        precise_time_out_not_void: Result /= Void
append_to_string (a_string: STRING)
        -- Append printable representation
        -- (hour:minute:second[.millisecond]) to a_string.
        -- (The millisecond part appears only when not zero.)
        -- (From DT_TIME_VALUE.)
    require
        a_string_not_void: a_string /= Void
append_time_to_string (a_string: STRING)
        -- Append printable representation
        -- (hour:minute:second[.millisecond]) to a_string.
        -- (The millisecond part appears only when not zero.)
        -- (From DT_TIME_VALUE.)
    require
        a_string_not_void: a_string /= Void
append_precise_to_string (a_string: STRING)
        -- Append printable representation (hour:minute:second.millisecond)
        -- to a_string.
        -- (From DT_TIME_VALUE.)
    require
        a_string_not_void: a_string /= Void
append_precise_time_to_string (a_string: STRING)
        -- Append printable representation (hour:minute:second.millisecond)
        -- to a_string.
        -- (From DT_TIME_VALUE.)
    require
        a_string_not_void: a_string /= Void
feature -- Year
leap_year (y: INTEGER): BOOLEAN
        -- Is y a leap year?
        -- (From DT_GREGORIAN_CALENDAR.)
Months_in_year: INTEGER
        -- Number of months in a year
        -- (From DT_GREGORIAN_CALENDAR.)
    ensure
        definition: Result = (December - Januray + 1)
Days_in_year: INTEGER
Days_in_leap_year: INTEGER
        -- Number of days in a (leap) year
        -- (From DT_GREGORIAN_CALENDAR.)
Days_in_400_years: INTEGER
Days_in_100_years: INTEGER
Days_in_4_years: INTEGER
Days_in_3_years: INTEGER
Days_in_3_leap_years: INTEGER
Days_in_2_years: INTEGER
Days_in_2_leap_years: INTEGER
        -- Number of days in multiple years
        -- (From DT_GREGORIAN_CALENDAR.)
feature -- Month
January: INTEGER
February: INTEGER
March: INTEGER
April: INTEGER
May: INTEGER
June: INTEGER
July: INTEGER
August: INTEGER
September: INTEGER
October: INTEGER
November: INTEGER
December: INTEGER
        -- Months
        -- (From DT_GREGORIAN_CALENDAR.)
days_in_month (m, y: INTEGER): INTEGER
        -- Number of days in month m of year y
        -- (From DT_GREGORIAN_CALENDAR.)
    require
        m_large_enough: m >= January
        m_small_enough: m <= December
    ensure
        at_least_one: Result >= 1
        max_days_in_month: Result <= Max_days_in_month
Max_days_in_month: INTEGER
        -- Maximum number of days in a month
        -- (From DT_GREGORIAN_CALENDAR.)
days_at_month (m, y: INTEGER): INTEGER
        -- Number of days from beginning of year
        -- y until beginning of month m
        -- (From DT_GREGORIAN_CALENDAR.)
    require
        m_large_enough: m >= January
        m_small_enough: m <= December
    ensure
        days_positive: Result >= 0
feature -- Week day
Sunday: INTEGER
Monday: INTEGER
Tuesday: INTEGER
Wednesday: INTEGER
Thursday: INTEGER
Friday: INTEGER
Saturday: INTEGER
        -- Week days
        -- (From DT_GREGORIAN_CALENDAR.)
Days_in_week: INTEGER
        -- Number of days in a week
        -- (From DT_GREGORIAN_CALENDAR.)
    ensure
        definition: Result = (Saturday - Sunday + 1)
next_day (d: INTEGER): INTEGER
        -- Week day after d
        -- (From DT_GREGORIAN_CALENDAR.)
    require
        d_large_enough: d >= Sunday
        d_small_enough: d <= Saturday
    ensure
        sunday_definition: (d = Sunday) implies (Result = Monday)
        monday_definition: (d = Monday) implies (Result = Tuesday)
        tuesday_definition: (d = Tuesday) implies (Result = Wednesday)
        wednesday_definition: (d = Wednesday) implies (Result = Thursday)
        thursday_definition: (d = Thursday) implies (Result= Friday)
        friday_definition: (d = Friday) implies (Result = Saturday)
        saturday_definition: (d = Saturday) implies (Result = Sunday)
previous_day (d: INTEGER): INTEGER
        -- Week day before d
        -- (From DT_GREGORIAN_CALENDAR.)
    require
        d_large_enough: d >= Sunday
        d_small_enough: d <= Saturday
    ensure
        sunday_definition: (d = Sunday) implies (Result = Saturday)
        monday_definition: (d = Monday) implies (Result = Sunday)
        tuesday_definition: (d = Tuesday) implies (Result = Monday)
        wednesday_definition: (d = Wednesday) implies (Result = Tuesday)
        thursday_definition: (d = Thursday) implies (Result= Wednesday)
        friday_definition: (d = Friday) implies (Result = Thursday)
        saturday_definition: (d = Saturday) implies (Result = Friday)
feature -- Time
Seconds_in_minute: INTEGER
        -- Number of seconds in a minute
        -- (From DT_GREGORIAN_CALENDAR.)
Seconds_in_hour: INTEGER
        -- Number of seconds in an hour
        -- (From DT_GREGORIAN_CALENDAR.)
Seconds_in_day: INTEGER
        -- Number of seconds in a day
        -- (From DT_GREGORIAN_CALENDAR.)
Milliseconds_in_day: INTEGER
        -- Number of milliseconds in a day
        -- (From DT_GREGORIAN_CALENDAR.)
Minutes_in_hour: INTEGER
        -- Number of minutes in an hour
        -- (From DT_GREGORIAN_CALENDAR.)
Hours_in_day: INTEGER
        -- Number of hours in a day
        -- (From DT_GREGORIAN_CALENDAR.)
feature -- Epoch
Epoch_year: INTEGER
Epoch_month: INTEGER
Epoch_day: INTEGER
        -- Epoch date (1 Jan 1970)
        -- (From DT_GREGORIAN_CALENDAR.)
epoch_days (y, m, d: INTEGER): INTEGER
        -- Number of days since epoch date (1 Jan 1970)
        -- (From DT_GREGORIAN_CALENDAR.)
    require
        m_large_enough: m >= January
        m_small_enough: m <= December
        d_large_enough: d >= 1
        d_small_enough: d <= days_in_month (m, y)
end -- class DT_TIME_DURATION

Copyright 2000-2001, Eric Bezault
mailto:
ericb@gobosoft.com
http:
//www.gobosoft.com
Last Updated: 9 April 2001

HomeTocPreviousNext