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 : 900 : is_leap_year(const int64_t year) 15 : : { 16 [ + + + + : 900 : 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 : 3113 : days_in_month(const int16_t year, const uint8_t month) 22 : : { 23 : 900 : return month == 2U ? (is_leap_year(year) ? 29U : 28U) 24 [ + + + + ]: 4013 : : (uint8_t)(30U + ((month + (month / 8U)) % 2U)); 25 : : } 26 : : 27 : : /// Read YYYY-MM-DD date numbers without a timezone 28 : : EXESS_NONBLOCKING ExessResult 29 : : read_date_numbers(ExessDate* out, const char* str); 30 : : 31 : : #endif // EXESS_SRC_DATE_UTILS_H