Proper daylight savings time check
This commit is contained in:
@@ -428,7 +428,7 @@ u64 Memory::timeSince3DSEpoch() {
|
|||||||
std::time_t rawTime = std::time(nullptr); // Get current UTC time
|
std::time_t rawTime = std::time(nullptr); // Get current UTC time
|
||||||
auto localTime = std::localtime(&rawTime); // Convert to local time
|
auto localTime = std::localtime(&rawTime); // Convert to local time
|
||||||
|
|
||||||
bool daylightSavings = localTime->tm_isdst; // Get if time includes DST
|
bool daylightSavings = localTime->tm_isdst > 0; // Get if time includes DST
|
||||||
localTime = std::gmtime(&rawTime);
|
localTime = std::gmtime(&rawTime);
|
||||||
|
|
||||||
// Use gmtime + mktime to calculate difference between local time and UTC
|
// Use gmtime + mktime to calculate difference between local time and UTC
|
||||||
@@ -437,7 +437,8 @@ u64 Memory::timeSince3DSEpoch() {
|
|||||||
timezoneDifference += 60ull * 60ull; // Add 1 hour (60 seconds * 60 minutes)
|
timezoneDifference += 60ull * 60ull; // Add 1 hour (60 seconds * 60 minutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
milliseconds ms = duration_cast<milliseconds>(seconds(rawTime + timezoneDifference));
|
// seconds between Jan 1 1900 and Jan 1 1970
|
||||||
constexpr u64 offset = 2208988800ull * 1000;
|
constexpr u64 offset = 2208988800ull;
|
||||||
return ms.count() + offset;
|
milliseconds ms = duration_cast<milliseconds>(seconds(rawTime + timezoneDifference + offset));
|
||||||
|
return ms.count();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user