indexing
	description: "Duration of dates and times"
	status: "See notice at end of class"
	date: "$Date$"
	revision: "$Revision$"
	access: date, time
class interface
	DATE_TIME_DURATION
create 
	make (y, mo, d, h, mi, s: INTEGER)
			yearmonthdayymod
			hourminutesecondhmis
		ensure
			date_exists: date /= void
			time_exists: time /= void
			year_set: year = y
			month_set: month = mo
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = mi
			second_set: second = s
	make_definite (d, h, m, s: INTEGER)
			dayd
			hourminutesecondhms
		ensure
			date_exists: date /= void
			time_exists: time /= void
			definite_result: definite
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = m
			second_set: second = s
	make_fine (y, mo, d, h, mi: INTEGER; s: DOUBLE)
			yearmonthdayymod
			hourminutesecondhmis
		ensure
			date_exists: date /= void
			time_exists: time /= void
			year_set: year = y
			month_set: month = mo
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = mi
			fine_second_set: fine_second = s
	make_by_date_time (d: DATE_DURATION; t: TIME_DURATION)
			datedtimet
		require
			date_exists: d /= void
			time_exists: t /= void
		ensure
			date_set: date = d
			time_set: time = t
	make_by_date (d: DATE_DURATION)
			datedtime
		require
			d_exists: d /= void
		ensure
			date_set: date = d
			time_exists: time /= void
			time_set: time.is_equal (time.zero)
feature 
	make (y, mo, d, h, mi, s: INTEGER)
			yearmonthdayymod
			hourminutesecondhmis
		ensure
			date_exists: date /= void
			time_exists: time /= void
			year_set: year = y
			month_set: month = mo
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = mi
			second_set: second = s
	make_by_date (d: DATE_DURATION)
			datedtime
		require
			d_exists: d /= void
		ensure
			date_set: date = d
			time_exists: time /= void
			time_set: time.is_equal (time.zero)
	make_by_date_time (d: DATE_DURATION; t: TIME_DURATION)
			datedtimet
		require
			date_exists: d /= void
			time_exists: t /= void
		ensure
			date_set: date = d
			time_set: time = t
	make_definite (d, h, m, s: INTEGER)
			dayd
			hourminutesecondhms
		ensure
			date_exists: date /= void
			time_exists: time /= void
			definite_result: definite
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = m
			second_set: second = s
	make_fine (y, mo, d, h, mi: INTEGER; s: DOUBLE)
			yearmonthdayymod
			hourminutesecondhmis
		ensure
			date_exists: date /= void
			time_exists: time /= void
			year_set: year = y
			month_set: month = mo
			day_set: day = d
			hour_set: hour = h
			minute_set: minute = mi
			fine_second_set: fine_second = s
	
feature 
	date: DATE_DURATION
			
	date_default_format_string: STRING
			
			 DATE_CONSTANTS
	day: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_day: Result = date.day
	days_in_i_th_month (i, y: INTEGER): INTEGER
			iy
			 DATE_CONSTANTS
		require  DATE_CONSTANTS
			i_large_enough: i >= 1
			i_small_enough: i <= months_in_year
	Days_in_leap_year: INTEGER is 366
			
			 DATE_CONSTANTS
	Days_in_non_leap_year: INTEGER is 365
			
			 DATE_CONSTANTS
	Days_in_week: INTEGER is 7
			
			 DATE_CONSTANTS
	days_text: ARRAY [STRING]
			
			 DATE_CONSTANTS
	fine_second: DOUBLE
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_fine_second: Result = time.fine_second
	fine_seconds_count: DOUBLE
			
		require
			has_origin: has_origin_date_time
	hour: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_hour: Result = time.hour
	Hours_in_day: INTEGER is 24
			
			 TIME_CONSTANTS
	long_days_text: ARRAY [STRING]
			
			 DATE_CONSTANTS
	long_months_text: ARRAY [STRING]
			
			 DATE_CONSTANTS
	Max_weeks_in_year: INTEGER is 53
			
			 DATE_CONSTANTS
	minute: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_minute: Result = time.minute
	Minutes_in_hour: INTEGER is 60
			
			 TIME_CONSTANTS
	month: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_month: Result = date.month
	Months_in_year: INTEGER is 12
			
			 DATE_CONSTANTS
	months_text: ARRAY [STRING]
			
			 DATE_CONSTANTS
	origin_date_time: DATE_TIME
			
	second: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_second: Result = time.second
	seconds_count: INTEGER_64
			
		require
			has_origin: has_origin_date_time
	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: TIME_DURATION
			
	time_default_format_string: STRING
			
			 TIME_CONSTANTS
	year: INTEGER
			
			 DATE_TIME_MEASUREMENT
		ensure  DATE_TIME_MEASUREMENT
			same_year: Result = date.year
	zero: DATE_TIME_DURATION
			
		ensure  GROUP_ELEMENT
			result_exists: Result /= void
	
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
		ensure then
			non_definite_result: not (definite and other.definite) implies Result = False
	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 (start_date: DATE_TIME): BOOLEAN
			
			
	definite: BOOLEAN
			
			dayyearmonth
		ensure
			result_definition: Result = (year = 0 and then month = 0)
	has_origin_date_time: BOOLEAN
			origin_date_time
	is_leap_year (y: INTEGER): BOOLEAN
			y
			 DATE_CONSTANTS
	is_negative: BOOLEAN
			
			 DURATION
	is_positive: BOOLEAN
			
	is_zero: BOOLEAN
			
			 DURATION
	
feature 
	set_origin_date_time (dt: DATE_TIME)
			origin_date_timedt
		ensure
			origin_date_time_set: origin_date_time = dt
			origin_date_set: origin_date_time.date = date.origin_date
	
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_to_canonical: like Current
			
			timedate
		require
			definite_duration: definite
		ensure
			time_canonical: Result.time.canonical
			same_sign: ((Result.date > date.zero) implies (Result.time >= time.zero)) and then ((Result.date < date.zero) implies (Result.time <= time.zero))
	to_canonical (start_date: DATE_TIME): like Current
			
			start_date
		ensure
			canonical_set: Result.canonical (start_date)
			duration_not_changed: equal (start_date + Current, start_date + Result)
	
feature 
	day_add (d: INTEGER)
			d
		ensure
			result_definition: day = old day + d
	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)
		ensure then
			origin_date_time: equal (origin_date_time, Result.origin_date_time)
	prefix "-": like Current
			
		ensure  GROUP_ELEMENT
			result_exists: Result /= void
			result_definition: (Result + Current).is_equal (zero)
		ensure then
			origin_date_time: equal (origin_date_time, Result.origin_date_time)
	
feature 
	set_date (d: DATE_DURATION)
			dated
		require
			d_exists: d /= void
		ensure
			date_set: date = d
	set_time (t: TIME_DURATION)
			timet
		require
			t_exists: time /= void
		ensure
			time_set: time = t
	
invariant
	date_exists: date /= void
	time_exists: time /= void
	origin_constraint: (origin_date_time = void and date.origin_date = void) or else origin_date_time.date = date.origin_date
	same_signs: (has_origin_date_time and then canonical (origin_date_time)) implies ((date.is_positive or date.is_zero) and (time.is_positive or time.is_zero)) or else ((date.is_negative or date.is_zero) and (time.is_negative or time.is_zero))
		 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)
		 DATE_TIME_MEASUREMENT
	date_exists: date /= void
	time_exists: time /= void
end -- DATE_TIME_DURATION