Commit graph

20 commits

Author SHA1 Message Date
Rocco Corsi
e3e78f4372 AK: Verify datetime fetching results and initialize struct tm
Cppcheck 2.17 tool found issue with struct tm under Windows

Checking AK/Time.cpp ...
Checking AK/Time.cpp: AK_OS_WINDOWS...
AK/Time.cpp:488:15: error: Uninitialized variable: &tm [uninitvar]
        (void)localtime_r(&timestamp, &tm);
              ^
32/39 files checked 87% done

Also the gmtime_X` and localtime_X calls were not checked for failures,
so those are now checked too.
2026-06-04 17:32:49 +02:00
Pavel Shliak
1c20baf3f3 AK: Remove duplicate Time expectations 2026-05-23 09:16:27 +02:00
Zaggy1024
40d1957d6a AK+Tests: Add a Duration function to scale by a rational 2026-05-19 15:20:58 -05:00
Zaggy1024
3844edaaed AK: Avoid overflow in Duration::to_time_units() with fraction near 1
With numerators or denominators approaching NumericLimits<u32>::max(),
we could overflow in the sum of the remainder and the rounding
contribution. Instead, divide them separately and sum them afterward.
2026-04-16 15:08:27 -05:00
Zaggy1024
affbe61da0 AK: Simplify Duration::from_time_units and handle remainder overflow
Overflow could happen in the multiplication of the remainder seconds
back into time units. Instead, take a remainder of the time units from
the division and use that for the nanoseconds.
2026-04-16 15:08:27 -05:00
Zaggy1024
9ce018cd0c AK: Handle integer negative seconds in Duration::from_time_units()
When passed values that result in a negative integer number of seconds,
we would end up with a nanoseconds component that was outside the
allowed range in Duration. When we get an exact second of nanoseconds,
we can just increment the seconds and reset the nanoseconds to correct
this.

Fixes a crash on https://athenacrisis.com/#athena-crisis.
2026-01-23 20:36:35 +01:00
Zaggy1024
a1358fa970 AK+Tests: Add time units conversion functions to Duration
These take a numerator and denominator defining the unit in a fractions
of a second. Conversion is done in integers, meaning that these must
clamp when approaching numeric limits.
2025-11-17 16:51:18 +01:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Zaggy1024
aa8c28eb24 AK+Tests: Allow creating a Duration from 64-bit floating point seconds 2025-10-27 17:28:49 -07:00
Tomasz Strejczek
5cde267979 AK: Implement Formatter<UnixDateTime>
Implement StringBuilder's Formatter<UnixDateTime>. Add necessary tests.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
ea32e39d68 AK: Add UnixDateTime::parse() method
Copy parse() method from LibCore::DateTime::parse(). Augment the method
to handle parsing from GMT time. Fix incorrect handling of year in '%D'
format specifier. Remove all format specifiers related to time zones.
Copy relevant tests and add additional ones.
2025-09-30 12:39:01 +02:00
Glenn Skrzypczak
d25d62e74c AK/Time+LibWeb/HTML: Fix ISO8601 week conversions
This reimplements conversions between unix date times and ISO8601
weeks. The new algorithms also do not use loops, so they should be
faster.
2025-08-14 11:05:28 -04:00
Tomasz Strejczek
8f8e51b1fc AK: Implement AK::UnixDateTime::to_string()
Copy implementation of LibCore::DateTime::to_string()
to AK.
Rename TestDuration.cpp to TestTime.cpp and add
there tests for to_string().
2025-06-19 18:42:45 -06:00
kleines Filmröllchen
213025f210 AK: Rename Time to Duration
That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
2023-05-24 23:18:07 +02:00
Andrew Kaster
a8fcd39b88 AK: Reimplement comparisons on AK::Time using operator<=>
This allows us to make all comparision operators on the class constexpr
without pulling in a bunch of boilerplate. We don't use the `<compare>`
header because it doesn't compile in the main serenity cross-build due
to the include paths to LibC being incompatible with how libc++ expects
them to be for clang builds.
2023-01-07 14:51:04 +01:00
Ben Wiederhake
3334cf675a AK+Kernel: Eliminate UB (signed overflow) from days_since_epoch 2023-01-02 16:19:35 -05:00
Ben Wiederhake
7a69219a35 AK+Tests: Replace years_to_days_since_epoch by near-instant function
This solves half the problem of #12729. Note that the inverse function
time_to_tm() in LibC/time.cpp still uses a slow for-loop.

See also #13138
2023-01-02 16:19:35 -05:00
Ben Wiederhake
60ee695287 AK+Tests: Demonstrate slowness of years_to_days_since_epoch
In practice, this function does not take any perceptible amount of time.
However, this benchmark demonstrates that for extreme values, the
internal for-loop does matter.
2023-01-02 16:19:35 -05:00
Brian Gianforcaro
a2a5cb0f24 AK: Add Time::is_negative() to detect negative time values 2021-08-15 12:20:38 +02:00
Brian Gianforcaro
67322b0702 Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
Renamed from AK/Tests/TestTime.cpp (Browse further)