21#if !defined(_PSYTIME_H_)
84#define USEC_YEAR_0_TO_1970 62167305600000000L
86#define SECS_PER_YEAR 31536000
88#define SECS_PER_MONTH 2629744
89#define SECS_PER_WEEK 604800
90#define SECS_PER_DAY 86400
91#define SECS_PER_HOUR 3600
92#define SECS_PER_MIN 60
94#define TIME_YEAR_1970 62167305600000000L
100#define SECOND_MS 1000
101#define MINUTE_MS SECS_PER_MIN * 1000
102#define HOUR_MS SECS_PER_HOUR * 1000
103#define DAY_MS SECS_PER_DAY * 1000
104#define WEEK_MS SECS_PER_WEEK * 1000
105#define MONTH_MS (uint64)SECS_PER_MONTH * 1000
106#define YEAR_MS (uint64)SECS_PER_YEAR * 1000
112#define SECOND_US (uint64)1000000
113#define MINUTE_US (uint64)SECS_PER_MIN * 1000000
114#define HOUR_US (uint64)SECS_PER_HOUR * 1000000
115#define DAY_US (uint64)SECS_PER_DAY * 1000000
116#define WEEK_US (uint64)SECS_PER_WEEK * 1000000
117#define MONTH_US (uint64)SECS_PER_MONTH * 1000000
118#define YEAR_US (uint64)SECS_PER_YEAR * 1000000
124#define PSYSECOND SECOND_US
125#define PSYMINUTE MINUTE_US
126#define PSYHOUR HOUR_US
128#define PSYWEEK WEEK_US
129#define PSYMONTH MONTH_US
130#define PSYYEAR YEAR_US
134static char PsyDays[][5] = {
"None",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"};
136static char PsyDaysFull[][10] = {
"None",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"};
138static char PsyMonths[][5] = {
"None",
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
140static char PsyMonthsFull[][10] = {
"None",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
219#define TMC_SYNC_INTERVAL 60000000
262uint32
GetHTTPTime(uint64 time,
char* buffer, uint32 size);
297char*
PrintTime(uint64 t,
bool local =
true,
bool us =
true,
bool ms =
true);
298char*
PrintTimeOnly(uint64 t,
bool local =
true,
bool us =
true,
bool ms =
true);
299char*
PrintTimeDif(uint64 t,
bool us =
true,
bool ms =
true);
300char*
PrintDate(uint64 t,
bool local =
true);
324std::string
PrintTimeString(uint64 t,
bool local =
true,
bool us =
true,
bool ms =
true);
325std::string
PrintTimeOnlyString(uint64 t,
bool local =
true,
bool us =
true,
bool ms =
true);
Core fixed-width scalar typedefs and the PsyType / PsyContext hierarchical identifiers.
static uint64 CurrentTMC
Current Time Mapping Constant (µs offset from monotonic clock to absolute PsyTime).
std::string PrintTimeString(uint64 t, bool local=true, bool us=true, bool ms=true)
static char PsyDaysFull[][10]
Full weekday names indexed 1..7 (Monday..Sunday); index 0 is "None".
char * PrintDateSortable(uint64 t, bool local=true)
Date only, sortable (e.g.
std::string PrintDateStringSortableDelimiter(uint64 t, const char *del, bool local=true)
char * PrintTime(uint64 t, bool local=true, bool us=true, bool ms=true)
Full date + time-of-day.
std::string PrintTimeSortableMillisecString(uint64 t, bool local=true)
Sortable date+time with milliseconds.
char * PrintTimeSortableMicrosec(uint64 t, bool local)
Sortable date+time with microseconds.
uint64 GetTimeFromPsyDateAndTime(struct PsyDateAndTime &tad)
Convert a broken-down PsyDateAndTime back into a µs timestamp.
uint64 FTime2PsyTime(uint64 t)
Convert an ftime-style value (ms since Unix epoch) to a PsyTime µs timestamp.
static uint8 CurrentTMCMode
Current TMC role: TMC_MASTER or TMC_SLAVE.
char * PrintTimeDif(uint64 t, bool us=true, bool ms=true)
Format a µs duration with scale-adaptive units: "250us", "1.500ms", "2.750s", "2m 3s",...
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
std::string PrintDateString(uint64 t, bool local=true)
uint32 GetTimeOffsetGMT()
static char PsyMonthsFull[][10]
Full month names indexed 1..12; index 0 is "None".
char * PrintTimeSortableMillisec(uint64 t, bool local)
Sortable date+time with milliseconds.
static char PsyDays[][5]
Abbreviated weekday names indexed 1..7 (Mon..Sun); index 0 is "None".
char * PrintTimeOnly(uint64 t, bool local=true, bool us=true, bool ms=true)
Time-of-day only.
static int64 NetTimeAdjust
Signed network time adjustment (µs) applied when slaved to a remote master.
bool SetCurrentTimeSyncData(uint64 tmc, int64 netTimeAdjust)
Install externally computed sync data (e.g.
bool PsyTime_UnitTest()
Run the PsyTime unit tests.
uint32 GetHTTPTime(uint64 time, char *buffer, uint32 size)
Format a timestamp as an HTTP-date (RFC 7231) string, e.g.
std::string PrintTimeSortableString(uint64 t, bool local=true)
Sortable date+time, second resolution.
uint64 SyncToHardwareClock()
Recompute the Time Mapping Constant by anchoring the monotonic clock to the wall clock.
std::string PrintTimeNowString(bool local=true, bool us=true, bool ms=true)
Format GetTimeNow().
std::string PrintTimeDifString(uint64 t, bool us=true, bool ms=true)
char * PrintDateSortableDelimiter(uint64 t, const char *del, bool local=true)
Sortable date with custom field delimiter.
bool SetCurrentNetSyncDif(int64 netTimeDif)
Set the network time difference for a slave node so its GetTimeNow() matches the master.
uint64 GetTimeFromString(const char *str)
Parse a textual date/time into a PsyTime timestamp.
std::string PrintTimeOnlyString(uint64 t, bool local=true, bool us=true, bool ms=true)
int32 GetTimeAgeMS(uint64 t)
Age of a timestamp relative to now, in milliseconds.
#define TMC_MASTER
This node is the time master; others sync to it.
struct PsyDateAndTime GetTimeDifference(uint64 t1, uint64 t2)
Express the difference t1 - t2 as calendar fields (negative flag set when t2 > t1).
int64 GetTimeAge(uint64 t)
Age of a timestamp relative to now.
static char PsyMonths[][5]
Abbreviated month names indexed 1..12 (Jan..Dec); index 0 is "None".
struct PsyDateAndTime GetDateAndTimeUTC(uint64 t)
Break a timestamp into calendar fields in UTC.
static uint64 LastTMCSync
PsyTime timestamp of the last hardware-clock sync.
std::string PrintTimeSortableMicrosecString(uint64 t, bool local=true)
Sortable date+time with microseconds.
struct PsyDateAndTime GetDateAndTime(uint64 t, bool local=true)
Break a timestamp into calendar fields.
std::string PrintDateStringSortable(uint64 t, bool local=true)
char * PrintDate(uint64 t, bool local=true)
Date only, human-readable.
bool GetCurrentTimeSyncData(uint64 &tmc, int64 &netTimeAdjust)
Read the current sync data.
char * PrintTimeSortable(uint64 t, bool local)
Sortable date+time, second resolution.
uint64 EstNextTMCWrap()
Estimate when the underlying hardware counter will next wrap around.
A PsyTime timestamp or time difference broken down into calendar fields.