aboutsummaryrefslogtreecommitdiff
path: root/src/date.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-04-20 03:39:40 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-04-20 03:39:40 +0300
commit1cc7990ef7d5483d0434dda412f2d88e0b17df27 (patch)
tree93c9945318908c4f593251c0b8f9ecf57c3bde96 /src/date.c
parentedf56e3444d5333d4362277ee97a5cdf0c2f52af (diff)
downloadposthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.tar.gz
posthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.zip
initial working bytecode
Diffstat (limited to 'src/date.c')
-rw-r--r--src/date.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/date.c b/src/date.c
index 7e6bc77..11f35c4 100644
--- a/src/date.c
+++ b/src/date.c
@@ -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;