[libc-commits] [libc] change the return value type of mktime_internal to time_t (PR #132231)
via libc-commits
libc-commits at lists.llvm.org
Thu Mar 20 08:33:47 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 0f646fc84883d6044691d2d60404de3cc4e60d5b f973ff93b2fa5cee7a96ec261f1b6e5a7baec88b --extensions h,cpp -- libc/src/time/mktime.cpp libc/src/time/time_utils.cpp libc/src/time/time_utils.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp
index f4f06e276a..aa5c489a8d 100644
--- a/libc/src/time/time_utils.cpp
+++ b/libc/src/time/time_utils.cpp
@@ -18,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace time_utils {
// TODO: clean this up in a followup patch
-time_t mktime_internal(const tm *tm_out, bool* out_of_range_flag) {
+time_t mktime_internal(const tm *tm_out, bool *out_of_range_flag) {
// Unlike most C Library functions, mktime doesn't just die on bad input.
// TODO(rtenneti); Handle leap seconds.
int64_t tm_year_from_base = tm_out->tm_year + time_constants::TIME_YEAR_BASE;
@@ -37,18 +37,15 @@ time_t mktime_internal(const tm *tm_out, bool* out_of_range_flag) {
if (tm_out->tm_mday > 19) {
*out_of_range_flag = true;
return time_constants::OUT_OF_RANGE_RETURN_VALUE;
- }
- else if (tm_out->tm_mday == 19) {
+ } else if (tm_out->tm_mday == 19) {
if (tm_out->tm_hour > 3) {
*out_of_range_flag = true;
return time_constants::OUT_OF_RANGE_RETURN_VALUE;
- }
- else if (tm_out->tm_hour == 3) {
+ } else if (tm_out->tm_hour == 3) {
if (tm_out->tm_min > 14) {
*out_of_range_flag = true;
return time_constants::OUT_OF_RANGE_RETURN_VALUE;
- }
- else if (tm_out->tm_min == 14) {
+ } else if (tm_out->tm_min == 14) {
if (tm_out->tm_sec > 7) {
*out_of_range_flag = true;
return time_constants::OUT_OF_RANGE_RETURN_VALUE;
@@ -115,9 +112,9 @@ time_t mktime_internal(const tm *tm_out, bool* out_of_range_flag) {
// TODO: https://github.com/llvm/llvm-project/issues/121962
// Need to handle timezone and update of tm_isdst.
time_t seconds = tm_out->tm_sec +
- tm_out->tm_min * time_constants::SECONDS_PER_MIN +
- tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
- total_days * time_constants::SECONDS_PER_DAY;
+ tm_out->tm_min * time_constants::SECONDS_PER_MIN +
+ tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
+ total_days * time_constants::SECONDS_PER_DAY;
return seconds;
}
diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 6081f250d1..0be35710af 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -26,7 +26,7 @@ namespace time_utils {
// calculates the seconds from the epoch for tm_in. Does not update the struct,
// you must call update_from_seconds for that.
-time_t mktime_internal(const tm *tm_out, bool* out_of_range_flag);
+time_t mktime_internal(const tm *tm_out, bool *out_of_range_flag);
// Update the "tm" structure's year, month, etc. members from seconds.
// "total_seconds" is the number of seconds since January 1st, 1970.
``````````
</details>
https://github.com/llvm/llvm-project/pull/132231
More information about the libc-commits
mailing list