Class DT_DATE PreviousNext

note
description:

    "Dates (Gregorian calendar)"

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_DATE
inherit
DT_ABSOLUTE_TIME
    COMPARABLE
    HASHABLE
DT_DATE_VALUE
DT_GREGORIAN_CALENDAR
create
make (y, m, d: INTEGER)
        -- Create a new date.
    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)
    ensure
        year_set: year = y
        month_set: month = m
        day_set: day = d
make_from_day_count (d: INTEGER)
        -- Create a new date from the number
        -- of days since epoch (1 Jan 1970).
    ensure
        day_count_set: day_count = d
feature -- Access
year: INTEGER
        -- Year
        -- (From DT_DATE_VALUE.)
month: INTEGER
        -- Month
        -- (From DT_DATE_VALUE.)
    ensure
        month_large_enough: Result >= January
        month_small_enough: Result <= December
day: INTEGER
        -- Day
        -- (From DT_DATE_VALUE.)
    ensure
        day_large_enough: Result >= 1
        day_small_enough: Result <= days_in_month (month, year)
year_day: INTEGER
        -- Day in current year
    ensure
        non_leap_year: not is_leap_year implies (Result >= 1 and Result <= Days_in_year)
        leap_year: is_leap_year implies (Result >= 1 and Result <= Days_in_leap_year)
week_day: INTEGER
        -- Day in current week
    ensure
        valid_day: Result >= Sunday and Result <= Saturday
infix "-" (other: like Current): like duration
        -- Duration between other and Current
        -- (From DT_ABSOLUTE_TIME.)
    require
        other_not_void: other /= Void
    ensure
        duration_not_void: Result /= Void
        definition: (other + Result).is_equal (Current)
infix "+" (a_duration: like duration): like Current
        -- Addition of a_duration to Current
        -- (Create a new object at each call.)
        -- (From DT_ABSOLUTE_TIME.)
    require
        a_duration_not_void: a_duration /= Void
    ensure
        addition_not_void: Result /= Void
infix "&d" (a_duration: like date_duration): like Current
        -- Addition of a_duration to current date
        -- (Create a new object at each call.)
    require
        a_duration_not_void: a_duration /= Void
    ensure
        addition_not_void: Result /= Void
duration (other: like Current): DT_DATE_DURATION
        -- Duration between other and curent date
        -- (From DT_ABSOLUTE_TIME.)
    require
        other_not_void: other /= Void
    ensure
        duration_not_void: Result /= Void
        definition: (other + Result).is_equal (Current)
        definite_duration: Result.is_definite
canonical_duration (other: like Current): like duration
        -- Canonical duration between other and current date
    require
        other_not_void: other /= Void
    ensure
        duration_not_void: Result /= Void
        canonical_duration: Result.is_canonical (other)
        definition: (other + Result).is_equal (Current)
date_duration (other: like Current): DT_DATE_DURATION
        -- Duration between other and current date
    require
        other_not_void: other /= Void
    ensure
        date_duration_not_void: Result /= Void
        definite_duration: Result.is_definite
        definition: (other &d Result).is_equal (Current)
day_count: INTEGER
        -- Number of days since epoch (1 Jan 1970)
days_in_current_month: INTEGER
        -- Number of days in current month
    ensure
        at_least_one: Result >= 1
        max_days_in_month: Result <= Max_days_in_month
days_in_previous_month: INTEGER
        -- Number of days in previous month
    ensure
        at_least_one: Result >= 1
        max_days_in_month: Result <= Max_days_in_month
hash_code: INTEGER
        -- Hash code value
        -- (From HASHABLE.)
    ensure
        good_hash_value: Result >= 0
feature -- Status report
is_leap_year: BOOLEAN
        -- Is year a leap year?
feature -- Comparison
infix "<" (other: like Current): BOOLEAN
        -- Is current date before other on the time axis?
        -- (From COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        asymmetric: Result implies not (other < Current)
infix "<=" (other: like Current): BOOLEAN
        -- Is current object less than or equal to other?
        -- (From COMPARABLE.)
    require
        other_exists: 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 COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        definition: Result = (other <= Current)
infix ">" (other: like Current): BOOLEAN
        -- Is current object greater than other?
        -- (From COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        definition: Result = (other < Current)
is_equal (other: like Current): BOOLEAN
        -- Is other attached to an object considered equal
        -- to current object?
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
    ensure
        symmetric: Result implies other.is_equal (Current)
        consistent: standard_is_equal (other) implies Result
        trichotomy: Result = (not (Current < other) and not (other < Current))
max (other: like Current): like Current
        -- The greater of current object and other
        -- (From COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        current_if_not_smaller: (Current >= other) implies (Result = Current)
        other_if_smaller: (Current < other) implies (Result = other)
min (other: like Current): like Current
        -- The smaller of current object and other
        -- (From COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        current_if_not_greater: (Current <= other) implies (Result = Current)
        other_if_greater: (Current > other) implies (Result = other)
three_way_comparison (other: like Current): INTEGER
        -- If current object equal to other, 0; if smaller,
        -- -1; if greater, 1.
        -- (From COMPARABLE.)
    require
        other_exists: other /= Void
    ensure
        equal_zero: (Result = 0) = is_equal (other)
        smaller_negative: (Result = -1) = (Current < other)
        greater_positive: (Result = 1) = (Current > other)
feature -- Duplication
copy (other: like Current)
        -- Copy other to current date.
        -- (From GENERAL.)
    require
        other_not_void: other /= Void
        type_identity: same_type (other)
    ensure
        is_equal: is_equal (other)
feature -- Setting
set_date (a_date: DT_DATE)
        -- Set year, month and day from a_date.
    require
        a_date_not_void: a_date /= Void
    ensure
        year_set: year = a_date.year
        month_set: month = a_date.month
        day_set: day = a_date.day
set_year_month_day (y, m, d: INTEGER)
        -- Set year to y, month to m and day to d.
    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)
    ensure
        year_set: year = y
        month_set: month = m
        day_set: day = d
set_year (y: INTEGER)
        -- Set year to y.
    require
        leap_year_aware: day <= days_in_month (month, y)
    ensure
        year_set: year = y
        same_month: month = old month
        same_day: day = old day
set_month (m: INTEGER)
        -- Set month to m.
    require
        m_large_enough: m >= January
        m_small_enough: m <= December
        leap_year_aware: day <= days_in_month (m, year)
    ensure
        month_set: month = m
        same_year: year = old year
        same_day: day = old day
set_day (d: INTEGER)
        -- Set day to d.
    require
        d_large_enough: d >= 1
        d_small_enough: d <= days_in_month (month, year)
    ensure
        day_set: day = d
        same_year: year = old year
        same_month: month = old month
set_day_count (d: INTEGER)
        -- Set day_count to d.
    ensure
        day_count_set: day_count = d
feature -- Element change
add_duration (a_duration: like duration)
        -- Add a_duration to current date.
        -- (Add a_duration.year and a_duration.month first, then
        -- set day to day.min (days_in_month (new_month, new_year))
        -- and finally add a_duration.day.)
        -- (From DT_ABSOLUTE_TIME.)
    require
        a_duration_not_void: a_duration /= Void
add_date_duration (a_duration: like date_duration)
        -- Add a_duration to current date.
        -- (Add a_duration.year and a_duration.month first, then
        -- set day to day.min (days_in_month (new_month, new_year))
        -- and finally add a_duration.day.)
    require
        a_duration_not_void: a_duration /= Void
add_years_months_days (y, m, d: INTEGER)
        -- Add y years, m months and d days to current date.
        -- (Add y and m first, then set day to
        -- day.min (days_in_month (new_month, new_year))
        -- and finally add d.)
add_years (y: INTEGER)
        -- Add y years to current date.
    ensure
        day_adjusted: day = (old day).min (days_in_month (month, year))
add_months (m: INTEGER)
        -- Add m months to current date.
    ensure
        day_adjusted: day = (old day).min (days_in_month (month, year))
add_days (d: INTEGER)
        -- Add d days to current date.
feature -- Output
out: STRING
        -- Printable representation (yyyy/mm/dd)
        -- (From GENERAL.)
    ensure
        out_not_void: Result /= Void
date_out: STRING
        -- Printable representation (yyyy/mm/dd)
        -- (From DT_DATE_VALUE.)
    ensure
        date_out_not_void: Result /= Void
append_to_string (a_string: STRING)
        -- Append printable representation
        -- (yyyy/mm/dd) to a_string.
        -- (From DT_DATE_VALUE.)
    require
        a_string_not_void: a_string /= Void
append_date_to_string (a_string: STRING)
        -- Append printable representation
        -- (yyyy/mm/dd) to a_string.
        -- (From DT_DATE_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)
invariant
irreflexive_comparison: not (Current < Current)
    -- (From COMPARABLE.)
end -- class DT_DATE

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

HomeTocPreviousNext