note
	description: "Values of date"
	legal: "See notice at end of class."
	status: "See notice at end of class."
	date: "$Date: 2017-03-29 12:26:46 +0000 (Wed, 29 Mar 2017) $"
	revision: "$Revision: 100065 $"
	access: date

class 
	DATE_VALUE

inherit
	DATE_MEASUREMENT

	MISMATCH_CORRECTOR
		redefine
			correct_mismatch
		end

create 
	default_create

feature -- Access

	day: INTEGER_32
			-- Day of the current object
		do
			Result := ordered_compact_date & Day_mask
		end

	month: INTEGER_32
			-- Month of the current object
		do
			Result := (ordered_compact_date & Month_mask) |>> Month_shift
		end

	year: INTEGER_32
			-- Year of the current object
		do
			Result := ((ordered_compact_date & Year_mask) |>> Year_shift) & 65535
		end

	compact_date: INTEGER_32
		obsolete "Use `ordered_compact_date' instead. But be careful in your update since `compact_date' and `ordered_compact_date' do not have the same encoding. [2017-05-31]"
			-- Day, month and year coded.
		do
			Result := year | (month |<< 16) | (day |<< 24)
		end

	ordered_compact_date: INTEGER_32
			-- Year, month, day coded for fast comparison between dates.
	
feature -- Element change

	set_date (y, m, d: INTEGER_32)
			-- Set year with y, month with m and day with d.
		local
			l_date: like ordered_compact_date
		do
			l_date := l_date & Day_mask.bit_not
			l_date := l_date | d
			l_date := l_date & Month_mask.bit_not
			l_date := l_date | (m |<< Month_shift)
			l_date := l_date & Year_mask.bit_not
			l_date := l_date | (y |<< Year_shift)
			ordered_compact_date := l_date
		end

	set_day (d: INTEGER_32)
			-- Set day to d.
		local
			l_date: like ordered_compact_date
		do
			l_date := ordered_compact_date
			l_date := l_date & Day_mask.bit_not
			l_date := l_date | d
			ordered_compact_date := l_date
		end

	set_month (m: INTEGER_32)
			-- Set month to m.
		local
			l_date: like ordered_compact_date
		do
			l_date := ordered_compact_date
			l_date := l_date & Month_mask.bit_not
			l_date := l_date | (m |<< Month_shift)
			ordered_compact_date := l_date
		end

	set_year (y: INTEGER_32)
			-- Set year to y.
		local
			l_date: like ordered_compact_date
		do
			l_date := ordered_compact_date
			l_date := l_date & Year_mask.bit_not
			l_date := l_date | (y |<< Year_shift)
			ordered_compact_date := l_date
		end

	set_internal_compact_date (a_compact_date: like compact_date)
		obsolete "Use `ordered_compact_date' instead. But be careful in your update since `compact_date' and `ordered_compact_date' do not have the same encoding. [2017-05-31]"
			-- Set a_compact_date to compact_date.
		do
			set_private_internal_compact_date (a_compact_date)
		ensure
			compact_date_set: year | (month |<< 16) | (day |<< 24) = a_compact_date
		end

	set_internal_ordered_compact_date (a_ordered_compact_date: like ordered_compact_date)
			-- Set a_ordered_compact_date to ordered_compact_date.
		do
			ordered_compact_date := a_ordered_compact_date
		ensure
			ordered_compact_date_set: ordered_compact_date = a_ordered_compact_date
		end
	
feature -- Correction

	correct_mismatch
			-- Attempt to correct object mismatch using Mismatch_information.
		do
			if attached {INTEGER_32_REF} Mismatch_information.item (Compact_date_attribute_name) as l_compact_date then
				set_private_internal_compact_date (l_compact_date.item)
			else
				Precursor {MISMATCH_CORRECTOR}
			end
		end
	
feature {NONE} -- Implementation

	Day_mask: INTEGER_32 = 255

	Month_mask: INTEGER_32 = 65280

	Year_mask: INTEGER_32 = 4294901760
			-- Mask used to extract/set year, month and day.

	Year_shift: INTEGER_32 = 16

	Month_shift: INTEGER_32 = 8

	Day_shift: INTEGER_32 = 0
			-- Shift needed to extract/set year, month and day.

	Compact_date_attribute_name: STRING_8 = "compact_date"
			-- Name of compacte_date attribute in 5.3 and older version.

	set_private_internal_compact_date (a_compact_date: like compact_date)
			-- Set a_compact_date to compact_date.
		do
			set_date (a_compact_date & 65535, (a_compact_date & 16711680) |>> 16, ((a_compact_date & 4278190080) |>> 24) & 255)
		ensure
			compact_date_set: year | (month |<< 16) | (day |<< 24) = a_compact_date
		end
	
note
	copyright: "Copyright (c) 1984-2017, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class DATE_VALUE

Generated by ISE EiffelStudio