From 9a238a937e31b36e7ee35109c09764019ee3af1f Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 09:23:43 +0200 Subject: Added some preliminary support for time zones (for scheduled posts). --- xs_time.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'xs_time.h') diff --git a/xs_time.h b/xs_time.h index 0e004dc..eaced75 100644 --- a/xs_time.h +++ b/xs_time.h @@ -15,6 +15,8 @@ time_t xs_parse_time(const char *str, const char *fmt, int local); #define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) #define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) xs_str *xs_str_time_diff(time_t time_diff); +xs_list *xs_tz_list(void); +int xs_tz_offset(const char *tz); #ifdef XS_IMPLEMENTATION @@ -106,6 +108,75 @@ time_t xs_parse_iso_date(const char *iso_date, int local) } +/** timezones **/ + +/* intentionally dead simple */ + +struct { + const char *tz; /* timezone name */ + float h_offset; /* hour offset */ +} xs_tz[] = { + { "UTC", 0 }, + { "GMT", 0 }, + { "GMT+1", -1 }, + { "GMT+2", -2 }, + { "GMT+3", -3 }, + { "GMT+4", -4 }, + { "GMT+5", -5 }, + { "GMT+6", -6 }, + { "GMT+7", -7 }, + { "GMT+8", -8 }, + { "GMT+9", -9 }, + { "GMT+10", -10 }, + { "GMT+11", -11 }, + { "GMT+12", -12 }, + { "GMT-1", 1 }, + { "GMT-2", 2 }, + { "GMT-3", 3 }, + { "GMT-4", 4 }, + { "GMT-5", 5 }, + { "GMT-6", 6 }, + { "GMT-7", 7 }, + { "GMT-8", 8 }, + { "GMT-9", 9 }, + { "GMT-10", 10 }, + { "GMT-11", 11 }, + { "GMT-12", 12 }, + { "GMT-13", 13 }, + { "GMT-14", 14 }, + { "GMT-15", 15 }, + { "CET", -1 }, + { "CST", -6 }, + { "MST", -7 }, + { "PST", -8 }, + { NULL, 0 } +}; + + +xs_list *xs_tz_list(void) +/* returns the list of supported timezones */ +{ + xs_list *l = xs_list_new(); + + for (int n = 0; xs_tz[n].tz != NULL; n++) + l = xs_list_append(l, xs_tz[n].tz); + + return l; +} + + +int xs_tz_offset(const char *tz) +/* returns the offset in seconds from the specified Time Zone to UTC */ +{ + for (int n = 0; xs_tz[n].tz != NULL; n++) { + if (strcmp(xs_tz[n].tz, tz) == 0) + return xs_tz[n].h_offset * 3600; + } + + return 0; +} + + #endif /* XS_IMPLEMENTATION */ #endif /* _XS_TIME_H */ -- cgit v1.2.3 From d78bd5a4f98fab9c7eb82837b0d783cdd28d00ca Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 09:51:44 +0200 Subject: Added more timezones. --- xs_time.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'xs_time.h') diff --git a/xs_time.h b/xs_time.h index eaced75..4da9463 100644 --- a/xs_time.h +++ b/xs_time.h @@ -145,7 +145,9 @@ struct { { "GMT-13", 13 }, { "GMT-14", 14 }, { "GMT-15", 15 }, + { "WET", 0 }, { "CET", -1 }, + { "AST", -4 }, { "CST", -6 }, { "MST", -7 }, { "PST", -8 }, -- cgit v1.2.3 From 81538904210e9092760ce7c6b043eaaa166509b6 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 14:12:37 +0200 Subject: More timezone tweaks. --- xs_time.h | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'xs_time.h') diff --git a/xs_time.h b/xs_time.h index 4da9463..6872c51 100644 --- a/xs_time.h +++ b/xs_time.h @@ -116,7 +116,36 @@ struct { const char *tz; /* timezone name */ float h_offset; /* hour offset */ } xs_tz[] = { - { "UTC", 0 }, + { "UTC", 0 }, + { "WET (Western European Time)", 0 }, + { "WEST (Western European Summer Time)", 1 }, + { "CET (Central European Time)", 1 }, + { "CEST (Central European Summer Time)", 2 }, + { "EET (Eastern European Time)", 2 }, + { "EEST (Eastern European Summer Time)", 3 }, + { "MSK (Moskow Time Zone)", 3 }, + { "EST (Eastern Time Zone)", -5 }, + { "AST (Atlantic Time Zone)", -4 }, + { "ADT (Atlantic Daylight Time Zone)", -3 }, + { "CST (Central Time Zone)", -6 }, + { "CDT (Central Daylight Time Zone)", -5 }, + { "MST (Mountain Time Zone)", -7 }, + { "MDT (Mountain Daylight Time Zone)", -6 }, + { "PST (Pacific Time Zone)", -8 }, + { "PDT (Pacific Daylight Time Zone)", -7 }, + { "AKST (Alaska Time Zone)", -9 }, + { "AKDT (Alaska Daylight Time Zone)", -8 }, + { "China Time Zone", 8 }, + { "IST (Israel Standard Time)", 2 }, + { "IDT (Israel Daylight Standard Time)", 3 }, + { "WITA (Western Indonesia Time)", 8 }, + { "AWST (Australian Western Time)", 8 }, + { "ACST (Australian Eastern Time)", 9.5 }, + { "ACDT (Australian Daylight Eastern Time)", 10.5 }, + { "AEST (Australian Eastern Time)", 10 }, + { "AEDT (Australian Daylight Eastern Time)", 11 }, + { "NZST (New Zealand Time)", 12 }, + { "NZDT (New Zealand Daylight Time)", 13 }, { "GMT", 0 }, { "GMT+1", -1 }, { "GMT+2", -2 }, @@ -144,13 +173,6 @@ struct { { "GMT-12", 12 }, { "GMT-13", 13 }, { "GMT-14", 14 }, - { "GMT-15", 15 }, - { "WET", 0 }, - { "CET", -1 }, - { "AST", -4 }, - { "CST", -6 }, - { "MST", -7 }, - { "PST", -8 }, { NULL, 0 } }; -- cgit v1.2.3 From 7349c626cfd66d0b7f4bff1c4bb698adbf291ecb Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 16:17:19 +0200 Subject: Updated timezones. --- xs_time.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'xs_time.h') diff --git a/xs_time.h b/xs_time.h index 6872c51..4347e09 100644 --- a/xs_time.h +++ b/xs_time.h @@ -138,7 +138,9 @@ struct { { "China Time Zone", 8 }, { "IST (Israel Standard Time)", 2 }, { "IDT (Israel Daylight Standard Time)", 3 }, - { "WITA (Western Indonesia Time)", 8 }, + { "WIB (Western Indonesia Time)", 7 }, + { "WITA (Central Indonesia Time)", 8 }, + { "WIT (Eastern Indonesia Time)", 9 }, { "AWST (Australian Western Time)", 8 }, { "ACST (Australian Eastern Time)", 9.5 }, { "ACDT (Australian Daylight Eastern Time)", 10.5 }, -- cgit v1.2.3 From aa2539104d1a2c0c0bc985d269255fe7c3e00715 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 16 Apr 2025 05:05:51 +0200 Subject: Also added UTC+... timezones. --- xs_time.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'xs_time.h') diff --git a/xs_time.h b/xs_time.h index 4347e09..a5792bc 100644 --- a/xs_time.h +++ b/xs_time.h @@ -148,6 +148,33 @@ struct { { "AEDT (Australian Daylight Eastern Time)", 11 }, { "NZST (New Zealand Time)", 12 }, { "NZDT (New Zealand Daylight Time)", 13 }, + { "UTC", 0 }, + { "UTC+1", 1 }, + { "UTC+2", 2 }, + { "UTC+3", 3 }, + { "UTC+4", 4 }, + { "UTC+5", 5 }, + { "UTC+6", 6 }, + { "UTC+7", 7 }, + { "UTC+8", 8 }, + { "UTC+9", 9 }, + { "UTC+10", 10 }, + { "UTC+11", 11 }, + { "UTC+12", 12 }, + { "UTC-1", -1 }, + { "UTC-2", -2 }, + { "UTC-3", -3 }, + { "UTC-4", -4 }, + { "UTC-5", -5 }, + { "UTC-6", -6 }, + { "UTC-7", -7 }, + { "UTC-8", -8 }, + { "UTC-9", -9 }, + { "UTC-10", -10 }, + { "UTC-11", -11 }, + { "UTC-12", -12 }, + { "UTC-13", -13 }, + { "UTC-14", -14 }, { "GMT", 0 }, { "GMT+1", -1 }, { "GMT+2", -2 }, -- cgit v1.2.3