1 //===-- Collection of constants for time functions --------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H 10 #define LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H 11 12 #include "hdr/types/time_t.h" 13 #include "src/__support/CPP/array.h" 14 #include "src/__support/CPP/string_view.h" 15 #include <stdint.h> 16 17 namespace LIBC_NAMESPACE_DECL { 18 namespace time_constants { 19 20 enum Month : int { 21 JANUARY, 22 FEBRUARY, 23 MARCH, 24 APRIL, 25 MAY, 26 JUNE, 27 JULY, 28 AUGUST, 29 SEPTEMBER, 30 OCTOBER, 31 NOVEMBER, 32 DECEMBER 33 }; 34 35 constexpr int SECONDS_PER_MIN = 60; 36 constexpr int MINUTES_PER_HOUR = 60; 37 constexpr int HOURS_PER_DAY = 24; 38 constexpr int DAYS_PER_WEEK = 7; 39 constexpr int MONTHS_PER_YEAR = 12; 40 constexpr int DAYS_PER_NON_LEAP_YEAR = 365; 41 constexpr int DAYS_PER_LEAP_YEAR = 366; 42 43 constexpr int SECONDS_PER_HOUR = SECONDS_PER_MIN * MINUTES_PER_HOUR; 44 constexpr int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; 45 constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR = 46 DAYS_PER_LEAP_YEAR * SECONDS_PER_DAY; 47 48 constexpr int TIME_YEAR_BASE = 1900; 49 constexpr int EPOCH_YEAR = 1970; 50 constexpr int EPOCH_WEEK_DAY = 4; 51 52 // For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are 53 // not within the normal ranges as defined in <time.h>, or if struct tm's 54 // tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm 55 // would attempt to generate more than 26 bytes of output (including the 56 // terminating null). 57 constexpr int ASCTIME_BUFFER_SIZE = 256; 58 constexpr int ASCTIME_MAX_BYTES = 26; 59 60 /* 2000-03-01 (mod 400 year, immediately after feb29 */ 61 constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST = 62 (946684800LL + SECONDS_PER_DAY * (31 + 29)); 63 constexpr int WEEK_DAY_OF2000_MARCH_FIRST = 3; 64 65 constexpr int DAYS_PER400_YEARS = 66 (DAYS_PER_NON_LEAP_YEAR * 400) + (400 / 4) - 3; 67 constexpr int DAYS_PER100_YEARS = 68 (DAYS_PER_NON_LEAP_YEAR * 100) + (100 / 4) - 1; 69 constexpr int DAYS_PER4_YEARS = (DAYS_PER_NON_LEAP_YEAR * 4) + 1; 70 71 // The latest time that can be represented in this form is 03:14:07 UTC on 72 // Tuesday, 19 January 2038 (corresponding to 2,147,483,647 seconds since the 73 // start of the epoch). This means that systems using a 32-bit time_t type are 74 // susceptible to the Year 2038 problem. 75 constexpr int END_OF32_BIT_EPOCH_YEAR = 2038; 76 77 constexpr time_t OUT_OF_RANGE_RETURN_VALUE = -1; 78 79 constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_NAMES = { 80 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 81 82 constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_FULL_NAMES = { 83 "Sunday", "Monday", "Tuesday", "Wednesday", 84 "Thursday", "Friday", "Saturday"}; 85 86 constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_NAMES = { 87 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 88 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 89 90 constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_FULL_NAMES = { 91 "January", "February", "March", "April", "May", "June", 92 "July", "August", "September", "October", "November", "December"}; 93 94 constexpr int NON_LEAP_YEAR_DAYS_IN_MONTH[] = {31, 28, 31, 30, 31, 30, 95 31, 31, 30, 31, 30, 31}; 96 97 } // namespace time_constants 98 } // namespace LIBC_NAMESPACE_DECL 99 100 #endif // LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H 101