diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/CMakeLists.txt | 1 | ||||
-rw-r--r-- | AK/DOSPackedTime.cpp | 39 | ||||
-rw-r--r-- | AK/DOSPackedTime.h | 48 |
3 files changed, 88 insertions, 0 deletions
diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 8ce72a78c9..1188c0f916 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -4,6 +4,7 @@ set(AK_SOURCES CircularBuffer.cpp DeprecatedFlyString.cpp DeprecatedString.cpp + DOSPackedTime.cpp Error.cpp FloatingPointStringConversions.cpp FlyString.cpp diff --git a/AK/DOSPackedTime.cpp b/AK/DOSPackedTime.cpp new file mode 100644 index 0000000000..28d869f444 --- /dev/null +++ b/AK/DOSPackedTime.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022, Undefine <undefine@undefine.pl> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/DOSPackedTime.h> + +namespace AK { + +Time time_from_packed_dos(DOSPackedDate date, DOSPackedTime time) +{ + if (date.value == 0) + return Time(); + + return Time::from_timestamp(first_dos_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0); +} + +DOSPackedDate to_packed_dos_date(unsigned year, unsigned month, unsigned day) +{ + DOSPackedDate date; + date.year = year - first_dos_year; + date.month = month; + date.day = day; + + return date; +} + +DOSPackedTime to_packed_dos_time(unsigned hour, unsigned minute, unsigned second) +{ + DOSPackedTime time; + time.hour = hour; + time.minute = minute; + time.second = second / 2; + + return time; +} + +} diff --git a/AK/DOSPackedTime.h b/AK/DOSPackedTime.h new file mode 100644 index 0000000000..3dd46aa10e --- /dev/null +++ b/AK/DOSPackedTime.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022, Undefine <undefine@undefine.pl> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Time.h> +#include <AK/Types.h> + +namespace AK { + +union DOSPackedTime { + u16 value; + struct { + u16 second : 5; + u16 minute : 6; + u16 hour : 5; + }; +}; +static_assert(sizeof(DOSPackedTime) == 2); + +union DOSPackedDate { + u16 value; + struct { + u16 day : 5; + u16 month : 4; + u16 year : 7; + }; +}; +static_assert(sizeof(DOSPackedDate) == 2); + +inline constexpr u16 first_dos_year = 1980; + +Time time_from_packed_dos(DOSPackedDate, DOSPackedTime); +DOSPackedDate to_packed_dos_date(unsigned year, unsigned month, unsigned day); +DOSPackedTime to_packed_dos_time(unsigned hour, unsigned minute, unsigned second); + +} + +#if USING_AK_GLOBALLY +using AK::DOSPackedDate; +using AK::DOSPackedTime; +using AK::time_from_packed_dos; +using AK::to_packed_dos_date; +using AK::to_packed_dos_time; +#endif |