js: Implement pretty-printing of Temporal.PlainDateTime objects

This commit is contained in:
Linus Groh 2021-07-22 20:07:16 +01:00
parent 93e52f6ad8
commit 40580696a6
Notes: sideshowbarker 2024-07-18 08:33:01 +09:00

View file

@ -45,6 +45,7 @@
#include <LibJS/Runtime/Temporal/Duration.h>
#include <LibJS/Runtime/Temporal/Instant.h>
#include <LibJS/Runtime/Temporal/PlainDate.h>
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
#include <LibJS/Runtime/Temporal/TimeZone.h>
#include <LibJS/Runtime/TypedArray.h>
#include <LibJS/Runtime/Value.h>
@ -461,6 +462,13 @@ static void print_temporal_plain_date(JS::Object const& object, HashTable<JS::Ob
out(" \033[34;1m{:04}-{:02}-{:02}\033[0m", plain_date.iso_year(), plain_date.iso_month(), plain_date.iso_day());
}
static void print_temporal_plain_date_time(JS::Object const& object, HashTable<JS::Object*>&)
{
auto& plain_date_time = static_cast<JS::Temporal::PlainDateTime const&>(object);
print_type("Temporal.PlainDateTime");
out(" \033[34;1m{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}{:03}{:03}\033[0m", plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond());
}
static void print_temporal_time_zone(JS::Object const& object, HashTable<JS::Object*>& seen_objects)
{
auto& time_zone = static_cast<JS::Temporal::TimeZone const&>(object);
@ -538,6 +546,8 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
return print_temporal_instant(object, seen_objects);
if (is<JS::Temporal::PlainDate>(object))
return print_temporal_plain_date(object, seen_objects);
if (is<JS::Temporal::PlainDateTime>(object))
return print_temporal_plain_date_time(object, seen_objects);
if (is<JS::Temporal::TimeZone>(object))
return print_temporal_time_zone(object, seen_objects);
return print_object(object, seen_objects);