Simplified timestampedFilename to use formatDate
All checks were successful
Build / Build NPM Project (push) Successful in 43s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 45s

This commit is contained in:
Zakary Timson 2025-03-02 21:37:48 -05:00
parent 5b9e0714ce
commit cd5741d6ab
2 changed files with 3 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.23.13",
"version": "0.23.14",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -1,6 +1,7 @@
import {makeArray} from './array.ts';
import {JSONAttemptParse} from './objects.ts';
import {PromiseProgress} from './promise-progress';
import {formatDate} from './time.ts';
/**
* Download blob as a file
@ -76,7 +77,7 @@ export function fileText(file: any): Promise<string | null> {
*/
export function timestampFilename(name?: string, date: Date | number | string = new Date()) {
if(typeof date == 'number' || typeof date == 'string') date = new Date(date);
const timestamp = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}_${date.getHours().toString().padStart(2, '0')}-${date.getMinutes().toString().padStart(2, '0')}-${date.getSeconds().toString().padStart(2, '0')}`;
const timestamp = formatDate('YYYY-MM-DD_HH:mm:ss', date);
return name ? name.replace('{{TIMESTAMP}}', timestamp) : timestamp;
}