Make more constexpr
This commit is contained in:
parent
2eaa458555
commit
762131a425
@ -6,23 +6,22 @@
|
|||||||
static u64 timer_ticks = 0;
|
static u64 timer_ticks = 0;
|
||||||
static u64 boot_timestamp;
|
static u64 boot_timestamp;
|
||||||
|
|
||||||
static int isleap(int year)
|
static inline constexpr int isleap(int year)
|
||||||
{
|
{
|
||||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int make_yday(int year, int month)
|
static constexpr int make_yday(int year, int month)
|
||||||
{
|
{
|
||||||
static const short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
constexpr short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
||||||
int yd;
|
|
||||||
|
|
||||||
yd = upto[month - 1];
|
int yd = upto[month - 1];
|
||||||
if (month > 2 && isleap(year)) yd++;
|
if (month > 2 && isleap(year)) yd++;
|
||||||
return yd;
|
return yd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16
|
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16
|
||||||
static u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec)
|
static constexpr u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec)
|
||||||
{
|
{
|
||||||
return sec + min * 60 + hour * 3600 + yday * 86400 + (year - 70) * 31536000 + ((year - 69) / 4) * 86400 -
|
return sec + min * 60 + hour * 3600 + yday * 86400 + (year - 70) * 31536000 + ((year - 69) / 4) * 86400 -
|
||||||
((year - 1) / 100) * 86400 + ((year + 299) / 400) * 86400;
|
((year - 1) / 100) * 86400 + ((year + 299) / 400) * 86400;
|
||||||
|
Loading…
Reference in New Issue
Block a user