Skip to content

Truly independent web browser

AK+LibWeb: Convert high resolution times from seconds as f64

Zaggy1024b3e128150b59
diff --git a/AK/Time.h b/AK/Time.h
index fcf33ecbcc3..754dad2cce4 100644
--- a/AK/Time.h
+++ b/AK/Time.h
@@ -473,6 +473,7 @@ public:
[[nodiscard]] i64 seconds_since_epoch() const { return m_offset.to_floored_seconds(); }
[[nodiscard]] i64 milliseconds_since_epoch() const { return m_offset.to_floored_milliseconds(); }
[[nodiscard]] i64 nanoseconds_since_epoch() const { return m_offset.to_nanoseconds(); }
+ [[nodiscard]] f64 to_seconds_f64() const { return m_offset.to_seconds_f64(); }
enum class LocalTime {
Yes,
@@ -569,6 +570,7 @@ public:
[[nodiscard]] i64 milliseconds() const { return m_offset.to_floored_milliseconds(); }
[[nodiscard]] i64 nanoseconds() const { return m_offset.to_nanoseconds(); }
[[nodiscard]] i64 nanoseconds_within_second() const { return to_timespec().tv_nsec; }
+ [[nodiscard]] f64 to_seconds_f64() const { return m_offset.to_seconds_f64(); }
constexpr bool operator==(MonotonicTime const& other) const { return this->m_offset == other.m_offset; }
constexpr int operator<=>(MonotonicTime const& other) const { return this->m_offset <=> other.m_offset; }
diff --git a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
index a9c80aa3dcc..174f649f376 100644
--- a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
+++ b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
@@ -104,7 +104,7 @@ DOMHighResTimeStamp coarsened_shared_current_time(HTML::CanUseCrossOriginIsolate
// https://w3c.github.io/hr-time/#wall-clock-unsafe-current-time
DOMHighResTimeStamp wall_clock_unsafe_current_time()
{
- return UnixDateTime::now().nanoseconds_since_epoch() / 1.0e6;
+ return UnixDateTime::now().to_seconds_f64() * 1000.0;
}
// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
@@ -112,7 +112,7 @@ DOMHighResTimeStamp unsafe_shared_current_time()
{
// The unsafe shared current time must return the current value of the shared monotonic clock.
// Note: This is in milliseconds (stored as a double).
- return MonotonicTime::now().nanoseconds() / 1.0e6;
+ return MonotonicTime::now().to_seconds_f64() * 1000.0;
}
}