summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-14 17:58:49 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-15 20:13:48 +0100
commit34a1dd4257367180eac212647bbc3614d5fb1129 (patch)
treeea88aaad17de54e88fd36157fa802367f687b975 /Userland
parent58ccca6a9dba937ee7c4b48592962be06955688a (diff)
downloadserenity-34a1dd4257367180eac212647bbc3614d5fb1129.zip
LibJS: Remove Core::DateTime logic from the Date object :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp63
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.h61
2 files changed, 0 insertions, 124 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index b3d59f1c3e..072bf31835 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -16,24 +16,11 @@
namespace JS {
-Date* Date::create(GlobalObject& global_object, Core::DateTime datetime, i16 milliseconds, bool is_invalid)
-{
- return global_object.heap().allocate<Date>(global_object, datetime, milliseconds, is_invalid, *global_object.date_prototype());
-}
-
Date* Date::create(GlobalObject& global_object, double date_value)
{
return global_object.heap().allocate<Date>(global_object, date_value, *global_object.date_prototype());
}
-Date::Date(Core::DateTime datetime, i16 milliseconds, bool is_invalid, Object& prototype)
- : Object(prototype)
- , m_datetime(datetime)
- , m_milliseconds(milliseconds)
- , m_is_invalid(is_invalid)
-{
-}
-
Date::Date(double date_value, Object& prototype)
: Object(prototype)
, m_date_value(date_value)
@@ -44,56 +31,6 @@ Date::~Date()
{
}
-tm Date::to_utc_tm() const
-{
- time_t timestamp = m_datetime.timestamp();
- struct tm tm;
- gmtime_r(&timestamp, &tm);
- return tm;
-}
-
-int Date::utc_date() const
-{
- return to_utc_tm().tm_mday;
-}
-
-int Date::utc_day() const
-{
- return to_utc_tm().tm_wday;
-}
-
-int Date::utc_full_year() const
-{
- return to_utc_tm().tm_year + 1900;
-}
-
-int Date::utc_hours() const
-{
- return to_utc_tm().tm_hour;
-}
-
-int Date::utc_minutes() const
-{
- return to_utc_tm().tm_min;
-}
-
-int Date::utc_month() const
-{
- return to_utc_tm().tm_mon;
-}
-
-int Date::utc_seconds() const
-{
- return to_utc_tm().tm_sec;
-}
-
-String Date::gmt_date_string() const
-{
- // Mon, 18 Dec 1995 17:28:35 GMT
- // FIXME: Note that we're totally cheating with the timezone part here..
- return datetime().to_string("%a, %e %b %Y %T GMT");
-}
-
String Date::iso_date_string() const
{
int year = year_from_time(m_date_value);
diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h
index 7072ae4e06..525cd9535d 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.h
+++ b/Userland/Libraries/LibJS/Runtime/Date.h
@@ -7,8 +7,6 @@
#pragma once
-#include <AK/Math.h>
-#include <LibCore/DateTime.h>
#include <LibJS/Runtime/Object.h>
namespace JS {
@@ -17,78 +15,19 @@ class Date final : public Object {
JS_OBJECT(Date, Object);
public:
- static constexpr double time_clip = 8.64e15;
-
- static Date* create(GlobalObject&, Core::DateTime, i16 milliseconds, bool is_invalid);
static Date* create(GlobalObject&, double date_value);
static Date* now(GlobalObject&);
- Date(Core::DateTime datetime, i16 milliseconds, bool is_invalid, Object& prototype);
Date(double date_value, Object& prototype);
virtual ~Date() override;
double date_value() const { return m_date_value; }
void set_date_value(double value) { m_date_value = value; }
- Core::DateTime& datetime() { return m_datetime; }
- const Core::DateTime& datetime() const { return m_datetime; }
-
- int date() const { return datetime().day(); }
- int day() const { return datetime().weekday(); }
- int hours() const { return datetime().hour(); }
- i16 milliseconds() const { return m_milliseconds; }
- int minutes() const { return datetime().minute(); }
- int month() const { return datetime().month() - 1; }
- int seconds() const { return datetime().second(); }
- double time() const { return datetime().timestamp() * 1000.0 + milliseconds(); }
- int year() const { return datetime().year(); }
-
- bool is_invalid() const { return m_is_invalid; }
- void set_is_invalid(bool value) { m_is_invalid = value; }
-
- int utc_date() const;
- int utc_day() const;
- int utc_full_year() const;
- int utc_hours() const;
- int utc_milliseconds() const { return milliseconds(); }
- int utc_minutes() const;
- int utc_month() const;
- int utc_seconds() const;
-
- void set_milliseconds(i16 milliseconds)
- {
- m_milliseconds = milliseconds;
- }
-
- // FIXME: Support %04Y in Core::DateTime::to_string()
- String date_string() const { return String::formatted(m_datetime.to_string("%a %b %d {:04}"), m_datetime.year()); }
- // FIXME: Deal with timezones once SerenityOS has a working tzset(3)
- String time_string() const { return m_datetime.to_string("%T GMT+0000 (UTC)"); }
- String string() const
- {
- if (is_invalid())
- return "Invalid Date";
-
- return String::formatted("{} {}", date_string(), time_string());
- }
-
- String gmt_date_string() const;
String iso_date_string() const;
- // FIXME: One day, implement real locale support. Until then, everyone gets what the Clock Applet displays.
- String locale_date_string() const { return m_datetime.to_string("%Y-%m-%d"); }
- String locale_string() const { return m_datetime.to_string(); }
- String locale_time_string() const { return m_datetime.to_string("%H:%M:%S"); }
-
private:
- tm to_utc_tm() const;
-
double m_date_value { 0 }; // [[DateValue]]
-
- Core::DateTime m_datetime;
- i16 m_milliseconds;
-
- bool m_is_invalid { false };
};
u16 day_within_year(double);