Files
geant4/source/externals/g4tools/include/tools/wroot/date
T
2021-06-25 16:12:29 +02:00

43 lines
1.2 KiB
Plaintext

// 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 <time.h>
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);
#ifdef _MSC_VER
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