diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-20 03:39:40 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-20 03:39:40 +0300 |
commit | 1cc7990ef7d5483d0434dda412f2d88e0b17df27 (patch) | |
tree | 93c9945318908c4f593251c0b8f9ecf57c3bde96 /src/date.c | |
parent | edf56e3444d5333d4362277ee97a5cdf0c2f52af (diff) | |
download | posthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.tar.gz posthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.zip |
initial working bytecode
Diffstat (limited to 'src/date.c')
-rw-r--r-- | src/date.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -23,6 +23,36 @@ ph_date_t date_from_numbers(unsigned year, unsigned month, unsigned day) return year << 9 | month << 5 | day; } +struct tm tm_from_date(ph_date_t date) +{ + unsigned year = 0; + unsigned month = 0; + unsigned day = 0; + date_split(date, &year, &month, &day); + + struct tm time = {.tm_year = year - 1900, .tm_mon = month - 1, .tm_mday = day}; + mktime(&time); + return time; +} + +ph_date_t date_from_tm(struct tm time) +{ + unsigned year = time.tm_year + 1900; + unsigned month = time.tm_mon + 1; + unsigned day = time.tm_mday; + return date_from_numbers(year, month, day); +} + +ph_date_t current_date() +{ + time_t t = time(NULL); + struct tm *time = localtime(&t); + unsigned year = time->tm_year + 1900; + unsigned month = time->tm_mon + 1; + unsigned day = time->tm_mday; + return date_from_numbers(year, month, day); +} + void date_split(ph_date_t date, unsigned *year, unsigned *month, unsigned *day) { if (year) *year = date >> 9; |