[*] I'm going to be autistic and say "everybody" is (read: industry midwits are) wrong about dates

(amend comments)
This commit is contained in:
Reece Wilson 2023-09-28 17:56:16 +01:00
parent ea241d86f3
commit 522def0a85
2 changed files with 74 additions and 28 deletions

View File

@ -11,42 +11,88 @@ namespace Aurora::Time
{ {
struct tm struct tm
{ {
int tm_sec {}; int year {}; // The absolute gregorian-calendar year
int tm_min {}; int mon {}; // Months since January
int tm_hour {};
int tm_mday {1}; int mday {}; // Days since last month
int tm_mon {}; AuOptional<int> wday {}; // Days since Monday [usually ignored]
int tm_year {70}; AuOptional<int> yday {}; // Days since January [usually ignored]
int tm_wday {};
int tm_yday {}; int hour {}; // Hours since yesterday
int tm_isdst {-1}; int min {}; // Minutes since the hour
int sec {}; // Seconds since the minute
AuOptionalEx<bool> isdst {};
template<typename Dest_t> template<typename Dest_t>
void CopyTo(Dest_t &out) const void CopyTo(Dest_t &out) const
{ {
out.tm_sec = tm_sec; out.tm_sec = sec;
out.tm_min = tm_min; out.tm_min = min;
out.tm_hour = tm_hour; out.tm_hour = hour;
out.tm_mday = tm_mday; out.tm_mday = mday + 1;
out.tm_mon = tm_mon; out.tm_mon = mon;
out.tm_year = tm_year;
out.tm_wday = tm_wday; #if 0
out.tm_yday = tm_yday; if (year < 1900)
out.tm_isdst = tm_isdst; {
out.tm_year = 0;
}
else
#endif
{
out.tm_year = year - 1900;
}
if (wday == 6)
{
out.tm_wday = 0;
}
else
{
out.tm_wday = wday.value() + 1;
}
out.tm_yday = yday.value();
if (!isdst.HasValue())
{
out.tm_isdst = -1;
}
else
{
out.tm_isdst = isdst.value();
}
} }
template<typename In_t> template<typename In_t>
void CopyFrom(const In_t &in) void CopyFrom(const In_t &in)
{ {
tm_sec = in.tm_sec; sec = in.tm_sec;
tm_min = in.tm_min; min = in.tm_min;
tm_hour = in.tm_hour; hour = in.tm_hour;
tm_mday = in.tm_mday; mday = in.tm_mday - 1;
tm_mon = in.tm_mon; mon = in.tm_mon;
tm_year = in.tm_year; year = in.tm_year + 1900;
tm_wday = in.tm_wday;
tm_yday = in.tm_yday; if (in.tm_wday == 0)
tm_isdst = in.tm_isdst; {
wday = 6;
} }
else
{
wday = in.tm_wday - 1;
}
yday = in.tm_yday;
isdst = in.tm_isdst; // (dont normalize -1. it's a quirk of most modern CRTs we can exploit to easily solve the [user-input + how do i guess DST] issue)
// (stupid c programs shouldn't be exploiting this anyway. assume all std::tm, ::tm, and similar types calling into us follow boolean logic)
}
// Note (*): We don't give a single solitary fuck about what ISO 8601 says nor the intentions of braindead boomers who thought there were 61 seconds to an hour...
// Sunday is not a Weekday; it's apart of the Week-END. No English speaker will disagree with this once we get past the obvious gaslighting attempts from NGOs and indoctrination institutions.
// In my estimation, it's every English speeker ever born after the Stuarts (17xxs+) versus a handful of CIA boys and the International Organization for Standardization
// In my tradition of upholding da norf, we're sticking by the 19th century industrialized understanding of time.
// tm_wday is the day offset since Monday, not days since last week.
// tm_mday is the day offset since the beginning of the month, not the calendar number - that's to say we deviate from other impls by asserting these members are all offsets, not whatever some CIA fuckbuddies at ANSI said it is.
}; };
} }

View File

@ -169,7 +169,7 @@ namespace Aurora::Time
AUKN_SYM tm NormalizeCivilTimezone(const Time::tm &time, ETimezoneShift shift) AUKN_SYM tm NormalizeCivilTimezone(const Time::tm &time, ETimezoneShift shift)
{ {
if ((time.tm_isdst == 0) && (shift == ETimezoneShift::eUTC)) if ((time.isdst.ValueOr(-1) == 0) && (shift == ETimezoneShift::eUTC))
{ {
return time; return time;
} }