libepoch/include/epoch.h
2024-02-05 19:12:51 -05:00

114 lines
2.2 KiB
C

#ifndef LIBEPOCH_H
#define LIBEPOCH_H 1
#include <stdint.h>
#define SECONDS_PER_MINUTE 60
#define SECONDS_PER_HOUR 60 * 60
#define SECONDS_PER_DAY 60 * 60 * 24
typedef enum {
normalYear,
leapYear,
} yearTag;
typedef struct {
yearTag tag;
uint32_t year;
} Year;
typedef enum {
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12,
} Month;
typedef enum {
Thursday = 0,
Friday = 1,
Saturday = 2,
Sunday = 3,
Monday = 4,
Tuesday = 5,
Wednesday = 6,
} Weekday;
typedef enum {
Offset,
UTC,
} timeZoneTag;
typedef enum {
Positive,
Negative,
} offsetSign;
typedef struct {
offsetSign sign;
uint8_t hours;
uint8_t minutes;
} TzOffset;
typedef struct {
timeZoneTag tag;
TzOffset *offset;
} TimeZone;
typedef struct {
Year year;
Month month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
int64_t nanoseconds;
TimeZone zone;
} DateTime;
typedef enum {
YearPrecision,
MonthPrecision,
DayPrecision,
HourPrecision,
MinutePrecision,
SecondPrecision,
NanoSecondPrecision,
} datetimePrecision;
void yearNew(Year *year, int32_t inner);
uint16_t yearGetDays(Year *year);
int64_t yearGetSeconds(Year *year);
int32_t yearGetInner(Year *year);
void yearIncrement(Year *year);
void yearDecrement(Year *year);
uint8_t monthGetDays(Month month, Year *year);
uint32_t monthGetSeconds(Month month, Year *year);
int monthIncrement(Month *month);
int monthDecrement(Month *month);
const char* monthName(Month month);
const char* monthAbbr(Month month);
int parseMonth(const char *s);
const char* weekdayName(Weekday day);
const char* weekdayAbbr(Weekday day);
int parseWeekday(const char *s);
int offsetNew(TzOffset *offs, offsetSign sign, uint8_t hours, uint8_t minutes);
void printTz(TimeZone *zone);
int64_t timezoneAsSeconds(TimeZone *tz);
int32_t dateTimeGetYear(DateTime *self);
int64_t dateTimeGetTimestampNaive(DateTime *self);
int64_t dateTimeGetTimestamp(DateTime *self);
#endif // !LIBEPOCH_H