mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:57: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:
parent
82ddc813d5
commit
213025f210
140 changed files with 634 additions and 628 deletions
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue