Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bootloader date format #1551

Merged
merged 3 commits into from Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions core/frontend/src/components/system-information/Firmware.vue
Expand Up @@ -61,6 +61,7 @@
</template>

<script lang="ts">
import { formatRFC7231 } from 'date-fns'
import Vue from 'vue'

import back_axios from '@/utils/api'
Expand Down Expand Up @@ -97,9 +98,10 @@ export default Vue.extend({
return this.cleanUpString(this.vcgencmd?.firmware?.stdout)
},
raspiberry_firmware_data(): string | undefined {
return this.raspiberry_firmware
const data = this.raspiberry_firmware
?.split('\n')
?.[0]
return this.formatDate(data)
},
raspberry_firmware_version(): string | undefined {
return this.raspiberry_firmware
Expand Down Expand Up @@ -128,11 +130,12 @@ export default Vue.extend({
const latest = []

for (const line of lines) {
if (!line.includes(':')) {
const result = line.splitOnce(':')
if (result === undefined) {
continue
}

let [key, value] = line.split(':')
let [key, value] = result
key = key.trim()
value = value.trim()

Expand All @@ -149,8 +152,8 @@ export default Vue.extend({
}

return {
latest_bootloader: latest?.[0],
current_bootloader: current?.[0],
latest_bootloader: this.formatDate(latest?.[0]),
current_bootloader: this.formatDate(current?.[0]),
latest_vl085: latest?.[1],
current_vl085: current?.[1],
}
Expand All @@ -166,6 +169,13 @@ export default Vue.extend({
}
return text.slice(1, -1).replace(/\\n/g, '\n').trim().trim()
},
formatDate(date_value: string | undefined): string | undefined {
if (date_value === undefined) {
return undefined
}

return formatRFC7231(Date.parse(date_value)) ?? date_value
},
formatError(output: ReturnStruct | undefined): string | undefined {
const return_code = output?.return_code
if (return_code === undefined || return_code === 0) {
Expand Down
12 changes: 12 additions & 0 deletions core/frontend/src/cosmos.ts
Expand Up @@ -8,6 +8,7 @@ declare global {

interface String {
isEmpty(): boolean;
splitOnce(separator: string): [string, string] | undefined
toTitle(): string;
}
}
Expand All @@ -27,6 +28,17 @@ String.prototype.isEmpty = function (this: String): boolean {
return this.length === 0
}

// eslint-disable-next-line
String.prototype.splitOnce = function (this: string, separator: string): [string, string] | undefined {
const index = this.indexOf(separator)
if (index === -1) {
return undefined
}
const first = this.substring(0, index)
const second = this.substring(index + separator.length)
return [first, second]
}

// eslint-disable-next-line
String.prototype.toTitle = function (this: string): string {
if (this.length < 1) {
Expand Down