A platform for community discussion. Free, open, simple.
DEV: maps IST rails timezone to kolkata (#32896)
Joffrey JAFFEUX5474ea4c03e1
diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/timezone-input-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/select-kit/timezone-input-test.gjsnew file mode 100644index 00000000000..216418b1e4f--- /dev/null+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/timezone-input-test.gjs@@ -0,0 +1,26 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";+import TimezoneInput from "select-kit/components/timezone-input";++module("Integration | Component | select-kit/timezone-input", function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.subject = selectKit();+ });++ test("errors for IST", async function (assert) {+ await render(<template><TimezoneInput /></template>);++ await this.subject.expand();+ await this.subject.fillInFilter("ist");+ await this.subject.selectRowByValue("IST");++ assert+ .dom(".select-kit-error")+ .hasText(i18n("timezone_input.ambiguous_ist"), "shows the error for IST");+ });+});diff --git a/app/assets/javascripts/select-kit/addon/components/timezone-input.js b/app/assets/javascripts/select-kit/addon/components/timezone-input.jsindex bcb8f5f9d6f..29fb35d02f9 100644--- a/app/assets/javascripts/select-kit/addon/components/timezone-input.js+++ b/app/assets/javascripts/select-kit/addon/components/timezone-input.js@@ -1,4 +1,5 @@import { classNames } from "@ember-decorators/component";+import { i18n } from "discourse-i18n";import ComboBoxComponent from "select-kit/components/combo-box";import {pluginApiIdentifiers,@@ -29,4 +30,15 @@ export default class TimezoneInput extends ComboBoxComponent {moment.locale() !== "en" && typeof moment.tz.localizedNames === "function");}++ _onChangeWrapper(timezone) {+ // We support IST for India, but IST is not a valid timezone+ // it's ambiguous with other timezones like Dublin or Jerusalem+ if (timezone === "IST") {+ this.addError(i18n("timezone_input.ambiguous_ist"));+ return null;+ }++ return super._onChangeWrapper(timezone);+ }}diff --git a/config/initializers/100-custom-timezones.rb b/config/initializers/100-custom-timezones.rbnew file mode 100644index 00000000000..c778e7a169d--- /dev/null+++ b/config/initializers/100-custom-timezones.rb@@ -0,0 +1,3 @@+# frozen_string_literal: true++ActiveSupport::TimeZone::MAPPING["IST"] = "Asia/Kolkata"diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex e5e1a43ee64..edfc2728767 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -2616,6 +2616,8 @@ en:one: "%{count} topic in this category"other: "%{count} topics in this category"+ timezone_input:+ ambiguous_ist: "IST is ambiguous, please select a specific timezone (eg: Asia/Kolkata)"select_kit:delete_item: "Delete %{name}"filter_by: "Filter by: %{name}"@@ -5100,7 +5102,7 @@ en:clear_filter: "Clear filter"no_results:title: "No results"- description_admin_search: 'We couldn’t find anything matching ‘%{filter}’.'+ description_admin_search: "We couldn’t find anything matching ‘%{filter}’."collapse_all_sections: "Collapse all sections"expand_all_sections: "Expand all sections"search: "Search"diff --git a/spec/initializers/custom_timezones_spec.rb b/spec/initializers/custom_timezones_spec.rbnew file mode 100644index 00000000000..a6a9c54d89c--- /dev/null+++ b/spec/initializers/custom_timezones_spec.rb@@ -0,0 +1,9 @@+# frozen_string_literal: true++RSpec.describe "Custom timezones initializer" do+ it "maps IST to Asia/Kolkata" do+ expect(ActiveSupport::TimeZone["IST"].tzinfo).to eq(+ ActiveSupport::TimeZone["Asia/Kolkata"].tzinfo,+ )+ end+end