Commit graph

22 commits

Author SHA1 Message Date
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
asynts
c9ca897a45 LibCore: Use new format functions in some places. 2020-10-17 23:20:31 +02:00
Nico Weber
9ad5a261f7 LibCore: Let DateTime::create()/set_time() take summer time into account
DateTime::create() takes a date/time in local time, but it set
tm_isdst to 0, which meant it was in local winter time always.
Set tm_isdst to -1 so that times during summer time are treated
in summer time, and times in winter time are treated as winter
time (when appropriate). When the time is adjusted backward by
one hour, the same time can be in winter time or summer time,
so this isn't 100% reliable, but for most of the year it should
work fine.

Since LibJS uses DateTime, this means that the Date tuple
ctor (which creates a timestamp from year/month/day/hours/etc
in local time) and getTime() should now have consistent (and
correct) output, which should fix #3327.

In Serenity itself, dst handling (and timezones) are unimplemented
and this doens't have any effect yet, but in Lagom this has an effect.
2020-08-30 16:56:47 +02:00
Nico Weber
1ab8939077 AK+LibC+LibCore: Have fewer implementations of day_of_week
The implementation in LibC did a timestamp->day-of-week conversion
which looks like a valuable thing to have. But we only need it in
time_to_tm, where we already computed year/month/day -- so let's
consolidate on the day_of_week function in DateTime (which is
getting extracted to AK).
2020-08-26 08:52:07 +02:00
Nico Weber
2236385e1f AK+LibC+LibCore: Add a days_in_year function 2020-08-26 08:52:07 +02:00
Nico Weber
a7a18b478e AK+LibC+LibCore: Have fewer implementations of days_in_month 2020-08-26 08:52:07 +02:00
Nico Weber
dcb81fc199 LibCore: Use is_leap_year more in DateTime 2020-08-26 08:52:07 +02:00
Nico Weber
c85e679e2d AK+LibCore+Kernel: Have fewer implementations of day_of_year
The JS tests pointed out that the implementation in DateTime
had an off-by-one in the month when doing the leap year check,
so this change fixes that bug.
2020-08-26 08:52:07 +02:00
Nico Weber
84ed257959 AK+LibC+LibCore+Kernel: Have fewer implementations of is_leap_year 2020-08-26 08:52:07 +02:00
Nico Weber
5b9d43767c LibCore: Make DateTime::create() and set_time() handle out-of-range values
Set member variables after calling mktime(), which canonicalizes
out-of-range values.

With this, DateTime::create(2020, 13, ...) will return a DateTime
on Jan 2021 (assuming the other parameters are in range).
2020-08-24 18:20:07 +02:00
Nico Weber
593b0b9fcc LibCore: Less code duplication in DateTime
DateTime::create() an just call DateTime::set_time().

No behavior change.
2020-08-24 18:20:07 +02:00
thankyouverycool
918f2c592d LibCore: Fix spelling for month of "August" 2020-08-22 11:54:30 +02:00
Nico Weber
221b412210 LibCore: Make DateTime::create() not fill in tm_wday and tm_yday for calling mktime() 2020-08-21 12:11:48 +02:00
AnotherTest
d051fffe25 LibCore: Add a primitive comparison function to DateTime
This should go away when we get the ability to parse strings to
DateTime's.
2020-05-07 10:23:58 +02:00
Andreas Kling
290ea11739 LibCore: Tweak DateTime.cpp so it compiles on Linux + drive-by bug fix 2020-03-23 13:13:36 +01:00
rhin123
08a30a4961 LibCore: Moved cal.cpp functions to DateTime 2020-03-18 08:17:01 +01:00
howar6hill
10e0d4a196
LibCore: Add format option for DateTime::to_string() (#1358) 2020-03-08 11:35:26 +01:00
howar6hill
35024154cc DateTime: Fix a typo 2020-02-26 09:31:43 +01:00
Andreas Kling
3866e0d4d4 LibCore: Move LogStream::operator<< overloads into cpp files 2020-02-15 00:58:52 +01:00
Andreas Kling
8f89cc85d1 LibCore: Add DateTime::from_timestamp(time_t) 2020-02-11 19:48:46 +01:00
Andreas Kling
b8cf83926a LibCore: Add a basic Core::DateTime class
This is just to have a pleasant way to print the current time for now:

    dbg() << Core::DateTime::now();

Or if you want it as a string:

    Core::DateTime::now().to_string();
2020-02-11 19:43:29 +01:00