I have to store the age (years, months, days ... maybe hours, minutes, seconds) of the user. I work with C ++ and promote.
I'm not sure which class boost::posix_time (or boost::date_time ) I should use.
I tried boost::posix_time::time_duration , but this is not obvious, because there is no constructor with counting the year, it is just a clock, so I did:
boost::posix_time::time_duration age = boost::posix_time::hours(24*365*ageInYears);
But I'm not sure that a good strategy, because all years do not have 365 days; -)
I also tried boost::gregorian::date , but this is complicated because this one does not allow to store year to 1400 (and this saves date, not duration).
- I do not want to store the user's date of birth, because I need to keep his age when my program was launched (medical data).
- I do not want to store a regular
int , because it is not accurate enough (24 years + 11 months - almost 25). - I don’t want to store a
float because I don’t want to invent a wheel with a float to the age that I would need to do ...
Is there really no class that allows you to easily store several years and, possibly, the number of months and days in boost?
Ideally, for a guy aged 30 or older, I would like to create such an object: boost::....... theAge( 30, 6, 0 ); , and then:
- You have a function to get the age in years: theAge.years () returns 30 (ignoring the months)
- Maybe there is a conversion to float that would give me 30.5 as an age
source share