summaryrefslogtreecommitdiff
path: root/libc/src/time/mktime.cpp
AgeCommit message (Collapse)Author
2025-03-25[libc] change the return value type of mktime_internal to time_t (#132231)Leslie
This pr is to resovle #126948 --------- Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-02-11[libc] create TimeReader to look at a struct tm (#126138)Michael Jones
In the process of adding strftime (#122556) I wrote this utility class to simplify reading from a struct tm. It provides helper functions that return basically everything needed by strftime. It's not tested directly, but it is thoroughly exercised by the strftime tests.
2025-01-08[libc][NFC] Cleanup time.h (#122027)Michael Jones
While working on strftime I noticed some constants were being defined in unexpected places. One thing led to another, and I ended up doing a major cleanup of the time functions. What's included: All uses of <time.h> in /src and /test removed (except for LibcTest.cpp) The various time constants have been moved to time_constants.h, and the `time_constants` namespace. struct tm gets its own type indirection header now.
2025-01-07[libc] update todo with bug linkNick Desaulniers
2024-08-06[libc] Fix overflow check for 32-bit mktime. (#101993)Simon Tatham
The 32-bit time_t rolls over to a value with its high bit set at 2038-01-19 03:14:07. The overflow check for this in mktime() was checking each individual component of the time: reject if year>2038, or if month>1, or if day>19, etc. As a result it would reject valid times before the overflow point, because a low-order component was out of range even though a higher-order one makes the time as a whole safe. The earliest failing value is 2145916808 == 2038-01-01 00:00:08, in which only the seconds field 'overflows'. Fixed so that if any component is _less_ than its threshold value, we don't check the lower-order components.
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-01-24[libc] Add C23 limits.h header. (#78887)lntue
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-07[libc] Fix overflow check for 32 bit long time_t (#65394)Mikhail R. Gadelha
This patch fixes the overflow check in update_from_seconds, used by gmtime, gmtime_r and mktime. In update_from_seconds, total_seconds is a int64_t and the previous overflow check for when sizeof(time_t) == 4 would check if it was < 0x80000000 and > 0x7FFFFFFF, however, this check would cause the following issues: 1. Valid negative numbers would be discarded, e.g., -1 is 0xffffffffffffffff as a int64_t, outside the range of the overflow check. 2. Some valid positive numbers would be discarded because the hex constants were being implicitly converted to int64_t, e.g., 0x80000000 would be implicitly converted to 2147483648, instead of -2147483648. The fix for both cases was to static_cast total_seconds and the constants to time_t if sizeof(time_t) == 4. The behaviour is not changed in systems with sizeof(time_t) == 8. --------- Signed-off-by: Mikhail R. Gadelha <mikhail@igalia.com>
2021-12-07[libc] apply new lint rulesMichael Jones
This patch applies the lint rules described in the previous patch. There was also a significant amount of effort put into manually fixing things, since all of the templated functions, or structs defined in /spec, were not updated and had to be handled manually. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D114302
2021-03-16This introduces gmtime to LLVM libc, based on C99/C2X/Single Unix Spec.Raman Tenneti
This change doesn't handle TIMEZONE, tm_isdst and leap seconds. Moved shared code between mktime and gmtime into time_utils.cpp. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D98467
2021-02-22[libc] [Obvious] Fix.Raman Tenneti
2021-02-22Changes to mktime to handle invalid dates, overflow and underflow ↵Raman Tenneti
andcalculating the correct date and thenumber of seconds even if invalid datesare passed as arguments. Added tests for invalid dates like the following Date 1970-01-01 00:00:-1 is treated as 1969-12-31 23:59:59 and seconds are returned for the modified date. Tested the code by doing ninja check-libc (and cmake). Reviewed By: sivachandra, rtenneti Differential Revision: https://reviews.llvm.org/D96684
2021-01-08[libc] Switch to use a macro which does not insert a section for every libc ↵Michael Jones
function. Summary: The new macro also inserts the C alias for the C++ implementations without needing an objcopy based post processing step. The CMake rules have been updated to reflect this. More CMake cleanup can be taken up in future rounds and appropriate TODOs have been added for them. Reviewers: mcgrathr, sivachandra Subscribers:
2020-11-30Initial commit of mktime.Raman Tenneti
This introduces mktime to LLVM libc, based on C99/C2X/Single Unix Spec. Co-authored-by: Jeff Bailey <jeffbailey@google.com> This change doesn't handle TIMEZONE, tm_isdst and leap seconds. It returns -1 for invalid dates. I have verified the return results for all the possible dates with glibc's mktime. TODO: + Handle leap seconds. + Handle out of range time and date values that don't overflow or underflow. + Implement the following suggestion Siva - As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value. If not keep accumulating. The benefit is that, we don't have to validate every input, and also do not need the special cases for sizeof(time_t) == 4. + Handle timezone and update of tm_isdst Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D91551