1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibJS: Implement Date.getUTC*

Test files created with:
    $ for f in Libraries/LibJS/Tests/builtins/Date/Date.prototype.get*js; do
          cp $f $(echo $f | sed -e 's/get/getUTC/') ;
      done
    $ rm Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCTime.js
    $ git add Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTC*.js
    $ ls Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTC*.js | \
          xargs sed -i -e 's/get/getUTC/g'
This commit is contained in:
Nico Weber 2020-08-23 13:30:18 -04:00 committed by Andreas Kling
parent d5eaefe87b
commit ad00462daa
12 changed files with 184 additions and 4 deletions

View file

@ -49,11 +49,47 @@ Date::~Date()
{
}
String Date::iso_date_string() const
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;
}
String Date::iso_date_string() const
{
auto tm = to_utc_tm();
int year = tm.tm_year + 1900;
int month = tm.tm_mon + 1;