hmd.h (2205B)
1#pragma once 2 3#include "allocator.h" 4 5#include <stdint.h> 6 7#define HMD_SEC_SPN (1) 8#define HMD_MIN_SPN (60) 9#define HMD_HOUR_SPN (HMD_MIN_SPN * 60) 10#define HMD_DAY_SPN (HMD_HOUR_SPN * 24) 11#define HMD_WEEK_SPN (HMD_DAY_SPN * 7) 12 13enum hmd_err { 14 HMD_OK = 0, 15 HMD_ERR_OOB, 16 HMD_ERR_FMT, 17 HMD_ERR_SYS, 18 HMD_ERR_ARG, 19 HMD_ERR_INT 20}; 21 22enum hmd_mon { 23 HMD_JAN, 24 HMD_FEB, 25 HMD_MAR, 26 HMD_APR, 27 HMD_MAY, 28 HMD_JUN, 29 HMD_JUL, 30 HMD_AUG, 31 HMD_SEP, 32 HMD_OCT, 33 HMD_NOV, 34 HMD_DEC 35}; 36 37enum hmd_wday { 38 HMD_SUN, 39 HMD_MON, 40 HMD_TUE, 41 HMD_WED, 42 HMD_THU, 43 HMD_FRI, 44 HMD_SAT, 45}; 46 47struct hmd_spn { 48 uint32_t years; 49 uint32_t weeks; 50 uint32_t days; 51 uint32_t hours; 52 uint32_t mins; 53 uint32_t secs; 54}; 55 56struct hmd_date { 57 uint64_t ts; /* unix epoch */ 58 uint64_t spn; 59}; 60 61struct hmd_dd { 62 uint16_t year; 63 uint8_t month; 64 uint8_t day; 65}; 66 67struct hmd_tod { 68 uint8_t hour; 69 uint8_t min; 70 uint8_t sec; 71 uint16_t spn; 72}; 73 74enum hmd_err hmd_spn_parse(struct hmd_spn *spn, const char *arg); 75enum hmd_err hmd_spn_ival_parse(struct hmd_spn *spn, const char *arg); 76 77enum hmd_err hmd_spn_calc(struct hmd_spn *spn, uint64_t start, uint64_t end); 78uint64_t hmd_spn_secs(struct hmd_spn *spn); 79 80char *hmd_spn_str(struct hmd_spn *spn, 81 const struct allocator *allocator, int *rc); 82char *hmd_spn_ival_str(struct hmd_spn *spn, 83 const struct allocator *allocator, int *rc); 84 85enum hmd_err hmd_date_parse_daydate_reltime_weekday( 86 struct hmd_date *date, char *arg); 87enum hmd_err hmd_date_parse_daydate_reltime_coarse( 88 struct hmd_date *date, char *arg); 89enum hmd_err hmd_date_parse_daydate_iso8601(struct hmd_date *date, char *arg); 90enum hmd_err hmd_timeofday_parse(struct hmd_tod *tod, char *arg); 91enum hmd_err hmd_date_parse(struct hmd_date *date, char *arg); 92 93char *hmd_date_str_reltime_exact(struct hmd_date *date, 94 const struct allocator *allocator, int *rc); 95char *hmd_date_str_reltime_coarse(struct hmd_date *date, 96 const struct allocator *allocator, int *rc); 97char *hmd_date_str_iso8601(struct hmd_date *date, 98 const struct allocator *allocator, int *rc); 99char *hmd_date_str(struct hmd_date *date, 100 const struct allocator *allocator, int *rc); 101 102extern const char *hmd_wdnames[7]; 103extern const char *hmd_mnames[12]; 104extern const int hmd_mdays[12];