Skip to content

Commit eaf7c7d

Browse files
authored
fix: format timestamp for selected files download (#2415)
1 parent a29966a commit eaf7c7d

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/components/panels/Gcodefiles/GcodefilesPanelHeader.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import BaseMixin from '@/components/mixins/base'
6969
import GcodefilesMixin from '@/components/mixins/gcodefiles'
7070
import { mdiCloudDownload, mdiDelete, mdiFolderPlus, mdiMagnify, mdiRefresh, mdiUpload } from '@mdi/js'
7171
import { FileStateFile } from '@/store/files/types'
72-
import { escapePath } from '@/plugins/helpers'
72+
import { escapePath, generateTimestamp } from '@/plugins/helpers'
7373
import ConfirmationDialog from '@/components/dialogs/ConfirmationDialog.vue'
7474
import { validGcodeExtensions } from '@/store/variables'
7575
@@ -130,12 +130,10 @@ export default class GcodefilesPanelHeader extends Mixins(BaseMixin, GcodefilesM
130130
}
131131
132132
addElementToItems('gcodes/' + this.currentPath, this.selectedFiles)
133-
const date = new Date()
134-
const timestamp = `${date.getFullYear()}${date.getMonth()}${date.getDate()}-${date.getHours()}${date.getMinutes()}${date.getSeconds()}`
135133
136134
this.$socket.emit(
137135
'server.files.zip',
138-
{ items, dest: `config/gcodes-${timestamp}.zip` },
136+
{ items, dest: `config/gcodes-${generateTimestamp()}.zip` },
139137
{ action: 'files/downloadZip', loading: 'gcodeDownloadZip' }
140138
)
141139

src/components/panels/Machine/ConfigFilesPanel.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
import { Component, Mixins } from 'vue-property-decorator'
467467
import BaseMixin from '@/components/mixins/base'
468468
import ThemeMixin from '@/components/mixins/theme'
469-
import { escapePath, formatFilesize, sortFiles } from '@/plugins/helpers'
469+
import { escapePath, formatFilesize, generateTimestamp, sortFiles } from '@/plugins/helpers'
470470
import { FileStateFile, FileStateGcodefile } from '@/store/files/types'
471471
import axios from 'axios'
472472
import Panel from '@/components/ui/Panel.vue'
@@ -1003,17 +1003,9 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin, ThemeMixin) {
10031003
10041004
await addElementToItems(this.absolutePath, this.selectedFiles)
10051005
1006-
const date = new Date()
1007-
const month = (date.getMonth() + 1).toString().padStart(2, '0')
1008-
const day = date.getDate().toString().padStart(2, '0')
1009-
const hours = date.getHours().toString().padStart(2, '0')
1010-
const minutes = date.getMinutes().toString().padStart(2, '0')
1011-
const seconds = date.getSeconds().toString().padStart(2, '0')
1012-
const timestamp = `${date.getFullYear()}${month}${day}-${hours}${minutes}${seconds}`
1013-
10141006
this.$socket.emit(
10151007
'server.files.zip',
1016-
{ items, dest: `config/${this.root}-${timestamp}.zip` },
1008+
{ items, dest: `config/${this.root}-${generateTimestamp()}.zip` },
10171009
{ action: 'files/downloadZip', loading: 'configDownloadZip' }
10181010
)
10191011

src/plugins/helpers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,21 @@ export const deletePath = (obj: any, path: string) => {
527527

528528
if (current && typeof current === 'object') delete current[last]
529529
}
530+
531+
/**
532+
* Generates a timestamp string in the format `YYYYMMDD-HHMMSS`.
533+
*
534+
* @param date - Optional date object. Defaults to current date/time.
535+
* @returns Formatted timestamp string (e.g., `20260130-070253`)
536+
*
537+
* @example
538+
* generateTimestamp() // '20260130-070253' (current time)
539+
* generateTimestamp(new Date('2025-12-25T10:30:00')) // '20251225-103000'
540+
*/
541+
export function generateTimestamp(date: Date = new Date()): string {
542+
const pad = (n: number) => n.toString().padStart(2, '0')
543+
const dateString = `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
544+
const timeString = `${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
545+
546+
return `${dateString}-${timeString}`
547+
}

0 commit comments

Comments
 (0)