From 39871bfaaefd60e07eba9be108198a237e3a4d38 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 22:21:46 +0000 Subject: [PATCH 1/6] Explain that state is optional. --- templates/add.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/add.html b/templates/add.html index 92e3462f..f9623cec 100644 --- a/templates/add.html +++ b/templates/add.html @@ -108,6 +108,9 @@

Add event

  • +

    + Leave blank if the country does not have states. +

    {% for country in countries %} {% for state in country.states %} From a4622fa927979dff6180b24710063c834b66dae3 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 22:22:03 +0000 Subject: [PATCH 2/6] Fix warning about label for nonexistent field. --- templates/add.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/add.html b/templates/add.html index f9623cec..19b72076 100644 --- a/templates/add.html +++ b/templates/add.html @@ -141,7 +141,7 @@

    Add event

  • - +
      {% for style in crate::model::dancestyle::DanceStyle::values() %} From f3146d2e88dfe9216e48134a55981dfb3aeeb760 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 22:35:54 +0000 Subject: [PATCH 3/6] Move location about time in add event form. --- templates/add.html | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/templates/add.html b/templates/add.html index 19b72076..ea427d0d 100644 --- a/templates/add.html +++ b/templates/add.html @@ -57,38 +57,6 @@

      Add event

  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • The country in which the event will take place.

    @@ -140,6 +108,38 @@

    Add event

    {% endfor %} {% endfor %}
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • From a8db873c63314c8850119697f628dfca0328b64a Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 22:36:12 +0000 Subject: [PATCH 4/6] Set timezone automatically based on country and state. --- public/scripts/add.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/public/scripts/add.js b/public/scripts/add.js index 950b2929..e1be5d82 100644 --- a/public/scripts/add.js +++ b/public/scripts/add.js @@ -1,3 +1,15 @@ +/** The first timezone in the list, which will be the default value. */ +const FIRST_TIMEZONE = "Africa/Abidjan"; + +/** Timezones to set automatically based on the country and state. */ +const DEFAULT_TIMEZONES = new Map([ + ["Austria/", "Europe/Vienna"], + ["Belgium/", "Europe/Brussels"], + ["New Zealand/", "Pacific/Auckland"], + ["UK/", "Europe/London"], + ["USA/AZ", "US/Mountain"], +]); + function add_input(list, name, type, id, datalist) { var input = document.createElement("input"); input.setAttribute("type", type); @@ -49,13 +61,30 @@ function update_datetimes() { }); } +function update_timezone() { + let country = document.getElementById("country").value; + let state = document.getElementById("state").value; + let country_state = country + "/" + state; + let timezone_field = document.getElementById("timezone"); + + if ( + timezone.value == FIRST_TIMEZONE && + DEFAULT_TIMEZONES.has(country_state) + ) { + timezone_field.value = DEFAULT_TIMEZONES.get(country_state); + } +} + function initialise() { document.getElementById("links_list").oninput = update_inputs; document.getElementById("bands_list").oninput = update_inputs; document.getElementById("callers_list").oninput = update_inputs; document.getElementById("with_time").onchange = update_datetimes; + document.getElementById("country").onchange = update_timezone; + document.getElementById("state").onchange = update_timezone; update_datetimes(); + update_timezone(); } window.onload = initialise; From fa5f97bf12fa76b2a840a0fcef6ea5f7b74ae5d5 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 22:53:55 +0000 Subject: [PATCH 5/6] Timezone defaults in Rust rather than hardcoded JavaScript. --- public/scripts/add.js | 9 --------- src/util.rs | 8 ++++++++ templates/add.html | 8 ++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/public/scripts/add.js b/public/scripts/add.js index e1be5d82..f7364ec2 100644 --- a/public/scripts/add.js +++ b/public/scripts/add.js @@ -1,15 +1,6 @@ /** The first timezone in the list, which will be the default value. */ const FIRST_TIMEZONE = "Africa/Abidjan"; -/** Timezones to set automatically based on the country and state. */ -const DEFAULT_TIMEZONES = new Map([ - ["Austria/", "Europe/Vienna"], - ["Belgium/", "Europe/Brussels"], - ["New Zealand/", "Pacific/Auckland"], - ["UK/", "Europe/London"], - ["USA/AZ", "US/Mountain"], -]); - function add_input(list, name, type, id, datalist) { var input = document.createElement("input"); input.setAttribute("type", type); diff --git a/src/util.rs b/src/util.rs index 630fccfa..77fd87b2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,6 +15,14 @@ use chrono::{DateTime, FixedOffset, NaiveDateTime, Offset, TimeZone}; use chrono_tz::Tz; +pub const DEFAULT_TIMEZONES: [((&str, Option<&str>), Tz); 5] = [ + (("Austria", None), Tz::Europe__Vienna), + (("Belgium", None), Tz::Europe__Brussels), + (("New Zealand", None), Tz::Pacific__Auckland), + (("UK", None), Tz::Europe__London), + (("USA", Some("AZ")), Tz::US__Mountain), +]; + fn to_fixed_offset(date_time: DateTime) -> DateTime { let fixed_offset = date_time.offset().fix(); date_time.with_timezone(&fixed_offset) diff --git a/templates/add.html b/templates/add.html index ea427d0d..d8824082 100644 --- a/templates/add.html +++ b/templates/add.html @@ -4,6 +4,14 @@ Add event + From 73bb56b1491429ebd2eba870ef176b2c9af95191 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 15 Jan 2024 23:05:57 +0000 Subject: [PATCH 6/6] Add more default timezones. --- src/util.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 77fd87b2..b1d87e73 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,12 +15,34 @@ use chrono::{DateTime, FixedOffset, NaiveDateTime, Offset, TimeZone}; use chrono_tz::Tz; -pub const DEFAULT_TIMEZONES: [((&str, Option<&str>), Tz); 5] = [ +pub const DEFAULT_TIMEZONES: [((&str, Option<&str>), Tz); 27] = [ (("Austria", None), Tz::Europe__Vienna), (("Belgium", None), Tz::Europe__Brussels), + (("Bulgaria", None), Tz::Europe__Sofia), + (("Canada", Some("Ontario")), Tz::Canada__Eastern), + (("Czechia", None), Tz::Europe__Prague), + (("France", None), Tz::Europe__Paris), + (("Germany", None), Tz::Europe__Berlin), + (("Iraq", None), Tz::Asia__Baghdad), + (("Ireland", None), Tz::Europe__Dublin), + (("Italy", None), Tz::Europe__Rome), + (("Latvia", None), Tz::Europe__Riga), + (("Lithuania", None), Tz::Europe__Vilnius), + (("Netherlands", None), Tz::Europe__Amsterdam), (("New Zealand", None), Tz::Pacific__Auckland), + (("Norway", None), Tz::Europe__Oslo), + (("Poland", None), Tz::Europe__Warsaw), + (("Portugal", None), Tz::Europe__Lisbon), + (("Slovenia", None), Tz::Europe__Ljubljana), + (("Spain", None), Tz::Europe__Madrid), + (("Sweden", None), Tz::Europe__Stockholm), + (("Switzerland", None), Tz::Europe__Zurich), + (("Turkey", None), Tz::Europe__Istanbul), (("UK", None), Tz::Europe__London), (("USA", Some("AZ")), Tz::US__Mountain), + (("USA", Some("CA")), Tz::US__Pacific), + (("USA", Some("MA")), Tz::US__Eastern), + (("USA", Some("NY")), Tz::US__Eastern), ]; fn to_fixed_offset(date_time: DateTime) -> DateTime {