diff options
author | Vitalii Lysak <v.lysak@dunice.net> | 2022-09-16 16:53:08 +0300 |
---|---|---|
committer | Vitalii Lysak <v.lysak@dunice.net> | 2022-09-16 16:53:08 +0300 |
commit | a72c39d39f2c2fa127139c9e161bacaecbcb5a07 (patch) | |
tree | 2efa43295d0da364f2c23c3286f68dc55f94d0dd /src/store | |
parent | 2cb62b657f9e806bdbeadd50ba932d204f696393 (diff) | |
download | webui-vue-a72c39d39f2c2fa127139c9e161bacaecbcb5a07.tar.xz |
add timeZone select
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/modules/GlobalStore.js | 26 |
1 files changed, 24 insertions, 2 deletions
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)); |