1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:37:35 +00:00

AK: Rename Time to Duration

That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
This commit is contained in:
kleines Filmröllchen 2023-03-13 16:30:34 +01:00 committed by Jelle Raaijmakers
parent 82ddc813d5
commit 213025f210
140 changed files with 634 additions and 628 deletions

View file

@ -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>());

View file

@ -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 };

View file

@ -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>());

View file

@ -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 };

View file

@ -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());

View file

@ -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;

View file

@ -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:

View file

@ -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;
}

View file

@ -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;

View file

@ -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

View file

@ -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:

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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; }

View file

@ -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;
});