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