mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
AK: Add AK::Time factory method to construct from individual time fields
This commit is contained in:
parent
548643bcc9
commit
2b5840296a
Notes:
sideshowbarker
2024-07-17 21:10:07 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/2b5840296a8 Pull-request: https://github.com/SerenityOS/serenity/pull/11813 Reviewed-by: https://github.com/linusg ✅
18
AK/Time.h
18
AK/Time.h
@ -136,6 +136,24 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] constexpr static Time from_timestamp(u16 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u8 millisecond)
|
||||
{
|
||||
constexpr auto milliseconds_per_day = 86'400'000;
|
||||
constexpr auto milliseconds_per_hour = 3'600'000;
|
||||
constexpr auto milliseconds_per_minute = 60'000;
|
||||
constexpr auto milliseconds_per_second = 1'000;
|
||||
|
||||
i64 milliseconds_since_epoch = days_since_epoch(year, month, day);
|
||||
milliseconds_since_epoch *= milliseconds_per_day;
|
||||
|
||||
milliseconds_since_epoch += hour * milliseconds_per_hour;
|
||||
milliseconds_since_epoch += minute * milliseconds_per_minute;
|
||||
milliseconds_since_epoch += second * milliseconds_per_second;
|
||||
milliseconds_since_epoch += millisecond;
|
||||
|
||||
return from_milliseconds(milliseconds_since_epoch);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr static Time from_seconds(i64 seconds) { return Time(seconds, 0); }
|
||||
[[nodiscard]] constexpr static Time from_nanoseconds(i64 nanoseconds)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user