Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_date 5 #define tools_wroot_date 6 7 //_MSC_VER (= Microsoft VisualC++) : 8 // localtime_r() does not exist on Windows an 9 // Windows ::GetLocalTime() since G4 do not w 10 // Then we stay with the not thread safe loca 11 12 #include <time.h> 13 14 namespace tools { 15 namespace wroot { 16 17 typedef unsigned int date; 18 19 inline date get_date(){ 20 // Set Date/Time to current time as reported 21 // Date and Time are encoded into one single 22 // Date is stored with the origin being the 23 // Time has 1 second precision. 24 time_t tloc = ::time(0); 25 #if defined(_MSC_VER) || defined(__MINGW32__) 26 struct tm *tp = (tm*)::localtime(&tloc); //n 27 #else 28 struct tm tpa; 29 struct tm *tp = (tm*)::localtime_r(&tloc, &t 30 #endif 31 unsigned int _year = tp->tm_year; 32 unsigned int _month = tp->tm_mon + 1; 33 unsigned int _day = tp->tm_mday; 34 unsigned int _hour = tp->tm_hour; 35 unsigned int _min = tp->tm_min; 36 unsigned int _sec = tp->tm_sec; 37 return ((_year-95)<<26 | _month<<22 | _day<< 38 } 39 40 }} 41 42 #endif