mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00
Userland: Remove remaining users of Duration::now_realtime()
This is a clear sign that they want to use a UnixDateTime instead. This also adds support for placing durations and date times into SQL databases via their millisecond offset to UTC.
This commit is contained in:
parent
82c681e44b
commit
effcd080ca
16 changed files with 62 additions and 45 deletions
|
@ -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<Duration> parse_date_time(StringView date_string);
|
||||
static Optional<UnixDateTime> 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 = Duration::min();
|
||||
parsed_cookie.expiry_time_from_max_age_attribute = UnixDateTime::earliest();
|
||||
} else {
|
||||
// Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.
|
||||
parsed_cookie.expiry_time_from_max_age_attribute = Duration::now_realtime() + Duration::from_seconds(*delta_seconds);
|
||||
parsed_cookie.expiry_time_from_max_age_attribute = UnixDateTime::now() + 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<Duration> parse_date_time(StringView date_string)
|
||||
Optional<UnixDateTime> parse_date_time(StringView date_string)
|
||||
{
|
||||
// https://tools.ietf.org/html/rfc6265#section-5.1.1
|
||||
unsigned hour = 0;
|
||||
|
@ -345,7 +345,8 @@ Optional<Duration> 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 = Duration::from_timestamp(year, month, day_of_month, hour, minute, second, 0);
|
||||
// FIXME: This currently uses UNIX time, which is not equivalent to UTC due to leap seconds.
|
||||
auto parsed_cookie_date = UnixDateTime::from_unix_time_parts(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 +375,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<Duration>>());
|
||||
auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<Duration>>());
|
||||
auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<UnixDateTime>>());
|
||||
auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<UnixDateTime>>());
|
||||
auto domain = TRY(decoder.decode<Optional<DeprecatedString>>());
|
||||
auto path = TRY(decoder.decode<Optional<DeprecatedString>>());
|
||||
auto secure_attribute_present = TRY(decoder.decode<bool>());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue