diff --git a/ruby_event_store-browser/Makefile b/ruby_event_store-browser/Makefile index e55354faf8..0c8f66c4e8 100644 --- a/ruby_event_store-browser/Makefile +++ b/ruby_event_store-browser/Makefile @@ -59,3 +59,6 @@ $(JS_OUTFILE): @echo "Building browser JS" @cd elm; npx elm make --optimize --output=../public/ruby_event_store_browser.js src/Main.elm > /dev/null @cd elm; npx uglify-js ../public/ruby_event_store_browser.js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | npx uglify-js --mangle --output ../public/ruby_event_store_browser.js + +generate-timezones-map: + @ruby bin/generate_timezones_map.rb diff --git a/ruby_event_store-browser/bin/generate_timezones_map.rb b/ruby_event_store-browser/bin/generate_timezones_map.rb new file mode 100644 index 0000000000..a9b04cb46f --- /dev/null +++ b/ruby_event_store-browser/bin/generate_timezones_map.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile do + source "https://rubygems.org" + gem "tzinfo" + gem "tzinfo-data", "~> 1.2024.1" +end + +def header + [ + "-- This is a generated file. Do not edit.", + "-- To regenerate it with the latest data, run:", + "-- `make generate-timezones-map`", + "", + "module LinkedTimezones exposing (mapLinkedTimeZone)", + "mapLinkedTimeZone : String -> String", + "mapLinkedTimeZone str =", + " case str of" + ] +end + +def links + TZInfo::Timezone.all_linked_zones.map do |zone| + " \"#{zone.identifier}\" -> \"#{zone.canonical_identifier}\"" + end +end + +def footer + [" _ -> str"] +end + + +File.write("elm/src/LinkedTimezones.elm", (header + links + footer).join("\n")) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 0a86ddc966..6665be2639 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -6,6 +6,7 @@ import Dict import Html exposing (..) import Html.Attributes exposing (class, href, placeholder, selected, value) import Html.Events exposing (onInput, onSubmit) +import LinkedTimezones exposing(mapLinkedTimeZone) import List.Extra import Route import TimeZone exposing (zones) @@ -56,8 +57,10 @@ update msg model = else let + betterZoneName = + mapLinkedTimeZone zoneName maybeZone = - Dict.get zoneName zones + Dict.get betterZoneName zones in case maybeZone of Just zone -> diff --git a/ruby_event_store-browser/elm/src/LinkedTimezones.elm b/ruby_event_store-browser/elm/src/LinkedTimezones.elm new file mode 100644 index 0000000000..f5347bb871 --- /dev/null +++ b/ruby_event_store-browser/elm/src/LinkedTimezones.elm @@ -0,0 +1,254 @@ +-- This is a generated file. Do not edit. +-- To regenerate it with the latest data, run: +-- `make generate-timezones-map` + +module LinkedTimezones exposing (mapLinkedTimeZone) +mapLinkedTimeZone : String -> String +mapLinkedTimeZone str = + case str of + "Africa/Accra" -> "Africa/Abidjan" + "Africa/Addis_Ababa" -> "Africa/Nairobi" + "Africa/Asmara" -> "Africa/Nairobi" + "Africa/Asmera" -> "Africa/Nairobi" + "Africa/Bamako" -> "Africa/Abidjan" + "Africa/Bangui" -> "Africa/Lagos" + "Africa/Banjul" -> "Africa/Abidjan" + "Africa/Blantyre" -> "Africa/Maputo" + "Africa/Brazzaville" -> "Africa/Lagos" + "Africa/Bujumbura" -> "Africa/Maputo" + "Africa/Conakry" -> "Africa/Abidjan" + "Africa/Dakar" -> "Africa/Abidjan" + "Africa/Dar_es_Salaam" -> "Africa/Nairobi" + "Africa/Djibouti" -> "Africa/Nairobi" + "Africa/Douala" -> "Africa/Lagos" + "Africa/Freetown" -> "Africa/Abidjan" + "Africa/Gaborone" -> "Africa/Maputo" + "Africa/Harare" -> "Africa/Maputo" + "Africa/Kampala" -> "Africa/Nairobi" + "Africa/Kigali" -> "Africa/Maputo" + "Africa/Kinshasa" -> "Africa/Lagos" + "Africa/Libreville" -> "Africa/Lagos" + "Africa/Lome" -> "Africa/Abidjan" + "Africa/Luanda" -> "Africa/Lagos" + "Africa/Lubumbashi" -> "Africa/Maputo" + "Africa/Lusaka" -> "Africa/Maputo" + "Africa/Malabo" -> "Africa/Lagos" + "Africa/Maseru" -> "Africa/Johannesburg" + "Africa/Mbabane" -> "Africa/Johannesburg" + "Africa/Mogadishu" -> "Africa/Nairobi" + "Africa/Niamey" -> "Africa/Lagos" + "Africa/Nouakchott" -> "Africa/Abidjan" + "Africa/Ouagadougou" -> "Africa/Abidjan" + "Africa/Porto-Novo" -> "Africa/Lagos" + "Africa/Timbuktu" -> "Africa/Abidjan" + "America/Anguilla" -> "America/Puerto_Rico" + "America/Antigua" -> "America/Puerto_Rico" + "America/Argentina/ComodRivadavia" -> "America/Argentina/Catamarca" + "America/Aruba" -> "America/Puerto_Rico" + "America/Atikokan" -> "America/Panama" + "America/Atka" -> "America/Adak" + "America/Blanc-Sablon" -> "America/Puerto_Rico" + "America/Buenos_Aires" -> "America/Argentina/Buenos_Aires" + "America/Catamarca" -> "America/Argentina/Catamarca" + "America/Cayman" -> "America/Panama" + "America/Coral_Harbour" -> "America/Panama" + "America/Cordoba" -> "America/Argentina/Cordoba" + "America/Creston" -> "America/Phoenix" + "America/Curacao" -> "America/Puerto_Rico" + "America/Dominica" -> "America/Puerto_Rico" + "America/Ensenada" -> "America/Tijuana" + "America/Fort_Wayne" -> "America/Indiana/Indianapolis" + "America/Godthab" -> "America/Nuuk" + "America/Grenada" -> "America/Puerto_Rico" + "America/Guadeloupe" -> "America/Puerto_Rico" + "America/Indianapolis" -> "America/Indiana/Indianapolis" + "America/Jujuy" -> "America/Argentina/Jujuy" + "America/Knox_IN" -> "America/Indiana/Knox" + "America/Kralendijk" -> "America/Puerto_Rico" + "America/Louisville" -> "America/Kentucky/Louisville" + "America/Lower_Princes" -> "America/Puerto_Rico" + "America/Marigot" -> "America/Puerto_Rico" + "America/Mendoza" -> "America/Argentina/Mendoza" + "America/Montreal" -> "America/Toronto" + "America/Montserrat" -> "America/Puerto_Rico" + "America/Nassau" -> "America/Toronto" + "America/Nipigon" -> "America/Toronto" + "America/Pangnirtung" -> "America/Iqaluit" + "America/Port_of_Spain" -> "America/Puerto_Rico" + "America/Porto_Acre" -> "America/Rio_Branco" + "America/Rainy_River" -> "America/Winnipeg" + "America/Rosario" -> "America/Argentina/Cordoba" + "America/Santa_Isabel" -> "America/Tijuana" + "America/Shiprock" -> "America/Denver" + "America/St_Barthelemy" -> "America/Puerto_Rico" + "America/St_Kitts" -> "America/Puerto_Rico" + "America/St_Lucia" -> "America/Puerto_Rico" + "America/St_Thomas" -> "America/Puerto_Rico" + "America/St_Vincent" -> "America/Puerto_Rico" + "America/Thunder_Bay" -> "America/Toronto" + "America/Tortola" -> "America/Puerto_Rico" + "America/Virgin" -> "America/Puerto_Rico" + "America/Yellowknife" -> "America/Edmonton" + "Antarctica/DumontDUrville" -> "Pacific/Port_Moresby" + "Antarctica/McMurdo" -> "Pacific/Auckland" + "Antarctica/South_Pole" -> "Pacific/Auckland" + "Antarctica/Syowa" -> "Asia/Riyadh" + "Arctic/Longyearbyen" -> "Europe/Berlin" + "Asia/Aden" -> "Asia/Riyadh" + "Asia/Ashkhabad" -> "Asia/Ashgabat" + "Asia/Bahrain" -> "Asia/Qatar" + "Asia/Brunei" -> "Asia/Kuching" + "Asia/Calcutta" -> "Asia/Kolkata" + "Asia/Chongqing" -> "Asia/Shanghai" + "Asia/Chungking" -> "Asia/Shanghai" + "Asia/Dacca" -> "Asia/Dhaka" + "Asia/Harbin" -> "Asia/Shanghai" + "Asia/Istanbul" -> "Europe/Istanbul" + "Asia/Kashgar" -> "Asia/Urumqi" + "Asia/Katmandu" -> "Asia/Kathmandu" + "Asia/Kuala_Lumpur" -> "Asia/Singapore" + "Asia/Kuwait" -> "Asia/Riyadh" + "Asia/Macao" -> "Asia/Macau" + "Asia/Muscat" -> "Asia/Dubai" + "Asia/Phnom_Penh" -> "Asia/Bangkok" + "Asia/Rangoon" -> "Asia/Yangon" + "Asia/Saigon" -> "Asia/Ho_Chi_Minh" + "Asia/Tel_Aviv" -> "Asia/Jerusalem" + "Asia/Thimbu" -> "Asia/Thimphu" + "Asia/Ujung_Pandang" -> "Asia/Makassar" + "Asia/Ulan_Bator" -> "Asia/Ulaanbaatar" + "Asia/Vientiane" -> "Asia/Bangkok" + "Atlantic/Faeroe" -> "Atlantic/Faroe" + "Atlantic/Jan_Mayen" -> "Europe/Berlin" + "Atlantic/Reykjavik" -> "Africa/Abidjan" + "Atlantic/St_Helena" -> "Africa/Abidjan" + "Australia/ACT" -> "Australia/Sydney" + "Australia/Canberra" -> "Australia/Sydney" + "Australia/Currie" -> "Australia/Hobart" + "Australia/LHI" -> "Australia/Lord_Howe" + "Australia/NSW" -> "Australia/Sydney" + "Australia/North" -> "Australia/Darwin" + "Australia/Queensland" -> "Australia/Brisbane" + "Australia/South" -> "Australia/Adelaide" + "Australia/Tasmania" -> "Australia/Hobart" + "Australia/Victoria" -> "Australia/Melbourne" + "Australia/West" -> "Australia/Perth" + "Australia/Yancowinna" -> "Australia/Broken_Hill" + "Brazil/Acre" -> "America/Rio_Branco" + "Brazil/DeNoronha" -> "America/Noronha" + "Brazil/East" -> "America/Sao_Paulo" + "Brazil/West" -> "America/Manaus" + "Canada/Atlantic" -> "America/Halifax" + "Canada/Central" -> "America/Winnipeg" + "Canada/Eastern" -> "America/Toronto" + "Canada/Mountain" -> "America/Edmonton" + "Canada/Newfoundland" -> "America/St_Johns" + "Canada/Pacific" -> "America/Vancouver" + "Canada/Saskatchewan" -> "America/Regina" + "Canada/Yukon" -> "America/Whitehorse" + "Chile/Continental" -> "America/Santiago" + "Chile/EasterIsland" -> "Pacific/Easter" + "Cuba" -> "America/Havana" + "Egypt" -> "Africa/Cairo" + "Eire" -> "Europe/Dublin" + "Etc/GMT+0" -> "Etc/GMT" + "Etc/GMT-0" -> "Etc/GMT" + "Etc/GMT0" -> "Etc/GMT" + "Etc/Greenwich" -> "Etc/GMT" + "Etc/UCT" -> "Etc/UTC" + "Etc/Universal" -> "Etc/UTC" + "Etc/Zulu" -> "Etc/UTC" + "Europe/Amsterdam" -> "Europe/Brussels" + "Europe/Belfast" -> "Europe/London" + "Europe/Bratislava" -> "Europe/Prague" + "Europe/Busingen" -> "Europe/Zurich" + "Europe/Copenhagen" -> "Europe/Berlin" + "Europe/Guernsey" -> "Europe/London" + "Europe/Isle_of_Man" -> "Europe/London" + "Europe/Jersey" -> "Europe/London" + "Europe/Kiev" -> "Europe/Kyiv" + "Europe/Ljubljana" -> "Europe/Belgrade" + "Europe/Luxembourg" -> "Europe/Brussels" + "Europe/Mariehamn" -> "Europe/Helsinki" + "Europe/Monaco" -> "Europe/Paris" + "Europe/Nicosia" -> "Asia/Nicosia" + "Europe/Oslo" -> "Europe/Berlin" + "Europe/Podgorica" -> "Europe/Belgrade" + "Europe/San_Marino" -> "Europe/Rome" + "Europe/Sarajevo" -> "Europe/Belgrade" + "Europe/Skopje" -> "Europe/Belgrade" + "Europe/Stockholm" -> "Europe/Berlin" + "Europe/Tiraspol" -> "Europe/Chisinau" + "Europe/Uzhgorod" -> "Europe/Kyiv" + "Europe/Vaduz" -> "Europe/Zurich" + "Europe/Vatican" -> "Europe/Rome" + "Europe/Zagreb" -> "Europe/Belgrade" + "Europe/Zaporozhye" -> "Europe/Kyiv" + "GB" -> "Europe/London" + "GB-Eire" -> "Europe/London" + "GMT" -> "Etc/GMT" + "GMT+0" -> "Etc/GMT" + "GMT-0" -> "Etc/GMT" + "GMT0" -> "Etc/GMT" + "Greenwich" -> "Etc/GMT" + "Hongkong" -> "Asia/Hong_Kong" + "Iceland" -> "Africa/Abidjan" + "Indian/Antananarivo" -> "Africa/Nairobi" + "Indian/Christmas" -> "Asia/Bangkok" + "Indian/Cocos" -> "Asia/Yangon" + "Indian/Comoro" -> "Africa/Nairobi" + "Indian/Kerguelen" -> "Indian/Maldives" + "Indian/Mahe" -> "Asia/Dubai" + "Indian/Mayotte" -> "Africa/Nairobi" + "Indian/Reunion" -> "Asia/Dubai" + "Iran" -> "Asia/Tehran" + "Israel" -> "Asia/Jerusalem" + "Jamaica" -> "America/Jamaica" + "Japan" -> "Asia/Tokyo" + "Kwajalein" -> "Pacific/Kwajalein" + "Libya" -> "Africa/Tripoli" + "Mexico/BajaNorte" -> "America/Tijuana" + "Mexico/BajaSur" -> "America/Mazatlan" + "Mexico/General" -> "America/Mexico_City" + "NZ" -> "Pacific/Auckland" + "NZ-CHAT" -> "Pacific/Chatham" + "Navajo" -> "America/Denver" + "PRC" -> "Asia/Shanghai" + "Pacific/Chuuk" -> "Pacific/Port_Moresby" + "Pacific/Enderbury" -> "Pacific/Kanton" + "Pacific/Funafuti" -> "Pacific/Tarawa" + "Pacific/Johnston" -> "Pacific/Honolulu" + "Pacific/Majuro" -> "Pacific/Tarawa" + "Pacific/Midway" -> "Pacific/Pago_Pago" + "Pacific/Pohnpei" -> "Pacific/Guadalcanal" + "Pacific/Ponape" -> "Pacific/Guadalcanal" + "Pacific/Saipan" -> "Pacific/Guam" + "Pacific/Samoa" -> "Pacific/Pago_Pago" + "Pacific/Truk" -> "Pacific/Port_Moresby" + "Pacific/Wake" -> "Pacific/Tarawa" + "Pacific/Wallis" -> "Pacific/Tarawa" + "Pacific/Yap" -> "Pacific/Port_Moresby" + "Poland" -> "Europe/Warsaw" + "Portugal" -> "Europe/Lisbon" + "ROC" -> "Asia/Taipei" + "ROK" -> "Asia/Seoul" + "Singapore" -> "Asia/Singapore" + "Turkey" -> "Europe/Istanbul" + "UCT" -> "Etc/UTC" + "US/Alaska" -> "America/Anchorage" + "US/Aleutian" -> "America/Adak" + "US/Arizona" -> "America/Phoenix" + "US/Central" -> "America/Chicago" + "US/East-Indiana" -> "America/Indiana/Indianapolis" + "US/Eastern" -> "America/New_York" + "US/Hawaii" -> "Pacific/Honolulu" + "US/Indiana-Starke" -> "America/Indiana/Knox" + "US/Michigan" -> "America/Detroit" + "US/Mountain" -> "America/Denver" + "US/Pacific" -> "America/Los_Angeles" + "US/Samoa" -> "Pacific/Pago_Pago" + "UTC" -> "Etc/UTC" + "Universal" -> "Etc/UTC" + "W-SU" -> "Europe/Moscow" + "Zulu" -> "Etc/UTC" + _ -> str \ No newline at end of file diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index f655a699f1..699e19e5f2 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -3,9 +3,11 @@ module Main exposing (main) import Browser import Browser.Navigation import BrowserTime +import Dict import Flags exposing (Flags, RawFlags, buildFlags) import Html exposing (..) import Layout +import LinkedTimezones exposing(mapLinkedTimeZone) import Page.ShowEvent import Page.ShowStream import Route @@ -47,7 +49,7 @@ type Msg | GotLayoutMsg Layout.Msg | GotShowEventMsg Page.ShowEvent.Msg | GotShowStreamMsg Page.ShowStream.Msg - | ReceiveTimeZone (Result TimeZone.Error ( String, Time.Zone )) + | ReceiveTimeZone (Result String Time.ZoneName) type Page @@ -81,10 +83,13 @@ buildModel rawFlags location key = ( model , Cmd.batch [ cmd - , TimeZone.getZone |> Task.attempt ReceiveTimeZone + , requestBrowserTimeZone ] ) +requestBrowserTimeZone : Cmd Msg +requestBrowserTimeZone = + Task.attempt ReceiveTimeZone Time.getZoneName update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = @@ -142,18 +147,37 @@ update msg model = , Cmd.map GotLayoutMsg layoutCmd ) - ( ReceiveTimeZone (Ok ( zoneName, zone )), _ ) -> - let - detectedTime = - { zone = zone, zoneName = zoneName } - - time = - model.time - - newTime = - { time | detected = detectedTime, selected = detectedTime } - in - ( { model | time = newTime }, Cmd.none ) + ( ReceiveTimeZone result, _ ) -> + case result of + Ok zoneName -> + case zoneName of + Time.Name newZoneName -> + let + betterZoneName = + mapLinkedTimeZone newZoneName + in + case Dict.get betterZoneName TimeZone.zones of + Just zone -> + let + time = + model.time + + detectedTime = + { zone = zone (), zoneName = newZoneName} + + newTime = + { time | detected = detectedTime, selected = detectedTime} + in + ( { model | time = newTime}, Cmd.none ) + + Nothing -> + ( model, Cmd.none ) + + Time.Offset _ -> + ( model, Cmd.none ) + + Err _ -> + ( model, Cmd.none ) ( _, _ ) -> ( model, Cmd.none )