[+] AURORA_BUILD_TIME
[+] AuGetBuildTime [+] AuGetBuildTimeUnix
This commit is contained in:
parent
16edbb6064
commit
541e31b198
122
Include/auROXTL/auBuildTime.hpp
Normal file
122
Include/auROXTL/auBuildTime.hpp
Normal file
@ -0,0 +1,122 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuBuildTime.hpp
|
||||
Date: 2023-2-22
|
||||
Author: Reece
|
||||
Credit: https://stackoverflow.com/a/44271643
|
||||
***/
|
||||
|
||||
// extracts 1..4 characters from a string and interprets it as a decimal value
|
||||
#define __CONV_STR2DEC_1(str, i) (str[i]>'0'?str[i]-'0':0)
|
||||
#define __CONV_STR2DEC_2(str, i) (__CONV_STR2DEC_1(str, i)*10 + str[i+1]-'0')
|
||||
#define __CONV_STR2DEC_3(str, i) (__CONV_STR2DEC_2(str, i)*10 + str[i+2]-'0')
|
||||
#define __CONV_STR2DEC_4(str, i) (__CONV_STR2DEC_3(str, i)*10 + str[i+3]-'0')
|
||||
|
||||
// Some definitions for calculation
|
||||
#define __SEC_PER_MIN 60UL
|
||||
#define __SEC_PER_HOUR 3600UL
|
||||
#define __SEC_PER_DAY 86400UL
|
||||
#define __SEC_PER_YEAR (__SEC_PER_DAY*365)
|
||||
#define __UNIX_START_YEAR 1970UL
|
||||
|
||||
// Custom "glue logic" to convert the month name to a usable number
|
||||
#define __GET_MONTH(str, i) (str[i]=='J' && str[i+1]=='a' && str[i+2]=='n' ? 1 : \
|
||||
str[i]=='F' && str[i+1]=='e' && str[i+2]=='b' ? 2 : \
|
||||
str[i]=='M' && str[i+1]=='a' && str[i+2]=='r' ? 3 : \
|
||||
str[i]=='A' && str[i+1]=='p' && str[i+2]=='r' ? 4 : \
|
||||
str[i]=='M' && str[i+1]=='a' && str[i+2]=='y' ? 5 : \
|
||||
str[i]=='J' && str[i+1]=='u' && str[i+2]=='n' ? 6 : \
|
||||
str[i]=='J' && str[i+1]=='u' && str[i+2]=='l' ? 7 : \
|
||||
str[i]=='A' && str[i+1]=='u' && str[i+2]=='g' ? 8 : \
|
||||
str[i]=='S' && str[i+1]=='e' && str[i+2]=='p' ? 9 : \
|
||||
str[i]=='O' && str[i+1]=='c' && str[i+2]=='t' ? 10 : \
|
||||
str[i]=='N' && str[i+1]=='o' && str[i+2]=='v' ? 11 : \
|
||||
str[i]=='D' && str[i+1]=='e' && str[i+2]=='c' ? 12 : 0)
|
||||
|
||||
#define __GET_MONTH2DAYS(month) ((month == 1 ? 0 : 31 + \
|
||||
(month == 2 ? 0 : 28 + \
|
||||
(month == 3 ? 0 : 31 + \
|
||||
(month == 4 ? 0 : 30 + \
|
||||
(month == 5 ? 0 : 31 + \
|
||||
(month == 6 ? 0 : 30 + \
|
||||
(month == 7 ? 0 : 31 + \
|
||||
(month == 8 ? 0 : 31 + \
|
||||
(month == 9 ? 0 : 30 + \
|
||||
(month == 10 ? 0 : 31 + \
|
||||
(month == 11 ? 0 : 30))))))))))))
|
||||
|
||||
#define __TIME_SECONDS__ __CONV_STR2DEC_2(__TIME__, 6)
|
||||
#define __TIME_MINUTES__ __CONV_STR2DEC_2(__TIME__, 3)
|
||||
#define __TIME_HOURS__ __CONV_STR2DEC_2(__TIME__, 0)
|
||||
#define __TIME_DAYS__ __CONV_STR2DEC_2(__DATE__, 4)
|
||||
#define __TIME_MONTH__ __GET_MONTH(__DATE__, 0)
|
||||
#define __TIME_YEARS__ __CONV_STR2DEC_4(__DATE__, 7)
|
||||
|
||||
#define GET_LEAP_DAYS ((__TIME_YEARS__-1968)/4 - (__TIME_MONTH__ <=2 ? 1 : 0))
|
||||
|
||||
// Days in February
|
||||
#define _UNIX_TIMESTAMP_FDAY(year) \
|
||||
(((year) % 400) == 0UL ? 29UL : \
|
||||
(((year) % 100) == 0UL ? 28UL : \
|
||||
(((year) % 4) == 0UL ? 29UL : \
|
||||
28UL)))
|
||||
|
||||
// Days in the year
|
||||
#define _UNIX_TIMESTAMP_YDAY(year, month, day) \
|
||||
( \
|
||||
/* January */ day \
|
||||
/* February */ + (month >= 2 ? 31UL : 0UL) \
|
||||
/* March */ + (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) \
|
||||
/* April */ + (month >= 4 ? 31UL : 0UL) \
|
||||
/* May */ + (month >= 5 ? 30UL : 0UL) \
|
||||
/* June */ + (month >= 6 ? 31UL : 0UL) \
|
||||
/* July */ + (month >= 7 ? 30UL : 0UL) \
|
||||
/* August */ + (month >= 8 ? 31UL : 0UL) \
|
||||
/* September */+ (month >= 9 ? 31UL : 0UL) \
|
||||
/* October */ + (month >= 10 ? 30UL : 0UL) \
|
||||
/* November */ + (month >= 11 ? 31UL : 0UL) \
|
||||
/* December */ + (month >= 12 ? 30UL : 0UL) \
|
||||
)
|
||||
|
||||
// get the UNIX timestamp from a digits representation
|
||||
#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \
|
||||
( /* time */ second \
|
||||
+ minute *__SEC_PER_MIN \
|
||||
+ hour *__SEC_PER_HOUR \
|
||||
+ /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) *__SEC_PER_DAY \
|
||||
+ /* year */ (year - 1970UL) *__SEC_PER_YEAR \
|
||||
+ ((year - 1969UL) / 4UL) *__SEC_PER_DAY \
|
||||
- ((year - 1901UL) / 100UL) *__SEC_PER_DAY \
|
||||
+ ((year - 1601UL) / 400UL) *__SEC_PER_DAY \
|
||||
)
|
||||
|
||||
static constexpr AuUInt64 AuGetBuildTimeUnix()
|
||||
{
|
||||
return _UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__);
|
||||
}
|
||||
|
||||
static constexpr AuUInt64 AuGetBuildTime()
|
||||
{
|
||||
return AuGetBuildTimeUnix() - 999'080'100ull;
|
||||
}
|
||||
|
||||
#undef __TIME_SECONDS__
|
||||
#undef __TIME_MINUTES__
|
||||
#undef __TIME_HOURS__
|
||||
#undef __TIME_DAYS__
|
||||
#undef __TIME_MONTH__
|
||||
#undef __TIME_YEARS__
|
||||
#undef __GET_MONTH
|
||||
#undef __GET_MONTH2DAYS
|
||||
#undef __CONV_STR2DEC_1
|
||||
#undef __CONV_STR2DEC_2
|
||||
#undef __CONV_STR2DEC_3
|
||||
#undef __CONV_STR2DEC_4
|
||||
#undef __SEC_PER_MIN
|
||||
#undef __SEC_PER_HOUR
|
||||
#undef __SEC_PER_DAY
|
||||
#undef __SEC_PER_YEAR
|
||||
#undef __UNIX_START_YEAR
|
||||
|
||||
#define AURORA_BUILD_TIME AuGetBuildTime()
|
@ -53,6 +53,8 @@
|
||||
#include <auROXTL/Objects/SafeDestroy.hpp>
|
||||
#include <auROXTL/Objects/ResetMember.hpp>
|
||||
|
||||
#include <auROXTL/auBuildTime.hpp>
|
||||
|
||||
struct IAuNullDelegate
|
||||
{
|
||||
virtual void OnCall() = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user