// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_wroot_date #define tools_wroot_date //_MSC_VER (= Microsoft VisualC++) : // localtime_r() does not exist on Windows and we can't use the // Windows ::GetLocalTime() since G4 do not want to include windows.h. // Then we stay with the not thread safe localtime(). #include namespace tools { namespace wroot { typedef unsigned int date; inline date get_date(){ // Set Date/Time to current time as reported by the system. // Date and Time are encoded into one single unsigned 32 bit word. // Date is stored with the origin being the 1st january 1995. // Time has 1 second precision. time_t tloc = ::time(0); #if defined(_MSC_VER) || defined(__MINGW32__) struct tm *tp = (tm*)::localtime(&tloc); //not thread safe (but exist on Windows). #else struct tm tpa; struct tm *tp = (tm*)::localtime_r(&tloc, &tpa); //does not exist on Windows. #endif unsigned int _year = tp->tm_year; unsigned int _month = tp->tm_mon + 1; unsigned int _day = tp->tm_mday; unsigned int _hour = tp->tm_hour; unsigned int _min = tp->tm_min; unsigned int _sec = tp->tm_sec; return ((_year-95)<<26 | _month<<22 | _day<<17 | _hour<<12 | _min<<6 | _sec); } }} #endif