118 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H10#define LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H11 12#include "hdr/stdint_proxy.h"13#include "hdr/types/time_t.h"14#include "src/__support/CPP/array.h"15#include "src/__support/CPP/string_view.h"16 17namespace LIBC_NAMESPACE_DECL {18namespace time_constants {19 20enum Month : int {21 JANUARY = 0,22 FEBRUARY,23 MARCH,24 APRIL,25 MAY,26 JUNE,27 JULY,28 AUGUST,29 SEPTEMBER,30 OCTOBER,31 NOVEMBER,32 DECEMBER33};34 35enum WeekDay : int {36 SUNDAY = 0,37 MONDAY,38 TUESDAY,39 WEDNESDAY,40 THURSDAY,41 FRIDAY,42 SATURDAY43};44 45constexpr int SECONDS_PER_MIN = 60;46constexpr int MINUTES_PER_HOUR = 60;47constexpr int HOURS_PER_DAY = 24;48constexpr int DAYS_PER_WEEK = 7;49constexpr int WEEKS_PER_YEAR = 52;50constexpr int MONTHS_PER_YEAR = 12;51constexpr int MAX_DAYS_PER_MONTH = 31;52constexpr int DAYS_PER_NON_LEAP_YEAR = 365;53constexpr int DAYS_PER_LEAP_YEAR = 366;54 55constexpr int LAST_DAY_OF_NON_LEAP_YEAR = DAYS_PER_NON_LEAP_YEAR - 1;56constexpr int LAST_DAY_OF_LEAP_YEAR = DAYS_PER_LEAP_YEAR - 1;57 58constexpr int SECONDS_PER_HOUR = SECONDS_PER_MIN * MINUTES_PER_HOUR;59constexpr int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;60constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR =61 DAYS_PER_LEAP_YEAR * SECONDS_PER_DAY;62 63constexpr int TIME_YEAR_BASE = 1900;64constexpr int EPOCH_YEAR = 1970;65constexpr int EPOCH_WEEK_DAY = 4;66 67constexpr int ISO_FIRST_DAY_OF_YEAR = 3; // the 4th day of the year, 0-indexed.68 69// For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are70// not within the normal ranges as defined in <time.h>, or if struct tm's71// tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm72// would attempt to generate more than 26 bytes of output (including the73// terminating null).74constexpr int ASCTIME_BUFFER_SIZE = 256;75constexpr int ASCTIME_MAX_BYTES = 26;76 77/* 2000-03-01 (mod 400 year, immediately after feb29 */78constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST =79 (946684800LL + SECONDS_PER_DAY * (31 + 29));80constexpr int WEEK_DAY_OF2000_MARCH_FIRST = 3;81 82constexpr int DAYS_PER400_YEARS =83 (DAYS_PER_NON_LEAP_YEAR * 400) + (400 / 4) - 3;84constexpr int DAYS_PER100_YEARS =85 (DAYS_PER_NON_LEAP_YEAR * 100) + (100 / 4) - 1;86constexpr int DAYS_PER4_YEARS = (DAYS_PER_NON_LEAP_YEAR * 4) + 1;87 88// The latest time that can be represented in this form is 03:14:07 UTC on89// Tuesday, 19 January 2038 (corresponding to 2,147,483,647 seconds since the90// start of the epoch). This means that systems using a 32-bit time_t type are91// susceptible to the Year 2038 problem.92constexpr int END_OF32_BIT_EPOCH_YEAR = 2038;93 94constexpr time_t OUT_OF_RANGE_RETURN_VALUE = -1;95 96constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_NAMES = {97 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};98 99constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_FULL_NAMES = {100 "Sunday", "Monday", "Tuesday", "Wednesday",101 "Thursday", "Friday", "Saturday"};102 103constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_NAMES = {104 "Jan", "Feb", "Mar", "Apr", "May", "Jun",105 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};106 107constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_FULL_NAMES = {108 "January", "February", "March", "April", "May", "June",109 "July", "August", "September", "October", "November", "December"};110 111constexpr int NON_LEAP_YEAR_DAYS_IN_MONTH[] = {31, 28, 31, 30, 31, 30,112 31, 31, 30, 31, 30, 31};113 114} // namespace time_constants115} // namespace LIBC_NAMESPACE_DECL116 117#endif // LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H118