Branch data Line data Source code
1 : : // Copyright 2019-2026 David Robillard <d@drobilla.net> 2 : : // SPDX-License-Identifier: ISC 3 : : 4 : : #ifndef EXESS_SRC_DATE_UTILS_H 5 : : #define EXESS_SRC_DATE_UTILS_H 6 : : 7 : : #include <exess/exess.h> 8 : : 9 : : #include <stdbool.h> 10 : : #include <stdint.h> 11 : : 12 : : /// Return whether a year is a leap year in the proleptic Gregorian calendar 13 : : static inline bool 14 : 950 : is_leap_year(const int64_t year) 15 : : { 16 [ + + + + : 950 : return !(year % 4) && ((year % 100) || !(year % 400)); + + ] 17 : : } 18 : : 19 : : /// Return the number of days in some month of the proleptic Gregorian calendar 20 : : static inline uint8_t 21 : 3374 : days_in_month(const int16_t year, const uint8_t month) 22 : : { 23 : 950 : return month == 2U ? (is_leap_year(year) ? 29U : 28U) 24 [ + + + + ]: 4324 : : (uint8_t)(30U + ((month + (month / 8U)) % 2U)); 25 : : } 26 : : 27 : : /// Read date -MM number 28 : : EXESS_NONBLOCKING ExessResult 29 : : read_date_m(uint8_t* m_out, const char* str); 30 : : 31 : : // Read date YYYY-MM numbers 32 : : EXESS_NONBLOCKING ExessResult 33 : : read_date_ym(int16_t* y_out, uint8_t* m_out, const char* str); 34 : : 35 : : // Read date -DD number 36 : : EXESS_NONBLOCKING ExessResult 37 : : read_date_d(uint8_t* d_out, const char* str); 38 : : 39 : : /// Read date YYYY-MM-DD numbers 40 : : EXESS_NONBLOCKING ExessResult 41 : : read_date_numbers(ExessDate* out, const char* str); 42 : : 43 : : #endif // EXESS_SRC_DATE_UTILS_H