[boost][chrono] time_since_epoch different on windows and linux

Hi,
I've run into a bit of a funny one and I'm not sure if I'm missing
something or whether I've encountered a bug.
The following code excerpt *seems* to have 2 different results on
windows 7 (VS2010) and linux (gcc4.6) using boost version 1.47.
#include <iostream>
#include <cstdint>
#include

Hi, The documentation makes clear that epoch is implementation dependent : "The library leaves epochs unspecified."
From : http://www.boost.org/doc/libs/1_48_0/doc/html/chrono.html
"In each of the examples above, a different epoch is implied. Sometimes an epoch has meaning for several millennia. Other times the meaning of an epoch is lost after a while (such as the start of a timer, or when the computer booted). However, if two time_pointhttp://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#chrono.r...s are known to share the same epoch, they can be subtracted, yielding a valid durationhttp://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#chrono.r..., even if the definition of the epoch no longer has meaning. In *Boost.Chrono*, an epoch is a purely abstract and unspecified concept. There is no type representing an epoch. It is simply an idea that relates (or doesn't) time_pointhttp://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#chrono.r...s to a clock, and in the case that they share a clock, time_pointhttp://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#chrono.r...s to one another. time_pointhttp://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#chrono.r...s associated with different clocks are generally not interoperable unless the relationship between the epochs associated with each clock is known."
From http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/users_guide.html
My understanding is that chrono isn't meant to provide absolute time "position", but time measurement and manipulations. The difference being that epoch is an arbitrary referential used to allow now() to be written and worked with. Joël Lamotte

On 08/12/2011 at 23:57, in message
, Klaim - Joël Lamotte wrote: Hi, The documentation makes clear that epoch is implementation dependent :
"The library leaves epochs unspecified."
From : http://www.boost.org/doc/libs/1_48_0/doc/html/chrono.html
"In each of the examples above, a different epoch is implied. Sometimes an epoch has meaning for several millennia. Other times the meaning of an epoch is lost after a while (such as the start of a timer, or when the computer booted). However, if two
time_point<http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.htm
l#chrono.reference.cpp0x.time_point_hpp.time_point>s are known to share the same epoch, they can be subtracted, yielding a valid
duration<http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.html#
chrono.reference.cpp0x.duration_hpp.duration>, even if the definition of the epoch no longer has meaning.
In *Boost.Chrono*, an epoch is a purely abstract and unspecified concept. There is no type representing an epoch. It is simply an idea that relates (or doesn't)
time_point<http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.htm
l#chrono.reference.cpp0x.time_point_hpp.time_point>s to a clock, and in the case that they share a clock,
time_point<http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.htm
l#chrono.reference.cpp0x.time_point_hpp.time_point>s to one another.
time_point<http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/reference.htm
l#chrono.reference.cpp0x.time_point_hpp.time_point>s associated with different clocks are generally not interoperable unless the relationship between the epochs associated with each clock is known."
From http://www.boost.org/doc/libs/1_48_0/doc/html/chrono/users_guide.html
My understanding is that chrono isn't meant to provide absolute time "position", but time measurement and manipulations. The difference being that epoch is an arbitrary referential used to
allow
now() to be written and worked with.
Joël Lamotte
Thanks a lot for the clarification Joël, I had read the quoted section, but interpreted it incorrectly. Regards, Ralf -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

Le 08/12/11 19:09, Ralf Globisch a écrit :
Hi,
I've run into a bit of a funny one and I'm not sure if I'm missing something or whether I've encountered a bug.
The following code excerpt *seems* to have 2 different results on windows 7 (VS2010) and linux (gcc4.6) using boost version 1.47.
#include<iostream> #include<cstdint> #include
int main(int argc, char** argv) { boost::chrono::duration<double> sec = boost::chrono::system_clock::now().time_since_epoch(); uint32_t uiSeconds = sec.count(); double dMinutes = uiSeconds/60.0; double dHours = dMinutes/60.0; double dDays = dHours/24.0; double dYears = dDays/365.0;
std::cout<< "Sec: "<< uiSeconds<< " Min: "<< dMinutes<< " Hours: "<< dHours<< " Days: "<< dDays<< " Years: "<< dYears<< std::endl;
return 0; }
This outputs the following: Linux: Sec: 1323362917 Min: 2.2056e+07 Hours: 367601 Days: 15316.7 Years: 41.9636
Windows: Sec: 82934819 Min: 1.38225e+006 Hours: 23037.4 Days: 959.894 Years: 2.62985
The linux results is the expected result: 1970 + 41 years = ~2011. Why does the windows result differ? I've run the windows version on two different windows machines with the same result.
Am I using the library incorrectly? I'm trying to obtain seconds since 1970 so that I can from there calculate seconds since 1900 to calculate an NTP timestamp.
Thanks for any help/suggestions! Hi,
time_since_epoch() gives the time since an undetermined epoch. I will use instead boost::chrono:time_system_clock::to_time_t which gives you the number of nanoseconds since 1970. std::time_t sec = boost::chrono:time_system_clock::to_time_t( boost::chrono::system_clock::now().time_since_epoch() ); Hth, Vicente

On 09/12/2011 at 00:20, in message <4EE13819.20403@wanadoo.fr>, "Vicente J. Botet Escriba"
wrote: Le 08/12/11 19:09, Ralf Globisch a écrit : Hi, I've run into a bit of a funny one and I'm not sure if I'm missing something or whether I've encountered a bug.
The following code excerpt *seems* to have 2 different results on windows 7 (VS2010) and linux (gcc4.6) using boost version 1.47.
#include<iostream> #include<cstdint> #include
int main(int argc, char** argv) { boost::chrono::duration<double> sec = boost::chrono::system_clock::now().time_since_epoch(); uint32_t uiSeconds = sec.count(); double dMinutes = uiSeconds/60.0; double dHours = dMinutes/60.0; double dDays = dHours/24.0; double dYears = dDays/365.0;
std::cout<< "Sec: "<< uiSeconds<< " Min: "<< dMinutes<< " Hours: "<< dHours<< " Days: "<< dDays<< " Years: "<< dYears<< std::endl;
return 0; }
This outputs the following: Linux: Sec: 1323362917 Min: 2.2056e+07 Hours: 367601 Days: 15316.7 Years: 41.9636
Windows: Sec: 82934819 Min: 1.38225e+006 Hours: 23037.4 Days: 959.894 Years: 2.62985
The linux results is the expected result: 1970 + 41 years = ~2011. Why does the windows result differ? I've run the windows version on two different windows machines with the same result.
Am I using the library incorrectly? I'm trying to obtain seconds since 1970 so that I can from there calculate seconds since 1900 to calculate an NTP timestamp.
Thanks for any help/suggestions! Hi,
time_since_epoch() gives the time since an undetermined epoch. I will use instead boost::chrono:time_system_clock::to_time_t which gives you the number of nanoseconds since 1970.
std::time_t sec = boost::chrono:time_system_clock::to_time_t( boost::chrono::system_clock::now().time_since_epoch() );
Hth, Vicente
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Vicente, That helps a lot, thanks! Regards, Ralf -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

On 09/12/2011 at 00:20, in message <4EE13819.20403@wanadoo.fr>, "Vicente J. Botet Escriba"
wrote: Le 08/12/11 19:09, Ralf Globisch a écrit : Hi, I've run into a bit of a funny one and I'm not sure if I'm missing something or whether I've encountered a bug.
The following code excerpt *seems* to have 2 different results on windows 7 (VS2010) and linux (gcc4.6) using boost version 1.47.
#include<iostream> #include<cstdint> #include
int main(int argc, char** argv) { boost::chrono::duration<double> sec = boost::chrono::system_clock::now().time_since_epoch(); uint32_t uiSeconds = sec.count(); double dMinutes = uiSeconds/60.0; double dHours = dMinutes/60.0; double dDays = dHours/24.0; double dYears = dDays/365.0;
std::cout<< "Sec: "<< uiSeconds<< " Min: "<< dMinutes<< " Hours: "<< dHours<< " Days: "<< dDays<< " Years: "<< dYears<< std::endl;
return 0; }
This outputs the following: Linux: Sec: 1323362917 Min: 2.2056e+07 Hours: 367601 Days: 15316.7 Years: 41.9636
Windows: Sec: 82934819 Min: 1.38225e+006 Hours: 23037.4 Days: 959.894 Years: 2.62985
The linux results is the expected result: 1970 + 41 years = ~2011. Why does the windows result differ? I've run the windows version on two different windows machines with the same result.
Am I using the library incorrectly? I'm trying to obtain seconds since 1970 so that I can from there calculate seconds since 1900 to calculate an NTP timestamp.
Thanks for any help/suggestions! Hi,
time_since_epoch() gives the time since an undetermined epoch. I will use instead boost::chrono:time_system_clock::to_time_t which gives you the number of nanoseconds since 1970.
std::time_t sec = boost::chrono:time_system_clock::to_time_t( boost::chrono::system_clock::now().time_since_epoch() );
Hth, Vicente
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Have verified that I get the correct time now. Just a minor correction in case someone stumbles on this thread and fails to compile: It should be std::time_t sec = boost::chrono:system_clock::to_time_t( boost::chrono::system_clock::now() ); Thanks for writing and maintaining this wonderful library Vicente. Regards, Ralf -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
participants (4)
-
Klaim - Joël Lamotte
-
Ralf Globisch
-
Ralf Globisch
-
Vicente J. Botet Escriba