diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/_sila/Mixins/LocalTimezoneLabelMixin.js | 10 | ||||
-rw-r--r-- | src/locales/ru-RU.json | 1 | ||||
-rw-r--r-- | src/store/modules/GlobalStore.js | 26 | ||||
-rw-r--r-- | src/views/_sila/Overview/DateTime/DateTime.vue | 26 |
4 files changed, 61 insertions, 2 deletions
diff --git a/src/components/_sila/Mixins/LocalTimezoneLabelMixin.js b/src/components/_sila/Mixins/LocalTimezoneLabelMixin.js index 7ef7636b..ffa54d59 100644 --- a/src/components/_sila/Mixins/LocalTimezoneLabelMixin.js +++ b/src/components/_sila/Mixins/LocalTimezoneLabelMixin.js @@ -7,6 +7,16 @@ const LocalTimezoneLabelMixin = { const pattern = ' O'; return format(new Date(), pattern, { timezone }).replace('GMT', 'UTC'); }, + timeZones() { + const intlTimeZones = Intl.supportedValuesOf('timeZone'); + const pattern = 'O'; + return intlTimeZones.map((timeZone) => { + let utc = format(new Date(), pattern, { + timeZone, + }).replace('GMT', 'UTC'); + return `(${utc}) ${timeZone}`; + }); + }, }, }; diff --git a/src/locales/ru-RU.json b/src/locales/ru-RU.json index eacd2a7a..ff39c1e9 100644 --- a/src/locales/ru-RU.json +++ b/src/locales/ru-RU.json @@ -245,6 +245,7 @@ "link": "Настройки профиля" }, "configureSettings": "Настройки", + "timezone": "Часовой пояс", "form": { "date": "Дата", "manual": "Ручное", diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js index 262d1163..3f512087 100644 --- a/src/store/modules/GlobalStore.js +++ b/src/store/modules/GlobalStore.js @@ -7,6 +7,14 @@ const HOST_STATE = { diagnosticMode: 'xyz.openbmc_project.State.Host.HostState.DiagnosticMode', }; +const convertTZ = (date, tzString) => { + return new Date( + (typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { + timeZone: tzString, + }) + ); +}; + const serverStateMapper = (hostState) => { switch (hostState) { case HOST_STATE.on: @@ -37,6 +45,7 @@ const GlobalStore = { modelType: null, serialNumber: null, serverStatus: 'unreachable', + timeZone: localStorage.getItem('storedTimeZone'), languagePreference: localStorage.getItem('storedLanguage') || 'en-US', isUtcDisplay: localStorage.getItem('storedUtcDisplay') ? JSON.parse(localStorage.getItem('storedUtcDisplay')) @@ -52,6 +61,7 @@ const GlobalStore = { bmcTime: (state) => state.bmcTime, liveBmcTime: (state) => state.liveBmcTime, liveClock: (state) => state.liveClock, + timeZone: (state) => state.timeZone, languagePreference: (state) => state.languagePreference, isUtcDisplay: (state) => state.isUtcDisplay, username: (state) => state.username, @@ -65,6 +75,10 @@ const GlobalStore = { setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), setLiveBmcTime: (state, liveBmcTime) => (state.liveBmcTime = liveBmcTime), setLiveClock: (state, liveClock) => (state.liveClock = liveClock), + setTimeZone: (state, timeZone) => { + state.timeZone = timeZone; + localStorage.setItem('storedTimeZone', timeZone); + }, setClockInterval: (state, clockInterval) => (state.clockInterval = clockInterval), setServerStatus: (state, serverState) => @@ -81,6 +95,9 @@ const GlobalStore = { }, }, actions: { + changeTimeZone({ commit }, timeZone) { + commit('setTimeZone', timeZone); + }, changeServerStatus({ commit, dispatch }, status) { commit('setServerStatus', status); @@ -112,13 +129,18 @@ const GlobalStore = { }, 1000); commit('setClockInterval', clockInterval); }, - async getBmcTime({ commit, dispatch }) { + async getBmcTime({ commit, dispatch, getters }) { + if (!getters.timeZone) { + commit('setTimeZone', '(UTC+3) Europe/Moscow'); + } + return await api .get('/redfish/v1/Managers/bmc') .then((response) => { const bmcDateTime = response.data.DateTime; const date = new Date(bmcDateTime); - commit('setBmcTime', date); + const timeZone = getters.timeZone.split(' ')[1]; + commit('setBmcTime', convertTZ(date, timeZone)); dispatch('initLiveClock'); }) .catch((error) => console.log(error)); diff --git a/src/views/_sila/Overview/DateTime/DateTime.vue b/src/views/_sila/Overview/DateTime/DateTime.vue index 3437a324..55193d64 100644 --- a/src/views/_sila/Overview/DateTime/DateTime.vue +++ b/src/views/_sila/Overview/DateTime/DateTime.vue @@ -38,6 +38,21 @@ :disabled="loading" label-sr-only > + <b-row class="mt-3 ml-3"> + <b-col sm="6" lg="4" xl="3"> + <b-form-group + :label="$t('pageDateTime.timezone')" + label-for="time-zone-select" + > + <b-form-select + id="time-zone-select" + v-model="timeZone" + :options="timeZones()" + > + </b-form-select> + </b-form-group> + </b-col> + </b-row> <b-form-radio v-model="form.configurationSelected" value="manual" @@ -252,6 +267,8 @@ export default { }, data() { return { + timeZone: null, + timeZoneOptions: null, locale: this.$store.getters['global/languagePreference'], form: { configurationSelected: '', @@ -312,6 +329,9 @@ export default { bmcTime() { return this.$store.getters['global/bmcTime']; }, + storeTimeZone() { + return this.$store.getters['global/timeZone']; + }, ntpOptionSelected() { return this.form.configurationSelected === 'ntp'; }, @@ -344,6 +364,7 @@ export default { this.$store.dispatch('dateTime/getNtpData').finally(() => { this.getNtpValues(); this.getBmcTime(); + this.getTimeZone(); this.endLoader(); this.isBusy = false; }); @@ -356,6 +377,9 @@ export default { manualDate: this.manualDate ? new Date(this.manualDate) : null, }); }, + getTimeZone() { + this.timeZone = this.storeTimeZone; + }, getNtpValues() { this.form.configurationSelected = this.isNtpProtocolEnabled ? 'ntp' @@ -377,6 +401,7 @@ export default { submitForm() { this.$v.$touch(); if (this.$v.$invalid) return; + this.startLoader(); let dateTimeForm = {}; @@ -428,6 +453,7 @@ export default { this.successToast(success); }); } + this.$store.dispatch('global/changeTimeZone', this.timeZone); }) .catch(({ message }) => this.errorToast(message)) .finally(() => { |