commit 27f6020924c3cf57e180dad757c69975dab6efb4
parent 82880ac92499148484ea31b626a43e4e6a21e642
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Wed, 27 Sep 2023 23:39:32 +0200
feat: use iana tzids
Diffstat:
3 files changed, 193 insertions(+), 2 deletions(-)
diff --git a/server.go b/server.go
@@ -14,6 +14,7 @@ import (
"github.com/teambition/rrule-go"
"hivedav/caldav"
"hivedav/config"
+ "hivedav/tzdb"
"html/template"
"io"
"log"
@@ -663,6 +664,7 @@ func (s *Server) sendMail(recepient string, msg string, dtstart time.Time) error
// TODO: This will probably have to change for winter (standard) time
// TODO: Check the 1/2h timezones
zone, offsetSec := dtstart.Zone()
+ tzdbZone := tzdb.GetTzdbFromLocation(zone)
offsetHours := offsetSec / 60 / 60
var (
@@ -691,7 +693,7 @@ func (s *Server) sendMail(recepient string, msg string, dtstart time.Time) error
Timestamp: time.Now().Format("20060102T150405Z"),
Dtstart: dtstart.Format("20060102T150405"),
Dtend: dtstart.Add(time.Hour).Format("20060102T150405"),
- Timezone: zone,
+ Timezone: tzdbZone,
StandardTzOffsetFrom: standardTzOffsetFrom,
StandardTzOffsetTo: standardTzOffsetTo,
DstTzOffsetFrom: dstTzOffsetFrom,
diff --git a/templates/booking.ics b/templates/booking.ics
@@ -19,7 +19,8 @@ RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3;WKST=SU
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:{{ .Organizer }}
+STATUS:CONFIRMED
+ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:{{ .Organizer }}
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:{{ .Attendee }}
ORGANIZER:mailto:{{ .Organizer }}
CREATED:{{ .Timestamp }}
diff --git a/tzdb/tzdb.go b/tzdb/tzdb.go
@@ -0,0 +1,188 @@
+package tzdb
+
+func GetTzdbFromLocation(l string) string {
+ return locationTzdb[l]
+}
+
+// This list of locations to region mappings was generated using a modified
+// version of https://go.dev/src/time/genzabbrs.go
+var locationTzdb = map[string]string{
+ "+00": "Africa/Casablanca",
+ //"+00": "Atlantic/Azores",
+ "+01": "Africa/Casablanca",
+ "-01": "Atlantic/Azores",
+ //"-01": "Atlantic/Cape_Verde",
+ "-02": "America/Godthab",
+ //"-02": "America/Miquelon",
+ //"-02": "Etc/GMT+2",
+ "+0330": "Asia/Tehran",
+ "-03": "America/Araguaina",
+ //"-03": "America/Asuncion",
+ //"-03": "America/Bahia",
+ //"-03": "America/Buenos_Aires",
+ //"-03": "America/Cayenne",
+ //"-03": "America/Godthab",
+ //"-03": "America/Miquelon",
+ //"-03": "America/Montevideo",
+ //"-03": "America/Punta_Arenas",
+ //"-03": "America/Santiago",
+ //"-03": "America/Sao_Paulo",
+ "+03": "Asia/Amman",
+ //"+03": "Asia/Baghdad",
+ //"+03": "Asia/Damascus",
+ //"+03": "Asia/Riyadh",
+ //"+03": "Europe/Istanbul",
+ //"+03": "Europe/Minsk",
+ "+0430": "Asia/Kabul",
+ "-04": "America/Asuncion",
+ //"-04": "America/Caracas",
+ //"-04": "America/Cuiaba",
+ //"-04": "America/La_Paz",
+ //"-04": "America/Santiago",
+ "+04": "Asia/Baku",
+ //"+04": "Asia/Dubai",
+ //"+04": "Asia/Tbilisi",
+ //"+04": "Asia/Yerevan",
+ //"+04": "Europe/Astrakhan",
+ //"+04": "Europe/Samara",
+ //"+04": "Europe/Saratov",
+ //"+04": "Indian/Mauritius",
+ "+0530": "Asia/Colombo",
+ "+0545": "Asia/Katmandu",
+ "-05": "Pacific/Easter",
+ //"-05": "America/Bogota",
+ "+05": "Asia/Qyzylorda",
+ //"+05": "Asia/Tashkent",
+ //"+05": "Asia/Yekaterinburg",
+ "+0630": "Asia/Rangoon",
+ "+06": "Asia/Almaty",
+ //"+06": "Asia/Dhaka",
+ //"+06": "Asia/Omsk",
+ "-06": "Pacific/Easter",
+ "+07": "Asia/Bangkok",
+ //"+07": "Asia/Barnaul",
+ //"+07": "Asia/Hovd",
+ //"+07": "Asia/Krasnoyarsk",
+ //"+07": "Asia/Novosibirsk",
+ //"+07": "Asia/Tomsk",
+ "+0845": "Australia/Eucla",
+ "+08": "Asia/Irkutsk",
+ //"+08": "Asia/Singapore",
+ //"+08": "Asia/Ulaanbaatar",
+ "-08": "Etc/GMT+8",
+ "-0930": "Pacific/Marquesas",
+ "+09": "Asia/Chita",
+ //"+09": "Asia/Yakutsk",
+ "-09": "Etc/GMT+9",
+ "+1030": "Australia/Lord_Howe",
+ "+10": "Asia/Vladivostok",
+ //"+10": "Pacific/Port_Moresby",
+ "+11": "Asia/Magadan",
+ //"+11": "Asia/Sakhalin",
+ //"+11": "Asia/Srednekolymsk",
+ //"+11": "Australia/Lord_Howe",
+ //"+11": "Pacific/Bougainville",
+ //"+11": "Pacific/Guadalcanal",
+ //"+11": "Pacific/Norfolk",
+ "-11": "Etc/GMT+11",
+ "+1245": "Pacific/Chatham",
+ "+12": "Asia/Kamchatka",
+ //"+12": "Etc/GMT-12",
+ //"+12": "Pacific/Fiji",
+ //"+12": "Pacific/Norfolk",
+ "-12": "Etc/GMT+12",
+ "+1345": "Pacific/Chatham",
+ "+13": "Etc/GMT-13",
+ //"+13": "Pacific/Apia",
+ //"+13": "Pacific/Tongatapu",
+ "+14": "Pacific/Kiritimati",
+ "ACDT": "Australia/Adelaide",
+ "ACST": "Australia/Adelaide",
+ //"ACST": "Australia/Darwin",
+ "ADT": "America/Halifax",
+ "AEDT": "Australia/Hobart",
+ //"AEDT": "Australia/Sydney",
+ "AEST": "Australia/Brisbane",
+ //"AEST": "Australia/Hobart",
+ //"AEST": "Australia/Sydney",
+ "AKDT": "America/Anchorage",
+ "AKST": "America/Anchorage",
+ "AST": "America/Halifax",
+ "AWST": "Australia/Perth",
+ "BST": "Europe/London",
+ "CAT": "Africa/Juba",
+ //"CAT": "Africa/Khartoum",
+ //"CAT": "Africa/Windhoek",
+ "CDT": "America/Chicago",
+ //"CDT": "America/Havana",
+ "CEST": "Europe/Berlin",
+ //"CEST": "Europe/Budapest",
+ //"CEST": "Europe/Paris",
+ //"CEST": "Europe/Warsaw",
+ "CET": "Europe/Berlin",
+ //"CET": "Europe/Budapest",
+ //"CET": "Europe/Paris",
+ //"CET": "Europe/Warsaw",
+ "CST": "America/Chicago",
+ //"CST": "America/Guatemala",
+ //"CST": "America/Havana",
+ //"CST": "America/Mexico_City",
+ //"CST": "America/Regina",
+ //"CST": "Asia/Shanghai",
+ //"CST": "Asia/Taipei",
+ "EAT": "Africa/Nairobi",
+ "EDT": "America/Grand_Turk",
+ //"EDT": "America/Indianapolis",
+ //"EDT": "America/New_York",
+ //"EDT": "America/Port-au-Prince",
+ "EEST": "Africa/Cairo",
+ //"EEST": "Asia/Beirut",
+ //"EEST": "Asia/Hebron",
+ //"EEST": "Europe/Bucharest",
+ //"EEST": "Europe/Chisinau",
+ //"EEST": "Europe/Kiev",
+ "EET": "Africa/Cairo",
+ //"EET": "Africa/Tripoli",
+ //"EET": "Asia/Beirut",
+ //"EET": "Asia/Hebron",
+ //"EET": "Europe/Bucharest",
+ //"EET": "Europe/Chisinau",
+ //"EET": "Europe/Kaliningrad",
+ //"EET": "Europe/Kiev",
+ //"EST": "America/Cancun",
+ //"EST": "America/Grand_Turk",
+ //"EST": "America/Indianapolis",
+ //"EST": "America/New_York",
+ //"EST": "America/Port-au-Prince",
+ "GMT": "Europe/London",
+ //"GMT": "Africa/Sao_Tome",
+ //"GMT": "Atlantic/Reykjavik",
+ "HDT": "America/Adak",
+ "HST": "America/Adak",
+ //"HST": "Pacific/Honolulu",
+ "IDT": "Asia/Jerusalem",
+ "IST": "Asia/Calcutta",
+ //"IST": "Asia/Jerusalem",
+ "JST": "Asia/Tokyo",
+ "KST": "Asia/Pyongyang",
+ //"KST": "Asia/Seoul",
+ "MDT": "America/Denver",
+ "MSK": "Europe/Moscow",
+ //"MSK": "Europe/Volgograd",
+ "MST": "America/Denver",
+ //"MST": "America/Mazatlan",
+ //"MST": "America/Phoenix",
+ //"MST": "America/Whitehorse",
+ "NDT": "America/St_Johns",
+ "NST": "America/St_Johns",
+ "NZDT": "Pacific/Auckland",
+ "NZST": "Pacific/Auckland",
+ "PDT": "America/Los_Angeles",
+ //"PDT": "America/Tijuana",
+ "PKT": "Asia/Karachi",
+ "PST": "America/Los_Angeles",
+ //"PST": "America/Tijuana",
+ "SAST": "Africa/Johannesburg",
+ "UTC": "Etc/UTC",
+ "WAT": "Africa/Lagos",
+}