mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
writeComposerImage stamped filenames via Date.toISOString(), which is UTC, so the embedded timestamp disagreed with the file's mtime (shown in local time) by the user's zone offset - e.g. 8 hours off for UTC+8. Extract the stamp into composerImageTimestamp() (local wall-clock components, same YYYY-MM-DD_HH-MM-SS-mmm shape) with regression tests that distinguish local time from UTC on any host timezone. Machine-facing artifacts (bootstrap run logs, emergency state.db backups, corrupt-registry sidecars) keep their UTC stamps intentionally. Closes #96403
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
/**
|
|
* Filename stamping for pasted composer images (composer-images/).
|
|
*
|
|
* The timestamp embedded in a composer image filename must be the user's
|
|
* LOCAL wall-clock time: these files are browsed and sorted by humans
|
|
* alongside their filesystem mtimes, which the OS displays in local time.
|
|
* Rendering the stamp with Date.toISOString() writes UTC into the filename,
|
|
* so for anyone off UTC the name disagrees with the file's mtime by the zone
|
|
* offset (issue #96403 — e.g. 8 hours off for UTC+8 users).
|
|
*
|
|
* Machine-facing artifacts (run logs, emergency backups) intentionally keep
|
|
* UTC stamps; this helper is for the user-facing composer-images/ directory
|
|
* only.
|
|
*/
|
|
|
|
function pad(value: number, width: number): string {
|
|
return String(value).padStart(width, '0')
|
|
}
|
|
|
|
/**
|
|
* Format `date` as `YYYY-MM-DD_HH-MM-SS-mmm` in LOCAL time — the same shape
|
|
* the previous toISOString()-based stamp produced, but in the user's timezone.
|
|
*/
|
|
export function composerImageTimestamp(date: Date = new Date()): string {
|
|
return (
|
|
`${date.getFullYear()}-${pad(date.getMonth() + 1, 2)}-${pad(date.getDate(), 2)}` +
|
|
`_${pad(date.getHours(), 2)}-${pad(date.getMinutes(), 2)}-${pad(date.getSeconds(), 2)}` +
|
|
`-${pad(date.getMilliseconds(), 3)}`
|
|
)
|
|
}
|