summaryrefslogtreecommitdiff
path: root/AK/Time.h
AgeCommit message (Collapse)Author
2023-01-21Everywhere: Remove string.h include from AK/Traits.h and resolve falloutAndrew Kaster
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp, memcpy and other related declarations. In the quest to remove inclusion of LibC headers from Kernel files, deal with all the fallout of this included-everywhere header including less things.
2023-01-07AK: Reimplement comparisons on AK::Time using operator<=>Andrew Kaster
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-07AK: Remove global free function comparison operators for timespecAndrew Kaster
No code was using these, so let's just delete them. They pollute the lookup for every single comparison operator in the project.
2023-01-07AK: Add user defined literals for Time for ns, us, ms, and secAndrew Kaster
We can use these to simplify Time constants throughout the codebase, turning Time::from_milliseconds(10) into 10_ms, for example.
2023-01-02AK+Kernel: Eliminate UB (signed overflow) from days_since_epochBen Wiederhake
2023-01-02AK+Tests: Replace years_to_days_since_epoch by near-instant functionBen Wiederhake
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
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-11-06Everywhere: Remove redundant inequality comparison operatorsDaniel Bertalan
C++20 can automatically synthesize `operator!=` from `operator==`, so there is no point in writing such functions by hand if all they do is call through to `operator==`. This fixes a compile error with compilers that implement P2468 (Clang 16 currently). This paper restores the C++17 behavior that if both `T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators makes the rewriting possible again. See https://reviews.llvm.org/D134529#3853062
2022-09-29Lagom: Win32 support baby stepsDiego Iastrubni
This is the initial port of Lagom to win32. This will enable developers to use Lagom as an alternative to vanilla STL/StandardC++Library - which gives a much richer environment (think QtCore - but modern). My main incentive - is to have a native Windows Ladybird working. I am starting with AK, which does not yet fully compile (on mingw). When AK is compiling (currently fails building StringBuffer.cpp) - I will continue to LibCore and then the rest of the user space libraries (excluding the GUI, which will be another different effort). Most of the code is happily stollen from Andrew Kaster's fork - he deserves the credit. Co-authored-by: Andrew Kaster <akaster@serenityos.org>
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-02-28AK: Add Time::from_ticks()Lucas CHOLLET
This helper allows Time to be constructed from a tick count and a ticks per second value.
2022-01-23AK: Implement AK::Time's seconds_since_epoch_to_year without LibMTimothy Flynn
In order for this method to be used within LibC itself, avoid using the floor() method from LibM, which is not available from within LibC. This header similarly avoids other standard headers as well.
2022-01-19AK: Add helper to convert an epoch time in seconds to a yearTimothy Flynn
2022-01-14AK: Use appropriate types in AK::Time::from_timestamp factoryTimothy Flynn
Allow the provided year to be negative, and allow millisecond values larger than 255.
2022-01-11AK: Add AK::Time factory method to construct from individual time fieldsTimothy Flynn
2022-01-11AK: Redeclare a few AK::Time helpers as constexprTimothy Flynn
This is to allow using these methods within an upcoming constexpr factory method.
2022-01-05AK: Add Time.h helper to compute the number of days since epochTimothy Flynn
2022-01-05AK: Move TimeSpecType concept inside the AK namespaceTimothy Flynn
This is just to allow removing the 'clang-format off' directive. This concept is only used within this header, so it doesn't need to be in the global namespace.
2021-11-14AK: Avoid implicit conversion clang-tidy warnings in AK::TimeAndrew Kaster
2021-11-14AK: Resolve clang-tidy readability-bool-conversion warningsAndrew Kaster
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-08-19LibCore: Make DateTime's members signedIdan Horowitz
Core::DateTime is essentially a C++ wrapper of the tm struct, so we should support the same signed range as the underlying tm.
2021-08-15AK: Add Time::is_negative() to detect negative time valuesBrian Gianforcaro
2021-08-15AK: Annotate AK::Time APIs as [[nodiscard]]Brian Gianforcaro
2021-08-15AK: Add Time::now_<clock_id> functions for obtaining the current timeBrian Gianforcaro
In the quest of removing as timespec / timeval usage in the Userland as possible, we need a way to conveniently retrieving the current clock time from the kernel and storing it in `AK::Time` format.
2021-08-03AK: Mark Time::max() / Time::min() / Time::zero() as constexprBrian Gianforcaro
No reason for these static helper functions to not be constexpr.
2021-07-22AK: Disable clang-format for AK/Time.hGunnar Beutner
clang-format >=12 format this file incorrectly/differently.
2021-07-17AK: Restrict timespec comparison operator overloads in AK::TimeBrian Gianforcaro
The previous implementation was too generic, and would cause conflicting operator overload errors when included in certain code paths. Fix this by restricting the template parameters to types which have the same member names as `struct timespec`.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-13AK: Fix some overflows/underflows that weren't properly handledBen Wiederhake
Based on #5699. Closes #5699.
2021-03-08AK: Take advantage of constexpr in Time and add time conversion methodsTom
By making the Time constructor constexpr we can optimize creating a Time instance from hardcoded values. Also add more functions to convert between Time and various time units.
2021-03-08AK: Initialize the AK::Time membersTom
Since we tell the compiler to provide a default constructor we need to initialize the member variables.
2021-03-02AK: Make Time more usableBen Wiederhake
2021-03-02AK: Implement C++ 'Time' type for easier time-calculationsBen Wiederhake
This adds a bunch of code in the hope that other, wrong code can be deleted. Related to #5315.
2021-03-02AK: Remove unused templateBen Wiederhake
2020-12-28AK: Add CLOCK_*_COARSE aliases for darwin and BSD variantsAndrew Kaster
The coarse clocks in time.h are a linux extension that we've adopted. MacOS and the BSDs don't have it, so we need an alias in a platform header for Lagom builds.
2020-09-25Meta+AK: Make clang-format-10 cleanBen Wiederhake
2020-08-26AK+LibC+LibCore: Have fewer implementations of day_of_weekNico Weber
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-26AK+LibC+LibCore: Add a days_in_year functionNico Weber
2020-08-26AK+LibC+LibCore: Have fewer implementations of days_in_monthNico Weber
2020-08-26AK+LibCore+Kernel: Have fewer implementations of day_of_yearNico Weber
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-26AK+LibC+Kernel: Have fewer implementations of year_to_days_in_epochNico Weber
I believe the implementation in RTC.cpp had an off-by-one in the year passed to is_leap_year(). If that's true, then this fixes that too.
2020-08-26AK+LibC+LibCore+Kernel: Have fewer implementations of is_leap_yearNico Weber
2020-08-03AK: Add more time convenience functions and comparison operatorsTom
2020-08-03AK: Fix adding timeval/timespecTom
tv_usec and tv_nsec should always be less than one second.
2020-06-22AK: Add timespec_add and timespec_subNico Weber
2020-04-26AK: Add timeval_to_timespec and timespec_to_timeval conversion methodsBrian Gianforcaro
Add the ability to easily convert between timeval and timespec.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-06-06AK: Make timeval_add() and timeval_sub() take references.Andreas Kling
2019-05-28LibC: Move struct timeval to sys/time.h. #POSIXAndreas Kling