summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/DOSPackedTime.cpp6
-rw-r--r--AK/DOSPackedTime.h2
-rw-r--r--AK/Forward.h4
-rw-r--r--AK/Time.cpp74
-rw-r--r--AK/Time.h92
-rw-r--r--Kernel/Arch/x86_64/RTC.cpp4
-rw-r--r--Kernel/Arch/x86_64/RTC.h3
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIController.cpp4
-rw-r--r--Kernel/Devices/AsyncDeviceRequest.cpp2
-rw-r--r--Kernel/Devices/AsyncDeviceRequest.h2
-rw-r--r--Kernel/Devices/Audio/IntelHDA/Stream.cpp2
-rw-r--r--Kernel/FileSystem/DevPtsFS/Inode.cpp2
-rw-r--r--Kernel/FileSystem/Ext2FS/Inode.cpp10
-rw-r--r--Kernel/FileSystem/Ext2FS/Inode.h2
-rw-r--r--Kernel/FileSystem/ISO9660FS/Inode.cpp4
-rw-r--r--Kernel/FileSystem/ISO9660FS/Inode.h2
-rw-r--r--Kernel/FileSystem/Inode.cpp2
-rw-r--r--Kernel/FileSystem/Inode.h2
-rw-r--r--Kernel/FileSystem/InodeMetadata.h8
-rw-r--r--Kernel/FileSystem/ProcFS/Inode.h2
-rw-r--r--Kernel/FileSystem/RAMFS/Inode.cpp2
-rw-r--r--Kernel/FileSystem/RAMFS/Inode.h2
-rw-r--r--Kernel/FileSystem/SysFS/Inode.cpp2
-rw-r--r--Kernel/FileSystem/SysFS/Inode.h2
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp6
-rw-r--r--Kernel/Graphics/VMWare/Console.cpp2
-rw-r--r--Kernel/Graphics/VirtIOGPU/Console.cpp2
-rw-r--r--Kernel/Net/IPv4Socket.cpp6
-rw-r--r--Kernel/Net/IPv4Socket.h8
-rw-r--r--Kernel/Net/LocalSocket.cpp2
-rw-r--r--Kernel/Net/LocalSocket.h2
-rw-r--r--Kernel/Net/NetworkAdapter.cpp2
-rw-r--r--Kernel/Net/NetworkAdapter.h6
-rw-r--r--Kernel/Net/NetworkTask.cpp22
-rw-r--r--Kernel/Net/Socket.cpp2
-rw-r--r--Kernel/Net/Socket.h14
-rw-r--r--Kernel/Net/TCPSocket.cpp4
-rw-r--r--Kernel/Net/TCPSocket.h4
-rw-r--r--Kernel/PerformanceManager.h6
-rw-r--r--Kernel/Process.cpp2
-rw-r--r--Kernel/Process.h2
-rw-r--r--Kernel/StdLib.cpp16
-rw-r--r--Kernel/StdLib.h6
-rw-r--r--Kernel/Storage/NVMe/NVMeController.cpp2
-rw-r--r--Kernel/Storage/NVMe/NVMeController.h2
-rw-r--r--Kernel/Syscalls/alarm.cpp4
-rw-r--r--Kernel/Syscalls/beep.cpp2
-rw-r--r--Kernel/Syscalls/clock.cpp4
-rw-r--r--Kernel/Syscalls/resource.cpp8
-rw-r--r--Kernel/Syscalls/socket.cpp2
-rw-r--r--Kernel/Tasks/SyncTask.cpp2
-rw-r--r--Kernel/Thread.cpp4
-rw-r--r--Kernel/Thread.h22
-rw-r--r--Kernel/ThreadBlockers.cpp10
-rw-r--r--Kernel/Time/TimeManagement.cpp34
-rw-r--r--Kernel/Time/TimeManagement.h22
-rw-r--r--Kernel/TimerQueue.cpp8
-rw-r--r--Kernel/TimerQueue.h14
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp24
-rw-r--r--Ports/SDL2/patches/0001-Add-SerenityOS-platform-support.patch2
-rw-r--r--Tests/AK/CMakeLists.txt2
-rw-r--r--Tests/AK/TestDuration.cpp (renamed from Tests/AK/TestTime.cpp)284
-rw-r--r--Tests/Kernel/TestKernelAlarm.cpp8
-rw-r--r--Tests/LibLocale/TestDateTimeFormat.cpp10
-rw-r--r--Tests/LibTimeZone/TestTimeZone.cpp4
-rw-r--r--Userland/Applications/3DFileViewer/main.cpp2
-rw-r--r--Userland/Applications/Browser/CookieJar.cpp10
-rw-r--r--Userland/Applications/Browser/StorageWidget.cpp2
-rw-r--r--Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp2
-rw-r--r--Userland/Applications/HexEditor/HexDocument.cpp2
-rw-r--r--Userland/Applications/HexEditor/HexDocument.h6
-rw-r--r--Userland/Applications/Piano/AudioPlayerLoop.cpp2
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.cpp4
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.h2
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp8
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.h4
-rw-r--r--Userland/DevTools/HackStudio/LanguageClient.cpp2
-rw-r--r--Userland/Games/BrickGame/BrickGame.cpp36
-rw-r--r--Userland/Libraries/LibAudio/ConnectionToServer.cpp2
-rw-r--r--Userland/Libraries/LibC/time.cpp8
-rw-r--r--Userland/Libraries/LibCore/ElapsedTimer.cpp6
-rw-r--r--Userland/Libraries/LibCore/ElapsedTimer.h6
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp26
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementationUnix.h2
-rw-r--r--Userland/Libraries/LibCore/FileWatcherMacOS.mm5
-rw-r--r--Userland/Libraries/LibCore/Socket.cpp6
-rw-r--r--Userland/Libraries/LibCore/Socket.h6
-rw-r--r--Userland/Libraries/LibDesktop/Screensaver.cpp2
-rw-r--r--Userland/Libraries/LibDesktop/Screensaver.h4
-rw-r--r--Userland/Libraries/LibGUI/MessageBox.cpp6
-rw-r--r--Userland/Libraries/LibGUI/MessageBox.h4
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp4
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.h6
-rw-r--r--Userland/Libraries/LibGUI/UndoStack.cpp2
-rw-r--r--Userland/Libraries/LibGUI/UndoStack.h4
-rw-r--r--Userland/Libraries/LibIPC/Decoder.cpp4
-rw-r--r--Userland/Libraries/LibIPC/Decoder.h2
-rw-r--r--Userland/Libraries/LibIPC/Encoder.cpp2
-rw-r--r--Userland/Libraries/LibIPC/Encoder.h2
-rw-r--r--Userland/Libraries/LibJS/Bytecode/PassManager.h2
-rw-r--r--Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/DateConstructor.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp4
-rw-r--r--Userland/Libraries/LibLocale/DateTimeFormat.cpp2
-rw-r--r--Userland/Libraries/LibLocale/DateTimeFormat.h2
-rw-r--r--Userland/Libraries/LibTimeZone/TimeZone.cpp8
-rw-r--r--Userland/Libraries/LibTimeZone/TimeZone.h8
-rw-r--r--Userland/Libraries/LibVideo/Containers/Demuxer.h4
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Document.h22
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp6
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h4
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp18
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Reader.h8
-rw-r--r--Userland/Libraries/LibVideo/PlaybackManager.cpp36
-rw-r--r--Userland/Libraries/LibVideo/PlaybackManager.h30
-rw-r--r--Userland/Libraries/LibVideo/Sample.h6
-rw-r--r--Userland/Libraries/LibVideo/Track.h2
-rw-r--r--Userland/Libraries/LibWeb/Cookie/Cookie.cpp8
-rw-r--r--Userland/Libraries/LibWeb/Cookie/Cookie.h6
-rw-r--r--Userland/Libraries/LibWeb/Cookie/ParsedCookie.cpp14
-rw-r--r--Userland/Libraries/LibWeb/Cookie/ParsedCookie.h4
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h2
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/File.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/VideoTrack.cpp6
-rw-r--r--Userland/Libraries/LibWeb/HTML/VideoTrack.h6
-rw-r--r--Userland/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Loader/LoadRequest.h2
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp4
-rw-r--r--Userland/Services/LookupServer/LookupServer.cpp2
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.cpp8
-rw-r--r--Userland/Utilities/disk_benchmark.cpp2
-rw-r--r--Userland/Utilities/touch.cpp4
140 files changed, 645 insertions, 639 deletions
diff --git a/AK/DOSPackedTime.cpp b/AK/DOSPackedTime.cpp
index 28d869f444..f964db14d2 100644
--- a/AK/DOSPackedTime.cpp
+++ b/AK/DOSPackedTime.cpp
@@ -8,12 +8,12 @@
namespace AK {
-Time time_from_packed_dos(DOSPackedDate date, DOSPackedTime time)
+Duration time_from_packed_dos(DOSPackedDate date, DOSPackedTime time)
{
if (date.value == 0)
- return Time();
+ return Duration();
- return Time::from_timestamp(first_dos_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0);
+ return Duration::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)
diff --git a/AK/DOSPackedTime.h b/AK/DOSPackedTime.h
index 3dd46aa10e..dfce4114d8 100644
--- a/AK/DOSPackedTime.h
+++ b/AK/DOSPackedTime.h
@@ -33,7 +33,7 @@ static_assert(sizeof(DOSPackedDate) == 2);
inline constexpr u16 first_dos_year = 1980;
-Time time_from_packed_dos(DOSPackedDate, DOSPackedTime);
+Duration 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);
diff --git a/AK/Forward.h b/AK/Forward.h
index 42f9d3a8c0..a11fe2c6f2 100644
--- a/AK/Forward.h
+++ b/AK/Forward.h
@@ -27,6 +27,7 @@ class CountingStream;
class DeprecatedFlyString;
class DeprecatedString;
class DeprecatedStringCodePointIterator;
+class Duration;
class Error;
class FlyString;
class GenericLexer;
@@ -44,7 +45,6 @@ class String;
class StringBuilder;
class StringImpl;
class StringView;
-class Time;
class URL;
class Utf16View;
class Utf32CodePointIterator;
@@ -163,6 +163,7 @@ using AK::DeprecatedFlyString;
using AK::DeprecatedString;
using AK::DeprecatedStringCodePointIterator;
using AK::DoublyLinkedList;
+using AK::Duration;
using AK::Error;
using AK::ErrorOr;
using AK::FixedArray;
@@ -194,7 +195,6 @@ using AK::String;
using AK::StringBuilder;
using AK::StringImpl;
using AK::StringView;
-using AK::Time;
using AK::Traits;
using AK::URL;
using AK::Utf16View;
diff --git a/AK/Time.cpp b/AK/Time.cpp
index f91dd358dd..369226f3df 100644
--- a/AK/Time.cpp
+++ b/AK/Time.cpp
@@ -38,31 +38,31 @@ unsigned day_of_week(int year, unsigned month, int day)
return (year + year / 4 - year / 100 + year / 400 + seek_table[month - 1] + day) % 7;
}
-Time Time::from_ticks(clock_t ticks, time_t ticks_per_second)
+Duration Duration::from_ticks(clock_t ticks, time_t ticks_per_second)
{
auto secs = ticks % ticks_per_second;
i32 nsecs = 1'000'000'000 * (ticks - (ticks_per_second * secs)) / ticks_per_second;
i32 extra_secs = sane_mod(nsecs, 1'000'000'000);
- return Time::from_half_sanitized(secs, extra_secs, nsecs);
+ return Duration::from_half_sanitized(secs, extra_secs, nsecs);
}
-Time Time::from_timespec(const struct timespec& ts)
+Duration Duration::from_timespec(const struct timespec& ts)
{
i32 nsecs = ts.tv_nsec;
i32 extra_secs = sane_mod(nsecs, 1'000'000'000);
- return Time::from_half_sanitized(ts.tv_sec, extra_secs, nsecs);
+ return Duration::from_half_sanitized(ts.tv_sec, extra_secs, nsecs);
}
-Time Time::from_timeval(const struct timeval& tv)
+Duration Duration::from_timeval(const struct timeval& tv)
{
i32 usecs = tv.tv_usec;
i32 extra_secs = sane_mod(usecs, 1'000'000);
VERIFY(0 <= usecs && usecs < 1'000'000);
- return Time::from_half_sanitized(tv.tv_sec, extra_secs, usecs * 1'000);
+ return Duration::from_half_sanitized(tv.tv_sec, extra_secs, usecs * 1'000);
}
-i64 Time::to_truncated_seconds() const
+i64 Duration::to_truncated_seconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
if (m_seconds < 0 && m_nanoseconds) {
@@ -72,7 +72,7 @@ i64 Time::to_truncated_seconds() const
return m_seconds;
}
-i64 Time::to_truncated_milliseconds() const
+i64 Duration::to_truncated_milliseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
Checked<i64> milliseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
@@ -91,7 +91,7 @@ i64 Time::to_truncated_milliseconds() const
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
}
-i64 Time::to_truncated_microseconds() const
+i64 Duration::to_truncated_microseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
Checked<i64> microseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
@@ -110,7 +110,7 @@ i64 Time::to_truncated_microseconds() const
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
}
-i64 Time::to_seconds() const
+i64 Duration::to_seconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
if (m_seconds >= 0 && m_nanoseconds) {
@@ -121,7 +121,7 @@ i64 Time::to_seconds() const
return m_seconds;
}
-i64 Time::to_milliseconds() const
+i64 Duration::to_milliseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
Checked<i64> milliseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
@@ -138,7 +138,7 @@ i64 Time::to_milliseconds() const
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
}
-i64 Time::to_microseconds() const
+i64 Duration::to_microseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
Checked<i64> microseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
@@ -155,7 +155,7 @@ i64 Time::to_microseconds() const
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
}
-i64 Time::to_nanoseconds() const
+i64 Duration::to_nanoseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
Checked<i64> nanoseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
@@ -170,13 +170,13 @@ i64 Time::to_nanoseconds() const
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
}
-timespec Time::to_timespec() const
+timespec Duration::to_timespec() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
return { static_cast<time_t>(m_seconds), static_cast<long>(m_nanoseconds) };
}
-timeval Time::to_timeval() const
+timeval Duration::to_timeval() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
// This is done because winsock defines tv_sec and tv_usec as long, and Linux64 as long int.
@@ -185,7 +185,7 @@ timeval Time::to_timeval() const
return { static_cast<sec_type>(m_seconds), static_cast<usec_type>(m_nanoseconds) / 1000 };
}
-Time Time::operator+(Time const& other) const
+Duration Duration::operator+(Duration const& other) const
{
VERIFY(m_nanoseconds < 1'000'000'000);
VERIFY(other.m_nanoseconds < 1'000'000'000);
@@ -209,7 +209,7 @@ Time Time::operator+(Time const& other) const
other_secs += 1;
} else {
/* If *both* are INT64_MAX, then adding them will overflow in any case. */
- return Time::max();
+ return Duration::max();
}
}
@@ -217,46 +217,46 @@ Time Time::operator+(Time const& other) const
new_secs += other_secs;
if (new_secs.has_overflow()) {
if (other_secs > 0)
- return Time::max();
+ return Duration::max();
else
- return Time::min();
+ return Duration::min();
}
- return Time { new_secs.value(), new_nsecs };
+ return Duration { new_secs.value(), new_nsecs };
}
-Time& Time::operator+=(Time const& other)
+Duration& Duration::operator+=(Duration const& other)
{
*this = *this + other;
return *this;
}
-Time Time::operator-(Time const& other) const
+Duration Duration::operator-(Duration const& other) const
{
VERIFY(m_nanoseconds < 1'000'000'000);
VERIFY(other.m_nanoseconds < 1'000'000'000);
if (other.m_nanoseconds)
- return *this + Time((i64) ~(u64)other.m_seconds, 1'000'000'000 - other.m_nanoseconds);
+ return *this + Duration((i64) ~(u64)other.m_seconds, 1'000'000'000 - other.m_nanoseconds);
if (other.m_seconds != (i64)-0x8000'0000'0000'0000)
- return *this + Time(-other.m_seconds, 0);
+ return *this + Duration(-other.m_seconds, 0);
// Only remaining case: We want to subtract -0x8000'0000'0000'0000 seconds,
// i.e. add a very large number.
if (m_seconds >= 0)
- return Time::max();
- return Time { (m_seconds + 0x4000'0000'0000'0000) + 0x4000'0000'0000'0000, m_nanoseconds };
+ return Duration::max();
+ return Duration { (m_seconds + 0x4000'0000'0000'0000) + 0x4000'0000'0000'0000, m_nanoseconds };
}
-Time& Time::operator-=(Time const& other)
+Duration& Duration::operator-=(Duration const& other)
{
*this = *this - other;
return *this;
}
-Time Time::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
+Duration Duration::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
{
VERIFY(nanoseconds < 1'000'000'000);
@@ -269,41 +269,41 @@ Time Time::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
// Now the only possible way to become invalid is overflowing i64 towards positive infinity:
if (Checked<i64>::addition_would_overflow<i64, i64>(seconds, extra_seconds)) {
if (seconds < 0) {
- return Time::min();
+ return Duration::min();
} else {
- return Time::max();
+ return Duration::max();
}
}
- return Time { seconds + extra_seconds, nanoseconds };
+ return Duration { seconds + extra_seconds, nanoseconds };
}
#ifndef KERNEL
namespace {
-static Time now_time_from_clock(clockid_t clock_id)
+static Duration now_time_from_clock(clockid_t clock_id)
{
timespec now_spec {};
::clock_gettime(clock_id, &now_spec);
- return Time::from_timespec(now_spec);
+ return Duration::from_timespec(now_spec);
}
}
-Time Time::now_realtime()
+Duration Duration::now_realtime()
{
return now_time_from_clock(CLOCK_REALTIME);
}
-Time Time::now_realtime_coarse()
+Duration Duration::now_realtime_coarse()
{
return now_time_from_clock(CLOCK_REALTIME_COARSE);
}
-Time Time::now_monotonic()
+Duration Duration::now_monotonic()
{
return now_time_from_clock(CLOCK_MONOTONIC);
}
-Time Time::now_monotonic_coarse()
+Duration Duration::now_monotonic_coarse()
{
return now_time_from_clock(CLOCK_MONOTONIC_COARSE);
}
diff --git a/AK/Time.h b/AK/Time.h
index 8a2382522a..2c1af84313 100644
--- a/AK/Time.h
+++ b/AK/Time.h
@@ -130,26 +130,28 @@ constexpr i64 seconds_since_epoch_to_year(i64 seconds)
return 1970 + round_down(years_since_epoch);
}
-/*
- * Represents a time amount in a "safe" way.
- * Minimum: 0 seconds, 0 nanoseconds
- * Maximum: 2**63-1 seconds, 999'999'999 nanoseconds
- * If any operation (e.g. 'from_timeval' or operator-) would over- or underflow, the closest legal value is returned instead.
- * Inputs (e.g. to 'from_timespec') are allowed to be in non-normal form (e.g. "1 second, 2'012'345'678 nanoseconds" or "1 second, -2 microseconds").
- * Outputs (e.g. from 'to_timeval') are always in normal form.
- */
-class Time {
+// Represents a duration in a "safe" way.
+// Minimum: -(2**63) seconds, 0 nanoseconds
+// Maximum: 2**63-1 seconds, 999'999'999 nanoseconds
+// If any operation (e.g. 'from_timeval' or operator-) would over- or underflow, the closest legal value is returned instead.
+// Inputs (e.g. to 'from_timespec') are allowed to be in non-normal form (e.g. "1 second, 2'012'345'678 nanoseconds" or "1 second, -2 microseconds").
+// Outputs (e.g. from 'to_timeval') are always in normal form.
+//
+// NOTE: This class is naive. It may represent either absolute offsets or relative durations. It does not have a reference point in itself,
+// and therefore comparing multiple instances of this class is only sensible if you are sure that their reference point is identical.
+// You should not be using this class directly to represent absolute time.
+class Duration {
public:
- Time() = default;
- Time(Time const&) = default;
- Time& operator=(Time const&) = default;
+ Duration() = default;
+ Duration(Duration const&) = default;
+ Duration& operator=(Duration const&) = default;
- Time(Time&& other)
+ Duration(Duration&& other)
: m_seconds(exchange(other.m_seconds, 0))
, m_nanoseconds(exchange(other.m_nanoseconds, 0))
{
}
- Time& operator=(Time&& other)
+ Duration& operator=(Duration&& other)
{
if (this != &other) {
m_seconds = exchange(other.m_seconds, 0);
@@ -188,7 +190,7 @@ private:
}
public:
- [[nodiscard]] constexpr static Time from_timestamp(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
+ [[nodiscard]] constexpr static Duration from_timestamp(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
{
constexpr auto milliseconds_per_day = 86'400'000;
constexpr auto milliseconds_per_hour = 3'600'000;
@@ -206,35 +208,35 @@ public:
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)
+ [[nodiscard]] constexpr static Duration from_seconds(i64 seconds) { return Duration(seconds, 0); }
+ [[nodiscard]] constexpr static Duration from_nanoseconds(i64 nanoseconds)
{
i64 seconds = sane_mod(nanoseconds, 1'000'000'000);
- return Time(seconds, nanoseconds);
+ return Duration(seconds, nanoseconds);
}
- [[nodiscard]] constexpr static Time from_microseconds(i64 microseconds)
+ [[nodiscard]] constexpr static Duration from_microseconds(i64 microseconds)
{
i64 seconds = sane_mod(microseconds, 1'000'000);
- return Time(seconds, microseconds * 1'000);
+ return Duration(seconds, microseconds * 1'000);
}
- [[nodiscard]] constexpr static Time from_milliseconds(i64 milliseconds)
+ [[nodiscard]] constexpr static Duration from_milliseconds(i64 milliseconds)
{
i64 seconds = sane_mod(milliseconds, 1'000);
- return Time(seconds, milliseconds * 1'000'000);
+ return Duration(seconds, milliseconds * 1'000'000);
}
- [[nodiscard]] static Time from_ticks(clock_t, time_t);
- [[nodiscard]] static Time from_timespec(const struct timespec&);
- [[nodiscard]] static Time from_timeval(const struct timeval&);
+ [[nodiscard]] static Duration from_ticks(clock_t, time_t);
+ [[nodiscard]] static Duration from_timespec(const struct timespec&);
+ [[nodiscard]] static Duration from_timeval(const struct timeval&);
// We don't pull in <stdint.h> for the pretty min/max definitions because this file is also included in the Kernel
- [[nodiscard]] constexpr static Time min() { return Time(-__INT64_MAX__ - 1LL, 0); };
- [[nodiscard]] constexpr static Time zero() { return Time(0, 0); };
- [[nodiscard]] constexpr static Time max() { return Time(__INT64_MAX__, 999'999'999); };
+ [[nodiscard]] constexpr static Duration min() { return Duration(-__INT64_MAX__ - 1LL, 0); };
+ [[nodiscard]] constexpr static Duration zero() { return Duration(0, 0); };
+ [[nodiscard]] constexpr static Duration max() { return Duration(__INT64_MAX__, 999'999'999); };
#ifndef KERNEL
- [[nodiscard]] static Time now_realtime();
- [[nodiscard]] static Time now_realtime_coarse();
- [[nodiscard]] static Time now_monotonic();
- [[nodiscard]] static Time now_monotonic_coarse();
+ [[nodiscard]] static Duration now_realtime();
+ [[nodiscard]] static Duration now_realtime_coarse();
+ [[nodiscard]] static Duration now_monotonic();
+ [[nodiscard]] static Duration now_monotonic_coarse();
#endif
// Truncates towards zero (2.8s to 2s, -2.8s to -2s).
@@ -253,13 +255,13 @@ public:
[[nodiscard]] bool is_zero() const { return (m_seconds == 0) && (m_nanoseconds == 0); }
[[nodiscard]] bool is_negative() const { return m_seconds < 0; }
- Time operator+(Time const& other) const;
- Time& operator+=(Time const& other);
- Time operator-(Time const& other) const;
- Time& operator-=(Time const& other);
+ Duration operator+(Duration const& other) const;
+ Duration& operator+=(Duration const& other);
+ Duration operator-(Duration const& other) const;
+ Duration& operator-=(Duration const& other);
- constexpr bool operator==(Time const& other) const = default;
- constexpr int operator<=>(Time const& other) const
+ constexpr bool operator==(Duration const& other) const = default;
+ constexpr int operator<=>(Duration const& other) const
{
if (int cmp = (m_seconds > other.m_seconds ? 1 : m_seconds < other.m_seconds ? -1
: 0);
@@ -273,13 +275,13 @@ public:
}
private:
- constexpr explicit Time(i64 seconds, u32 nanoseconds)
+ constexpr explicit Duration(i64 seconds, u32 nanoseconds)
: m_seconds(seconds)
, m_nanoseconds(nanoseconds)
{
}
- [[nodiscard]] static Time from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
+ [[nodiscard]] static Duration from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
i64 m_seconds { 0 };
u32 m_nanoseconds { 0 }; // Always less than 1'000'000'000
@@ -357,10 +359,10 @@ inline void timespec_to_timeval(TimespecType const& ts, TimevalType& tv)
// To use these, add a ``using namespace AK::TimeLiterals`` at block or file scope
namespace TimeLiterals {
-constexpr Time operator""_ns(unsigned long long nanoseconds) { return Time::from_nanoseconds(static_cast<i64>(nanoseconds)); }
-constexpr Time operator""_us(unsigned long long microseconds) { return Time::from_microseconds(static_cast<i64>(microseconds)); }
-constexpr Time operator""_ms(unsigned long long milliseconds) { return Time::from_milliseconds(static_cast<i64>(milliseconds)); }
-constexpr Time operator""_sec(unsigned long long seconds) { return Time::from_seconds(static_cast<i64>(seconds)); }
+constexpr Duration operator""_ns(unsigned long long nanoseconds) { return Duration::from_nanoseconds(static_cast<i64>(nanoseconds)); }
+constexpr Duration operator""_us(unsigned long long microseconds) { return Duration::from_microseconds(static_cast<i64>(microseconds)); }
+constexpr Duration operator""_ms(unsigned long long milliseconds) { return Duration::from_milliseconds(static_cast<i64>(milliseconds)); }
+constexpr Duration operator""_sec(unsigned long long seconds) { return Duration::from_seconds(static_cast<i64>(seconds)); }
}
@@ -372,9 +374,9 @@ using AK::day_of_year;
using AK::days_in_month;
using AK::days_in_year;
using AK::days_since_epoch;
+using AK::Duration;
using AK::is_leap_year;
using AK::seconds_since_epoch_to_year;
-using AK::Time;
using AK::timespec_add;
using AK::timespec_add_timeval;
using AK::timespec_sub;
diff --git a/Kernel/Arch/x86_64/RTC.cpp b/Kernel/Arch/x86_64/RTC.cpp
index e7a8cd48f8..d932e5b422 100644
--- a/Kernel/Arch/x86_64/RTC.cpp
+++ b/Kernel/Arch/x86_64/RTC.cpp
@@ -19,9 +19,9 @@ void initialize()
s_boot_time = now();
}
-Time boot_time()
+Duration boot_time()
{
- return Time::from_timespec({ s_boot_time, 0 });
+ return Duration::from_timespec({ s_boot_time, 0 });
}
static bool update_in_progress()
diff --git a/Kernel/Arch/x86_64/RTC.h b/Kernel/Arch/x86_64/RTC.h
index 80e49ff1e7..859baa82d7 100644
--- a/Kernel/Arch/x86_64/RTC.h
+++ b/Kernel/Arch/x86_64/RTC.h
@@ -6,12 +6,13 @@
#pragma once
+#include <AK/Time.h>
#include <Kernel/UnixTypes.h>
namespace Kernel::RTC {
void initialize();
time_t now();
-Time boot_time();
+Duration boot_time();
}
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp
index a2411ee526..ce373e7acb 100644
--- a/Kernel/Bus/USB/UHCI/UHCIController.cpp
+++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp
@@ -590,7 +590,7 @@ ErrorOr<void> UHCIController::spawn_port_process()
if (m_root_hub)
m_root_hub->check_for_port_updates();
- (void)Thread::current()->sleep(Time::from_seconds(1));
+ (void)Thread::current()->sleep(Duration::from_seconds(1));
}
}));
return {};
@@ -616,7 +616,7 @@ ErrorOr<void> UHCIController::spawn_async_poll_process()
}
}
}
- (void)Thread::current()->sleep(Time::from_milliseconds(poll_interval_ms));
+ (void)Thread::current()->sleep(Duration::from_milliseconds(poll_interval_ms));
}
}));
return {};
diff --git a/Kernel/Devices/AsyncDeviceRequest.cpp b/Kernel/Devices/AsyncDeviceRequest.cpp
index 2a70a28b28..a45f70dea0 100644
--- a/Kernel/Devices/AsyncDeviceRequest.cpp
+++ b/Kernel/Devices/AsyncDeviceRequest.cpp
@@ -51,7 +51,7 @@ void AsyncDeviceRequest::request_finished()
m_queue.wake_all();
}
-auto AsyncDeviceRequest::wait(Time* timeout) -> RequestWaitResult
+auto AsyncDeviceRequest::wait(Duration* timeout) -> RequestWaitResult
{
VERIFY(!m_parent_request);
auto request_result = get_request_result();
diff --git a/Kernel/Devices/AsyncDeviceRequest.h b/Kernel/Devices/AsyncDeviceRequest.h
index 350ded3d11..8e9d57610c 100644
--- a/Kernel/Devices/AsyncDeviceRequest.h
+++ b/Kernel/Devices/AsyncDeviceRequest.h
@@ -60,7 +60,7 @@ public:
void add_sub_request(NonnullLockRefPtr<AsyncDeviceRequest>);
- [[nodiscard]] RequestWaitResult wait(Time* = nullptr);
+ [[nodiscard]] RequestWaitResult wait(Duration* = nullptr);
void do_start(SpinlockLocker<Spinlock<LockRank::None>>&& requests_lock)
{
diff --git a/Kernel/Devices/Audio/IntelHDA/Stream.cpp b/Kernel/Devices/Audio/IntelHDA/Stream.cpp
index 52f8a886ae..d7eb1ee7e7 100644
--- a/Kernel/Devices/Audio/IntelHDA/Stream.cpp
+++ b/Kernel/Devices/Audio/IntelHDA/Stream.cpp
@@ -192,7 +192,7 @@ ErrorOr<size_t> OutputStream::write(UserOrKernelBuffer const& data, size_t lengt
dbgln_if(INTEL_HDA_DEBUG, "IntelHDA: Waiting {} µs until buffer {} becomes writeable", microseconds_to_wait, buffer_index);
// NOTE: we don't care about the reason for interruption - we simply calculate the next delay
- [[maybe_unused]] auto block_result = Thread::current()->sleep(Time::from_microseconds(microseconds_to_wait));
+ [[maybe_unused]] auto block_result = Thread::current()->sleep(Duration::from_microseconds(microseconds_to_wait));
}
};
diff --git a/Kernel/FileSystem/DevPtsFS/Inode.cpp b/Kernel/FileSystem/DevPtsFS/Inode.cpp
index 92f3de94b6..419d73c5bc 100644
--- a/Kernel/FileSystem/DevPtsFS/Inode.cpp
+++ b/Kernel/FileSystem/DevPtsFS/Inode.cpp
@@ -38,7 +38,7 @@ InodeMetadata DevPtsFSInode::metadata() const
{
if (auto pty = m_pty.strong_ref()) {
auto metadata = m_metadata;
- metadata.mtime = Time::from_timespec({ pty->time_of_last_write(), 0 });
+ metadata.mtime = Duration::from_timespec({ pty->time_of_last_write(), 0 });
return metadata;
}
return m_metadata;
diff --git a/Kernel/FileSystem/Ext2FS/Inode.cpp b/Kernel/FileSystem/Ext2FS/Inode.cpp
index 3698cc6467..dfd50f124d 100644
--- a/Kernel/FileSystem/Ext2FS/Inode.cpp
+++ b/Kernel/FileSystem/Ext2FS/Inode.cpp
@@ -474,10 +474,10 @@ InodeMetadata Ext2FSInode::metadata() const
metadata.uid = m_raw_inode.i_uid;
metadata.gid = m_raw_inode.i_gid;
metadata.link_count = m_raw_inode.i_links_count;
- metadata.atime = Time::from_timespec({ m_raw_inode.i_atime, 0 });
- metadata.ctime = Time::from_timespec({ m_raw_inode.i_ctime, 0 });
- metadata.mtime = Time::from_timespec({ m_raw_inode.i_mtime, 0 });
- metadata.dtime = Time::from_timespec({ m_raw_inode.i_dtime, 0 });
+ metadata.atime = Duration::from_timespec({ m_raw_inode.i_atime, 0 });
+ metadata.ctime = Duration::from_timespec({ m_raw_inode.i_ctime, 0 });
+ metadata.mtime = Duration::from_timespec({ m_raw_inode.i_mtime, 0 });
+ metadata.dtime = Duration::from_timespec({ m_raw_inode.i_dtime, 0 });
metadata.block_size = fs().block_size();
metadata.block_count = m_raw_inode.i_blocks;
@@ -985,7 +985,7 @@ ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
return fs().get_inode({ fsid(), inode_index });
}
-ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
+ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime)
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
diff --git a/Kernel/FileSystem/Ext2FS/Inode.h b/Kernel/FileSystem/Ext2FS/Inode.h
index 53e2f664ce..cc6acab147 100644
--- a/Kernel/FileSystem/Ext2FS/Inode.h
+++ b/Kernel/FileSystem/Ext2FS/Inode.h
@@ -37,7 +37,7 @@ private:
virtual ErrorOr<void> add_child(Inode& child, StringView name, mode_t) override;
virtual ErrorOr<void> remove_child(StringView name) override;
virtual ErrorOr<void> replace_child(StringView name, Inode& child) override;
- virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
+ virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
virtual ErrorOr<void> increment_link_count() override;
virtual ErrorOr<void> decrement_link_count() override;
virtual ErrorOr<void> chmod(mode_t) override;
diff --git a/Kernel/FileSystem/ISO9660FS/Inode.cpp b/Kernel/FileSystem/ISO9660FS/Inode.cpp
index 4f6f7c3b2d..2a1dc195fa 100644
--- a/Kernel/FileSystem/ISO9660FS/Inode.cpp
+++ b/Kernel/FileSystem/ISO9660FS/Inode.cpp
@@ -145,7 +145,7 @@ ErrorOr<void> ISO9660Inode::truncate(u64)
return EROFS;
}
-ErrorOr<void> ISO9660Inode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
+ErrorOr<void> ISO9660Inode::update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>)
{
return EROFS;
}
@@ -169,7 +169,7 @@ void ISO9660Inode::create_metadata()
{
u32 data_length = LittleEndian { m_record.data_length.little };
bool is_directory = has_flag(m_record.file_flags, ISO::FileFlags::Directory);
- auto recorded_at = Time::from_timespec({ parse_numerical_date_time(m_record.recording_date_and_time), 0 });
+ auto recorded_at = Duration::from_timespec({ parse_numerical_date_time(m_record.recording_date_and_time), 0 });
m_metadata = {
.inode = identifier(),
diff --git a/Kernel/FileSystem/ISO9660FS/Inode.h b/Kernel/FileSystem/ISO9660FS/Inode.h
index 76641431a3..06ba006205 100644
--- a/Kernel/FileSystem/ISO9660FS/Inode.h
+++ b/Kernel/FileSystem/ISO9660FS/Inode.h
@@ -32,7 +32,7 @@ public:
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
- virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
+ virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
private:
// HACK: The base ISO 9660 standard says the maximum filename length is 37
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index aab18cf1c3..5e2809ef9e 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -115,7 +115,7 @@ ErrorOr<size_t> Inode::read_until_filled_or_end(off_t offset, size_t length, Use
return length - remaining_length;
}
-ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Time> atime, [[maybe_unused]] Optional<Time> ctime, [[maybe_unused]] Optional<Time> mtime)
+ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Duration> atime, [[maybe_unused]] Optional<Duration> ctime, [[maybe_unused]] Optional<Duration> mtime)
{
return ENOTIMPL;
}
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index 938bf86737..5bd7298c5f 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -82,7 +82,7 @@ public:
bool is_metadata_dirty() const { return m_metadata_dirty; }
- virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime);
+ virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime);
virtual ErrorOr<void> increment_link_count();
virtual ErrorOr<void> decrement_link_count();
diff --git a/Kernel/FileSystem/InodeMetadata.h b/Kernel/FileSystem/InodeMetadata.h
index e6300f6146..6cd5e77e90 100644
--- a/Kernel/FileSystem/InodeMetadata.h
+++ b/Kernel/FileSystem/InodeMetadata.h
@@ -120,10 +120,10 @@ struct InodeMetadata {
UserID uid { 0 };
GroupID gid { 0 };
nlink_t link_count { 0 };
- Time atime {};
- Time ctime {};
- Time mtime {};
- Time dtime {};
+ Duration atime {};
+ Duration ctime {};
+ Duration mtime {};
+ Duration dtime {};
blkcnt_t block_count { 0 };
blksize_t block_size { 0 };
MajorNumber major_device { 0 };
diff --git a/Kernel/FileSystem/ProcFS/Inode.h b/Kernel/FileSystem/ProcFS/Inode.h
index d060293dd8..97ebb4fa92 100644
--- a/Kernel/FileSystem/ProcFS/Inode.h
+++ b/Kernel/FileSystem/ProcFS/Inode.h
@@ -54,7 +54,7 @@ private:
// ^Inode (Silent ignore handling)
virtual ErrorOr<void> flush_metadata() override { return {}; }
- virtual ErrorOr<void> update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>) override { return {}; }
+ virtual ErrorOr<void> update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>) override { return {}; }
// ^Inode
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
diff --git a/Kernel/FileSystem/RAMFS/Inode.cpp b/Kernel/FileSystem/RAMFS/Inode.cpp
index 0441a34c46..5de6cd654e 100644
--- a/Kernel/FileSystem/RAMFS/Inode.cpp
+++ b/Kernel/FileSystem/RAMFS/Inode.cpp
@@ -381,7 +381,7 @@ ErrorOr<void> RAMFSInode::truncate(u64 size)
return {};
}
-ErrorOr<void> RAMFSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
+ErrorOr<void> RAMFSInode::update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime)
{
MutexLocker locker(m_inode_lock);
diff --git a/Kernel/FileSystem/RAMFS/Inode.h b/Kernel/FileSystem/RAMFS/Inode.h
index 72ddeb0ea3..2d6a07a2e3 100644
--- a/Kernel/FileSystem/RAMFS/Inode.h
+++ b/Kernel/FileSystem/RAMFS/Inode.h
@@ -35,7 +35,7 @@ public:
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
- virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
+ virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
private:
RAMFSInode(RAMFS& fs, InodeMetadata const& metadata, LockWeakPtr<RAMFSInode> parent);
diff --git a/Kernel/FileSystem/SysFS/Inode.cpp b/Kernel/FileSystem/SysFS/Inode.cpp
index 626167b8d3..daa42dff93 100644
--- a/Kernel/FileSystem/SysFS/Inode.cpp
+++ b/Kernel/FileSystem/SysFS/Inode.cpp
@@ -110,7 +110,7 @@ ErrorOr<void> SysFSInode::truncate(u64 size)
return m_associated_component->truncate(size);
}
-ErrorOr<void> SysFSInode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
+ErrorOr<void> SysFSInode::update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>)
{
return {};
}
diff --git a/Kernel/FileSystem/SysFS/Inode.h b/Kernel/FileSystem/SysFS/Inode.h
index c313a337ed..172cd6290e 100644
--- a/Kernel/FileSystem/SysFS/Inode.h
+++ b/Kernel/FileSystem/SysFS/Inode.h
@@ -35,7 +35,7 @@ protected:
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
- virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
+ virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
virtual void did_seek(OpenFileDescription&, off_t) override final;
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index a381305f25..4a65e0cca9 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -306,7 +306,7 @@ ErrorOr<void> VirtualFileSystem::utime(Credentials const& credentials, StringVie
if (custody->is_readonly())
return EROFS;
- TRY(inode.update_timestamps(Time::from_timespec({ atime, 0 }), {}, Time::from_timespec({ mtime, 0 })));
+ TRY(inode.update_timestamps(Duration::from_timespec({ atime, 0 }), {}, Duration::from_timespec({ mtime, 0 })));
return {};
}
@@ -326,9 +326,9 @@ ErrorOr<void> VirtualFileSystem::do_utimens(Credentials const& credentials, Cust
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
TRY(inode.update_timestamps(
- (atime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(atime) : Optional<Time> {},
+ (atime.tv_nsec != UTIME_OMIT) ? Duration::from_timespec(atime) : Optional<Duration> {},
{},
- (mtime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(mtime) : Optional<Time> {}));
+ (mtime.tv_nsec != UTIME_OMIT) ? Duration::from_timespec(mtime) : Optional<Duration> {}));
return {};
}
diff --git a/Kernel/Graphics/VMWare/Console.cpp b/Kernel/Graphics/VMWare/Console.cpp
index b55bab0722..033caa21a4 100644
--- a/Kernel/Graphics/VMWare/Console.cpp
+++ b/Kernel/Graphics/VMWare/Console.cpp
@@ -9,7 +9,7 @@
namespace Kernel {
-constexpr static AK::Time refresh_interval = AK::Time::from_milliseconds(16);
+constexpr static AK::Duration refresh_interval = AK::Duration::from_milliseconds(16);
NonnullLockRefPtr<VMWareFramebufferConsole> VMWareFramebufferConsole::initialize(VMWareDisplayConnector& parent_display_connector)
{
diff --git a/Kernel/Graphics/VirtIOGPU/Console.cpp b/Kernel/Graphics/VirtIOGPU/Console.cpp
index 2979af1421..57a338fcdf 100644
--- a/Kernel/Graphics/VirtIOGPU/Console.cpp
+++ b/Kernel/Graphics/VirtIOGPU/Console.cpp
@@ -10,7 +10,7 @@
namespace Kernel::Graphics::VirtIOGPU {
-constexpr static AK::Time refresh_interval = AK::Time::from_milliseconds(16);
+constexpr static AK::Duration refresh_interval = AK::Duration::from_milliseconds(16);
NonnullLockRefPtr<Console> Console::initialize(VirtIODisplayConnector& parent_display_connector)
{
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 61bdb59441..4094701265 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -287,7 +287,7 @@ ErrorOr<size_t> IPv4Socket::receive_byte_buffered(OpenFileDescription& descripti
return nreceived_or_error;
}
-ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Time& packet_timestamp, bool blocking)
+ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Duration& packet_timestamp, bool blocking)
{
MutexLocker locker(mutex());
ReceivedPacket taken_packet;
@@ -382,7 +382,7 @@ ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& descrip
return protocol_receive(packet->data->bytes(), buffer, buffer_length, flags);
}
-ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp, bool blocking)
+ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Duration& packet_timestamp, bool blocking)
{
if (user_addr_length) {
socklen_t addr_length;
@@ -415,7 +415,7 @@ ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKer
return total_nreceived;
}
-bool IPv4Socket::did_receive(IPv4Address const& source_address, u16 source_port, ReadonlyBytes packet, Time const& packet_timestamp)
+bool IPv4Socket::did_receive(IPv4Address const& source_address, u16 source_port, ReadonlyBytes packet, Duration const& packet_timestamp)
{
MutexLocker locker(mutex());
diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h
index 3cc5d360e7..2518df798b 100644
--- a/Kernel/Net/IPv4Socket.h
+++ b/Kernel/Net/IPv4Socket.h
@@ -40,13 +40,13 @@ public:
virtual bool can_read(OpenFileDescription const&, u64) const override;
virtual bool can_write(OpenFileDescription const&, u64) const override;
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int, Userspace<sockaddr const*>, socklen_t) override;
- virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) override;
+ virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) override;
virtual ErrorOr<void> setsockopt(int level, int option, Userspace<void const*>, socklen_t) override;
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
- bool did_receive(IPv4Address const& peer_address, u16 peer_port, ReadonlyBytes, Time const&);
+ bool did_receive(IPv4Address const& peer_address, u16 peer_port, ReadonlyBytes, Duration const&);
IPv4Address const& local_address() const { return m_local_address; }
u16 local_port() const { return m_local_port; }
@@ -99,7 +99,7 @@ private:
virtual bool is_ipv4() const override { return true; }
ErrorOr<size_t> receive_byte_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, bool blocking);
- ErrorOr<size_t> receive_packet_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking);
+ ErrorOr<size_t> receive_packet_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking);
void set_can_read(bool);
@@ -112,7 +112,7 @@ private:
struct ReceivedPacket {
IPv4Address peer_address;
u16 peer_port;
- Time timestamp;
+ Duration timestamp;
OwnPtr<KBuffer> data;
};
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index f5963e8be2..fc625e0c44 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -333,7 +333,7 @@ DoubleBuffer* LocalSocket::send_buffer_for(OpenFileDescription& description)
return nullptr;
}
-ErrorOr<size_t> LocalSocket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking)
+ErrorOr<size_t> LocalSocket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking)
{
auto* socket_buffer = receive_buffer_for(description);
if (!socket_buffer)
diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h
index 25d1716122..a573248b0a 100644
--- a/Kernel/Net/LocalSocket.h
+++ b/Kernel/Net/LocalSocket.h
@@ -47,7 +47,7 @@ public:
virtual bool can_read(OpenFileDescription const&, u64) const override;
virtual bool can_write(OpenFileDescription const&, u64) const override;
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int, Userspace<sockaddr const*>, socklen_t) override;
- virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) override;
+ virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) override;
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<void> chown(Credentials const&, OpenFileDescription&, UserID, GroupID) override;
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp
index 9ccfd88d84..3d21995267 100644
--- a/Kernel/Net/NetworkAdapter.cpp
+++ b/Kernel/Net/NetworkAdapter.cpp
@@ -95,7 +95,7 @@ void NetworkAdapter::did_receive(ReadonlyBytes payload)
on_receive();
}
-size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp)
+size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, Duration& packet_timestamp)
{
InterruptDisabler disabler;
if (m_packet_queue.is_empty())
diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h
index 6fd6cabbd3..7549e8d8f0 100644
--- a/Kernel/Net/NetworkAdapter.h
+++ b/Kernel/Net/NetworkAdapter.h
@@ -29,7 +29,7 @@ class NetworkAdapter;
using NetworkByteBuffer = AK::Detail::ByteBuffer<1500>;
struct PacketWithTimestamp final : public AtomicRefCounted<PacketWithTimestamp> {
- PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Time timestamp)
+ PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Duration timestamp)
: buffer(move(buffer))
, timestamp(timestamp)
{
@@ -38,7 +38,7 @@ struct PacketWithTimestamp final : public AtomicRefCounted<PacketWithTimestamp>
ReadonlyBytes bytes() { return buffer->bytes(); }
NonnullOwnPtr<KBuffer> buffer;
- Time timestamp;
+ Duration timestamp;
IntrusiveListNode<PacketWithTimestamp, RefPtr<PacketWithTimestamp>> packet_node;
};
@@ -79,7 +79,7 @@ public:
void send(MACAddress const&, ARPPacket const&);
void fill_in_ipv4_header(PacketWithTimestamp&, IPv4Address const&, MACAddress const&, IPv4Address const&, IPv4Protocol, size_t, u8 type_of_service, u8 ttl);
- size_t dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp);
+ size_t dequeue_packet(u8* buffer, size_t buffer_size, Duration& packet_timestamp);
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index a89860452c..2f6ad1b9bd 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/Kernel/Net/NetworkTask.cpp
@@ -26,10 +26,10 @@
namespace Kernel {
static void handle_arp(EthernetFrameHeader const&, size_t frame_size);
-static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Time const& packet_timestamp);
-static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Time const& packet_timestamp);
-static void handle_udp(IPv4Packet const&, Time const& packet_timestamp);
-static void handle_tcp(IPv4Packet const&, Time const& packet_timestamp);
+static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Duration const& packet_timestamp);
+static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Duration const& packet_timestamp);
+static void handle_udp(IPv4Packet const&, Duration const& packet_timestamp);
+static void handle_tcp(IPv4Packet const&, Duration const& packet_timestamp);
static void send_delayed_tcp_ack(TCPSocket& socket);
static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, RefPtr<NetworkAdapter> adapter);
static void flush_delayed_tcp_acks();
@@ -74,7 +74,7 @@ void NetworkTask_main(void*)
};
});
- auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, Time& packet_timestamp) -> size_t {
+ auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, Duration& packet_timestamp) -> size_t {
if (pending_packets == 0)
return 0;
size_t packet_size = 0;
@@ -94,14 +94,14 @@ void NetworkTask_main(void*)
TODO();
auto buffer_region = region_or_error.release_value();
auto buffer = (u8*)buffer_region->vaddr().get();
- Time packet_timestamp;
+ Duration packet_timestamp;
for (;;) {
flush_delayed_tcp_acks();
retransmit_tcp_packets();
size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp);
if (!packet_size) {
- auto timeout_time = Time::from_milliseconds(500);
+ auto timeout_time = Duration::from_milliseconds(500);
auto timeout = Thread::BlockTimeout { false, &timeout_time };
[[maybe_unused]] auto result = packet_wait_queue.wait_on(timeout, "NetworkTask"sv);
continue;
@@ -177,7 +177,7 @@ void handle_arp(EthernetFrameHeader const& eth, size_t frame_size)
}
}
-void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const& packet_timestamp)
+void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Duration const& packet_timestamp)
{
constexpr size_t minimum_ipv4_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet);
if (frame_size < minimum_ipv4_frame_size) {
@@ -222,7 +222,7 @@ void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const&
}
}
-void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
+void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
{
auto& icmp_header = *static_cast<ICMPHeader const*>(ipv4_packet.payload());
dbgln_if(ICMP_DEBUG, "handle_icmp: source={}, destination={}, type={:#02x}, code={:#02x}", ipv4_packet.source().to_string(), ipv4_packet.destination().to_string(), icmp_header.type(), icmp_header.code());
@@ -273,7 +273,7 @@ void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet,
}
}
-void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
+void handle_udp(IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
{
if (ipv4_packet.payload_size() < sizeof(UDPPacket)) {
dbgln("handle_udp: Packet too small ({}, need {})", ipv4_packet.payload_size(), sizeof(UDPPacket));
@@ -367,7 +367,7 @@ void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, Re
routing_decision.adapter->release_packet_buffer(*packet);
}
-void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
+void handle_tcp(IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
{
if (ipv4_packet.payload_size() < sizeof(TCPPacket)) {
dbgln("handle_tcp: IPv4 payload is too small to be a TCP packet ({}, need {})", ipv4_packet.payload_size(), sizeof(TCPPacket));
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index f5e8357a70..7ecda5b41d 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -245,7 +245,7 @@ ErrorOr<size_t> Socket::read(OpenFileDescription& description, u64, UserOrKernel
{
if (is_shut_down_for_reading())
return 0;
- Time t {};
+ Duration t {};
return recvfrom(description, buffer, size, 0, {}, 0, t, description.is_blocking());
}
diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h
index ff071d2d83..ebe42032a8 100644
--- a/Kernel/Net/Socket.h
+++ b/Kernel/Net/Socket.h
@@ -79,7 +79,7 @@ public:
virtual bool is_local() const { return false; }
virtual bool is_ipv4() const { return false; }
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int flags, Userspace<sockaddr const*>, socklen_t) = 0;
- virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) = 0;
+ virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) = 0;
virtual ErrorOr<void> setsockopt(int level, int option, Userspace<void const*>, socklen_t);
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>);
@@ -100,11 +100,11 @@ public:
virtual ErrorOr<struct stat> stat() const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override = 0;
- bool has_receive_timeout() const { return m_receive_timeout != Time::zero(); }
- Time const& receive_timeout() const { return m_receive_timeout; }
+ bool has_receive_timeout() const { return m_receive_timeout != Duration::zero(); }
+ Duration const& receive_timeout() const { return m_receive_timeout; }
- bool has_send_timeout() const { return m_send_timeout != Time::zero(); }
- Time const& send_timeout() const { return m_send_timeout; }
+ bool has_send_timeout() const { return m_send_timeout != Duration::zero(); }
+ Duration const& send_timeout() const { return m_send_timeout; }
bool wants_timestamp() const { return m_timestamp; }
@@ -173,8 +173,8 @@ private:
SpinlockProtected<RefPtr<NetworkAdapter>, LockRank::None> m_bound_interface;
- Time m_receive_timeout {};
- Time m_send_timeout {};
+ Duration m_receive_timeout {};
+ Duration m_send_timeout {};
int m_timestamp { 0 };
SpinlockProtected<Optional<ErrnoCode>, LockRank::None> m_so_error;
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index 5f1dc365fe..2f86cb7719 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -354,7 +354,7 @@ bool TCPSocket::should_delay_next_ack() const
return false;
// RFC 1122 says we should not delay ACKs for more than 500 milliseconds.
- if (kgettimeofday() >= m_last_ack_sent_time + Time::from_milliseconds(500))
+ if (kgettimeofday() >= m_last_ack_sent_time + Duration::from_milliseconds(500))
return false;
return true;
@@ -586,7 +586,7 @@ void TCPSocket::retransmit_packets()
for (decltype(m_retransmit_attempts) i = 0; i < m_retransmit_attempts; i++)
retransmit_interval *= 2;
- if (m_last_retransmit_time > now - Time::from_seconds(retransmit_interval))
+ if (m_last_retransmit_time > now - Duration::from_seconds(retransmit_interval))
return;
dbgln_if(TCP_SOCKET_DEBUG, "TCPSocket({}) handling retransmit", this);
diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h
index a949a0e92b..a110cdf421 100644
--- a/Kernel/Net/TCPSocket.h
+++ b/Kernel/Net/TCPSocket.h
@@ -216,11 +216,11 @@ private:
u32 m_duplicate_acks { 0 };
u32 m_last_ack_number_sent { 0 };
- Time m_last_ack_sent_time;
+ Duration m_last_ack_sent_time;
// FIXME: Make this configurable (sysctl)
static constexpr u32 maximum_retransmits = 5;
- Time m_last_retransmit_time;
+ Duration m_last_retransmit_time;
u32 m_retransmit_attempts { 0 };
// FIXME: Parse window size TCP option from the peer
diff --git a/Kernel/PerformanceManager.h b/Kernel/PerformanceManager.h
index cc41cb9f7f..6de5155739 100644
--- a/Kernel/PerformanceManager.h
+++ b/Kernel/PerformanceManager.h
@@ -164,11 +164,11 @@ public:
static void timer_tick(RegisterState const& regs)
{
- static Time last_wakeup;
+ static Duration last_wakeup;
auto now = kgettimeofday();
- constexpr auto ideal_interval = Time::from_microseconds(1000'000 / OPTIMAL_PROFILE_TICKS_PER_SECOND_RATE);
+ constexpr auto ideal_interval = Duration::from_microseconds(1000'000 / OPTIMAL_PROFILE_TICKS_PER_SECOND_RATE);
auto expected_wakeup = last_wakeup + ideal_interval;
- auto delay = (now > expected_wakeup) ? now - expected_wakeup : Time::from_microseconds(0);
+ auto delay = (now > expected_wakeup) ? now - expected_wakeup : Duration::from_microseconds(0);
last_wakeup = now;
auto* current_thread = Thread::current();
// FIXME: We currently don't collect samples while idle.
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 5ccb1e370d..a597d7876e 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -635,7 +635,7 @@ ErrorOr<Process::ScopedDescriptionAllocation> Process::OpenFileDescriptions::all
return EMFILE;
}
-Time kgettimeofday()
+Duration kgettimeofday()
{
return TimeManagement::now();
}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 14b92e5c49..e35fbb0a82 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -41,7 +41,7 @@
namespace Kernel {
MutexProtected<OwnPtr<KString>>& hostname();
-Time kgettimeofday();
+Duration kgettimeofday();
#define ENUMERATE_PLEDGE_PROMISES \
__ENUMERATE_PLEDGE_PROMISE(stdio) \
diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp
index 19c7ea30c2..6a984710e9 100644
--- a/Kernel/StdLib.cpp
+++ b/Kernel/StdLib.cpp
@@ -39,28 +39,28 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<cha
return new_string;
}
-ErrorOr<Time> copy_time_from_user(timespec const* ts_user)
+ErrorOr<Duration> copy_time_from_user(timespec const* ts_user)
{
timespec ts {};
TRY(copy_from_user(&ts, ts_user, sizeof(timespec)));
- return Time::from_timespec(ts);
+ return Duration::from_timespec(ts);
}
-ErrorOr<Time> copy_time_from_user(timeval const* tv_user)
+ErrorOr<Duration> copy_time_from_user(timeval const* tv_user)
{
timeval tv {};
TRY(copy_from_user(&tv, tv_user, sizeof(timeval)));
- return Time::from_timeval(tv);
+ return Duration::from_timeval(tv);
}
template<>
-ErrorOr<Time> copy_time_from_user<timeval const>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
+ErrorOr<Duration> copy_time_from_user<timeval const>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
template<>
-ErrorOr<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
+ErrorOr<Duration> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
template<>
-ErrorOr<Time> copy_time_from_user<timespec const>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
+ErrorOr<Duration> copy_time_from_user<timespec const>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
template<>
-ErrorOr<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
+ErrorOr<Duration> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
Optional<u32> user_atomic_fetch_add_relaxed(u32 volatile* var, u32 val)
{
diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h
index 09bb646ffd..7cdd2986ea 100644
--- a/Kernel/StdLib.h
+++ b/Kernel/StdLib.h
@@ -15,10 +15,10 @@
#include <Kernel/UnixTypes.h>
ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<char const*>, size_t);
-ErrorOr<Time> copy_time_from_user(timespec const*);
-ErrorOr<Time> copy_time_from_user(timeval const*);
+ErrorOr<Duration> copy_time_from_user(timespec const*);
+ErrorOr<Duration> copy_time_from_user(timeval const*);
template<typename T>
-ErrorOr<Time> copy_time_from_user(Userspace<T*>);
+ErrorOr<Duration> copy_time_from_user(Userspace<T*>);
[[nodiscard]] Optional<u32> user_atomic_fetch_add_relaxed(u32 volatile* var, u32 val);
[[nodiscard]] Optional<u32> user_atomic_exchange_relaxed(u32 volatile* var, u32 val);
diff --git a/Kernel/Storage/NVMe/NVMeController.cpp b/Kernel/Storage/NVMe/NVMeController.cpp
index 89d2dd2e7d..d2753e9af0 100644
--- a/Kernel/Storage/NVMe/NVMeController.cpp
+++ b/Kernel/Storage/NVMe/NVMeController.cpp
@@ -50,7 +50,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::initialize(bool is_queue_polled)
m_controller_regs = TRY(Memory::map_typed_writable<ControllerRegister volatile>(PhysicalAddress(m_bar)));
auto caps = m_controller_regs->cap;
- m_ready_timeout = Time::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units
+ m_ready_timeout = Duration::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units
calculate_doorbell_stride();
// IO queues + 1 admin queue
diff --git a/Kernel/Storage/NVMe/NVMeController.h b/Kernel/Storage/NVMe/NVMeController.h
index 50c8428ec7..072e97aeb7 100644
--- a/Kernel/Storage/NVMe/NVMeController.h
+++ b/Kernel/Storage/NVMe/NVMeController.h
@@ -74,7 +74,7 @@ private:
Memory::TypedMapping<ControllerRegister volatile> m_controller_regs;
bool m_admin_queue_ready { false };
size_t m_device_count { 0 };
- AK::Time m_ready_timeout;
+ AK::Duration m_ready_timeout;
u32 m_bar { 0 };
u8 m_dbl_stride { 0 };
PCI::InterruptType m_irq_type;
diff --git a/Kernel/Syscalls/alarm.cpp b/Kernel/Syscalls/alarm.cpp
index 66ddc5211a..169dd070c8 100644
--- a/Kernel/Syscalls/alarm.cpp
+++ b/Kernel/Syscalls/alarm.cpp
@@ -20,7 +20,7 @@ ErrorOr<FlatPtr> Process::sys$alarm(unsigned seconds)
bool was_in_use = false;
if (TimerQueue::the().cancel_timer(*timer, &was_in_use)) {
// The timer hasn't fired. Round up the remaining time (if any)
- Time remaining = timer->remaining() + Time::from_nanoseconds(999'999'999);
+ Duration remaining = timer->remaining() + Duration::from_nanoseconds(999'999'999);
previous_alarm_remaining = remaining.to_truncated_seconds();
}
// We had an existing alarm, must return a non-zero value here!
@@ -30,7 +30,7 @@ ErrorOr<FlatPtr> Process::sys$alarm(unsigned seconds)
if (seconds > 0) {
auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
- deadline = deadline + Time::from_seconds(seconds);
+ deadline = deadline + Duration::from_seconds(seconds);
if (!timer) {
timer = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Timer));
}
diff --git a/Kernel/Syscalls/beep.cpp b/Kernel/Syscalls/beep.cpp
index bc9a4f24b0..7c4f547e17 100644
--- a/Kernel/Syscalls/beep.cpp
+++ b/Kernel/Syscalls/beep.cpp
@@ -21,7 +21,7 @@ ErrorOr<FlatPtr> Process::sys$beep(int tone)
return EINVAL;
#if ARCH(X86_64)
PCSpeaker::tone_on(tone);
- auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
+ auto result = Thread::current()->sleep(Duration::from_nanoseconds(200'000'000));
PCSpeaker::tone_off();
if (result.was_interrupted())
return EINTR;
diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp
index b8ab20c97f..8d574ab4ea 100644
--- a/Kernel/Syscalls/clock.cpp
+++ b/Kernel/Syscalls/clock.cpp
@@ -82,7 +82,7 @@ ErrorOr<FlatPtr> Process::sys$clock_nanosleep(Userspace<Syscall::SC_clock_nanosl
if (is_absolute) {
was_interrupted = Thread::current()->sleep_until(params.clock_id, requested_sleep).was_interrupted();
} else {
- Time remaining_sleep;
+ Duration remaining_sleep;
was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep, &remaining_sleep).was_interrupted();
timespec remaining_sleep_ts = remaining_sleep.to_timespec();
if (was_interrupted && params.remaining_sleep) {
@@ -123,7 +123,7 @@ ErrorOr<FlatPtr> Process::sys$adjtime(Userspace<timeval const*> user_delta, User
return EPERM;
auto delta = TRY(copy_time_from_user(user_delta));
- // FIXME: Should use AK::Time internally
+ // FIXME: Should use AK::Duration internally
TimeManagement::the().set_remaining_epoch_time_adjustment(delta.to_timespec());
}
diff --git a/Kernel/Syscalls/resource.cpp b/Kernel/Syscalls/resource.cpp
index b7ab629632..fd3976ebcf 100644
--- a/Kernel/Syscalls/resource.cpp
+++ b/Kernel/Syscalls/resource.cpp
@@ -19,12 +19,12 @@ ErrorOr<FlatPtr> Process::sys$getrusage(int who, Userspace<rusage*> user_usage)
switch (who) {
case RUSAGE_SELF:
- usage.ru_utime = Time::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
- usage.ru_stime = Time::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
+ usage.ru_utime = Duration::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
+ usage.ru_stime = Duration::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
break;
case RUSAGE_CHILDREN:
- usage.ru_utime = Time::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
- usage.ru_stime = Time::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
+ usage.ru_utime = Duration::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
+ usage.ru_stime = Duration::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
break;
default:
return EINVAL;
diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp
index d7746ab468..10ab6748f6 100644
--- a/Kernel/Syscalls/socket.cpp
+++ b/Kernel/Syscalls/socket.cpp
@@ -272,7 +272,7 @@ ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user
return 0;
auto data_buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)iovs[0].iov_base, iovs[0].iov_len));
- Time timestamp {};
+ Duration timestamp {};
bool blocking = (flags & MSG_DONTWAIT) ? false : description->is_blocking();
auto result = socket.recvfrom(*description, data_buffer, iovs[0].iov_len, flags, user_addr, user_addr_length, timestamp, blocking);
diff --git a/Kernel/Tasks/SyncTask.cpp b/Kernel/Tasks/SyncTask.cpp
index 973cbe5786..b4715a11eb 100644
--- a/Kernel/Tasks/SyncTask.cpp
+++ b/Kernel/Tasks/SyncTask.cpp
@@ -18,7 +18,7 @@ UNMAP_AFTER_INIT void SyncTask::spawn()
dbgln("VFS SyncTask is running");
for (;;) {
VirtualFileSystem::sync();
- (void)Thread::current()->sleep(Time::from_seconds(1));
+ (void)Thread::current()->sleep(Duration::from_seconds(1));
}
}));
}
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index f5df3a1374..d7ab03840b 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -495,14 +495,14 @@ void Thread::relock_process(LockMode previous_locked, u32 lock_count_to_restore)
}
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
-auto Thread::sleep(clockid_t clock_id, Time const& duration, Time* remaining_time) -> BlockResult
+auto Thread::sleep(clockid_t clock_id, Duration const& duration, Duration* remaining_time) -> BlockResult
{
VERIFY(state() == Thread::State::Running);
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time);
}
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
-auto Thread::sleep_until(clockid_t clock_id, Time const& deadline) -> BlockResult
+auto Thread::sleep_until(clockid_t clock_id, Duration const& deadline) -> BlockResult
{
VERIFY(state() == Thread::State::Running);
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(true, &deadline, nullptr, clock_id));
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index 8e8b9d7d32..a13259e5e6 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -159,16 +159,16 @@ public:
: m_infinite(true)
{
}
- explicit BlockTimeout(bool is_absolute, Time const* time, Time const* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE);
+ explicit BlockTimeout(bool is_absolute, Duration const* time, Duration const* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE);
- Time const& absolute_time() const { return m_time; }
- Time const* start_time() const { return !m_infinite ? &m_start_time : nullptr; }
+ Duration const& absolute_time() const { return m_time; }
+ Duration const* start_time() const { return !m_infinite ? &m_start_time : nullptr; }
clockid_t clock_id() const { return m_clock_id; }
bool is_infinite() const { return m_infinite; }
private:
- Time m_time {};
- Time m_start_time {};
+ Duration m_time {};
+ Duration m_start_time {};
clockid_t m_clock_id { CLOCK_MONOTONIC_COARSE };
bool m_infinite { false };
};
@@ -559,7 +559,7 @@ public:
class SleepBlocker final : public Blocker {
public:
- explicit SleepBlocker(BlockTimeout const&, Time* = nullptr);
+ explicit SleepBlocker(BlockTimeout const&, Duration* = nullptr);
virtual StringView state_string() const override { return "Sleeping"sv; }
virtual Type blocker_type() const override { return Type::Sleep; }
virtual BlockTimeout const& override_timeout(BlockTimeout const&) override;
@@ -571,7 +571,7 @@ public:
void calculate_remaining();
BlockTimeout m_deadline;
- Time* m_remaining;
+ Duration* m_remaining;
};
class SelectBlocker final : public FileBlocker {
@@ -824,13 +824,13 @@ public:
return block<Thread::WaitQueueBlocker>(timeout, wait_queue, forward<Args>(args)...);
}
- BlockResult sleep(clockid_t, Time const&, Time* = nullptr);
- BlockResult sleep(Time const& duration, Time* remaining_time = nullptr)
+ BlockResult sleep(clockid_t, Duration const&, Duration* = nullptr);
+ BlockResult sleep(Duration const& duration, Duration* remaining_time = nullptr)
{
return sleep(CLOCK_MONOTONIC_COARSE, duration, remaining_time);
}
- BlockResult sleep_until(clockid_t, Time const&);
- BlockResult sleep_until(Time const& duration)
+ BlockResult sleep_until(clockid_t, Duration const&);
+ BlockResult sleep_until(Duration const& duration)
{
return sleep_until(CLOCK_MONOTONIC_COARSE, duration);
}
diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp
index 3035701d04..50e0b8b736 100644
--- a/Kernel/ThreadBlockers.cpp
+++ b/Kernel/ThreadBlockers.cpp
@@ -15,13 +15,13 @@
namespace Kernel {
-Thread::BlockTimeout::BlockTimeout(bool is_absolute, Time const* time, Time const* start_time, clockid_t clock_id)
+Thread::BlockTimeout::BlockTimeout(bool is_absolute, Duration const* time, Duration const* start_time, clockid_t clock_id)
: m_clock_id(clock_id)
, m_infinite(!time)
{
if (m_infinite)
return;
- if (*time > Time::zero())
+ if (*time > Duration::zero())
m_time = *time;
m_start_time = start_time ? *start_time : TimeManagement::the().current_time(clock_id);
if (!is_absolute)
@@ -272,7 +272,7 @@ auto Thread::WriteBlocker::override_timeout(BlockTimeout const& timeout) -> Bloc
if (description.is_socket()) {
auto const& socket = *description.socket();
if (socket.has_send_timeout()) {
- Time send_timeout = socket.send_timeout();
+ Duration send_timeout = socket.send_timeout();
m_timeout = BlockTimeout(false, &send_timeout, timeout.start_time(), timeout.clock_id());
if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time()))
return m_timeout;
@@ -292,7 +292,7 @@ auto Thread::ReadBlocker::override_timeout(BlockTimeout const& timeout) -> Block
if (description.is_socket()) {
auto const& socket = *description.socket();
if (socket.has_receive_timeout()) {
- Time receive_timeout = socket.receive_timeout();
+ Duration receive_timeout = socket.receive_timeout();
m_timeout = BlockTimeout(false, &receive_timeout, timeout.start_time(), timeout.clock_id());
if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time()))
return m_timeout;
@@ -301,7 +301,7 @@ auto Thread::ReadBlocker::override_timeout(BlockTimeout const& timeout) -> Block
return timeout;
}
-Thread::SleepBlocker::SleepBlocker(BlockTimeout const& deadline, Time* remaining)
+Thread::SleepBlocker::SleepBlocker(BlockTimeout const& deadline, Duration* remaining)
: m_deadline(deadline)
, m_remaining(remaining)
{
diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp
index 7dd87343f7..31cb2085b5 100644
--- a/Kernel/Time/TimeManagement.cpp
+++ b/Kernel/Time/TimeManagement.cpp
@@ -77,7 +77,7 @@ ErrorOr<void> TimeManagement::validate_clock_id(clockid_t clock_id)
};
}
-Time TimeManagement::current_time(clockid_t clock_id) const
+Duration TimeManagement::current_time(clockid_t clock_id) const
{
switch (clock_id) {
case CLOCK_MONOTONIC:
@@ -101,15 +101,15 @@ bool TimeManagement::is_system_timer(HardwareTimerBase const& timer) const
return &timer == m_system_timer.ptr();
}
-void TimeManagement::set_epoch_time(Time ts)
+void TimeManagement::set_epoch_time(Duration ts)
{
InterruptDisabler disabler;
- // FIXME: Should use AK::Time internally
+ // FIXME: Should use AK::Duration internally
m_epoch_time = ts.to_timespec();
m_remaining_epoch_time_adjustment = { 0, 0 };
}
-Time TimeManagement::monotonic_time(TimePrecision precision) const
+Duration TimeManagement::monotonic_time(TimePrecision precision) const
{
// This is the time when last updated by an interrupt.
u64 seconds;
@@ -144,10 +144,10 @@ Time TimeManagement::monotonic_time(TimePrecision precision) const
VERIFY(ticks < m_time_ticks_per_second);
u64 ns = ((u64)ticks * 1000000000ull) / m_time_ticks_per_second;
VERIFY(ns < 1000000000ull);
- return Time::from_timespec({ (i64)seconds, (i32)ns });
+ return Duration::from_timespec({ (i64)seconds, (i32)ns });
}
-Time TimeManagement::epoch_time(TimePrecision) const
+Duration TimeManagement::epoch_time(TimePrecision) const
{
// TODO: Take into account precision
timespec ts;
@@ -156,7 +156,7 @@ Time TimeManagement::epoch_time(TimePrecision) const
update_iteration = m_update1.load(AK::MemoryOrder::memory_order_acquire);
ts = m_epoch_time;
} while (update_iteration != m_update2.load(AK::MemoryOrder::memory_order_acquire));
- return Time::from_timespec(ts);
+ return Duration::from_timespec(ts);
}
u64 TimeManagement::uptime_ms() const
@@ -186,14 +186,14 @@ UNMAP_AFTER_INIT void TimeManagement::initialize([[maybe_unused]] u32 cpu)
// would trigger a deadlock trying to get the s_the instance while
// creating it.
if (auto* apic_timer = APIC::the().initialize_timers(*s_the->m_system_timer)) {
- dmesgln("Time: Using APIC timer as system timer");
+ dmesgln("Duration: Using APIC timer as system timer");
s_the->set_system_timer(*apic_timer);
}
}
} else {
VERIFY(s_the.is_initialized());
if (auto* apic_timer = APIC::the().get_timer()) {
- dmesgln("Time: Enable APIC timer on CPU #{}", cpu);
+ dmesgln("Duration: Enable APIC timer on CPU #{}", cpu);
apic_timer->enable_local_timer();
}
}
@@ -226,26 +226,26 @@ time_t TimeManagement::ticks_per_second() const
return m_time_keeper_timer->ticks_per_second();
}
-Time TimeManagement::boot_time()
+Duration TimeManagement::boot_time()
{
#if ARCH(X86_64)
return RTC::boot_time();
#elif ARCH(AARCH64)
// FIXME: Return correct boot time
- return Time::from_seconds(0);
+ return Duration::from_seconds(0);
#else
# error Unknown architecture
#endif
}
-Time TimeManagement::clock_resolution() const
+Duration TimeManagement::clock_resolution() const
{
long nanoseconds_per_tick = 1'000'000'000 / m_time_keeper_timer->ticks_per_second();
- return Time::from_nanoseconds(nanoseconds_per_tick);
+ return Duration::from_nanoseconds(nanoseconds_per_tick);
}
UNMAP_AFTER_INIT TimeManagement::TimeManagement()
- : m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
+ : m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Duration page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
{
#if ARCH(X86_64)
bool probe_non_legacy_hardware_timers = !(kernel_command_line().is_legacy_time_enabled());
@@ -275,7 +275,7 @@ UNMAP_AFTER_INIT TimeManagement::TimeManagement()
#endif
}
-Time TimeManagement::now()
+Duration TimeManagement::now()
{
return s_the.ptr()->epoch_time();
}
@@ -283,7 +283,7 @@ Time TimeManagement::now()
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_periodic_timers()
{
bool should_enable = is_hpet_periodic_mode_allowed();
- dbgln("Time: Scanning for periodic timers");
+ dbgln("Duration: Scanning for periodic timers");
Vector<HardwareTimerBase*> timers;
for (auto& hardware_timer : m_hardware_timers) {
if (hardware_timer->is_periodic_capable()) {
@@ -297,7 +297,7 @@ UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_for_non_periodic_timers()
{
- dbgln("Time: Scanning for non-periodic timers");
+ dbgln("Duration: Scanning for non-periodic timers");
Vector<HardwareTimerBase*> timers;
for (auto& hardware_timer : m_hardware_timers) {
if (!hardware_timer->is_periodic_capable())
diff --git a/Kernel/Time/TimeManagement.h b/Kernel/Time/TimeManagement.h
index 4c073614fa..75c161559c 100644
--- a/Kernel/Time/TimeManagement.h
+++ b/Kernel/Time/TimeManagement.h
@@ -41,18 +41,18 @@ public:
static u64 scheduler_current_time();
static ErrorOr<void> validate_clock_id(clockid_t);
- Time current_time(clockid_t) const;
- Time monotonic_time(TimePrecision = TimePrecision::Coarse) const;
- Time monotonic_time_raw() const
+ Duration current_time(clockid_t) const;
+ Duration monotonic_time(TimePrecision = TimePrecision::Coarse) const;
+ Duration monotonic_time_raw() const
{
// TODO: implement
return monotonic_time(TimePrecision::Precise);
}
- Time epoch_time(TimePrecision = TimePrecision::Precise) const;
- void set_epoch_time(Time);
+ Duration epoch_time(TimePrecision = TimePrecision::Precise) const;
+ void set_epoch_time(Duration);
time_t ticks_per_second() const;
- static Time boot_time();
- Time clock_resolution() const;
+ static Duration boot_time();
+ Duration clock_resolution() const;
bool is_system_timer(HardwareTimerBase const&) const;
@@ -64,12 +64,12 @@ public:
bool disable_profile_timer();
u64 uptime_ms() const;
- static Time now();
+ static Duration now();
- // FIXME: Should use AK::Time internally
+ // FIXME: Should use AK::Duration internally
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
timespec remaining_epoch_time_adjustment() const { return m_remaining_epoch_time_adjustment; }
- // FIXME: Should use AK::Time internally
+ // FIXME: Should use AK::Duration internally
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
void set_remaining_epoch_time_adjustment(timespec const& adjustment) { m_remaining_epoch_time_adjustment = adjustment; }
@@ -102,7 +102,7 @@ private:
Atomic<u32> m_update1 { 0 };
u32 m_ticks_this_second { 0 };
u64 m_seconds_since_boot { 0 };
- // FIXME: Should use AK::Time internally
+ // FIXME: Should use AK::Duration internally
timespec m_epoch_time { 0, 0 };
timespec m_remaining_epoch_time_adjustment { 0, 0 };
Atomic<u32> m_update2 { 0 };
diff --git a/Kernel/TimerQueue.cpp b/Kernel/TimerQueue.cpp
index bcb7001e74..599ecf6248 100644
--- a/Kernel/TimerQueue.cpp
+++ b/Kernel/TimerQueue.cpp
@@ -16,12 +16,12 @@ namespace Kernel {
static Singleton<TimerQueue> s_the;
static Spinlock<LockRank::None> g_timerqueue_lock {};
-Time Timer::remaining() const
+Duration Timer::remaining() const
{
return m_remaining;
}
-Time Timer::now(bool is_firing) const
+Duration Timer::now(bool is_firing) const
{
// NOTE: If is_firing is true then TimePrecision::Precise isn't really useful here.
// We already have a quite precise time stamp because we just updated the time in the
@@ -55,7 +55,7 @@ UNMAP_AFTER_INIT TimerQueue::TimerQueue()
m_ticks_per_second = TimeManagement::the().ticks_per_second();
}
-bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, Time const& deadline, Function<void()>&& callback)
+bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, Duration const& deadline, Function<void()>&& callback)
{
if (deadline <= TimeManagement::the().current_time(clock_id))
return false;
@@ -86,7 +86,7 @@ TimerId TimerQueue::add_timer(NonnullRefPtr<Timer>&& timer)
void TimerQueue::add_timer_locked(NonnullRefPtr<Timer> timer)
{
- Time timer_expiration = timer->m_expires;
+ Duration timer_expiration = timer->m_expires;
timer->clear_cancelled();
timer->clear_callback_finished();
diff --git a/Kernel/TimerQueue.h b/Kernel/TimerQueue.h
index 049f95b1da..7258c33eca 100644
--- a/Kernel/TimerQueue.h
+++ b/Kernel/TimerQueue.h
@@ -22,7 +22,7 @@ class Timer final : public AtomicRefCounted<Timer> {
friend class TimerQueue;
public:
- void setup(clockid_t clock_id, Time expires, Function<void()>&& callback)
+ void setup(clockid_t clock_id, Duration expires, Function<void()>&& callback)
{
VERIFY(!is_queued());
m_clock_id = clock_id;
@@ -35,13 +35,13 @@ public:
VERIFY(!is_queued());
}
- Time remaining() const;
+ Duration remaining() const;
private:
TimerId m_id;
clockid_t m_clock_id;
- Time m_expires;
- Time m_remaining {};
+ Duration m_expires;
+ Duration m_remaining {};
Function<void()> m_callback;
Atomic<bool> m_cancelled { false };
Atomic<bool> m_callback_finished { false };
@@ -71,7 +71,7 @@ private:
void clear_callback_finished() { m_callback_finished.store(false, AK::memory_order_release); }
void set_callback_finished() { m_callback_finished.store(true, AK::memory_order_release); }
- Time now(bool) const;
+ Duration now(bool) const;
bool is_queued() const { return m_list_node.is_in_list(); }
@@ -88,14 +88,14 @@ public:
static TimerQueue& the();
TimerId add_timer(NonnullRefPtr<Timer>&&);
- bool add_timer_without_id(NonnullRefPtr<Timer>, clockid_t, Time const&, Function<void()>&&);
+ bool add_timer_without_id(NonnullRefPtr<Timer>, clockid_t, Duration const&, Function<void()>&&);
bool cancel_timer(Timer& timer, bool* was_in_use = nullptr);
void fire();
private:
struct Queue {
Timer::List list;
- Time next_timer_due {};
+ Duration next_timer_due {};
};
void remove_timer_locked(Queue&, Timer&);
void update_next_timer_due(Queue&);
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp
index 16d7049af4..4005941f94 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp
@@ -110,7 +110,7 @@ struct AK::Formatter<DaylightSavingsOffset> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
{
auto format_time = [&](auto year) {
- return DeprecatedString::formatted("AK::Time::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
+ return DeprecatedString::formatted("AK::Duration::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
};
static DeprecatedString max_year_as_time("max_year_as_time"sv);
@@ -494,13 +494,13 @@ static ErrorOr<void> generate_time_zone_data_implementation(Core::InputBufferedF
namespace TimeZone {
-static constexpr auto max_year_as_time = AK::Time::from_timestamp(NumericLimits<u16>::max(), 1, 1, 0, 0, 0, 0);
+static constexpr auto max_year_as_time = AK::Duration::from_timestamp(NumericLimits<u16>::max(), 1, 1, 0, 0, 0, 0);
struct DateTime {
- AK::Time time_since_epoch() const
+ AK::Duration time_since_epoch() const
{
// FIXME: This implementation does not take last_weekday, after_weekday, or before_weekday into account.
- return AK::Time::from_timestamp(year, month, day, hour, minute, second, 0);
+ return AK::Duration::from_timestamp(year, month, day, hour, minute, second, 0);
}
u16 year { 0 };
@@ -530,7 +530,7 @@ struct TimeZoneOffset {
};
struct DaylightSavingsOffset {
- AK::Time time_in_effect(AK::Time time) const
+ AK::Duration time_in_effect(AK::Duration time) const
{
auto in_effect = this->in_effect;
in_effect.year = seconds_since_epoch_to_year(time.to_seconds());
@@ -539,8 +539,8 @@ struct DaylightSavingsOffset {
}
i64 offset { 0 };
- AK::Time year_from {};
- AK::Time year_to {};
+ AK::Duration year_from {};
+ AK::Duration year_to {};
DateTime in_effect {};
@string_index_type@ format { 0 };
@@ -635,7 +635,7 @@ static constexpr Array<Location, @size@> s_time_zone_locations { {
TRY(append_string_conversions("Region"sv, "region"sv, time_zone_data.time_zone_region_names));
generator.append(R"~~~(
-static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset const& time_zone_offset, AK::Time time)
+static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset const& time_zone_offset, AK::Duration time)
{
auto const& dst_rules = s_dst_offsets[time_zone_offset.dst_rule];
@@ -677,7 +677,7 @@ static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset co
return { standard_offset, daylight_offset ? daylight_offset : standard_offset };
}
-static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Time time)
+static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Duration time)
{
auto offsets = find_dst_offsets(time_zone_offset, time);
if (offsets[0] == offsets[1])
@@ -697,7 +697,7 @@ static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::
return { offsets[1]->offset, InDST::Yes };
}
-static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Time time)
+static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Duration time)
{
auto const& time_zone_offsets = s_time_zone_offsets[to_underlying(time_zone)];
@@ -713,7 +713,7 @@ static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Time
return time_zone_offsets[index];
}
-Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
+Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Duration time)
{
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
@@ -729,7 +729,7 @@ Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
return dst_offset;
}
-Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time)
+Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Duration time)
{
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
Array<NamedOffset, 2> named_offsets;
diff --git a/Ports/SDL2/patches/0001-Add-SerenityOS-platform-support.patch b/Ports/SDL2/patches/0001-Add-SerenityOS-platform-support.patch
index fbf7fd979f..6da2d106a8 100644
--- a/Ports/SDL2/patches/0001-Add-SerenityOS-platform-support.patch
+++ b/Ports/SDL2/patches/0001-Add-SerenityOS-platform-support.patch
@@ -316,7 +316,7 @@ index 0000000000000000000000000000000000000000..e1cd5348b67c23c49b25f99f4f36e020
+ return (static_cast<double>(input) - NumericLimits<i16>::min()) / NumericLimits<u16>::max() * 2. - 1.;
+ };
+
-+ auto const sleep_spec = Time::from_nanoseconds(100).to_timespec();
++ auto const sleep_spec = Duration::from_nanoseconds(100).to_timespec();
+ auto input_buffer = reinterpret_cast<i16*>(h->mixbuf);
+ auto input_samples = h->mixlen / that->spec.channels / sizeof(i16);
+ size_t input_position = 0;
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt
index 8a8622a316..258acdc2ac 100644
--- a/Tests/AK/CMakeLists.txt
+++ b/Tests/AK/CMakeLists.txt
@@ -74,7 +74,7 @@ set(AK_TEST_SOURCES
TestStringFloatingPointConversions.cpp
TestStringUtils.cpp
TestStringView.cpp
- TestTime.cpp
+ TestDuration.cpp
TestTrie.cpp
TestTuple.cpp
TestTypeTraits.cpp
diff --git a/Tests/AK/TestTime.cpp b/Tests/AK/TestDuration.cpp
index 00df305701..d3f3b3dad6 100644
--- a/Tests/AK/TestTime.cpp
+++ b/Tests/AK/TestDuration.cpp
@@ -9,7 +9,7 @@
#include <AK/Time.h>
#include <sys/time.h>
-#define EXPECT_TIME(t, s, ns) \
+#define EXPECT_DURATION(t, s, ns) \
do { \
auto ts = (t).to_timespec(); \
EXPECT_EQ(ts.tv_sec, (s)); \
@@ -18,116 +18,116 @@
TEST_CASE(is_sane)
{
- auto t0 = Time::from_seconds(0);
- auto t2 = Time::from_seconds(2);
- auto t5 = Time::from_seconds(5);
- auto tn3 = Time::from_seconds(-3);
+ auto t0 = Duration::from_seconds(0);
+ auto t2 = Duration::from_seconds(2);
+ auto t5 = Duration::from_seconds(5);
+ auto tn3 = Duration::from_seconds(-3);
EXPECT(t0 == t0);
EXPECT(t2 == t2);
EXPECT(t5 == t5);
EXPECT(t0 != t2);
EXPECT(t2 != tn3);
EXPECT(t2 != t5);
- EXPECT_TIME(t0, 0, 0);
- EXPECT_TIME(t2, 2, 0);
- EXPECT_TIME(t5, 5, 0);
- EXPECT_TIME(t2 + t5, 7, 0);
- EXPECT_TIME(tn3 + t2, -1, 0);
- EXPECT_TIME(tn3 + t5, 2, 0);
+ EXPECT_DURATION(t0, 0, 0);
+ EXPECT_DURATION(t2, 2, 0);
+ EXPECT_DURATION(t5, 5, 0);
+ EXPECT_DURATION(t2 + t5, 7, 0);
+ EXPECT_DURATION(tn3 + t2, -1, 0);
+ EXPECT_DURATION(tn3 + t5, 2, 0);
}
TEST_CASE(limits)
{
- EXPECT_TIME(Time::min(), (i64)-0x8000'0000'0000'0000, 0);
- EXPECT_TIME(Time::max(), 0x7fff'ffff'ffff'ffff, 999'999'999);
+ EXPECT_DURATION(Duration::min(), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::max(), 0x7fff'ffff'ffff'ffff, 999'999'999);
}
TEST_CASE(seconds_parsing)
{
- EXPECT_TIME(Time::from_seconds(0), 0, 0);
- EXPECT_TIME(Time::from_seconds(42), 42, 0);
- EXPECT_TIME(Time::from_seconds(-1), -1, 0);
+ EXPECT_DURATION(Duration::from_seconds(0), 0, 0);
+ EXPECT_DURATION(Duration::from_seconds(42), 42, 0);
+ EXPECT_DURATION(Duration::from_seconds(-1), -1, 0);
// "6.4.4.1.5: The type of an integer constant is the first of the corresponding list in which its value can be represented."
// In the case of "0x8000'0000", the list is "int, unsigned int, …", and unsigned int (u32) matches.
// Then the unary minus: On unsigned 32-bit integers, -0x8000'0000 == 0x8000'0000, which only then is made signed again.
// So we would pass a medium-large *positive* number to 'from_seconds', which is not what we want to test here.
// That's why this is the only place that needs an "LL" suffix.
- EXPECT_TIME(Time::from_seconds(-0x8000'0000LL), -0x8000'0000LL, 0);
- EXPECT_TIME(Time::from_seconds(-0x8000'0000'0000'0000), (i64)-0x8000'0000'0000'0000, 0);
- EXPECT_TIME(Time::from_seconds(0x7fff'ffff'ffff'ffff), 0x7fff'ffff'ffff'ffff, 0);
+ EXPECT_DURATION(Duration::from_seconds(-0x8000'0000LL), -0x8000'0000LL, 0);
+ EXPECT_DURATION(Duration::from_seconds(-0x8000'0000'0000'0000), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::from_seconds(0x7fff'ffff'ffff'ffff), 0x7fff'ffff'ffff'ffff, 0);
}
TEST_CASE(timespec_parsing)
{
- EXPECT_TIME(Time::from_timespec(timespec { 2, 4 }), 2, 4);
- EXPECT_TIME(Time::from_timespec(timespec { 1234, 5678 }), 1234, 5678);
-
- EXPECT_TIME(Time::from_timespec(timespec { 0, 1'000'000'000 }), 1, 0);
- EXPECT_TIME(Time::from_timespec(timespec { 8, 2'000'000'000 }), 10, 0);
- EXPECT_TIME(Time::from_timespec(timespec { 0, 2'147'483'647 }), 2, 147'483'647);
-
- EXPECT_TIME(Time::from_timespec(timespec { 1, -1 }), 0, 999'999'999);
- EXPECT_TIME(Time::from_timespec(timespec { 0, -1 }), -1, 999'999'999);
- EXPECT_TIME(Time::from_timespec(timespec { -1, 0 }), -1, 0);
- EXPECT_TIME(Time::from_timespec(timespec { -1, 1'000'000'001 }), 0, 1);
- EXPECT_TIME(Time::from_timespec(timespec { -2, 2'000'000'003 }), 0, 3);
- EXPECT_TIME(Time::from_timespec(timespec { -2, 1'999'999'999 }), -1, 999'999'999);
-
- EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 999'999'998 }), 0x7fff'ffff'ffff'fffe, 999'999'998);
- EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'998 }), 0x7fff'ffff'ffff'ffff, 999'999'998);
- EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
- EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 2'000'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
-
- EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'999);
- EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -999'999'999 }), -0x7fff'ffff'ffff'ffff, 1);
- EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1'999'999'999 }), (i64)-0x8000'0000'0000'0000, 1);
- EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
- EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 2, 4 }), 2, 4);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 1234, 5678 }), 1234, 5678);
+
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0, 1'000'000'000 }), 1, 0);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 8, 2'000'000'000 }), 10, 0);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0, 2'147'483'647 }), 2, 147'483'647);
+
+ EXPECT_DURATION(Duration::from_timespec(timespec { 1, -1 }), 0, 999'999'999);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0, -1 }), -1, 999'999'999);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -1, 0 }), -1, 0);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -1, 1'000'000'001 }), 0, 1);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -2, 2'000'000'003 }), 0, 3);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -2, 1'999'999'999 }), -1, 999'999'999);
+
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 999'999'998 }), 0x7fff'ffff'ffff'fffe, 999'999'998);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'998 }), 0x7fff'ffff'ffff'ffff, 999'999'998);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
+ EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 2'000'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
+
+ EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'999);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -999'999'999 }), -0x7fff'ffff'ffff'ffff, 1);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1'999'999'999 }), (i64)-0x8000'0000'0000'0000, 1);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
}
TEST_CASE(timeval_parsing)
{
- EXPECT_TIME(Time::from_timeval(timeval { 2, 4 }), 2, 4'000);
- EXPECT_TIME(Time::from_timeval(timeval { 1234, 5'678 }), 1234, 5'678'000);
- EXPECT_TIME(Time::from_timeval(timeval { -123, -45'678 }), -124, 954'322'000);
-
- EXPECT_TIME(Time::from_timeval(timeval { 0, 1'000'000 }), 1, 0);
- EXPECT_TIME(Time::from_timeval(timeval { 0, 1'000'000'000 }), 1'000, 0);
- EXPECT_TIME(Time::from_timeval(timeval { 8, 2'000'000 }), 10, 0);
- EXPECT_TIME(Time::from_timeval(timeval { 0, 2'147'483'647 }), 2'147, 483'647'000);
-
- EXPECT_TIME(Time::from_timeval(timeval { 1, -1 }), 0, 999'999'000);
- EXPECT_TIME(Time::from_timeval(timeval { 0, -1 }), -1, 999'999'000);
- EXPECT_TIME(Time::from_timeval(timeval { -1, 0 }), -1, 0);
- EXPECT_TIME(Time::from_timeval(timeval { -1, 1'000'001 }), 0, 1'000);
- EXPECT_TIME(Time::from_timeval(timeval { -2, 2'000'003 }), 0, 3'000);
- EXPECT_TIME(Time::from_timeval(timeval { -2, 1'999'999 }), -1, 999'999'000);
-
- EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 999'998 }), 0x7fff'ffff'ffff'fffe, 999'998'000);
- EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'998 }), 0x7fff'ffff'ffff'ffff, 999'998'000);
- EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'000);
- EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 2'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
-
- EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'000);
- EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -999'999 }), -0x7fff'ffff'ffff'ffff, 1'000);
- EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1'999'999 }), (i64)-0x8000'0000'0000'0000, 1'000);
- EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
- EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 2, 4 }), 2, 4'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 1234, 5'678 }), 1234, 5'678'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -123, -45'678 }), -124, 954'322'000);
+
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0, 1'000'000 }), 1, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0, 1'000'000'000 }), 1'000, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 8, 2'000'000 }), 10, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0, 2'147'483'647 }), 2'147, 483'647'000);
+
+ EXPECT_DURATION(Duration::from_timeval(timeval { 1, -1 }), 0, 999'999'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0, -1 }), -1, 999'999'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -1, 0 }), -1, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -1, 1'000'001 }), 0, 1'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -2, 2'000'003 }), 0, 3'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -2, 1'999'999 }), -1, 999'999'000);
+
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 999'998 }), 0x7fff'ffff'ffff'fffe, 999'998'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'998 }), 0x7fff'ffff'ffff'ffff, 999'998'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 2'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
+
+ EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -999'999 }), -0x7fff'ffff'ffff'ffff, 1'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1'999'999 }), (i64)-0x8000'0000'0000'0000, 1'000);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
+ EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
}
-#define TIME(s, ns) \
- Time::from_timespec(timespec { (s), (ns) })
+#define DURATION(s, ns) \
+ Duration::from_timespec(timespec { (s), (ns) })
TEST_CASE(addition)
{
-#define EXPECT_ADDITION(s1, ns1, s2, ns2, sr, nsr) \
- do { \
- EXPECT_TIME(TIME(s1, ns1) + TIME(s2, ns2), sr, nsr); \
- EXPECT_TIME(TIME(s2, ns2) + TIME(s1, ns1), sr, nsr); \
- auto t = TIME(s1, ns1); \
- t += TIME(s2, ns2); \
- EXPECT_TIME(t, sr, nsr); \
+#define EXPECT_ADDITION(s1, ns1, s2, ns2, sr, nsr) \
+ do { \
+ EXPECT_DURATION(DURATION(s1, ns1) + DURATION(s2, ns2), sr, nsr); \
+ EXPECT_DURATION(DURATION(s2, ns2) + DURATION(s1, ns1), sr, nsr); \
+ auto t = DURATION(s1, ns1); \
+ t += DURATION(s2, ns2); \
+ EXPECT_DURATION(t, sr, nsr); \
} while (0)
EXPECT_ADDITION(11, 123'456'789, 22, 900'000'000, 34, 23'456'789);
@@ -156,12 +156,12 @@ TEST_CASE(addition)
TEST_CASE(subtraction)
{
-#define EXPECT_SUBTRACTION(s1, ns1, s2, ns2, sr, nsr) \
- do { \
- EXPECT_TIME(TIME(s1, ns1) - TIME(s2, ns2), sr, nsr); \
- auto t = TIME(s1, ns1); \
- t -= TIME(s2, ns2); \
- EXPECT_TIME(t, sr, nsr); \
+#define EXPECT_SUBTRACTION(s1, ns1, s2, ns2, sr, nsr) \
+ do { \
+ EXPECT_DURATION(DURATION(s1, ns1) - DURATION(s2, ns2), sr, nsr); \
+ auto t = DURATION(s1, ns1); \
+ t -= DURATION(s2, ns2); \
+ EXPECT_DURATION(t, sr, nsr); \
} while (0)
EXPECT_SUBTRACTION(5, 0, 3, 0, 2, 0);
@@ -194,78 +194,78 @@ TEST_CASE(subtraction)
TEST_CASE(rounding)
{
- EXPECT_EQ(TIME(2, 800'800'800).to_seconds(), 3);
- EXPECT_EQ(TIME(2, 800'800'800).to_milliseconds(), 2'801);
- EXPECT_EQ(TIME(2, 800'800'800).to_microseconds(), 2'800'801);
- EXPECT_EQ(TIME(2, 800'800'800).to_nanoseconds(), 2'800'800'800);
- EXPECT_EQ(TIME(-2, 800'800'800).to_seconds(), -2);
- EXPECT_EQ(TIME(-2, 800'800'800).to_milliseconds(), -1'200);
- EXPECT_EQ(TIME(-2, 800'800'800).to_microseconds(), -1'199'200);
- EXPECT_EQ(TIME(-2, 800'800'800).to_nanoseconds(), -1'199'199'200);
-
- EXPECT_EQ(TIME(0, 0).to_seconds(), 0);
- EXPECT_EQ(TIME(0, 0).to_milliseconds(), 0);
- EXPECT_EQ(TIME(0, 0).to_microseconds(), 0);
- EXPECT_EQ(TIME(0, 0).to_nanoseconds(), 0);
-
- EXPECT_EQ(TIME(0, 1).to_seconds(), 1);
- EXPECT_EQ(TIME(0, 1).to_milliseconds(), 1);
- EXPECT_EQ(TIME(0, 1).to_microseconds(), 1);
- EXPECT_EQ(TIME(0, 1).to_nanoseconds(), 1);
- EXPECT_EQ(TIME(0, -1).to_seconds(), -1);
- EXPECT_EQ(TIME(0, -1).to_milliseconds(), -1);
- EXPECT_EQ(TIME(0, -1).to_microseconds(), -1);
- EXPECT_EQ(TIME(0, -1).to_nanoseconds(), -1);
-
- EXPECT_EQ(TIME(-9223372037, 145'224'191).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372037, 145'224'192).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372037, 145'224'193).to_nanoseconds(), -0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036, 854'775'806).to_nanoseconds(), 0x7fff'ffff'ffff'fffe);
- EXPECT_EQ(TIME(9223372036, 854'775'807).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036, 854'775'808).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_seconds(), 3);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_milliseconds(), 2'801);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_microseconds(), 2'800'801);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_nanoseconds(), 2'800'800'800);
+ EXPECT_EQ(DURATION(-2, 800'800'800).to_seconds(), -2);
+ EXPECT_EQ(DURATION(-2, 800'800'800).to_milliseconds(), -1'200);
+ EXPECT_EQ(DURATION(-2, 800'800'800).to_microseconds(), -1'199'200);
+ EXPECT_EQ(DURATION(-2, 800'800'800).to_nanoseconds(), -1'199'199'200);
+
+ EXPECT_EQ(DURATION(0, 0).to_seconds(), 0);
+ EXPECT_EQ(DURATION(0, 0).to_milliseconds(), 0);
+ EXPECT_EQ(DURATION(0, 0).to_microseconds(), 0);
+ EXPECT_EQ(DURATION(0, 0).to_nanoseconds(), 0);
+
+ EXPECT_EQ(DURATION(0, 1).to_seconds(), 1);
+ EXPECT_EQ(DURATION(0, 1).to_milliseconds(), 1);
+ EXPECT_EQ(DURATION(0, 1).to_microseconds(), 1);
+ EXPECT_EQ(DURATION(0, 1).to_nanoseconds(), 1);
+ EXPECT_EQ(DURATION(0, -1).to_seconds(), -1);
+ EXPECT_EQ(DURATION(0, -1).to_milliseconds(), -1);
+ EXPECT_EQ(DURATION(0, -1).to_microseconds(), -1);
+ EXPECT_EQ(DURATION(0, -1).to_nanoseconds(), -1);
+
+ EXPECT_EQ(DURATION(-9223372037, 145'224'191).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372037, 145'224'192).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372037, 145'224'193).to_nanoseconds(), -0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036, 854'775'806).to_nanoseconds(), 0x7fff'ffff'ffff'fffe);
+ EXPECT_EQ(DURATION(9223372036, 854'775'807).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036, 854'775'808).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
}
TEST_CASE(truncation)
{
// Sanity
- EXPECT_EQ(TIME(2, 0).to_truncated_seconds(), 2);
- EXPECT_EQ(TIME(-2, 0).to_truncated_seconds(), -2);
- EXPECT_EQ(TIME(2, 800'800'800).to_truncated_seconds(), 2);
- EXPECT_EQ(TIME(2, 800'800'800).to_truncated_milliseconds(), 2'800);
- EXPECT_EQ(TIME(2, 800'800'800).to_truncated_microseconds(), 2'800'800);
- EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_seconds(), -2);
- EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_milliseconds(), -2'800);
- EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_microseconds(), -2'800'800);
+ EXPECT_EQ(DURATION(2, 0).to_truncated_seconds(), 2);
+ EXPECT_EQ(DURATION(-2, 0).to_truncated_seconds(), -2);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_seconds(), 2);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_milliseconds(), 2'800);
+ EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_microseconds(), 2'800'800);
+ EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_seconds(), -2);
+ EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_milliseconds(), -2'800);
+ EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_microseconds(), -2'800'800);
// Overflow, seconds
- EXPECT_EQ(Time::min().to_truncated_seconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(Time::max().to_truncated_seconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(Duration::min().to_truncated_seconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(Duration::max().to_truncated_seconds(), 0x7fff'ffff'ffff'ffff);
// Overflow, milliseconds
- EXPECT_EQ(TIME(-9223372036854776, 191'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372036854776, 192'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372036854776, 192'000'001).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(-9223372036854776, 193'000'000).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036854775, 806'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
- EXPECT_EQ(TIME(9223372036854775, 806'999'999).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
- EXPECT_EQ(TIME(9223372036854775, 807'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036854775, 808'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(-9223372036854776, 191'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372036854776, 192'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372036854776, 192'000'001).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(-9223372036854776, 193'000'000).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036854775, 806'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
+ EXPECT_EQ(DURATION(9223372036854775, 806'999'999).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
+ EXPECT_EQ(DURATION(9223372036854775, 807'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036854775, 808'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
// Overflow, microseconds
- EXPECT_EQ(TIME(-9223372036855, 224'191'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372036855, 224'192'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
- EXPECT_EQ(TIME(-9223372036855, 224'192'001).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(-9223372036855, 224'193'000).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036854, 775'806'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
- EXPECT_EQ(TIME(9223372036854, 775'806'999).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
- EXPECT_EQ(TIME(9223372036854, 775'807'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
- EXPECT_EQ(TIME(9223372036854, 775'808'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(-9223372036855, 224'191'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372036855, 224'192'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
+ EXPECT_EQ(DURATION(-9223372036855, 224'192'001).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(-9223372036855, 224'193'000).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036854, 775'806'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
+ EXPECT_EQ(DURATION(9223372036854, 775'806'999).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
+ EXPECT_EQ(DURATION(9223372036854, 775'807'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
+ EXPECT_EQ(DURATION(9223372036854, 775'808'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
}
TEST_CASE(is_negative)
{
- auto small = Time::from_nanoseconds(10);
- auto large = Time::from_nanoseconds(15);
+ auto small = Duration::from_nanoseconds(10);
+ auto large = Duration::from_nanoseconds(15);
auto result = small - large;
EXPECT_EQ(result.to_nanoseconds(), -5);
EXPECT(result.is_negative());
@@ -479,7 +479,7 @@ TEST_CASE(years_to_days_since_epoch_span)
TEST_CASE(user_defined_literals)
{
using namespace AK::TimeLiterals;
- static_assert(Time::from_nanoseconds(123) == 123_ns, "Factory is same as UDL");
+ static_assert(Duration::from_nanoseconds(123) == 123_ns, "Factory is same as UDL");
static_assert(100_ms > 10_ms, "LT UDL");
static_assert(1000_ns == 1_us, "EQ UDL");
diff --git a/Tests/Kernel/TestKernelAlarm.cpp b/Tests/Kernel/TestKernelAlarm.cpp
index 843d8ecaf8..86b9431a91 100644
--- a/Tests/Kernel/TestKernelAlarm.cpp
+++ b/Tests/Kernel/TestKernelAlarm.cpp
@@ -17,7 +17,7 @@ public:
static Core::ElapsedTimer signal_timer;
- static constexpr auto timer_value = Time::from_seconds(1);
+ static constexpr auto timer_value = Duration::from_seconds(1);
static void test_signal_handler(int signal)
{
@@ -25,7 +25,7 @@ public:
auto expected_duration = SuccessContext::timer_value;
// Add a small buffer to allow for latency on the system.
- constexpr auto buffer_duration = Time::from_milliseconds(50);
+ constexpr auto buffer_duration = Duration::from_milliseconds(50);
dbgln("Signal Times - Actual: {} Expected: {}", actual_duration.to_milliseconds(), expected_duration.to_milliseconds());
EXPECT(actual_duration >= expected_duration);
@@ -47,7 +47,7 @@ TEST_CASE(success_case)
auto previous_time = alarm(SuccessContext::timer_value.to_seconds());
EXPECT_EQ(previous_time, 0u);
- auto sleep_time = SuccessContext::timer_value + Time::from_seconds(1);
+ auto sleep_time = SuccessContext::timer_value + Duration::from_seconds(1);
sleep(sleep_time.to_seconds());
EXPECT(SuccessContext::alarm_fired);
@@ -57,7 +57,7 @@ TEST_CASE(success_case)
// See: https://github.com/SerenityOS/serenity/issues/9071
TEST_CASE(regression_inifinite_loop)
{
- constexpr auto hour_long_timer_value = Time::from_seconds(60 * 60);
+ constexpr auto hour_long_timer_value = Duration::from_seconds(60 * 60);
// Create an alarm timer significantly far into the future.
auto previous_time = alarm(hour_long_timer_value.to_seconds());
diff --git a/Tests/LibLocale/TestDateTimeFormat.cpp b/Tests/LibLocale/TestDateTimeFormat.cpp
index 608e3c1669..221d33c079 100644
--- a/Tests/LibLocale/TestDateTimeFormat.cpp
+++ b/Tests/LibLocale/TestDateTimeFormat.cpp
@@ -72,7 +72,7 @@ TEST_CASE(time_zone_name)
TestData { "ar"sv, Locale::CalendarPatternStyle::ShortGeneric, "Africa/Accra"sv, "غرينتش"sv },
};
- constexpr auto jan_1_2022 = AK::Time::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
+ constexpr auto jan_1_2022 = AK::Duration::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
for (auto const& test : test_data) {
auto time_zone = MUST(Locale::format_time_zone(test.locale, test.time_zone, test.style, jan_1_2022));
@@ -122,7 +122,7 @@ TEST_CASE(time_zone_name_dst)
TestData { "ar"sv, Locale::CalendarPatternStyle::Short, "Africa/Accra"sv, "غرينتش"sv },
};
- constexpr auto sep_19_2022 = AK::Time::from_seconds(1663553728); // Monday, September 19, 2022 2:15:28 AM
+ constexpr auto sep_19_2022 = AK::Duration::from_seconds(1663553728); // Monday, September 19, 2022 2:15:28 AM
for (auto const& test : test_data) {
auto time_zone = MUST(Locale::format_time_zone(test.locale, test.time_zone, test.style, sep_19_2022));
@@ -132,13 +132,13 @@ TEST_CASE(time_zone_name_dst)
TEST_CASE(format_time_zone_offset)
{
- constexpr auto jan_1_1833 = AK::Time::from_seconds(-4323283200); // Tuesday, January 1, 1833 12:00:00 AM
- constexpr auto jan_1_2022 = AK::Time::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
+ constexpr auto jan_1_1833 = AK::Duration::from_seconds(-4323283200); // Tuesday, January 1, 1833 12:00:00 AM
+ constexpr auto jan_1_2022 = AK::Duration::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
struct TestData {
StringView locale;
Locale::CalendarPatternStyle style;
- AK::Time time;
+ AK::Duration time;
StringView time_zone;
StringView expected_result;
};
diff --git a/Tests/LibTimeZone/TestTimeZone.cpp b/Tests/LibTimeZone/TestTimeZone.cpp
index 5ebf8a129a..4fc4c39a8f 100644
--- a/Tests/LibTimeZone/TestTimeZone.cpp
+++ b/Tests/LibTimeZone/TestTimeZone.cpp
@@ -14,7 +14,7 @@ using enum TimeZone::InDST;
static void test_offset(StringView time_zone, i64 time, i64 expected_offset, TimeZone::InDST expected_in_dst)
{
- auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(time));
+ auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(time));
VERIFY(actual_offset.has_value());
EXPECT_EQ(actual_offset->seconds, expected_offset);
EXPECT_EQ(actual_offset->in_dst, expected_in_dst);
@@ -183,7 +183,7 @@ TEST_CASE(get_time_zone_offset_with_dst)
TEST_CASE(get_named_time_zone_offsets)
{
auto test_named_offsets = [](auto time_zone, i64 time, i64 expected_standard_offset, i64 expected_daylight_offset, auto expected_standard_name, auto expected_daylight_name) {
- auto actual_offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(time));
+ auto actual_offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Duration::from_seconds(time));
VERIFY(actual_offsets.has_value());
EXPECT_EQ(actual_offsets->at(0).seconds, expected_standard_offset);
diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp
index f1b32c7ea6..f2d5f3ea9f 100644
--- a/Userland/Applications/3DFileViewer/main.cpp
+++ b/Userland/Applications/3DFileViewer/main.cpp
@@ -115,7 +115,7 @@ private:
float m_rotation_speed = 60.f;
bool m_show_frame_rate = false;
int m_cycles = 0;
- Time m_accumulated_time = {};
+ Duration m_accumulated_time = {};
RefPtr<GUI::Label> m_stats;
GLint m_wrap_s_mode = GL_REPEAT;
GLint m_wrap_t_mode = GL_REPEAT;
diff --git a/Userland/Applications/Browser/CookieJar.cpp b/Userland/Applications/Browser/CookieJar.cpp
index 38dd10047d..4b1abf25f1 100644
--- a/Userland/Applications/Browser/CookieJar.cpp
+++ b/Userland/Applications/Browser/CookieJar.cpp
@@ -286,7 +286,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
// 2. Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time to the current date and time.
Web::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value, parsed_cookie.same_site_attribute };
- cookie.creation_time = Time::now_realtime();
+ cookie.creation_time = Duration::now_realtime();
cookie.last_access_time = cookie.creation_time;
if (parsed_cookie.expiry_time_from_max_age_attribute.has_value()) {
@@ -302,7 +302,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
} else {
// Set the cookie's persistent-flag to false. Set the cookie's expiry-time to the latest representable date.
cookie.persistent = false;
- cookie.expiry_time = Time::max();
+ cookie.expiry_time = Duration::max();
}
// 4. If the cookie-attribute-list contains an attribute with an attribute-name of "Domain":
@@ -421,7 +421,7 @@ Vector<Web::Cookie::Cookie> CookieJar::get_matching_cookies(const URL& url, Depr
});
// 3. Update the last-access-time of each cookie in the cookie-list to the current date and time.
- auto now = Time::now_realtime();
+ auto now = Duration::now_realtime();
for (auto& cookie : cookie_list) {
cookie.last_access_time = now;
@@ -462,7 +462,7 @@ static ErrorOr<Web::Cookie::Cookie> parse_cookie(ReadonlySpan<SQL::Value> row)
return Error::from_string_view(name);
auto time = value.to_int<i64>().value();
- field = Time::from_seconds(time);
+ field = Duration::from_seconds(time);
return {};
};
@@ -624,7 +624,7 @@ void CookieJar::select_all_cookies_from_database(OnSelectAllCookiesResult on_res
void CookieJar::purge_expired_cookies()
{
- auto now = Time::now_realtime().to_seconds();
+ auto now = Duration::now_realtime().to_seconds();
m_storage.visit(
[&](PersistedStorage& storage) {
diff --git a/Userland/Applications/Browser/StorageWidget.cpp b/Userland/Applications/Browser/StorageWidget.cpp
index 9837b879cd..9a9b20124a 100644
--- a/Userland/Applications/Browser/StorageWidget.cpp
+++ b/Userland/Applications/Browser/StorageWidget.cpp
@@ -130,7 +130,7 @@ void StorageWidget::clear_session_storage_entries()
void StorageWidget::delete_cookie(Web::Cookie::Cookie cookie)
{
// Delete cookie by making its expiry time in the past.
- cookie.expiry_time = Time::from_seconds(0);
+ cookie.expiry_time = Duration::from_seconds(0);
if (on_update_cookie)
on_update_cookie(move(cookie));
}
diff --git a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
index a4bee4981d..f3849a4edc 100644
--- a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
+++ b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
@@ -133,7 +133,7 @@ void TimeZoneSettingsWidget::set_time_zone_location()
m_time_zone_location = compute_time_zone_location();
auto locale = Locale::default_locale();
- auto now = AK::Time::now_realtime();
+ auto now = AK::Duration::now_realtime();
auto name = Locale::format_time_zone(locale, m_time_zone, Locale::CalendarPatternStyle::Long, now).release_value_but_fixme_should_propagate_errors();
auto offset = Locale::format_time_zone(locale, m_time_zone, Locale::CalendarPatternStyle::LongOffset, now).release_value_but_fixme_should_propagate_errors();
diff --git a/Userland/Applications/HexEditor/HexDocument.cpp b/Userland/Applications/HexEditor/HexDocument.cpp
index a350fd284a..b8b5f7ce43 100644
--- a/Userland/Applications/HexEditor/HexDocument.cpp
+++ b/Userland/Applications/HexEditor/HexDocument.cpp
@@ -229,7 +229,7 @@ bool HexDocumentUndoCommand::merge_with(GUI::Command const& other)
m_old[relative_start + i] = typed_other.m_old[i];
}
- m_timestamp = Time::now_monotonic();
+ m_timestamp = Duration::now_monotonic();
return true;
}
diff --git a/Userland/Applications/HexEditor/HexDocument.h b/Userland/Applications/HexEditor/HexDocument.h
index 256f753f65..c28a9aa885 100644
--- a/Userland/Applications/HexEditor/HexDocument.h
+++ b/Userland/Applications/HexEditor/HexDocument.h
@@ -15,7 +15,7 @@
#include <LibCore/Forward.h>
#include <LibGUI/Command.h>
-constexpr Time COMMAND_COMMIT_TIME = Time::from_milliseconds(400);
+constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
class HexDocument : public Weakable<HexDocument> {
public:
@@ -103,9 +103,9 @@ public:
ErrorOr<void> try_add_changed_bytes(ByteBuffer old_values, ByteBuffer new_values);
private:
- bool commit_time_expired() const { return Time::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
+ bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
- Time m_timestamp = Time::now_monotonic();
+ Duration m_timestamp = Duration::now_monotonic();
WeakPtr<HexDocument> m_document;
size_t m_position;
ByteBuffer m_old;
diff --git a/Userland/Applications/Piano/AudioPlayerLoop.cpp b/Userland/Applications/Piano/AudioPlayerLoop.cpp
index 82dd16edef..9117605ff9 100644
--- a/Userland/Applications/Piano/AudioPlayerLoop.cpp
+++ b/Userland/Applications/Piano/AudioPlayerLoop.cpp
@@ -112,7 +112,7 @@ ErrorOr<void> AudioPlayerLoop::send_audio_to_server()
auto sample_rate = static_cast<double>(m_resampler->target());
auto buffer_play_time_ns = 1'000'000'000.0 / (sample_rate / static_cast<double>(Audio::AUDIO_BUFFER_SIZE));
- auto good_sleep_time = Time::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
+ auto good_sleep_time = Duration::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
size_t start_of_chunk_to_write = 0;
while (start_of_chunk_to_write + Audio::AUDIO_BUFFER_SIZE <= m_remaining_samples.size()) {
diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp
index 889761dbdc..f579b948b2 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.cpp
+++ b/Userland/Applications/ThemeEditor/MainWidget.cpp
@@ -347,7 +347,7 @@ void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::File>
if (sync_result.is_error()) {
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to save theme file: {}", sync_result.error()));
} else {
- m_last_modified_time = Time::now_monotonic();
+ m_last_modified_time = Duration::now_monotonic();
set_path(filename.to_deprecated_string());
window()->set_modified(false);
}
@@ -643,7 +643,7 @@ ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<C
ENUMERATE_PATH_ROLES(__ENUMERATE_PATH_ROLE)
#undef __ENUMERATE_PATH_ROLE
- m_last_modified_time = Time::now_monotonic();
+ m_last_modified_time = Duration::now_monotonic();
window()->set_modified(false);
return {};
}
diff --git a/Userland/Applications/ThemeEditor/MainWidget.h b/Userland/Applications/ThemeEditor/MainWidget.h
index 269a9c6779..98cb9cc41d 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.h
+++ b/Userland/Applications/ThemeEditor/MainWidget.h
@@ -124,7 +124,7 @@ private:
Optional<DeprecatedString> m_path;
Gfx::Palette m_current_palette;
- Time m_last_modified_time { Time::now_monotonic() };
+ Duration m_last_modified_time { Duration::now_monotonic() };
RefPtr<AlignmentModel> m_alignment_model;
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index 32cdd0c0a7..69960606d4 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -59,7 +59,7 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
update_seek_slider_max();
auto progress = value / static_cast<double>(m_seek_slider->max());
auto duration = m_playback_manager->duration().to_milliseconds();
- Time timestamp = Time::from_milliseconds(static_cast<i64>(round(progress * static_cast<double>(duration))));
+ Duration timestamp = Duration::from_milliseconds(static_cast<i64>(round(progress * static_cast<double>(duration))));
auto seek_mode_to_use = m_seek_slider->knob_dragging() ? seek_mode() : Video::PlaybackManager::SeekMode::Accurate;
m_playback_manager->seek_to_timestamp(timestamp, seek_mode_to_use);
set_current_timestamp(m_playback_manager->current_playback_time());
@@ -252,7 +252,7 @@ void VideoPlayerWidget::update_seek_slider_max()
m_seek_slider->set_enabled(true);
}
-void VideoPlayerWidget::set_current_timestamp(Time timestamp)
+void VideoPlayerWidget::set_current_timestamp(Duration timestamp)
{
set_time_label(timestamp);
if (!m_playback_manager)
@@ -261,10 +261,10 @@ void VideoPlayerWidget::set_current_timestamp(Time timestamp)
m_seek_slider->set_value(static_cast<int>(round(progress * m_seek_slider->max())), GUI::AllowCallback::No);
}
-void VideoPlayerWidget::set_time_label(Time timestamp)
+void VideoPlayerWidget::set_time_label(Duration timestamp)
{
StringBuilder string_builder;
- auto append_time = [&](Time time) {
+ auto append_time = [&](Duration time) {
auto seconds = (time.to_milliseconds() + 500) / 1000;
string_builder.append(human_readable_digital_time(seconds));
};
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
index 93385bc2c2..745577b045 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
@@ -45,8 +45,8 @@ private:
ErrorOr<void> setup_interface();
void update_play_pause_icon();
void update_seek_slider_max();
- void set_current_timestamp(Time);
- void set_time_label(Time);
+ void set_current_timestamp(Duration);
+ void set_time_label(Duration);
void on_decoding_error(Video::DecoderError const&);
void cycle_sizing_modes();
diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp
index f9b3b3e14c..9dfb6f7e62 100644
--- a/Userland/DevTools/HackStudio/LanguageClient.cpp
+++ b/Userland/DevTools/HackStudio/LanguageClient.cpp
@@ -197,7 +197,7 @@ void ConnectionToServerWrapper::on_crash()
show_crash_notification();
m_connection.clear();
- static constexpr Time max_crash_frequency = 10_sec;
+ static constexpr Duration max_crash_frequency = 10_sec;
if (m_last_crash_timer.is_valid() && m_last_crash_timer.elapsed_time() < max_crash_frequency) {
dbgln("LanguageServer crash frequency is too high");
m_respawn_allowed = false;
diff --git a/Userland/Games/BrickGame/BrickGame.cpp b/Userland/Games/BrickGame/BrickGame.cpp
index a4cda37b14..b8532afa2c 100644
--- a/Userland/Games/BrickGame/BrickGame.cpp
+++ b/Userland/Games/BrickGame/BrickGame.cpp
@@ -355,7 +355,7 @@ public:
break;
m_level = i;
}
- auto const now { Time::now_realtime() };
+ auto const now { Duration::now_realtime() };
auto const delay = s_level_map[m_level].m_delay;
if (now - m_last_update > delay) {
m_last_update = now;
@@ -372,7 +372,7 @@ public:
m_block.random_shape();
m_next_block.random_shape();
update_shadow_hint_block();
- m_last_update = Time::now_realtime();
+ m_last_update = Duration::now_realtime();
m_state = GameState::Active;
}
@@ -384,28 +384,28 @@ private:
unsigned m_level {};
unsigned m_score {};
GameState m_state { GameState::GameOver };
- Time m_last_update {};
+ Duration m_last_update {};
struct LevelMap final {
unsigned const m_score;
- Time const m_delay;
+ Duration const m_delay;
};
static constexpr Array<LevelMap, 14> s_level_map = {
- LevelMap { 0, Time::from_milliseconds(38000 / 60) },
- LevelMap { 1000, Time::from_milliseconds(34000 / 60) },
- LevelMap { 2000, Time::from_milliseconds(29000 / 60) },
- LevelMap { 3000, Time::from_milliseconds(25000 / 60) },
- LevelMap { 4000, Time::from_milliseconds(22000 / 60) },
- LevelMap { 5000, Time::from_milliseconds(18000 / 60) },
- LevelMap { 6000, Time::from_milliseconds(15000 / 60) },
- LevelMap { 7000, Time::from_milliseconds(11000 / 60) },
- LevelMap { 8000, Time::from_milliseconds(7000 / 60) },
- LevelMap { 9000, Time::from_milliseconds(5000 / 60) },
- LevelMap { 10000, Time::from_milliseconds(4000 / 60) },
- LevelMap { 20000, Time::from_milliseconds(3000 / 60) },
- LevelMap { 30000, Time::from_milliseconds(2000 / 60) },
- LevelMap { 10000000, Time::from_milliseconds(1000 / 60) }
+ LevelMap { 0, Duration::from_milliseconds(38000 / 60) },
+ LevelMap { 1000, Duration::from_milliseconds(34000 / 60) },
+ LevelMap { 2000, Duration::from_milliseconds(29000 / 60) },
+ LevelMap { 3000, Duration::from_milliseconds(25000 / 60) },
+ LevelMap { 4000, Duration::from_milliseconds(22000 / 60) },
+ LevelMap { 5000, Duration::from_milliseconds(18000 / 60) },
+ LevelMap { 6000, Duration::from_milliseconds(15000 / 60) },
+ LevelMap { 7000, Duration::from_milliseconds(11000 / 60) },
+ LevelMap { 8000, Duration::from_milliseconds(7000 / 60) },
+ LevelMap { 9000, Duration::from_milliseconds(5000 / 60) },
+ LevelMap { 10000, Duration::from_milliseconds(4000 / 60) },
+ LevelMap { 20000, Duration::from_milliseconds(3000 / 60) },
+ LevelMap { 30000, Duration::from_milliseconds(2000 / 60) },
+ LevelMap { 10000000, Duration::from_milliseconds(1000 / 60) }
};
[[nodiscard]] RenderRequest set_current_block(Block const& block)
diff --git a/Userland/Libraries/LibAudio/ConnectionToServer.cpp b/Userland/Libraries/LibAudio/ConnectionToServer.cpp
index 480021c7e2..306a0fc3d3 100644
--- a/Userland/Libraries/LibAudio/ConnectionToServer.cpp
+++ b/Userland/Libraries/LibAudio/ConnectionToServer.cpp
@@ -88,7 +88,7 @@ void ConnectionToServer::update_good_sleep_time()
auto sample_rate = static_cast<double>(get_sample_rate());
auto buffer_play_time_ns = 1'000'000'000.0 / (sample_rate / static_cast<double>(AUDIO_BUFFER_SIZE));
// A factor of 1 should be good for now.
- m_good_sleep_time = Time::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
+ m_good_sleep_time = Duration::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
}
// Non-realtime audio writing loop
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index 450a25a689..2e81b4476b 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -117,7 +117,7 @@ static struct tm* time_to_tm(struct tm* tm, time_t t, StringView time_zone)
return nullptr;
}
- if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(t)); offset.has_value()) {
+ if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(t)); offset.has_value()) {
tm->tm_isdst = offset->in_dst == TimeZone::InDST::Yes;
t += offset->seconds;
}
@@ -171,12 +171,12 @@ static time_t tm_to_time(struct tm* tm, StringView time_zone)
auto timestamp = ((days_since_epoch * 24 + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
if (tm->tm_isdst < 0) {
- if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(timestamp)); offset.has_value())
+ if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(timestamp)); offset.has_value())
timestamp -= offset->seconds;
} else {
auto index = tm->tm_isdst == 0 ? 0 : 1;
- if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(timestamp)); offsets.has_value())
+ if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Duration::from_seconds(timestamp)); offsets.has_value())
timestamp -= offsets->at(index).seconds;
}
@@ -407,7 +407,7 @@ void tzset()
tzname[1] = const_cast<char*>(__utc);
};
- if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Time::now_realtime()); offsets.has_value()) {
+ if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Duration::now_realtime()); offsets.has_value()) {
if (!offsets->at(0).name.copy_characters_to_buffer(__tzname_standard, TZNAME_MAX))
return set_default_values();
if (!offsets->at(1).name.copy_characters_to_buffer(__tzname_daylight, TZNAME_MAX))
diff --git a/Userland/Libraries/LibCore/ElapsedTimer.cpp b/Userland/Libraries/LibCore/ElapsedTimer.cpp
index ea2af5d408..93036780f2 100644
--- a/Userland/Libraries/LibCore/ElapsedTimer.cpp
+++ b/Userland/Libraries/LibCore/ElapsedTimer.cpp
@@ -20,7 +20,7 @@ ElapsedTimer ElapsedTimer::start_new()
void ElapsedTimer::start()
{
m_valid = true;
- m_origin_time = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
+ m_origin_time = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
}
void ElapsedTimer::reset()
@@ -34,10 +34,10 @@ i64 ElapsedTimer::elapsed_milliseconds() const
return elapsed_time().to_milliseconds();
}
-Time ElapsedTimer::elapsed_time() const
+Duration ElapsedTimer::elapsed_time() const
{
VERIFY(is_valid());
- auto now = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
+ auto now = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
return now - m_origin_time;
}
diff --git a/Userland/Libraries/LibCore/ElapsedTimer.h b/Userland/Libraries/LibCore/ElapsedTimer.h
index 6741d242d2..e324755fab 100644
--- a/Userland/Libraries/LibCore/ElapsedTimer.h
+++ b/Userland/Libraries/LibCore/ElapsedTimer.h
@@ -24,7 +24,7 @@ public:
void reset();
i64 elapsed_milliseconds() const;
- Time elapsed_time() const;
+ Duration elapsed_time() const;
// FIXME: Move callers to elapsed_milliseconds(), remove this.
i64 elapsed() const // milliseconds
@@ -32,10 +32,10 @@ public:
return elapsed_milliseconds();
}
- Time const& origin_time() const { return m_origin_time; }
+ Duration const& origin_time() const { return m_origin_time; }
private:
- Time m_origin_time {};
+ Duration m_origin_time {};
bool m_precise { false };
bool m_valid { false };
};
diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
index 1910d1f58d..5ca382880d 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
+++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
@@ -29,14 +29,14 @@ thread_local ThreadData* s_thread_data;
struct EventLoopTimer {
int timer_id { 0 };
- Time interval;
- Time fire_time;
+ Duration interval;
+ Duration fire_time;
bool should_reload { false };
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
WeakPtr<Object> owner;
- void reload(Time const& now) { fire_time = now + interval; }
- bool has_expired(Time const& now) const { return now > fire_time; }
+ void reload(Duration const& now) { fire_time = now + interval; }
+ bool has_expired(Duration const& now) const { return now > fire_time; }
};
struct ThreadData {
@@ -171,16 +171,16 @@ retry:
// Figure out how long to wait at maximum.
// This mainly depends on the PumpMode and whether we have pending events, but also the next expiring timer.
- Time now;
+ Duration now;
struct timeval timeout = { 0, 0 };
bool should_wait_forever = false;
if (mode == EventLoopImplementation::PumpMode::WaitForEvents && !has_pending_events) {
auto next_timer_expiration = get_next_timer_expiration();
if (next_timer_expiration.has_value()) {
- now = Time::now_monotonic_coarse();
+ now = Duration::now_monotonic_coarse();
auto computed_timeout = next_timer_expiration.value() - now;
if (computed_timeout.is_negative())
- computed_timeout = Time::zero();
+ computed_timeout = Duration::zero();
timeout = computed_timeout.to_timeval();
} else {
should_wait_forever = true;
@@ -231,7 +231,7 @@ try_select_again:
}
if (!thread_data.timers.is_empty()) {
- now = Time::now_monotonic_coarse();
+ now = Duration::now_monotonic_coarse();
}
// Handle expired timers.
@@ -349,10 +349,10 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
thread_data.pid = getpid();
}
-Optional<Time> EventLoopManagerUnix::get_next_timer_expiration()
+Optional<Duration> EventLoopManagerUnix::get_next_timer_expiration()
{
- auto now = Time::now_monotonic_coarse();
- Optional<Time> soonest {};
+ auto now = Duration::now_monotonic_coarse();
+ Optional<Duration> soonest {};
for (auto& it : ThreadData::the().timers) {
auto& fire_time = it.value->fire_time;
auto owner = it.value->owner.strong_ref();
@@ -489,8 +489,8 @@ int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool
auto& thread_data = ThreadData::the();
auto timer = make<EventLoopTimer>();
timer->owner = object;
- timer->interval = Time::from_milliseconds(milliseconds);
- timer->reload(Time::now_monotonic_coarse());
+ timer->interval = Duration::from_milliseconds(milliseconds);
+ timer->reload(Duration::now_monotonic_coarse());
timer->should_reload = should_reload;
timer->fire_when_not_visible = fire_when_not_visible;
int timer_id = thread_data.id_allocator.allocate();
diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
index 720e5dcc49..7cc7b191a6 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
+++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
@@ -28,7 +28,7 @@ public:
virtual void unregister_signal(int handler_id) override;
void wait_for_events(EventLoopImplementation::PumpMode);
- static Optional<Time> get_next_timer_expiration();
+ static Optional<Duration> get_next_timer_expiration();
private:
void dispatch_signal(int signal_number);
diff --git a/Userland/Libraries/LibCore/FileWatcherMacOS.mm b/Userland/Libraries/LibCore/FileWatcherMacOS.mm
index c546698273..4b718c65f9 100644
--- a/Userland/Libraries/LibCore/FileWatcherMacOS.mm
+++ b/Userland/Libraries/LibCore/FileWatcherMacOS.mm
@@ -18,10 +18,13 @@
static_assert(false, "This file must only be used for macOS");
#endif
-#define FixedPoint FixedPointMacOS // AK::FixedPoint conflicts with FixedPoint from MacTypes.h.
+// Several AK types conflict with MacOS types.
+#define FixedPoint FixedPointMacOS
+#define Duration DurationMacOS
#include <CoreServices/CoreServices.h>
#include <dispatch/dispatch.h>
#undef FixedPoint
+#undef Duration
namespace Core {
diff --git a/Userland/Libraries/LibCore/Socket.cpp b/Userland/Libraries/LibCore/Socket.cpp
index 639837ae0b..72df8089ab 100644
--- a/Userland/Libraries/LibCore/Socket.cpp
+++ b/Userland/Libraries/LibCore/Socket.cpp
@@ -177,7 +177,7 @@ ErrorOr<void> PosixSocketHelper::set_close_on_exec(bool enabled)
return {};
}
-ErrorOr<void> PosixSocketHelper::set_receive_timeout(Time timeout)
+ErrorOr<void> PosixSocketHelper::set_receive_timeout(Duration timeout)
{
auto timeout_spec = timeout.to_timespec();
return System::setsockopt(m_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout_spec, sizeof(timeout_spec));
@@ -231,13 +231,13 @@ ErrorOr<size_t> PosixSocketHelper::pending_bytes() const
return static_cast<size_t>(value);
}
-ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Time> timeout)
+ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout)
{
auto ip_address = TRY(resolve_host(host, SocketType::Datagram));
return connect(SocketAddress { ip_address, port }, timeout);
}
-ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Time> timeout)
+ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Duration> timeout)
{
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) UDPSocket()));
diff --git a/Userland/Libraries/LibCore/Socket.h b/Userland/Libraries/LibCore/Socket.h
index f005fa2074..aca07477e7 100644
--- a/Userland/Libraries/LibCore/Socket.h
+++ b/Userland/Libraries/LibCore/Socket.h
@@ -141,7 +141,7 @@ public:
ErrorOr<void> set_blocking(bool enabled);
ErrorOr<void> set_close_on_exec(bool enabled);
- ErrorOr<void> set_receive_timeout(Time timeout);
+ ErrorOr<void> set_receive_timeout(Duration timeout);
void setup_notifier();
RefPtr<Core::Notifier> notifier() { return m_notifier; }
@@ -215,8 +215,8 @@ private:
class UDPSocket final : public Socket {
public:
- static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Time> timeout = {});
- static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Time> timeout = {});
+ static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout = {});
+ static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Duration> timeout = {});
UDPSocket(UDPSocket&& other)
: Socket(static_cast<Socket&&>(other))
diff --git a/Userland/Libraries/LibDesktop/Screensaver.cpp b/Userland/Libraries/LibDesktop/Screensaver.cpp
index f5f181acdc..92dc32fb03 100644
--- a/Userland/Libraries/LibDesktop/Screensaver.cpp
+++ b/Userland/Libraries/LibDesktop/Screensaver.cpp
@@ -40,7 +40,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
void Screensaver::mousemove_event(GUI::MouseEvent& event)
{
- auto now = AK::Time::now_monotonic();
+ auto now = AK::Duration::now_monotonic();
if ((now - m_start_time).to_milliseconds() < mouse_tracking_delay_milliseconds)
return;
diff --git a/Userland/Libraries/LibDesktop/Screensaver.h b/Userland/Libraries/LibDesktop/Screensaver.h
index 0cebf0082f..417a021951 100644
--- a/Userland/Libraries/LibDesktop/Screensaver.h
+++ b/Userland/Libraries/LibDesktop/Screensaver.h
@@ -30,7 +30,7 @@ public:
protected:
Screensaver()
- : m_start_time(AK::Time::now_monotonic())
+ : m_start_time(AK::Duration::now_monotonic())
{
}
@@ -38,7 +38,7 @@ private:
void trigger_exit();
Optional<Gfx::IntPoint> m_mouse_origin;
- AK::Time m_start_time;
+ AK::Duration m_start_time;
};
}
diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp
index 0502c0a89a..aabec2b861 100644
--- a/Userland/Libraries/LibGUI/MessageBox.cpp
+++ b/Userland/Libraries/LibGUI/MessageBox.cpp
@@ -63,12 +63,12 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_show_error(Window* parent_window, St
return TRY(try_show(parent_window, text, "Error"sv, GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK));
}
-Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
+Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
{
return MUST(try_ask_about_unsaved_changes(parent_window, path, last_unmodified_timestamp));
}
-ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
+ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
{
StringBuilder builder;
TRY(builder.try_append("Save changes to "sv));
@@ -79,7 +79,7 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* pa
TRY(builder.try_append(" before closing?"sv));
if (!path.is_empty() && last_unmodified_timestamp.has_value()) {
- auto age = (Time::now_monotonic() - *last_unmodified_timestamp).to_seconds();
+ auto age = (Duration::now_monotonic() - *last_unmodified_timestamp).to_seconds();
auto readable_time = human_readable_time(age);
TRY(builder.try_appendff("\nLast saved {} ago.", readable_time));
}
diff --git a/Userland/Libraries/LibGUI/MessageBox.h b/Userland/Libraries/LibGUI/MessageBox.h
index 04e2f429db..b6b76c70ba 100644
--- a/Userland/Libraries/LibGUI/MessageBox.h
+++ b/Userland/Libraries/LibGUI/MessageBox.h
@@ -40,12 +40,12 @@ public:
static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static ExecResult show_error(Window* parent_window, StringView text);
- static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
+ static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
static ErrorOr<ExecResult> try_show(Badge<FileSystemAccessServer::ConnectionFromClient>, i32 window_server_client_id, i32 parent_window_id, StringView text, StringView title);
static ErrorOr<ExecResult> try_show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static ErrorOr<ExecResult> try_show_error(Window* parent_window, StringView text);
- static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
+ static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
static ErrorOr<NonnullRefPtr<MessageBox>> create(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 0770cd41d6..8f68d156ed 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -894,7 +894,7 @@ bool InsertTextCommand::merge_with(GUI::Command const& other)
m_text = builder.to_deprecated_string();
m_range.set_end(typed_other.m_range.end());
- m_timestamp = Time::now_monotonic();
+ m_timestamp = Duration::now_monotonic();
return true;
}
@@ -994,7 +994,7 @@ bool RemoveTextCommand::merge_with(GUI::Command const& other)
m_text = builder.to_deprecated_string();
m_range.set_start(typed_other.m_range.start());
- m_timestamp = Time::now_monotonic();
+ m_timestamp = Duration::now_monotonic();
return true;
}
diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h
index acfde4091b..b6a7ce8b83 100644
--- a/Userland/Libraries/LibGUI/TextDocument.h
+++ b/Userland/Libraries/LibGUI/TextDocument.h
@@ -26,7 +26,7 @@
namespace GUI {
-constexpr Time COMMAND_COMMIT_TIME = Time::from_milliseconds(400);
+constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
struct TextDocumentSpan {
TextRange range;
@@ -228,9 +228,9 @@ public:
}
protected:
- bool commit_time_expired() const { return Time::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
+ bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
- Time m_timestamp = Time::now_monotonic();
+ Duration m_timestamp = Duration::now_monotonic();
TextDocument& m_document;
TextDocument::Client const* m_client { nullptr };
};
diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp
index f5a14eabce..1642ca9e63 100644
--- a/Userland/Libraries/LibGUI/UndoStack.cpp
+++ b/Userland/Libraries/LibGUI/UndoStack.cpp
@@ -81,7 +81,7 @@ void UndoStack::set_current_unmodified()
return;
m_clean_index = m_stack_index;
- m_last_unmodified_timestamp = Time::now_monotonic();
+ m_last_unmodified_timestamp = Duration::now_monotonic();
if (on_state_change)
on_state_change();
diff --git a/Userland/Libraries/LibGUI/UndoStack.h b/Userland/Libraries/LibGUI/UndoStack.h
index 5a0df357dc..40f14c4c23 100644
--- a/Userland/Libraries/LibGUI/UndoStack.h
+++ b/Userland/Libraries/LibGUI/UndoStack.h
@@ -31,7 +31,7 @@ public:
void set_current_unmodified();
bool is_current_modified() const;
- Optional<Time> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
+ Optional<Duration> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
void clear();
@@ -44,7 +44,7 @@ private:
Vector<NonnullOwnPtr<Command>> m_stack;
size_t m_stack_index { 0 };
Optional<size_t> m_clean_index;
- Optional<Time> m_last_unmodified_timestamp;
+ Optional<Duration> m_last_unmodified_timestamp;
};
}
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp
index fccfa96045..3a2f6347a4 100644
--- a/Userland/Libraries/LibIPC/Decoder.cpp
+++ b/Userland/Libraries/LibIPC/Decoder.cpp
@@ -70,10 +70,10 @@ ErrorOr<JsonValue> decode(Decoder& decoder)
}
template<>
-ErrorOr<Time> decode(Decoder& decoder)
+ErrorOr<Duration> decode(Decoder& decoder)
{
auto nanoseconds = TRY(decoder.decode<i64>());
- return AK::Time::from_nanoseconds(nanoseconds);
+ return AK::Duration::from_nanoseconds(nanoseconds);
}
template<>
diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h
index f81c41fce7..1422fec6f4 100644
--- a/Userland/Libraries/LibIPC/Decoder.h
+++ b/Userland/Libraries/LibIPC/Decoder.h
@@ -94,7 +94,7 @@ template<>
ErrorOr<JsonValue> decode(Decoder&);
template<>
-ErrorOr<Time> decode(Decoder&);
+ErrorOr<Duration> decode(Decoder&);
template<>
ErrorOr<URL> decode(Decoder&);
diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp
index 351b7a9c03..c14c163bcb 100644
--- a/Userland/Libraries/LibIPC/Encoder.cpp
+++ b/Userland/Libraries/LibIPC/Encoder.cpp
@@ -85,7 +85,7 @@ ErrorOr<void> encode(Encoder& encoder, JsonValue const& value)
}
template<>
-ErrorOr<void> encode(Encoder& encoder, Time const& value)
+ErrorOr<void> encode(Encoder& encoder, Duration const& value)
{
return encoder.encode(value.to_nanoseconds());
}
diff --git a/Userland/Libraries/LibIPC/Encoder.h b/Userland/Libraries/LibIPC/Encoder.h
index 61d9a7d452..d753a7940c 100644
--- a/Userland/Libraries/LibIPC/Encoder.h
+++ b/Userland/Libraries/LibIPC/Encoder.h
@@ -123,7 +123,7 @@ template<>
ErrorOr<void> encode(Encoder&, JsonValue const&);
template<>
-ErrorOr<void> encode(Encoder&, Time const&);
+ErrorOr<void> encode(Encoder&, Duration const&);
template<>
ErrorOr<void> encode(Encoder&, URL const&);
diff --git a/Userland/Libraries/LibJS/Bytecode/PassManager.h b/Userland/Libraries/LibJS/Bytecode/PassManager.h
index 3709612dbf..6f87ec91af 100644
--- a/Userland/Libraries/LibJS/Bytecode/PassManager.h
+++ b/Userland/Libraries/LibJS/Bytecode/PassManager.h
@@ -38,7 +38,7 @@ public:
protected:
Core::ElapsedTimer m_timer;
- Time m_time_difference {};
+ Duration m_time_difference {};
};
class PassManager : public Pass {
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp b/Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp
index 0408867e07..6d267280ce 100644
--- a/Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp
+++ b/Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp
@@ -33,7 +33,7 @@ JS::ThrowCompletionOr<void> AgentObject::initialize(JS::Realm& realm)
JS_DEFINE_NATIVE_FUNCTION(AgentObject::monotonic_now)
{
- auto time = Time::now_monotonic();
+ auto time = Duration::now_monotonic();
auto milliseconds = time.to_milliseconds();
return Value(static_cast<double>(milliseconds));
}
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp
index 6c228ad2ff..290e79a9c3 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.cpp
+++ b/Userland/Libraries/LibJS/Heap/Heap.cpp
@@ -323,7 +323,7 @@ void Heap::sweep_dead_cells(bool print_report, Core::ElapsedTimer const& measure
}
if (print_report) {
- Time const time_spent = measurement_timer.elapsed_time();
+ Duration const time_spent = measurement_timer.elapsed_time();
size_t live_block_count = 0;
for_each_block([&](auto&) {
++live_block_count;
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index 9fad2afd66..d5a92b64c5 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -298,7 +298,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
static Crypto::SignedBigInteger const min_bigint { NumericLimits<i64>::min() };
static Crypto::SignedBigInteger const max_bigint { NumericLimits<i64>::max() };
- // The provided epoch (nano)seconds value is potentially out of range for AK::Time and subsequently
+ // The provided epoch (nano)seconds value is potentially out of range for AK::Duration and subsequently
// get_time_zone_offset(). We can safely assume that the TZDB has no useful information that far
// into the past and future anyway, so clamp it to the i64 range.
if (value < min_bigint)
@@ -314,7 +314,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
Vector<Crypto::SignedBigInteger> get_named_time_zone_epoch_nanoseconds(StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
auto local_nanoseconds = get_utc_epoch_nanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
- auto local_time = Time::from_nanoseconds(clip_bigint_to_sane_time(local_nanoseconds));
+ auto local_time = Duration::from_nanoseconds(clip_bigint_to_sane_time(local_nanoseconds));
// FIXME: LibTimeZone does not behave exactly as the spec expects. It does not consider repeated or skipped time points.
auto offset = TimeZone::get_time_zone_offset(time_zone_identifier, local_time);
@@ -332,10 +332,10 @@ i64 get_named_time_zone_offset_nanoseconds(StringView time_zone_identifier, Cryp
auto time_zone = TimeZone::time_zone_from_string(time_zone_identifier);
VERIFY(time_zone.has_value());
- // Since Time::from_seconds() and Time::from_nanoseconds() both take an i64, converting to
+ // Since Duration::from_seconds() and Duration::from_nanoseconds() both take an i64, converting to
// seconds first gives us a greater range. The TZDB doesn't have sub-second offsets.
auto seconds = epoch_nanoseconds.divided_by(s_one_billion_bigint).quotient;
- auto time = Time::from_seconds(clip_bigint_to_sane_time(seconds));
+ auto time = Duration::from_seconds(clip_bigint_to_sane_time(seconds));
auto offset = TimeZone::get_time_zone_offset(*time_zone, time);
VERIFY(offset.has_value());
diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
index e9ceca6de2..0cadf2dbab 100644
--- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
@@ -131,7 +131,7 @@ static double parse_simplified_iso8601(DeprecatedString const& iso_8601)
// We parsed a valid date simplified ISO 8601 string.
VERIFY(year.has_value()); // A valid date string always has at least a year.
- auto time = AK::Time::from_timestamp(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0));
+ auto time = AK::Duration::from_timestamp(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0));
auto time_ms = static_cast<double>(time.to_milliseconds());
// https://tc39.es/ecma262/#sec-date.parse:
@@ -208,7 +208,7 @@ ThrowCompletionOr<Value> DateConstructor::call()
{
// 1. If NewTarget is undefined, then
// a. Let now be the time value (UTC) identifying the current time.
- auto now = AK::Time::now_realtime().to_milliseconds();
+ auto now = AK::Duration::now_realtime().to_milliseconds();
// b. Return ToDateString(now).
return PrimitiveString::create(vm(), to_date_string(now));
@@ -225,7 +225,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObjec
// 3. If numberOfArgs = 0, then
if (vm.argument_count() == 0) {
// a. Let dv be the time value (UTC) identifying the current time.
- auto now = AK::Time::now_realtime().to_milliseconds();
+ auto now = AK::Duration::now_realtime().to_milliseconds();
date_value = static_cast<double>(now);
}
// 4. Else if numberOfArgs = 1, then
diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
index ece7a9e6df..04c952d8cb 100644
--- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
@@ -1164,7 +1164,7 @@ DeprecatedString time_zone_string(double time)
auto tz_name = TimeZone::current_time_zone();
// Most implementations seem to prefer the long-form display name of the time zone. Not super important, but we may as well match that behavior.
- if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::Time::from_milliseconds(time)); maybe_offset.has_value()) {
+ if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::Duration::from_milliseconds(time)); maybe_offset.has_value()) {
if (auto long_name = Locale::get_time_zone_name(Locale::default_locale(), tz_name, Locale::CalendarPatternStyle::Long, maybe_offset->in_dst); long_name.has_value())
tz_name = long_name.release_value();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
index 42b5fbd441..0a36dc1d9a 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
@@ -162,9 +162,9 @@ enum class OptionDefaults {
// Table 8: Record returned by ToLocalTime, https://tc39.es/ecma402/#table-datetimeformat-tolocaltime-record
// Note: [[InDST]] is not included here - it is handled by LibUnicode / LibTimeZone.
struct LocalTime {
- AK::Time time_since_epoch() const
+ AK::Duration time_since_epoch() const
{
- return AK::Time::from_timestamp(year, month + 1, day + 1, hour, minute, second, millisecond);
+ return AK::Duration::from_timestamp(year, month + 1, day + 1, hour, minute, second, millisecond);
}
int weekday { 0 }; // [[Weekday]]
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
index 8c077ba386..97d7477efb 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
@@ -165,11 +165,11 @@ TimeZone* system_time_zone(VM& vm)
BigInt* system_utc_epoch_nanoseconds(VM& vm)
{
// 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch.
- auto now = Time::now_realtime().to_nanoseconds();
+ auto now = AK::Duration::now_realtime().to_nanoseconds();
auto ns = Crypto::SignedBigInteger { now };
// 2. Set ns to the result of clamping ns between nsMinInstant and nsMaxInstant.
- // NOTE: Time::to_nanoseconds() already clamps between -(2^63) and 2^63 - 1, the range of an i64,
+ // NOTE: Duration::to_nanoseconds() already clamps between -(2^63) and 2^63 - 1, the range of an i64,
// if an overflow occurs during seconds -> nanoseconds conversion.
// 3. Return ℤ(ns).
diff --git a/Userland/Libraries/LibLocale/DateTimeFormat.cpp b/Userland/Libraries/LibLocale/DateTimeFormat.cpp
index 6c9ba3f2aa..7b2eb68682 100644
--- a/Userland/Libraries/LibLocale/DateTimeFormat.cpp
+++ b/Userland/Libraries/LibLocale/DateTimeFormat.cpp
@@ -301,7 +301,7 @@ static ErrorOr<Optional<String>> format_time_zone_offset(StringView locale, Cale
}
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Format_Terminology
-ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time)
+ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Duration time)
{
auto offset = TimeZone::get_time_zone_offset(time_zone, time);
if (!offset.has_value())
diff --git a/Userland/Libraries/LibLocale/DateTimeFormat.h b/Userland/Libraries/LibLocale/DateTimeFormat.h
index 194eb3f550..ba483bc66b 100644
--- a/Userland/Libraries/LibLocale/DateTimeFormat.h
+++ b/Userland/Libraries/LibLocale/DateTimeFormat.h
@@ -226,7 +226,7 @@ ErrorOr<Optional<StringView>> get_calendar_weekday_symbol(StringView locale, Str
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
-ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);
+ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Duration time);
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style, TimeZone::InDST in_dst);
Optional<TimeZoneFormat> get_time_zone_format(StringView locale);
diff --git a/Userland/Libraries/LibTimeZone/TimeZone.cpp b/Userland/Libraries/LibTimeZone/TimeZone.cpp
index c290721fb4..0ce977c9be 100644
--- a/Userland/Libraries/LibTimeZone/TimeZone.cpp
+++ b/Userland/Libraries/LibTimeZone/TimeZone.cpp
@@ -186,7 +186,7 @@ Optional<StringView> canonicalize_time_zone(StringView time_zone)
Optional<DaylightSavingsRule> __attribute__((weak)) daylight_savings_rule_from_string(StringView) { return {}; }
StringView __attribute__((weak)) daylight_savings_rule_to_string(DaylightSavingsRule) { return {}; }
-Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] TimeZone time_zone, AK::Time)
+Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] TimeZone time_zone, AK::Duration)
{
#if !ENABLE_TIME_ZONE_DATA
VERIFY(time_zone == TimeZone::UTC);
@@ -196,14 +196,14 @@ Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] Tim
#endif
}
-Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time)
+Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Duration time)
{
if (auto maybe_time_zone = time_zone_from_string(time_zone); maybe_time_zone.has_value())
return get_time_zone_offset(*maybe_time_zone, time);
return {};
}
-Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offsets([[maybe_unused]] TimeZone time_zone, AK::Time)
+Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offsets([[maybe_unused]] TimeZone time_zone, AK::Duration)
{
#if !ENABLE_TIME_ZONE_DATA
VERIFY(time_zone == TimeZone::UTC);
@@ -217,7 +217,7 @@ Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offset
#endif
}
-Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time)
+Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Duration time)
{
if (auto maybe_time_zone = time_zone_from_string(time_zone); maybe_time_zone.has_value())
return get_named_time_zone_offsets(*maybe_time_zone, time);
diff --git a/Userland/Libraries/LibTimeZone/TimeZone.h b/Userland/Libraries/LibTimeZone/TimeZone.h
index 52e20170f3..7e77ecf702 100644
--- a/Userland/Libraries/LibTimeZone/TimeZone.h
+++ b/Userland/Libraries/LibTimeZone/TimeZone.h
@@ -61,11 +61,11 @@ Optional<StringView> canonicalize_time_zone(StringView time_zone);
Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
-Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time);
-Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time);
+Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Duration time);
+Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Duration time);
-Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time);
-Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time);
+Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Duration time);
+Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Duration time);
Optional<Location> get_time_zone_location(TimeZone time_zone);
Optional<Location> get_time_zone_location(StringView time_zone);
diff --git a/Userland/Libraries/LibVideo/Containers/Demuxer.h b/Userland/Libraries/LibVideo/Containers/Demuxer.h
index 0915b8685e..967326f9ec 100644
--- a/Userland/Libraries/LibVideo/Containers/Demuxer.h
+++ b/Userland/Libraries/LibVideo/Containers/Demuxer.h
@@ -31,9 +31,9 @@ public:
// Returns the timestamp of the keyframe that was seeked to.
// The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
// in the case that the timestamp is closer to the current time than the nearest keyframe.
- virtual DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) = 0;
+ virtual DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) = 0;
- virtual DecoderErrorOr<Time> duration() = 0;
+ virtual DecoderErrorOr<Duration> duration() = 0;
protected:
virtual DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) = 0;
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h
index 9c9e5abcac..39cce17ae5 100644
--- a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h
+++ b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h
@@ -32,11 +32,11 @@ public:
void set_writing_app(DeprecatedString writing_app) { m_writing_app = move(writing_app); }
Optional<double> duration_unscaled() const { return m_duration_unscaled; }
void set_duration_unscaled(double duration) { m_duration_unscaled.emplace(duration); }
- Optional<Time> duration() const
+ Optional<Duration> duration() const
{
if (!duration_unscaled().has_value())
return {};
- return Time::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value()));
+ return Duration::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value()));
}
private:
@@ -167,8 +167,8 @@ public:
u64 track_number() const { return m_track_number; }
void set_track_number(u64 track_number) { m_track_number = track_number; }
- Time timestamp() const { return m_timestamp; }
- void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
+ Duration timestamp() const { return m_timestamp; }
+ void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
bool only_keyframes() const { return m_only_keyframes; }
void set_only_keyframes(bool only_keyframes) { m_only_keyframes = only_keyframes; }
bool invisible() const { return m_invisible; }
@@ -185,7 +185,7 @@ public:
private:
u64 m_track_number { 0 };
- Time m_timestamp { Time::zero() };
+ Duration m_timestamp { Duration::zero() };
bool m_only_keyframes { false };
bool m_invisible { false };
Lacing m_lacing { None };
@@ -195,11 +195,11 @@ private:
class Cluster {
public:
- Time timestamp() const { return m_timestamp; }
- void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
+ Duration timestamp() const { return m_timestamp; }
+ void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
private:
- Time m_timestamp { Time::zero() };
+ Duration m_timestamp { Duration::zero() };
};
class CueTrackPosition {
@@ -219,14 +219,14 @@ private:
class CuePoint {
public:
- Time timestamp() const { return m_timestamp; }
- void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
+ Duration timestamp() const { return m_timestamp; }
+ void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
OrderedHashMap<u64, CueTrackPosition>& track_positions() { return m_track_positions; }
OrderedHashMap<u64, CueTrackPosition> const& track_positions() const { return m_track_positions; }
Optional<CueTrackPosition const&> position_for_track(u64 track_number) const { return m_track_positions.get(track_number); }
private:
- Time m_timestamp = Time::min();
+ Duration m_timestamp = Duration::min();
OrderedHashMap<u64, CueTrackPosition> m_track_positions;
};
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp
index e01da0cc6f..744356cd19 100644
--- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp
+++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp
@@ -71,7 +71,7 @@ DecoderErrorOr<MatroskaDemuxer::TrackStatus*> MatroskaDemuxer::get_track_status(
return &m_track_statuses.get(track).release_value();
}
-DecoderErrorOr<Optional<Time>> MatroskaDemuxer::seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample)
+DecoderErrorOr<Optional<Duration>> MatroskaDemuxer::seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample)
{
// Removing the track status will cause us to start from the beginning.
if (timestamp.is_zero()) {
@@ -113,10 +113,10 @@ DecoderErrorOr<NonnullOwnPtr<Sample>> MatroskaDemuxer::get_next_sample_for_track
return make<VideoSample>(status.block->frame(status.frame_index++), cicp, status.block->timestamp());
}
-DecoderErrorOr<Time> MatroskaDemuxer::duration()
+DecoderErrorOr<Duration> MatroskaDemuxer::duration()
{
auto duration = TRY(m_reader.segment_information()).duration();
- return duration.value_or(Time::zero());
+ return duration.value_or(Duration::zero());
}
}
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h
index eeddd16630..225ebed06f 100644
--- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h
+++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h
@@ -29,9 +29,9 @@ public:
DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) override;
- DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) override;
+ DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) override;
- DecoderErrorOr<Time> duration() override;
+ DecoderErrorOr<Duration> duration() override;
protected:
DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp
index b6a87b194d..43a1ee64a8 100644
--- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp
+++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp
@@ -543,11 +543,11 @@ static DecoderErrorOr<Cluster> parse_cluster(Streamer& streamer, u64 timestamp_s
TRY_READ(streamer.seek_to_position(first_element_position));
Cluster cluster;
- cluster.set_timestamp(Time::from_nanoseconds(timestamp.release_value() * timestamp_scale));
+ cluster.set_timestamp(Duration::from_nanoseconds(timestamp.release_value() * timestamp_scale));
return cluster;
}
-static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Time cluster_timestamp, u64 segment_timestamp_scale, TrackEntry track)
+static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Duration cluster_timestamp, u64 segment_timestamp_scale, TrackEntry track)
{
Block block;
@@ -567,11 +567,11 @@ static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Time cluster
// of that track. To get the timestamp in nanoseconds of the first frame in a Block or
// SimpleBlock, the formula becomes:
// `( ( Cluster\Timestamp + ( block timestamp * TrackTimestampScale ) ) * TimestampScale ) - CodecDelay`
- Time timestamp_offset = Time::from_nanoseconds(static_cast<i64>(static_cast<double>(TRY_READ(streamer.read_i16()) * segment_timestamp_scale) * track.timestamp_scale()));
- timestamp_offset -= Time::from_nanoseconds(static_cast<i64>(track.codec_delay()));
+ Duration timestamp_offset = Duration::from_nanoseconds(static_cast<i64>(static_cast<double>(TRY_READ(streamer.read_i16()) * segment_timestamp_scale) * track.timestamp_scale()));
+ timestamp_offset -= Duration::from_nanoseconds(static_cast<i64>(track.codec_delay()));
// This is only mentioned in the elements specification under TrackOffset.
// https://www.matroska.org/technical/elements.html
- timestamp_offset += Time::from_nanoseconds(static_cast<i64>(track.timestamp_offset()));
+ timestamp_offset += Duration::from_nanoseconds(static_cast<i64>(track.timestamp_offset()));
block.set_timestamp(cluster_timestamp + timestamp_offset);
auto flags = TRY_READ(streamer.read_octet());
@@ -704,7 +704,7 @@ static DecoderErrorOr<CuePoint> parse_cue_point(Streamer& streamer, u64 timestam
// https://github.com/mozilla/nestegg/tree/ec6adfbbf979678e3058cc4695257366f39e290b/src/nestegg.c#L2411-L2416
// https://github.com/mozilla/nestegg/tree/ec6adfbbf979678e3058cc4695257366f39e290b/src/nestegg.c#L1383-L1392
// Other fields that specify Matroska Ticks may also use Segment Ticks instead, who knows :^(
- auto timestamp = Time::from_nanoseconds(static_cast<i64>(TRY_READ(streamer.read_u64()) * timestamp_scale));
+ auto timestamp = Duration::from_nanoseconds(static_cast<i64>(TRY_READ(streamer.read_u64()) * timestamp_scale));
cue_point.set_timestamp(timestamp);
dbgln_if(MATROSKA_DEBUG, "Read CuePoint timestamp {}ms", cue_point.timestamp().to_milliseconds());
break;
@@ -775,7 +775,7 @@ DecoderErrorOr<void> Reader::ensure_cues_are_parsed()
return {};
}
-DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator, Time const& timestamp)
+DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator, Duration const& timestamp)
{
auto const& cue_points = MUST(cue_points_for_track(iterator.m_track.track_number())).release_value();
@@ -814,7 +814,7 @@ DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator,
return {};
}
-static DecoderErrorOr<void> search_clusters_for_keyframe_before_timestamp(SampleIterator& iterator, Time const& timestamp)
+static DecoderErrorOr<void> search_clusters_for_keyframe_before_timestamp(SampleIterator& iterator, Duration const& timestamp)
{
#if MATROSKA_DEBUG
size_t inter_frames_count;
@@ -856,7 +856,7 @@ DecoderErrorOr<bool> Reader::has_cues_for_track(u64 track_number)
return m_cues.contains(track_number);
}
-DecoderErrorOr<SampleIterator> Reader::seek_to_random_access_point(SampleIterator iterator, Time timestamp)
+DecoderErrorOr<SampleIterator> Reader::seek_to_random_access_point(SampleIterator iterator, Duration timestamp)
{
if (TRY(has_cues_for_track(iterator.m_track.track_number()))) {
TRY(seek_to_cue_for_timestamp(iterator, timestamp));
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h
index ccfd54ca75..80cf336e43 100644
--- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h
+++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h
@@ -39,7 +39,7 @@ public:
DecoderErrorOr<size_t> track_count();
DecoderErrorOr<SampleIterator> create_sample_iterator(u64 track_number);
- DecoderErrorOr<SampleIterator> seek_to_random_access_point(SampleIterator, Time);
+ DecoderErrorOr<SampleIterator> seek_to_random_access_point(SampleIterator, Duration);
DecoderErrorOr<Optional<Vector<CuePoint> const&>> cue_points_for_track(u64 track_number);
DecoderErrorOr<bool> has_cues_for_track(u64 track_number);
@@ -58,7 +58,7 @@ private:
DecoderErrorOr<void> parse_cues(Streamer&);
DecoderErrorOr<void> ensure_cues_are_parsed();
- DecoderErrorOr<void> seek_to_cue_for_timestamp(SampleIterator&, Time const&);
+ DecoderErrorOr<void> seek_to_cue_for_timestamp(SampleIterator&, Duration const&);
RefPtr<Core::MappedFile> m_mapped_file;
ReadonlyBytes m_data;
@@ -84,7 +84,7 @@ class SampleIterator {
public:
DecoderErrorOr<Block> next_block();
Cluster const& current_cluster() { return *m_current_cluster; }
- Optional<Time> const& last_timestamp() { return m_last_timestamp; }
+ Optional<Duration> const& last_timestamp() { return m_last_timestamp; }
private:
friend class Reader;
@@ -108,7 +108,7 @@ private:
// Must always point to an element ID or the end of the stream.
size_t m_position { 0 };
- Optional<Time> m_last_timestamp;
+ Optional<Duration> m_last_timestamp;
Optional<Cluster> m_current_cluster;
};
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp
index 8238fdcdd4..b6738461d5 100644
--- a/Userland/Libraries/LibVideo/PlaybackManager.cpp
+++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp
@@ -107,12 +107,12 @@ void PlaybackManager::pause_playback()
TRY_OR_FATAL_ERROR(m_playback_handler->pause());
}
-Time PlaybackManager::current_playback_time()
+Duration PlaybackManager::current_playback_time()
{
return m_playback_handler->current_time();
}
-Time PlaybackManager::duration()
+Duration PlaybackManager::duration()
{
auto duration_result = ({
auto demuxer_locker = Threading::MutexLocker(m_demuxer_mutex);
@@ -179,12 +179,12 @@ void PlaybackManager::timer_callback()
TRY_OR_FATAL_ERROR(m_playback_handler->do_timed_state_update());
}
-void PlaybackManager::seek_to_timestamp(Time target_timestamp, SeekMode seek_mode)
+void PlaybackManager::seek_to_timestamp(Duration target_timestamp, SeekMode seek_mode)
{
TRY_OR_FATAL_ERROR(m_playback_handler->seek(target_timestamp, seek_mode));
}
-Optional<Time> PlaybackManager::seek_demuxer_to_most_recent_keyframe(Time timestamp, Optional<Time> earliest_available_sample)
+Optional<Duration> PlaybackManager::seek_demuxer_to_most_recent_keyframe(Duration timestamp, Optional<Duration> earliest_available_sample)
{
auto result = m_demuxer->seek_to_most_recent_keyframe(m_selected_video_track, timestamp, move(earliest_available_sample));
if (result.is_error())
@@ -211,13 +211,13 @@ void PlaybackManager::set_state_update_timer(int delay_ms)
void PlaybackManager::restart_playback()
{
- seek_to_timestamp(Time::zero());
+ seek_to_timestamp(Duration::zero());
}
void PlaybackManager::decode_and_queue_one_sample()
{
#if PLAYBACK_MANAGER_DEBUG
- auto start_time = Time::now_monotonic();
+ auto start_time = Duration::now_monotonic();
#endif
FrameQueueItem item_to_enqueue;
@@ -326,12 +326,12 @@ void PlaybackManager::decode_and_queue_one_sample()
m_buffer_is_full.exchange(false);
}
-Time PlaybackManager::PlaybackStateHandler::current_time() const
+Duration PlaybackManager::PlaybackStateHandler::current_time() const
{
return m_manager.m_last_present_in_media_time;
}
-ErrorOr<void> PlaybackManager::PlaybackStateHandler::seek(Time target_timestamp, SeekMode seek_mode)
+ErrorOr<void> PlaybackManager::PlaybackStateHandler::seek(Duration target_timestamp, SeekMode seek_mode)
{
return replace_handler_and_delete_this<SeekingStateHandler>(is_playing(), target_timestamp, seek_mode);
}
@@ -408,7 +408,7 @@ public:
private:
ErrorOr<void> on_enter() override
{
- m_last_present_in_real_time = Time::now_monotonic();
+ m_last_present_in_real_time = Duration::now_monotonic();
return do_timed_state_update();
}
@@ -427,9 +427,9 @@ private:
return replace_handler_and_delete_this<BufferingStateHandler>(true);
}
- Time current_time() const override
+ Duration current_time() const override
{
- return manager().m_last_present_in_media_time + (Time::now_monotonic() - m_last_present_in_real_time);
+ return manager().m_last_present_in_media_time + (Duration::now_monotonic() - m_last_present_in_real_time);
}
ErrorOr<void> do_timed_state_update() override
@@ -498,7 +498,7 @@ private:
// If we have a frame, send it for presentation.
if (should_present_frame) {
- auto now = Time::now_monotonic();
+ auto now = Duration::now_monotonic();
manager().m_last_present_in_media_time += now - m_last_present_in_real_time;
m_last_present_in_real_time = now;
@@ -520,7 +520,7 @@ private:
return {};
}
- Time m_last_present_in_real_time = Time::zero();
+ Duration m_last_present_in_real_time = Duration::zero();
};
class PlaybackManager::PausedStateHandler : public PlaybackManager::PlaybackStateHandler {
@@ -574,7 +574,7 @@ class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingS
class PlaybackManager::SeekingStateHandler : public PlaybackManager::ResumingStateHandler {
public:
- SeekingStateHandler(PlaybackManager& manager, bool playing, Time target_timestamp, SeekMode seek_mode)
+ SeekingStateHandler(PlaybackManager& manager, bool playing, Duration target_timestamp, SeekMode seek_mode)
: ResumingStateHandler(manager, playing)
, m_target_timestamp(target_timestamp)
, m_seek_mode(seek_mode)
@@ -655,14 +655,14 @@ private:
StringView name() override { return "Seeking"sv; }
- ErrorOr<void> seek(Time target_timestamp, SeekMode seek_mode) override
+ ErrorOr<void> seek(Duration target_timestamp, SeekMode seek_mode) override
{
m_target_timestamp = target_timestamp;
m_seek_mode = seek_mode;
return on_enter();
}
- Time current_time() const override
+ Duration current_time() const override
{
return m_target_timestamp;
}
@@ -676,7 +676,7 @@ private:
PlaybackState get_state() const override { return PlaybackState::Seeking; }
- Time m_target_timestamp { Time::zero() };
+ Duration m_target_timestamp { Duration::zero() };
SeekMode m_seek_mode { SeekMode::Accurate };
};
@@ -700,7 +700,7 @@ private:
{
// When Stopped, the decoder thread will be waiting for a signal to start its loop going again.
manager().m_decode_wait_condition.broadcast();
- return replace_handler_and_delete_this<SeekingStateHandler>(true, Time::zero(), SeekMode::Fast);
+ return replace_handler_and_delete_this<SeekingStateHandler>(true, Duration::zero(), SeekMode::Fast);
}
bool is_playing() const override { return false; };
PlaybackState get_state() const override { return PlaybackState::Stopped; }
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.h b/Userland/Libraries/LibVideo/PlaybackManager.h
index 6fbb5dba6f..d5c82f4308 100644
--- a/Userland/Libraries/LibVideo/PlaybackManager.h
+++ b/Userland/Libraries/LibVideo/PlaybackManager.h
@@ -27,30 +27,30 @@ class FrameQueueItem {
public:
FrameQueueItem()
: m_data(Empty())
- , m_timestamp(Time::zero())
+ , m_timestamp(Duration::zero())
{
}
- static constexpr Time no_timestamp = Time::min();
+ static constexpr Duration no_timestamp = Duration::min();
enum class Type {
Frame,
Error,
};
- static FrameQueueItem frame(RefPtr<Gfx::Bitmap> bitmap, Time timestamp)
+ static FrameQueueItem frame(RefPtr<Gfx::Bitmap> bitmap, Duration timestamp)
{
return FrameQueueItem(move(bitmap), timestamp);
}
- static FrameQueueItem error_marker(DecoderError&& error, Time timestamp)
+ static FrameQueueItem error_marker(DecoderError&& error, Duration timestamp)
{
return FrameQueueItem(move(error), timestamp);
}
bool is_frame() const { return m_data.has<RefPtr<Gfx::Bitmap>>(); }
RefPtr<Gfx::Bitmap> bitmap() const { return m_data.get<RefPtr<Gfx::Bitmap>>(); }
- Time timestamp() const { return m_timestamp; }
+ Duration timestamp() const { return m_timestamp; }
bool is_error() const { return m_data.has<DecoderError>(); }
DecoderError const& error() const { return m_data.get<DecoderError>(); }
@@ -71,21 +71,21 @@ public:
}
private:
- FrameQueueItem(RefPtr<Gfx::Bitmap> bitmap, Time timestamp)
+ FrameQueueItem(RefPtr<Gfx::Bitmap> bitmap, Duration timestamp)
: m_data(move(bitmap))
, m_timestamp(timestamp)
{
VERIFY(m_timestamp != no_timestamp);
}
- FrameQueueItem(DecoderError&& error, Time timestamp)
+ FrameQueueItem(DecoderError&& error, Duration timestamp)
: m_data(move(error))
, m_timestamp(timestamp)
{
}
Variant<Empty, RefPtr<Gfx::Bitmap>, DecoderError> m_data { Empty() };
- Time m_timestamp { no_timestamp };
+ Duration m_timestamp { no_timestamp };
};
static constexpr size_t frame_buffer_count = 4;
@@ -122,7 +122,7 @@ public:
void resume_playback();
void pause_playback();
void restart_playback();
- void seek_to_timestamp(Time, SeekMode = DEFAULT_SEEK_MODE);
+ void seek_to_timestamp(Duration, SeekMode = DEFAULT_SEEK_MODE);
bool is_playing() const
{
return m_playback_handler->is_playing();
@@ -134,8 +134,8 @@ public:
u64 number_of_skipped_frames() const { return m_skipped_frames; }
- Time current_playback_time();
- Time duration();
+ Duration current_playback_time();
+ Duration duration();
Function<void(RefPtr<Gfx::Bitmap>)> on_video_frame;
Function<void()> on_playback_state_change;
@@ -158,7 +158,7 @@ private:
void timer_callback();
// This must be called with m_demuxer_mutex locked!
- Optional<Time> seek_demuxer_to_most_recent_keyframe(Time timestamp, Optional<Time> earliest_available_sample = OptionalNone());
+ Optional<Duration> seek_demuxer_to_most_recent_keyframe(Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone());
Optional<FrameQueueItem> dequeue_one_frame();
void set_state_update_timer(int delay_ms);
@@ -172,7 +172,7 @@ private:
void dispatch_state_change();
void dispatch_fatal_error(Error);
- Time m_last_present_in_media_time = Time::zero();
+ Duration m_last_present_in_media_time = Duration::zero();
NonnullOwnPtr<Demuxer> m_demuxer;
Threading::Mutex m_demuxer_mutex;
@@ -212,10 +212,10 @@ private:
virtual PlaybackState get_state() const = 0;
virtual ErrorOr<void> pause() { return {}; };
virtual ErrorOr<void> buffer() { return {}; };
- virtual ErrorOr<void> seek(Time target_timestamp, SeekMode);
+ virtual ErrorOr<void> seek(Duration target_timestamp, SeekMode);
virtual ErrorOr<void> stop();
- virtual Time current_time() const;
+ virtual Duration current_time() const;
virtual ErrorOr<void> do_timed_state_update() { return {}; };
diff --git a/Userland/Libraries/LibVideo/Sample.h b/Userland/Libraries/LibVideo/Sample.h
index 0a186103cc..e2c9f20415 100644
--- a/Userland/Libraries/LibVideo/Sample.h
+++ b/Userland/Libraries/LibVideo/Sample.h
@@ -21,7 +21,7 @@ public:
class VideoSample : public Sample {
public:
- VideoSample(ReadonlyBytes data, CodingIndependentCodePoints container_cicp, Time timestamp)
+ VideoSample(ReadonlyBytes data, CodingIndependentCodePoints container_cicp, Duration timestamp)
: m_data(data)
, m_container_cicp(container_cicp)
, m_timestamp(timestamp)
@@ -31,12 +31,12 @@ public:
bool is_video_sample() const override { return true; }
ReadonlyBytes const& data() const { return m_data; }
CodingIndependentCodePoints container_cicp() const { return m_container_cicp; }
- Time timestamp() const { return m_timestamp; }
+ Duration timestamp() const { return m_timestamp; }
private:
ReadonlyBytes m_data;
CodingIndependentCodePoints m_container_cicp;
- Time m_timestamp;
+ Duration m_timestamp;
};
// FIXME: Add samples for audio, subtitles, etc.
diff --git a/Userland/Libraries/LibVideo/Track.h b/Userland/Libraries/LibVideo/Track.h
index 4653cc22fc..d16ae1c024 100644
--- a/Userland/Libraries/LibVideo/Track.h
+++ b/Userland/Libraries/LibVideo/Track.h
@@ -22,7 +22,7 @@ enum class TrackType : u32 {
class Track {
struct VideoData {
- Time duration {};
+ Duration duration {};
u64 pixel_width { 0 };
u64 pixel_height { 0 };
};
diff --git a/Userland/Libraries/LibWeb/Cookie/Cookie.cpp b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp
index 3d4305f6ca..8d5edfdf83 100644
--- a/Userland/Libraries/LibWeb/Cookie/Cookie.cpp
+++ b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp
@@ -12,7 +12,7 @@
namespace Web::Cookie {
-static DeprecatedString time_to_string(Time const& time)
+static DeprecatedString time_to_string(Duration const& time)
{
auto local_time = Core::DateTime::from_timestamp(time.to_seconds());
return local_time.to_deprecated_string("%Y-%m-%d %H:%M:%S %Z"sv);
@@ -87,11 +87,11 @@ ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder)
auto value = TRY(decoder.decode<DeprecatedString>());
auto domain = TRY(decoder.decode<DeprecatedString>());
auto path = TRY(decoder.decode<DeprecatedString>());
- auto creation_time = TRY(decoder.decode<Time>());
- auto expiry_time = TRY(decoder.decode<Time>());
+ auto creation_time = TRY(decoder.decode<Duration>());
+ auto expiry_time = TRY(decoder.decode<Duration>());
auto host_only = TRY(decoder.decode<bool>());
auto http_only = TRY(decoder.decode<bool>());
- auto last_access_time = TRY(decoder.decode<Time>());
+ auto last_access_time = TRY(decoder.decode<Duration>());
auto persistent = TRY(decoder.decode<bool>());
auto secure = TRY(decoder.decode<bool>());
auto same_site = TRY(decoder.decode<Web::Cookie::SameSite>());
diff --git a/Userland/Libraries/LibWeb/Cookie/Cookie.h b/Userland/Libraries/LibWeb/Cookie/Cookie.h
index e54d168621..805dadb20c 100644
--- a/Userland/Libraries/LibWeb/Cookie/Cookie.h
+++ b/Userland/Libraries/LibWeb/Cookie/Cookie.h
@@ -32,9 +32,9 @@ struct Cookie {
DeprecatedString name;
DeprecatedString value;
SameSite same_site;
- Time creation_time {};
- Time last_access_time {};
- Time expiry_time {};
+ Duration creation_time {};
+ Duration last_access_time {};
+ Duration expiry_time {};
DeprecatedString domain {};
DeprecatedString path {};
bool secure { false };
diff --git a/Userland/Libraries/LibWeb/Cookie/ParsedCookie.cpp b/Userland/Libraries/LibWeb/Cookie/ParsedCookie.cpp
index ee61556e82..469106c02a 100644
--- a/Userland/Libraries/LibWeb/Cookie/ParsedCookie.cpp
+++ b/Userland/Libraries/LibWeb/Cookie/ParsedCookie.cpp
@@ -27,7 +27,7 @@ static void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_
static void on_secure_attribute(ParsedCookie& parsed_cookie);
static void on_http_only_attribute(ParsedCookie& parsed_cookie);
static void on_same_site_attribute(ParsedCookie& parsed_cookie, StringView attribute_value);
-static Optional<Time> parse_date_time(StringView date_string);
+static Optional<Duration> parse_date_time(StringView date_string);
Optional<ParsedCookie> parse_cookie(DeprecatedString const& cookie_string)
{
@@ -169,10 +169,10 @@ void on_max_age_attribute(ParsedCookie& parsed_cookie, StringView attribute_valu
if (auto delta_seconds = attribute_value.to_int(); delta_seconds.has_value()) {
if (*delta_seconds <= 0) {
// If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time.
- parsed_cookie.expiry_time_from_max_age_attribute = Time::min();
+ parsed_cookie.expiry_time_from_max_age_attribute = Duration::min();
} else {
// Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.
- parsed_cookie.expiry_time_from_max_age_attribute = Time::now_realtime() + Time::from_seconds(*delta_seconds);
+ parsed_cookie.expiry_time_from_max_age_attribute = Duration::now_realtime() + Duration::from_seconds(*delta_seconds);
}
}
}
@@ -236,7 +236,7 @@ void on_same_site_attribute(ParsedCookie& parsed_cookie, StringView attribute_va
parsed_cookie.same_site_attribute = same_site_from_string(attribute_value);
}
-Optional<Time> parse_date_time(StringView date_string)
+Optional<Duration> parse_date_time(StringView date_string)
{
// https://tools.ietf.org/html/rfc6265#section-5.1.1
unsigned hour = 0;
@@ -345,7 +345,7 @@ Optional<Time> parse_date_time(StringView date_string)
// day-of-month-value, the month-value, the year-value, the hour-value, the minute-value, and the second-value, respectively.
// If no such date exists, abort these steps and fail to parse the cookie-date.
// FIXME: Fail on dates that do not exist.
- auto parsed_cookie_date = Time::from_timestamp(year, month, day_of_month, hour, minute, second, 0);
+ auto parsed_cookie_date = Duration::from_timestamp(year, month, day_of_month, hour, minute, second, 0);
// 7. Return the parsed-cookie-date as the result of this algorithm.
return parsed_cookie_date;
@@ -374,8 +374,8 @@ ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
{
auto name = TRY(decoder.decode<DeprecatedString>());
auto value = TRY(decoder.decode<DeprecatedString>());
- auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<Time>>());
- auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<Time>>());
+ auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<Duration>>());
+ auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<Duration>>());
auto domain = TRY(decoder.decode<Optional<DeprecatedString>>());
auto path = TRY(decoder.decode<Optional<DeprecatedString>>());
auto secure_attribute_present = TRY(decoder.decode<bool>());
diff --git a/Userland/Libraries/LibWeb/Cookie/ParsedCookie.h b/Userland/Libraries/LibWeb/Cookie/ParsedCookie.h
index 5779f8d5ee..339716639b 100644
--- a/Userland/Libraries/LibWeb/Cookie/ParsedCookie.h
+++ b/Userland/Libraries/LibWeb/Cookie/ParsedCookie.h
@@ -18,8 +18,8 @@ struct ParsedCookie {
DeprecatedString name;
DeprecatedString value;
SameSite same_site_attribute { SameSite::Default };
- Optional<Time> expiry_time_from_expires_attribute {};
- Optional<Time> expiry_time_from_max_age_attribute {};
+ Optional<Duration> expiry_time_from_expires_attribute {};
+ Optional<Duration> expiry_time_from_max_age_attribute {};
Optional<DeprecatedString> domain {};
Optional<DeprecatedString> path {};
bool secure_attribute_present { false };
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index efc40f379a..0458bd506a 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1651,7 +1651,7 @@ void Document::completely_finish_loading()
VERIFY(browsing_context());
// 2. Set document's completely loaded time to the current time.
- m_completely_loaded_time = AK::Time::now_realtime();
+ m_completely_loaded_time = AK::Duration::now_realtime();
// 3. Let container be document's browsing context's container.
auto container = JS::make_handle(browsing_context()->container());
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index 41563b822d..7b85780da7 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -612,7 +612,7 @@ private:
JS::GCPtr<HTMLCollection> m_all;
// https://html.spec.whatwg.org/#completely-loaded-time
- Optional<AK::Time> m_completely_loaded_time;
+ Optional<AK::Duration> m_completely_loaded_time;
// https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
Optional<String> m_navigation_id;
diff --git a/Userland/Libraries/LibWeb/FileAPI/File.cpp b/Userland/Libraries/LibWeb/FileAPI/File.cpp
index 15b7507f05..87a5df33bc 100644
--- a/Userland/Libraries/LibWeb/FileAPI/File.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/File.cpp
@@ -59,7 +59,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vecto
// 3. If the lastModified member is provided, let d be set to the lastModified dictionary member. If it is not provided, set d to the current date and time represented as the number of milliseconds since the Unix Epoch (which is the equivalent of Date.now() [ECMA-262]).
// Note: Since ECMA-262 Date objects convert to long long values representing the number of milliseconds since the Unix Epoch, the lastModified member could be a Date object [ECMA-262].
- last_modified = options->last_modified.has_value() ? options->last_modified.value() : Time::now_realtime().to_milliseconds();
+ last_modified = options->last_modified.has_value() ? options->last_modified.value() : Duration::now_realtime().to_milliseconds();
}
// 4. Return a new File object F such that:
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 535aeb3b7f..e09afa573d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -1585,7 +1585,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::dispatch_time_update_event()
ScopeGuard guard { [this] { m_running_time_update_event_handler = false; } };
m_running_time_update_event_handler = true;
- m_last_time_update_event_time = Time::now_monotonic();
+ m_last_time_update_event_time = Duration::now_monotonic();
dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::timeupdate)));
return {};
@@ -1617,7 +1617,7 @@ void HTMLMediaElement::time_marches_on(TimeMarchesOnReason reason)
auto dispatch_event = true;
if (m_last_time_update_event_time.has_value()) {
- auto time_since_last_event = Time::now_monotonic() - *m_last_time_update_event_time;
+ auto time_since_last_event = Duration::now_monotonic() - *m_last_time_update_event_time;
dispatch_event = time_since_last_event.to_milliseconds() > 250;
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
index a052c17674..da57cf2216 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -211,7 +211,7 @@ private:
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
bool m_running_time_update_event_handler { false };
- Optional<Time> m_last_time_update_event_time;
+ Optional<Duration> m_last_time_update_event_time;
JS::GCPtr<DOM::DocumentObserver> m_document_observer;
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
index 4cee08b6b4..de993d6915 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
@@ -128,7 +128,7 @@ void HTMLVideoElement::on_paused()
void HTMLVideoElement::on_seek(double position, MediaSeekMode seek_mode)
{
if (m_video_track)
- m_video_track->seek(Time::from_milliseconds(position * 1000.0), seek_mode);
+ m_video_track->seek(Duration::from_milliseconds(position * 1000.0), seek_mode);
}
// https://html.spec.whatwg.org/multipage/media.html#attr-video-poster
diff --git a/Userland/Libraries/LibWeb/HTML/VideoTrack.cpp b/Userland/Libraries/LibWeb/HTML/VideoTrack.cpp
index 645a5fd248..8e6de4d61c 100644
--- a/Userland/Libraries/LibWeb/HTML/VideoTrack.cpp
+++ b/Userland/Libraries/LibWeb/HTML/VideoTrack.cpp
@@ -98,17 +98,17 @@ void VideoTrack::pause_video(Badge<HTMLVideoElement>)
m_playback_manager->pause_playback();
}
-Time VideoTrack::position() const
+Duration VideoTrack::position() const
{
return m_playback_manager->current_playback_time();
}
-Time VideoTrack::duration() const
+Duration VideoTrack::duration() const
{
return m_playback_manager->selected_video_track().video_data().duration;
}
-void VideoTrack::seek(Time position, MediaSeekMode seek_mode)
+void VideoTrack::seek(Duration position, MediaSeekMode seek_mode)
{
switch (seek_mode) {
case MediaSeekMode::Accurate:
diff --git a/Userland/Libraries/LibWeb/HTML/VideoTrack.h b/Userland/Libraries/LibWeb/HTML/VideoTrack.h
index 0678fdaf43..acaed7c90e 100644
--- a/Userland/Libraries/LibWeb/HTML/VideoTrack.h
+++ b/Userland/Libraries/LibWeb/HTML/VideoTrack.h
@@ -25,9 +25,9 @@ public:
void play_video(Badge<HTMLVideoElement>);
void pause_video(Badge<HTMLVideoElement>);
- Time position() const;
- Time duration() const;
- void seek(Time, MediaSeekMode);
+ Duration position() const;
+ Duration duration() const;
+ void seek(Duration, MediaSeekMode);
u64 pixel_width() const;
u64 pixel_height() const;
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
index d47c1b9b88..fe32cde660 100644
--- a/Userland/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
@@ -55,7 +55,7 @@ DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_cap
DOMHighResTimeStamp unsafe_shared_current_time()
{
// The unsafe shared current time must return the current value of the shared monotonic clock.
- return Time::now_monotonic().to_nanoseconds() / 1e6;
+ return Duration::now_monotonic().to_nanoseconds() / 1e6;
}
}
diff --git a/Userland/Libraries/LibWeb/Loader/LoadRequest.h b/Userland/Libraries/LibWeb/Loader/LoadRequest.h
index ad8545d6c5..44593836ae 100644
--- a/Userland/Libraries/LibWeb/Loader/LoadRequest.h
+++ b/Userland/Libraries/LibWeb/Loader/LoadRequest.h
@@ -41,7 +41,7 @@ public:
void set_body(ByteBuffer body) { m_body = move(body); }
void start_timer() { m_load_timer.start(); };
- Time load_time() const { return m_load_timer.elapsed_time(); }
+ Duration load_time() const { return m_load_timer.elapsed_time(); }
Optional<Page&>& page() { return m_page; };
void set_page(Page& page) { m_page = page; }
diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
index ee2d782364..9abb42dc59 100644
--- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
@@ -329,7 +329,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
auto* window = page.top_level_browsing_context().active_window();
auto& realm = window->realm();
auto& vm = window->vm();
- auto start = Time::now_monotonic();
+ auto start = Duration::now_monotonic();
// 4. Let promise be a new Promise.
auto promise = JS::Promise::create(realm);
@@ -383,7 +383,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
vm.custom_data()->spin_event_loop_until([&] {
if (script_promise.state() != JS::Promise::State::Pending)
return true;
- if (timeout.has_value() && (Time::now_monotonic() - start) > Time::from_seconds(static_cast<i64>(*timeout)))
+ if (timeout.has_value() && (Duration::now_monotonic() - start) > Duration::from_seconds(static_cast<i64>(*timeout)))
return true;
return false;
});
diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp
index 5d27cf330f..53e807a628 100644
--- a/Userland/Services/LookupServer/LookupServer.cpp
+++ b/Userland/Services/LookupServer/LookupServer.cpp
@@ -257,7 +257,7 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, DeprecatedString
auto buffer = TRY(request.to_byte_buffer());
- auto udp_socket = TRY(Core::UDPSocket::connect(nameserver, 53, Time::from_seconds(1)));
+ auto udp_socket = TRY(Core::UDPSocket::connect(nameserver, 53, Duration::from_seconds(1)));
TRY(udp_socket->set_blocking(true));
TRY(udp_socket->write_until_depleted(buffer));
diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp
index 41cd9c3f53..c6c64fee1e 100644
--- a/Userland/Services/WebContent/WebDriverConnection.cpp
+++ b/Userland/Services/WebContent/WebDriverConnection.cpp
@@ -1602,7 +1602,7 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso
if (data.has("expiry"sv)) {
// NOTE: less than 0 or greater than safe integer are handled by the JSON parser
auto expiry = TRY(get_property<u32>(data, "expiry"sv));
- cookie.expiry_time_from_expires_attribute = Time::from_seconds(expiry);
+ cookie.expiry_time_from_expires_attribute = Duration::from_seconds(expiry);
}
// Cookie same site
@@ -1958,7 +1958,7 @@ Gfx::IntRect WebDriverConnection::iconify_the_window()
ErrorOr<JsonArray, Web::WebDriver::Error> WebDriverConnection::find(StartNodeGetter&& start_node_getter, Web::WebDriver::LocationStrategy using_, StringView value)
{
// 1. Let end time be the current time plus the session implicit wait timeout.
- auto end_time = Time::now_monotonic() + Time::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
+ auto end_time = Duration::now_monotonic() + Duration::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
// 2. Let location strategy be equal to using.
auto location_strategy = using_;
@@ -1985,7 +1985,7 @@ ErrorOr<JsonArray, Web::WebDriver::Error> WebDriverConnection::find(StartNodeGet
return true;
// 6. If elements returned is empty and the current time is less than end time return to step 4. Otherwise, continue to the next step.
- return maybe_elements.value()->length() != 0 || Time::now_monotonic() >= end_time;
+ return maybe_elements.value()->length() != 0 || Duration::now_monotonic() >= end_time;
});
auto elements = TRY(maybe_elements);
@@ -2039,7 +2039,7 @@ void WebDriverConnection::delete_cookies(Optional<StringView> const& name)
// -> name is equal to cookie name
if (!name.has_value() || name.value() == cookie.name) {
// Set the cookie expiry time to a Unix timestamp in the past.
- cookie.expiry_time = Time::from_seconds(0);
+ cookie.expiry_time = Duration::from_seconds(0);
m_page_client.page_did_update_cookie(move(cookie));
}
// -> Otherwise
diff --git a/Userland/Utilities/disk_benchmark.cpp b/Userland/Utilities/disk_benchmark.cpp
index 99ee0c2989..e65ceac5e0 100644
--- a/Userland/Utilities/disk_benchmark.cpp
+++ b/Userland/Utilities/disk_benchmark.cpp
@@ -59,7 +59,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(block_sizes, "A comma-separated list of block sizes", "block-size", 'b', "block-size");
args_parser.parse(arguments);
- Time const time_per_benchmark = Time::from_seconds(time_per_benchmark_sec);
+ Duration const time_per_benchmark = Duration::from_seconds(time_per_benchmark_sec);
if (file_sizes.size() == 0) {
file_sizes = { 131072, 262144, 524288, 1048576, 5242880 };
diff --git a/Userland/Utilities/touch.cpp b/Userland/Utilities/touch.cpp
index 2f68d206fe..1492929f02 100644
--- a/Userland/Utilities/touch.cpp
+++ b/Userland/Utilities/touch.cpp
@@ -88,7 +88,7 @@ static void parse_time(StringView input_time, timespec& atime, timespec& mtime)
month = parameters.take_last();
if (validate_timestamp(year, month, day, hour, minute, second))
- atime = mtime = AK::Time::from_timestamp(year, month, day, hour, minute, second, 0).to_timespec();
+ atime = mtime = AK::Duration::from_timestamp(year, month, day, hour, minute, second, 0).to_timespec();
else
err("invalid time format '{}'", input_time);
}
@@ -159,7 +159,7 @@ static void parse_datetime(StringView input_datetime, timespec& atime, timespec&
}
if (validate_timestamp(year, month, day, hour, minute, second)) {
- auto timestamp = AK::Time::from_timestamp(year, month, day, hour, minute, second, millisecond);
+ auto timestamp = AK::Duration::from_timestamp(year, month, day, hour, minute, second, millisecond);
auto time = timestamp.to_timespec();
if (time_zone.is_empty() && TimeZone::system_time_zone() != "UTC") {
auto offset = TimeZone::get_time_zone_offset(TimeZone::system_time_zone(), timestamp);