diff --git a/packages/test-serializer/package-lock.json b/packages/test-serializer/package-lock.json index 5bfd6682308..d6a909518f4 100644 --- a/packages/test-serializer/package-lock.json +++ b/packages/test-serializer/package-lock.json @@ -20,7 +20,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } }, diff --git a/packages/uhk-agent/package-lock.json b/packages/uhk-agent/package-lock.json index d1783704c45..d61ebaa54c6 100644 --- a/packages/uhk-agent/package-lock.json +++ b/packages/uhk-agent/package-lock.json @@ -36,7 +36,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } }, diff --git a/packages/uhk-common/package-lock.json b/packages/uhk-common/package-lock.json index a156efc1953..4dca699e7b2 100644 --- a/packages/uhk-common/package-lock.json +++ b/packages/uhk-common/package-lock.json @@ -12,7 +12,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } }, @@ -122,15 +121,6 @@ "is-buffer": "~1.1.6" } }, - "node_modules/moment": { - "version": "2.30.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", - "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", diff --git a/packages/uhk-common/package.json b/packages/uhk-common/package.json index b44ccd6a6c0..d8b84ae981b 100644 --- a/packages/uhk-common/package.json +++ b/packages/uhk-common/package.json @@ -24,7 +24,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" }, "license": "GPL-3.0" diff --git a/packages/uhk-common/src/util/user-configuration-history-helpers.test.ts b/packages/uhk-common/src/util/user-configuration-history-helpers.test.ts new file mode 100644 index 00000000000..c442fdd68ca --- /dev/null +++ b/packages/uhk-common/src/util/user-configuration-history-helpers.test.ts @@ -0,0 +1,39 @@ +import { describe, it } from 'node:test'; + +import { + convertHistoryFilenameToDisplayText, + convertDateToDisplayText, + getUserConfigHistoryFilename, +} from './user-configuration-history-helpers.js'; + +it('getUserConfigHistoryFilename should return with proper name', ({ assert, mock }) => { + const md5Hash = '1234567890abcdef1234567890abcdef'; + const fakeNow = new Date(2026, 4, 28, 15, 23, 45) + mock.timers.enable({ apis: ['Date'], now: fakeNow }) + const filename = getUserConfigHistoryFilename(md5Hash); + + assert.strictEqual(filename, '20260528-152345-1234567890abcdef1234567890abcdef.bin'); +}); + +it('convertDateToDisplayText should properly format date', ({ assert }) => { + const testDate = new Date(2026, 4, 28, 15, 23, 45); + const displayText = convertDateToDisplayText(testDate); + + assert.strictEqual(displayText, '2026-05-28 15:23:45'); +}); + +describe('convertHistoryFilenameToDisplayText', () => { + it('should properly parses filename', ({ assert }) => { + const testFilename = '20260528-152345-1234567890abcdef1234567890abcdef.bin'; + const displayText = convertHistoryFilenameToDisplayText(testFilename); + + assert.strictEqual(displayText, '2026-05-28 15:23:45'); + }); + + it('should return with "Invalid date" when filename length shorter than 15 character', ({ assert }) => { + const testFilename = '20260528-15234'; + const displayText = convertHistoryFilenameToDisplayText(testFilename); + + assert.strictEqual(displayText, 'Invalid date'); + }); +}) diff --git a/packages/uhk-common/src/util/user-configuration-history-helpers.ts b/packages/uhk-common/src/util/user-configuration-history-helpers.ts index 7882ea1a33d..4eb3d0f1f75 100644 --- a/packages/uhk-common/src/util/user-configuration-history-helpers.ts +++ b/packages/uhk-common/src/util/user-configuration-history-helpers.ts @@ -1,20 +1,62 @@ -import moment from 'moment'; - -export const FILENAME_DATE_FORMAT = 'YYYYMMDD-HHmmss'; -export const DISPLAY_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss'; - export function getUserConfigHistoryFilename(md5Hash: string): string { - const timestamp = moment().format(FILENAME_DATE_FORMAT); + const timestamp = formatFilenameTimestamp(new Date()); return `${timestamp}-${md5Hash}.bin`; } export function convertHistoryFilenameToDisplayText(filename: string): string { - const timestamp = filename.substring(0, 16); + // simulates moment.js behavior + if (filename.length < 15) { + return 'Invalid date'; + } + + const timestamp = filename.substring(0, 15); - return moment(timestamp, FILENAME_DATE_FORMAT).format(DISPLAY_DATE_FORMAT); + const year = timestamp.substring(0, 4); + const month = timestamp.substring(4, 6); + const day = timestamp.substring(6, 8); + // index 8 is the '-' separator + const hours = timestamp.substring(9, 11); + const minutes = timestamp.substring(11, 13); + const seconds = timestamp.substring(13, 15); + + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } +/** + * Formats a Date as `YYYY-MM-DD HH:mm:ss` using local time. + */ export function convertDateToDisplayText(date: Date): string { - return moment(date).format(DISPLAY_DATE_FORMAT); + const segments = getDateSegments(date); + + return `${segments.year}-${segments.month}-${segments.day} ${segments.hours}:${segments.minutes}:${segments.seconds}`; +} + +/** + * Formats a Date as `YYYYMMDD-HHmmss` using local time. + */ +function formatFilenameTimestamp(date: Date): string { + const segments = getDateSegments(date); + + return `${segments.year}${segments.month}${segments.day}-${segments.hours}${segments.minutes}${segments.seconds}`; +} + +interface DateSegments { + year: string; + month: string; + day: string; + hours: string; + minutes: string; + seconds: string; +} + +function getDateSegments(date: Date): DateSegments { + return { + year: date.getFullYear().toString().padStart(4, '0'), + month: (date.getMonth() + 1).toString().padStart(2, '0'), + day: date.getDate().toString().padStart(2, '0'), + hours: date.getHours().toString().padStart(2, '0'), + minutes: date.getMinutes().toString().padStart(2, '0'), + seconds: date.getSeconds().toString().padStart(2, '0'), + }; } diff --git a/packages/uhk-usb/package-lock.json b/packages/uhk-usb/package-lock.json index b6ee75f053b..26aa7eb9e93 100644 --- a/packages/uhk-usb/package-lock.json +++ b/packages/uhk-usb/package-lock.json @@ -51,7 +51,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } }, diff --git a/packages/uhk-web/package-lock.json b/packages/uhk-web/package-lock.json index 07ff7912c0c..3881c02fce0 100644 --- a/packages/uhk-web/package-lock.json +++ b/packages/uhk-web/package-lock.json @@ -69,7 +69,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } }, diff --git a/packages/usb/package-lock.json b/packages/usb/package-lock.json index 126338b0c1b..60d1fbe6d4a 100644 --- a/packages/usb/package-lock.json +++ b/packages/usb/package-lock.json @@ -32,7 +32,6 @@ "buffer": "6.0.3", "lodash.isequal": "4.5.0", "md5": "2.3.0", - "moment": "2.30.1", "tslib": "2.8.1" } },