discourse/app/assets/javascripts/select-kit/addon/components/timezone-input.js
Joffrey JAFFEUX 5474ea4c03
DEV: maps IST rails timezone to kolkata (#32896)
This commit ensures rails will recognise `IST` as a timezone. It will be
mapped to the standard timezone `Asia/Kolkata`.

Its technically not a standard, but it's used by many people so we are
adding it as a timezone in core.

/t/-/150799
2025-05-26 08:56:04 +02:00

44 lines
1.1 KiB
JavaScript

import { classNames } from "@ember-decorators/component";
import { i18n } from "discourse-i18n";
import ComboBoxComponent from "select-kit/components/combo-box";
import {
pluginApiIdentifiers,
selectKitOptions,
} from "select-kit/components/select-kit";
@classNames("timezone-input")
@selectKitOptions({
filterable: true,
allowAny: false,
})
@pluginApiIdentifiers("timezone-input")
export default class TimezoneInput extends ComboBoxComponent {
get nameProperty() {
return this.isLocalized ? "name" : null;
}
get valueProperty() {
return this.isLocalized ? "value" : null;
}
get content() {
return this.isLocalized ? moment.tz.localizedNames() : moment.tz.names();
}
get isLocalized() {
return (
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);
}
}