diff options
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/datetime.c | 62 | ||||
| -rw-r--r-- | stdlib/datetime.h | 10 |
2 files changed, 71 insertions, 1 deletions
diff --git a/stdlib/datetime.c b/stdlib/datetime.c index 9fa4f8cd..98c23a8e 100644 --- a/stdlib/datetime.c +++ b/stdlib/datetime.c @@ -124,6 +124,68 @@ public void DateTime$get( if (weekday) *weekday = I(info.tm_wday + 1); } +public Int_t DateTime$year(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_year + 1900); +} + +public Int_t DateTime$month(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_mon + 1); +} + +public Int_t DateTime$day_of_week(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_wday + 1); +} + +public Int_t DateTime$day_of_month(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_mday); +} + +public Int_t DateTime$day_of_year(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_yday); +} + +public Int_t DateTime$hour(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_hour); +} + +public Int_t DateTime$minute(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_min); +} + +public Int_t DateTime$second(DateTime_t dt, OptionalText_t timezone) +{ + struct tm info = {}; + WITH_TIMEZONE(timezone, localtime_r(&dt.tv_sec, &info)); + return I(info.tm_sec); +} + +public Int_t DateTime$nanosecond(DateTime_t dt, OptionalText_t timezone) +{ + (void)timezone; + return I(dt.tv_usec); +} + public Text_t DateTime$format(DateTime_t dt, Text_t fmt, OptionalText_t timezone) { struct tm info; diff --git a/stdlib/datetime.h b/stdlib/datetime.h index 96669aa3..ccbc5190 100644 --- a/stdlib/datetime.h +++ b/stdlib/datetime.h @@ -18,7 +18,15 @@ DateTime_t DateTime$after(DateTime_t dt, double seconds, double minutes, double CONSTFUNC double DateTime$seconds_till(DateTime_t now, DateTime_t then); CONSTFUNC double DateTime$minutes_till(DateTime_t now, DateTime_t then); CONSTFUNC double DateTime$hours_till(DateTime_t now, DateTime_t then); -void DateTime$get(DateTime_t dt, Int_t *year, Int_t *month, Int_t *day, Int_t *hour, Int_t *minute, Int_t *second, Int_t *nanosecond, Int_t *weekday, OptionalText_t timezone); +Int_t DateTime$year(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$month(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$day_of_week(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$day_of_month(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$day_of_year(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$hour(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$minute(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$second(DateTime_t dt, OptionalText_t timezone); +Int_t DateTime$nanosecond(DateTime_t dt, OptionalText_t timezone); Text_t DateTime$format(DateTime_t dt, Text_t fmt, OptionalText_t timezone); Text_t DateTime$date(DateTime_t dt, OptionalText_t timezone); Text_t DateTime$time(DateTime_t dt, bool seconds, bool am_pm, OptionalText_t timezone); |
