-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix monorepo npm release, bring in incompatible nodenext timestamp fn (…
…#16) * use lerna for additional npm release, add verification via tsc, bring in timestamp fn that was incompatible with nodenext * timestamp only test utc values due to CI difference in time zone settings
- Loading branch information
Showing
7 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { timestamp } from '../timestamp.js' | ||
|
||
describe('timestamp', () => { | ||
// const date = new Date('2025-01-02T03:04:05.006Z') | ||
const date = new Date(Date.UTC(2025, 0, 2, 3, 4, 5, 6)) | ||
it('should format date', () => { | ||
// CI gives me grief on these values when using non-utc, so just test utc | ||
|
||
// expect(timestamp('YYYY-MM-DD HH:mm:ss.ms', false, date)).toEqual('2025-01-01 21:04:05.006') | ||
expect(timestamp('YYYY-MM-DD HH:mm:ss.ms', true, date)).toEqual('2025-01-02 03:04:05.006') | ||
// expect(timestamp('HH:mm:ss', false, date)).toEqual('21:04:05') | ||
expect(timestamp('HH:mm:ss', true, date)).toEqual('03:04:05') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* time-stamp <https://github.com/jonschlinkert/time-stamp> | ||
* | ||
* Copyright (c) 2015-2018, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
const dateRegex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:/]*)/g | ||
const timespan = { | ||
YYYY: ['getFullYear', 4], | ||
YY: ['getFullYear', 2], | ||
MM: ['getMonth', 2, 1], // getMonth is zero-based, thus the extra increment field | ||
DD: ['getDate', 2], | ||
HH: ['getHours', 2], | ||
mm: ['getMinutes', 2], | ||
ss: ['getSeconds', 2], | ||
ms: ['getMilliseconds', 3], | ||
} as const | ||
|
||
type timespanKeys = keyof typeof timespan | ||
|
||
export const timestamp = function (format: string, utc: boolean = false, date?: Date) { | ||
// if (typeof format !== 'string') { | ||
// date = format | ||
// format = 'YYYY-MM-DD' | ||
// } | ||
if (!date) date = new Date() | ||
return format.replace(dateRegex, function (match: string, key: timespanKeys, rest) { | ||
const args = timespan[key] | ||
let name = args[0] | ||
const chars = args[1] | ||
if (utc === true) name = 'getUTC' + name.slice(3) | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access | ||
const val = '00' + String((date as any)[name]() + (args[2] || 0)) | ||
return val.slice(-chars) + (rest || '') | ||
}) | ||
} | ||
|
||
// timestamp.utc = function (str, date) { | ||
// return timestamp(str, date, true) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters