mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibJS: Make regulate_iso_date() and iso_date_from_fields() use ISODate
No need for TemporalDate, we don't use the calendar field here anyway.
This commit is contained in:
parent
dd58d0f650
commit
e036f4a786
5 changed files with 8 additions and 8 deletions
|
@ -659,7 +659,7 @@ double resolve_iso_month(GlobalObject& global_object, Object& fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.1.38 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
|
// 12.1.38 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
|
||||||
Optional<TemporalDate> iso_date_from_fields(GlobalObject& global_object, Object& fields, Object& options)
|
Optional<ISODate> iso_date_from_fields(GlobalObject& global_object, Object& fields, Object& options)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/Object.h>
|
||||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
|
||||||
namespace JS::Temporal {
|
namespace JS::Temporal {
|
||||||
|
@ -58,7 +58,7 @@ u16 to_iso_day_of_year(i32 year, u8 month, u8 day);
|
||||||
u8 to_iso_week_of_year(i32 year, u8 month, u8 day);
|
u8 to_iso_week_of_year(i32 year, u8 month, u8 day);
|
||||||
String build_iso_month_code(u8 month);
|
String build_iso_month_code(u8 month);
|
||||||
double resolve_iso_month(GlobalObject&, Object& fields);
|
double resolve_iso_month(GlobalObject&, Object& fields);
|
||||||
Optional<TemporalDate> iso_date_from_fields(GlobalObject&, Object& fields, Object& options);
|
Optional<ISODate> iso_date_from_fields(GlobalObject&, Object& fields, Object& options);
|
||||||
i32 iso_year(Object& temporal_object);
|
i32 iso_year(Object& temporal_object);
|
||||||
u8 iso_month(Object& temporal_object);
|
u8 iso_month(Object& temporal_object);
|
||||||
String iso_month_code(Object& temporal_object);
|
String iso_month_code(Object& temporal_object);
|
||||||
|
|
|
@ -161,7 +161,7 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate
|
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate
|
||||||
Optional<TemporalDate> regulate_iso_date(GlobalObject& global_object, double year, double month, double day, String const& overflow)
|
Optional<ISODate> regulate_iso_date(GlobalObject& global_object, double year, double month, double day, String const& overflow)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
// 1. Assert: year, month, and day are integers.
|
// 1. Assert: year, month, and day are integers.
|
||||||
|
@ -187,7 +187,7 @@ Optional<TemporalDate> regulate_iso_date(GlobalObject& global_object, double yea
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
// b. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
|
// b. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
|
||||||
return TemporalDate { .year = y, .month = m, .day = d, .calendar = {} };
|
return ISODate { .year = y, .month = m, .day = d };
|
||||||
}
|
}
|
||||||
// 4. If overflow is "constrain", then
|
// 4. If overflow is "constrain", then
|
||||||
else if (overflow == "constrain"sv) {
|
else if (overflow == "constrain"sv) {
|
||||||
|
@ -206,7 +206,7 @@ Optional<TemporalDate> regulate_iso_date(GlobalObject& global_object, double yea
|
||||||
day = constrain_to_range(day, 1, iso_days_in_month(y, month));
|
day = constrain_to_range(day, 1, iso_days_in_month(y, month));
|
||||||
|
|
||||||
// c. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
|
// c. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
|
||||||
return TemporalDate { .year = y, .month = static_cast<u8>(month), .day = static_cast<u8>(day), .calendar = {} };
|
return ISODate { .year = y, .month = static_cast<u8>(month), .day = static_cast<u8>(day) };
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
|
||||||
namespace JS::Temporal {
|
namespace JS::Temporal {
|
||||||
|
@ -43,7 +42,7 @@ struct ISODate {
|
||||||
|
|
||||||
PlainDate* create_temporal_date(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject* new_target = nullptr);
|
PlainDate* create_temporal_date(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject* new_target = nullptr);
|
||||||
PlainDate* to_temporal_date(GlobalObject&, Value item, Object* options = nullptr);
|
PlainDate* to_temporal_date(GlobalObject&, Value item, Object* options = nullptr);
|
||||||
Optional<TemporalDate> regulate_iso_date(GlobalObject&, double year, double month, double day, String const& overflow);
|
Optional<ISODate> regulate_iso_date(GlobalObject&, double year, double month, double day, String const& overflow);
|
||||||
bool is_valid_iso_date(i32 year, u8 month, u8 day);
|
bool is_valid_iso_date(i32 year, u8 month, u8 day);
|
||||||
ISODate balance_iso_date(i32 year, i32 month, i32 day);
|
ISODate balance_iso_date(i32 year, i32 month, i32 day);
|
||||||
i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2);
|
i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||||
#include <LibJS/Runtime/Temporal/PlainDateConstructor.h>
|
#include <LibJS/Runtime/Temporal/PlainDateConstructor.h>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue