mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-19 08:51:57 +00:00
AK: Move some time conversion constants into global scope
These can be useful outside of the scope of the function these are used.
This commit is contained in:
parent
6c2ad49ed2
commit
08331f5d62
Notes:
github-actions[bot]
2025-02-22 19:10:59 +00:00
Author: https://github.com/shannonbooth
Commit: 08331f5d62
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3485
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/trflynn89
1 changed files with 6 additions and 6 deletions
12
AK/Time.h
12
AK/Time.h
|
@ -24,6 +24,12 @@ struct timeval {
|
|||
|
||||
namespace AK {
|
||||
|
||||
constexpr inline double ms_per_day = 86'400'000;
|
||||
constexpr inline double seconds_per_day = 86'400;
|
||||
constexpr inline double seconds_per_year = 60.0 * 60.0 * 24.0 * 365.2425;
|
||||
constexpr inline auto seconds_per_hour = 3'600;
|
||||
constexpr inline auto seconds_per_minute = 60;
|
||||
|
||||
// Concept to detect types which look like timespec without requiring the type.
|
||||
template<typename T>
|
||||
concept TimeSpecType = requires(T t) {
|
||||
|
@ -121,8 +127,6 @@ constexpr i64 days_since_epoch(int year, int month, int day)
|
|||
|
||||
constexpr i64 seconds_since_epoch_to_year(i64 seconds)
|
||||
{
|
||||
constexpr double seconds_per_year = 60.0 * 60.0 * 24.0 * 365.2425;
|
||||
|
||||
// NOTE: We are not using floor() from <math.h> to avoid LibC / DynamicLoader dependency issues.
|
||||
auto round_down = [](double value) -> i64 {
|
||||
auto as_i64 = static_cast<i64>(value);
|
||||
|
@ -379,10 +383,6 @@ public:
|
|||
// Note that the returned time is probably not equivalent to the same timestamp in UTC time, since UNIX time does not observe leap seconds.
|
||||
[[nodiscard]] constexpr static UnixDateTime from_unix_time_parts(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
|
||||
{
|
||||
constexpr auto seconds_per_day = 86'400;
|
||||
constexpr auto seconds_per_hour = 3'600;
|
||||
constexpr auto seconds_per_minute = 60;
|
||||
|
||||
i64 days = days_since_epoch(year, month, day);
|
||||
// With year=2'147'483'648, we can end up with days=569'603'931'504.
|
||||
// Expressing that in milliseconds would require more than 64 bits,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue