note
	description: "Values of time"
	legal: "See notice at end of class."
	status: "See notice at end of class."
	date: "$Date: 2009-01-01 12:38:30 +0000 (Thu, 01 Jan 2009) $"
	revision: "$Revision: 76534 $"
	access: time

class 
	TIME_VALUE

inherit
	TIME_MEASUREMENT

create 
	default_create

feature -- Access

	hour: INTEGER_32
			-- Hour of the current time
		do
			Result := (compact_time & Hour_mask) |>> Hour_shift
		end

	minute: INTEGER_32
			-- Minute of the current time
		do
			Result := (compact_time & Minute_mask) |>> Minute_shift
		end

	second: INTEGER_32
			-- Second of the current time
		do
			Result := compact_time & Second_mask
		end

	fractional_second: REAL_64
			-- Fractional part of fine_second

	compact_time: INTEGER_32
			-- Hour, minute, second coded.

	fine_second: REAL_64
			-- Representation of second with decimals
		do
			Result := second.to_double + fractional_second
		end

	milli_second: INTEGER_32
			-- Millisecond of the current time
		do
			Result := (fractional_second * 1000.to_double).truncated_to_integer
		end

	micro_second: INTEGER_32
			-- Microsecond of the current time
		do
			Result := (fractional_second * 1000000.to_double).truncated_to_integer
			Result := Result \\ 1000
		end

	nano_second: INTEGER_32
			-- Nanosecond of the current time
		do
			Result := (fractional_second * 1000000000.to_double).truncated_to_integer
			Result := Result \\ 1000
		end
	
feature -- Element change

	set_hour (h: INTEGER_32)
			-- Set hour to h.
		do
			compact_time := compact_time & Hour_mask.bit_not
			compact_time := compact_time | (h |<< Hour_shift)
		end

	set_minute (m: INTEGER_32)
			-- Set minute to m.
		do
			compact_time := compact_time & Minute_mask.bit_not
			compact_time := compact_time | (m |<< Minute_shift)
		end

	set_second (s: INTEGER_32)
			-- Set second to s.
		do
			compact_time := compact_time & Second_mask.bit_not
			compact_time := compact_time | s
		end

	set_fine_second (s: REAL_64)
			-- Set fine_second to s
		local
			s_tmp: INTEGER_32
		do
			s_tmp := s.truncated_to_integer
			set_second (s_tmp)
			fractional_second := s - s_tmp.to_double
		end

	set_fractionals (f: REAL_64)
			-- Set fractional_second to f.
		do
			fractional_second := f
		end
	
feature {NONE} -- Implementation

	Hour_mask: INTEGER_32 = 16711680

	Minute_mask: INTEGER_32 = 65280

	Second_mask: INTEGER_32 = 255
			-- Mask used to extract/set hour, minute and second.

	Hour_shift: INTEGER_32 = 16

	Minute_shift: INTEGER_32 = 8
			-- Shift needed to extract/set hour and minute.
	
note
	copyright: "Copyright (c) 1984-2009, 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 TIME_VALUE

Generated by ISE EiffelStudio