Skip to content

Commit

Permalink
type: fix type error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 5, 2023
1 parent 4578ddd commit 397e7bc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Expand Up @@ -17,17 +17,17 @@ function formatter(str?: string, date?: Date, utc?: boolean): string {
str = 'YYYY-MM-DD';
}

return str.replace(dateRegex, (match: string, key: string, rest?: string) => {
return str.replace(dateRegex, (match: string, key: keyof typeof timespan, rest?: string) => {
const args = timespan[key];
const chars = args[1];
let name = args[0];
let name = args[0] as keyof Date;
if (utc === true) {
name = `getUTC${name.slice(3)}`;
name = `getUTC${String(name).slice(3)}` as keyof Date;
}
if (!date) {
date = new Date();
}
const val = `00${String(date[name]() + (args[2] || 0))}`;
const val = `00${String((date[name] as typeof Date)() + (args[2] || 0))}`;
return val.slice(-chars) + (rest || '');
});
}
Expand Down

0 comments on commit 397e7bc

Please sign in to comment.