Class DT_DATE_DURATION |

    note

>     description:

>         "Date durations (Gregorian calendar)"

>     library:    "Gobo Eiffel Time Library"
>     copyright:  "Copyright (c) 2000-2001, Eric Bezault and others"
>     license:    "MIT License"

    class interface

>     DT_DATE_DURATION

    inherit

>     DT_DURATION
>         KL_PART_COMPARABLE
>         HASHABLE
>         KL_CLONABLE
>     DT_DATE_VALUE
>     DT_GREGORIAN_CALENDAR

    create

>     make (y, m, d: INTEGER)
>             -- Create a new date duration.
>         ensure
>             year_set: year = y
>             month_set: month = m
>             day_set: day = d

>     make_definite (d: INTEGER)
>             -- Create a new definite date duration.
>         ensure
>             is_definite: is_definite
>             day_set: day = d

    feature -- Access

>     year: INTEGER
>             -- Year
>             -- (From DT_DATE_VALUE.)

>     month: INTEGER
>             -- Month
>             -- (From DT_DATE_VALUE.)

>     day: INTEGER
>             -- Day
>             -- (From DT_DATE_VALUE.)

>     date (a_date: DT_DATE): DT_DATE
>             -- Addition of current duration to a_date
>             -- (Create a new object at each call.)
>             -- (From absolute_time in DT_DURATION.)
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             date_not_void: Result /= Void
>             definition: Result.is_equal (a_date + Current)

>     hash_code: INTEGER
>             -- Hash code value
>             -- (From HASHABLE.)
>         ensure
>             good_hash_value: Result >= 0

    feature -- Status report

>     is_definite: BOOLEAN
>             -- Is current duration independant of the date
>             -- on which it applies (use of day only)
>             -- or not (use of year, month and day)?
>         ensure
>             definition: Result = (year = 0 and month = 0)

>     is_canonical (a_date: like date): BOOLEAN
>             -- Has current duration a canonical form
>             -- when to be added to a_date?
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             positive_definition: Result implies ((a_date <= a_date + Current) implies
>                 (year >= 0 and month >= 0 and month < Months_in_year and day >= 0 and
>                 ((day >= (a_date + Current).day implies
>                     day < (a_date + Current).days_in_previous_month) or
>                 (day < (a_date + Current).day implies
>                     day < (a_date + Current).days_in_current_month))))
>             negative_definition: Result implies ((a_date >= a_date + Current) implies
>                 (year <= 0 and month <= 0 and month > -Months_in_year and
>                 day <= 0 and day > -(a_date + Current).days_in_current_month))

    feature -- Status setting

>     set_definite (a_date: like date)
>             -- Set current duration to be definite
>             -- when to be added to a_date.
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             is_definite: is_definite
>             same_duration: (a_date + Current).is_equal (a_date + old cloned_object)

>     set_canonical (a_date: like date)
>             -- Set current duration to be canonical
>             -- when to be added to a_date.
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             is_canonical: is_canonical (a_date)
>             same_duration: (a_date + Current).is_equal (a_date + old cloned_object)

    feature -- Setting

>     set_year_month_day (y, m, d: INTEGER)
>             -- Set year to y, month to m and day to d.
>         ensure
>             year_set: year = y
>             month_set: month = m
>             day_set: day = d

>     set_year (y: INTEGER)
>             -- Set year to y.
>         ensure
>             year_set: year = y
>             same_month: month = old month
>             same_day: day = old day

>     set_month (m: INTEGER)
>             -- Set month to m.
>         ensure
>             month_set: month = m
>             same_year: year = old year
>             same_day: day = old day

>     set_day (d: INTEGER)
>             -- Set day to d.
>         ensure
>             day_set: day = d
>             same_year: year = old year
>             same_month: month = old month

    feature -- Element change

>     add_years_months_days (y, m, d: INTEGER)
>             -- Add y years, m months and d days to current duration.
>         ensure
>             years_added: year = old year + y
>             months_added: month = old month + m
>             days_added: day = old day + d

>     add_years (y: INTEGER)
>             -- Add y years to current duration.
>         ensure
>             years_added: year = old year + y

>     add_months (m: INTEGER)
>             -- Add m months to current duration.
>         ensure
>             months_added: month = old month + m

>     add_days (d: INTEGER)
>             -- Add d days to current duration.
>         ensure
>             days_added: day = old day + d

    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 date 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 date 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_date_duration (other: DT_DATE_DURATION): BOOLEAN
>             -- Is current date duration equal to other?
>         require
>             other_not_void: other /= Void
>         ensure
>             definition: Result = ((day = other.day) and
>                 ((year * Months_in_year + month) =
>                     (other.year * Months_in_year + other.month)))

    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 date duration
>         ensure
>             date_time_duration_not_void: Result /= Void
>             year_set: Result.year = year
>             month_set: Result.month = month
>             day_set: Result.day = day
>             hour_set: Result.hour = 0
>             minute_set: Result.minute = 0
>             second_set: Result.second = 0
>             millisecond_set: Result.millisecond = 0

>     to_canonical (a_date: like date): like Current
>             -- Canonical version of current duration
>             -- when to be added to a_date
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             canonical_duration_not_void: Result /= Void
>             is_canonical: Result.is_canonical (a_date)
>             same_duration: (a_date + Current).is_equal (a_date + Result)

>     to_definite (a_date: like date): like Current
>             -- Definite version of current duration
>             -- when to be added to a_date
>         require
>             a_date_not_void: a_date /= Void
>         ensure
>             definite_duration_not_void: Result /= Void
>             is_definite: Result.is_definite
>             same_duration: (a_date + Current).is_equal (a_date + Result)

    feature -- Output

>     out: STRING
>             -- Printable representation (year/month/day)
>             -- (From GENERAL.)
>         ensure
>             out_not_void: Result /= Void

>     date_out: STRING
>             -- Printable representation (year/month/day)
>             -- (From DT_DATE_VALUE.)
>         ensure
>             date_out_not_void: Result /= Void

>     append_to_string (a_string: STRING)
>             -- Append printable representation
>             -- (year/month/day) 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
>             -- (year/month/day) 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)

    end -- class DT_DATE_DURATION