On Apr 25, 2013, at 6:06 PM, Anurag Kalia
This example also proved invaluable. After tweaking it, I have a good idea now of how to use Julian Dates (+/- reasonable constant) to represent dates. Thank you!
In addition to:
typedef std::chrono::duration
<
std::int32_t, std::ratio_multiply
days;
which is a non-SI unit accepted for use with SI:
http://en.wikipedia.org/wiki/SI_units#Non-SI_units_accepted_for_use_with_SI
One can then, taking the current definition of the civil (gregorian) calendar, create several more units which can be quite useful:
There are exactly 7 days in a week:
typedef std::chrono::duration
<
std::int32_t, std::ratio_multiply
weeks;
There are exactly 146097 days in 400 years, which could rightly be called an era:
typedef std::chrono::duration
<
std::int32_t, std::ratio_multiply
eras;
There are exactly 400 years in an era:
typedef std::chrono::duration
<
std::int32_t, std::ratio_divide
years;
And there are exactly 12 months in a year:
typedef std::chrono::duration
<
std::int32_t, std::ratio_divide
months;
Now the definitions of years and months must be understood to be the average length, when converted to other units. But this is not so different than days being 24 hours: this is an average length of a day.
No one is concerned that an average month is precisely 2,629,746 seconds long. However being able to say:
assert(round<months>(jul/first/2013 - jan/first/2012).count() == 18);
is arguably quite useful. Many financial calculations are done by the month (e.g. loan interest), even though the unit of "month" isn't as precisely defined as say "second". But with a round function things could "just work".
template