Skip to content

Commit 65a6a0a

Browse files
authored
Fixing timestamps to use user-defined timezone (#3019)
1 parent 63d0fc0 commit 65a6a0a

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/MicroservicesTab.vue

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<v-list-item-title>{{ microservice.name }}</v-list-item-title>
7272
<v-list-item-subtitle v-if="microservice_status[microservice.name]">
7373
Updated:
74-
{{ formatDate(microservice_status[microservice.name].updated_at) }},
74+
{{ formatNanoseconds(microservice_status[microservice.name].updated_at, timeZone) }},
7575
Enabled: {{ isEnabled(microservice.name) ? 'True' : 'False' }},
7676
Count:
7777
{{ microservice_status[microservice.name].count }}
@@ -171,15 +171,16 @@
171171
</template>
172172

173173
<script>
174-
import { toDate, format } from 'date-fns'
175-
import { Api } from '@openc3/js-common/services'
174+
import { Api, OpenC3Api } from '@openc3/js-common/services'
176175
import { OutputDialog, TextBoxDialog } from '@/components'
176+
import { TimeFilters } from '@/util'
177177
178178
export default {
179179
components: {
180180
OutputDialog,
181181
TextBoxDialog,
182182
},
183+
mixins: [TimeFilters],
183184
data() {
184185
return {
185186
filteredMicroservices: [],
@@ -194,6 +195,7 @@ export default {
194195
alertType: 'success',
195196
showAlert: false,
196197
updater: null,
198+
timeZone: 'local',
197199
// { service_name:
198200
// { operation: 'stopping' | 'restarting' | 'starting',
199201
// enabled_states: []
@@ -228,6 +230,18 @@ export default {
228230
this.applyServiceFilter()
229231
},
230232
},
233+
created() {
234+
new OpenC3Api()
235+
.get_setting('time_zone')
236+
.then((response) => {
237+
if (response) {
238+
this.timeZone = response
239+
}
240+
})
241+
.catch(() => {
242+
// Do nothing
243+
})
244+
},
231245
mounted() {
232246
this.update()
233247
this.updater = setInterval(() => {
@@ -489,12 +503,6 @@ export default {
489503
this.jsonContent = JSON.stringify(e, null, '\t')
490504
this.showError = true
491505
},
492-
formatDate(nanoSecs) {
493-
return format(
494-
toDate(Number.parseInt(nanoSecs) / 1000000),
495-
'yyyy-MM-dd HH:mm:ss.SSS',
496-
)
497-
},
498506
// States are determined by the microservice and not from an explicitly defined set
499507
// However, we can provide useful colors for errors and common states
500508
getStateColor(microserviceName) {

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/PackagesTab.vue

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
/>
5555
</v-list-item-title>
5656
<v-list-item-subtitle>
57-
<span v-text="' Updated At: ' + formatDate(process.updated_at)" />
57+
<span v-text="' Updated At: ' + formatNanoseconds(process.updated_at, timeZone)" />
5858
</v-list-item-subtitle>
5959

6060
<template v-if="process.state !== 'Running'" #append>
@@ -119,16 +119,17 @@
119119
</template>
120120

121121
<script>
122-
import { toDate, format } from 'date-fns'
123-
import { Api } from '@openc3/js-common/services'
122+
import { Api, OpenC3Api } from '@openc3/js-common/services'
124123
import { SimpleTextDialog } from '@/components'
125124
import { DownloadDialog } from '@/tools/admin'
125+
import { TimeFilters } from '@/util'
126126
127127
export default {
128128
components: {
129129
DownloadDialog,
130130
SimpleTextDialog,
131131
},
132+
mixins: [TimeFilters],
132133
data() {
133134
return {
134135
showDownloadDialog: false,
@@ -140,8 +141,21 @@ export default {
140141
gems: [],
141142
python: [],
142143
processes: {},
144+
timeZone: 'local',
143145
}
144146
},
147+
created() {
148+
new OpenC3Api()
149+
.get_setting('time_zone')
150+
.then((response) => {
151+
if (response) {
152+
this.timeZone = response
153+
}
154+
})
155+
.catch(() => {
156+
// Do nothing
157+
})
158+
},
145159
mounted() {
146160
this.update()
147161
this.updateProcesses()
@@ -171,12 +185,6 @@ export default {
171185
},
172186
)
173187
},
174-
formatDate(nanoSecs) {
175-
return format(
176-
toDate(Number.parseInt(nanoSecs) / 1000000),
177-
'yyyy-MM-dd HH:mm:ss.SSS',
178-
)
179-
},
180188
selectFile() {
181189
this.progress = 0
182190
this.$refs.fileInput.click()

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/PluginsTab.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
/>
8181
</v-list-item-title>
8282
<v-list-item-subtitle>
83-
<span v-text="' Updated At: ' + formatDate(process.updated_at)" />
83+
<span v-text="' Updated At: ' + formatNanoseconds(process.updated_at, timeZone)" />
8484
</v-list-item-subtitle>
8585

8686
<template #append>
@@ -164,12 +164,12 @@
164164
</template>
165165

166166
<script>
167-
import { toDate, format } from 'date-fns'
168167
import { Api, OpenC3Api } from '@openc3/js-common/services'
169168
import { SimpleTextDialog } from '@/components'
170169
import { ModifiedPluginDialog, PluginDialog } from '@/tools/admin'
171170
import { PluginList } from '@/tools/admin/tabs/plugins'
172171
import { PluginStore } from '@/plugins/plugin-store'
172+
import { TimeFilters } from '@/util'
173173
174174
export default {
175175
components: {
@@ -179,6 +179,7 @@ export default {
179179
ModifiedPluginDialog,
180180
SimpleTextDialog,
181181
},
182+
mixins: [TimeFilters],
182183
data() {
183184
return {
184185
// Control state
@@ -209,6 +210,7 @@ export default {
209210
showPluginDialog: false,
210211
showModifiedPluginDialog: false,
211212
showDefaultTools: false,
213+
timeZone: 'local',
212214
// When updating update local_mode.rb, local_mode.py, plugins.p.spec.ts
213215
defaultPlugins: [
214216
'openc3-cosmos-tool-admin',
@@ -251,6 +253,16 @@ export default {
251253
},
252254
created() {
253255
this.api.update_plugin_store()
256+
this.api
257+
.get_setting('time_zone')
258+
.then((response) => {
259+
if (response) {
260+
this.timeZone = response
261+
}
262+
})
263+
.catch(() => {
264+
// Do nothing
265+
})
254266
},
255267
mounted() {
256268
this.update()
@@ -322,12 +334,6 @@ export default {
322334
},
323335
)
324336
},
325-
formatDate(nanoSecs) {
326-
return format(
327-
toDate(Number.parseInt(nanoSecs) / 1000000),
328-
'yyyy-MM-dd HH:mm:ss.SSS',
329-
)
330-
},
331337
upload: function (existing = null, storeData = null) {
332338
const method = existing ? 'put' : 'post'
333339
const path = existing

0 commit comments

Comments
 (0)