Skip to content

steven-varga/clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This header only library is build on top of Howard Hinnan's date-time templates, wraps the underlying representation and provides conversion between std::chrono::system_clock and R/.NET/Windows clocks.

Concepts:

Epoch is the reference point time is counted from. The actual value is the representation, and the resolution or the smallest tick of the clock is the period. Time is measured in duration and may or may not be tied to an epoch. The epoch, duration, period and representation define a clock. Clock tells the current time: SomeClock<std::chrono::milliseconds>::now() and may provide means of conversion to other clocks. Provided the right conversion one can tap into Howard Hinnan's calandar and time-zone parsing/printing library: date-time. This library provides conversions between std::chrono::system_clock and R/.NET/Windows clocks.

internally uses IEEE 754 double precision float, storing fractional seconds in mantissa. This format allows missing values as NAN-s , and to define arbitrary epoch called origin. The roundoff error inherent in floats discussed on stack overflow.

Here are the planned templates to represent POSIXct type with C++11 chrono compatible templates:

using RClock = chrono::Clock< date::year{1970}/date::month{1}/date::day{1}, 	// epoch
				std::chrono::duration<double,std::ratio<1>> >;  				// representation and resolution

Use <date/tz.h> IO formatting function:

	std::cout 
	<< RClock::now()            
	<< date::format("%a %b %d, %Y", RClock::now() );

Lifted from the website: A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime::MinValue.

has been around on POSIX systems, conversion is supported between chrono and time_t. The fact that there is no guaranteed underlying representation, and no sub-second resolution makes it less suitable for Real Time Bidding, High Frequency Trading.

To find out the underlying type:

echo | gcc -E -xc -include 'time.h' - | grep time_t

On my system I get typedef long int __time_t same as you find on .NET with the difference in resolution, and epoch.

BOOST Time

TODO:

  • research date-time representations
  • should boost to date.h conversions be supplied