Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add todayStringNoHyphens() #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/datetime/localDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ test('todayString', () => {
expect(s < '2099-01-01').toBe(true)
})

test('todayStringNoHyphens', () => {
const s = todayString()
expect(s.startsWith(new Date().getFullYear())).toBe(true)
expect(s > '2024-05-01').toBe(true)
expect(s < '2099-01-01').toBe(true)
})

test('todayString tz', () => {
if (isUTC()) return
console.log(process.env['TZ'])
Expand Down
10 changes: 10 additions & 0 deletions src/datetime/localDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,13 @@ Object.setPrototypeOf(localDate, localDateFactory)
export function todayString(): IsoDateString {
return localDate.fromDate(new Date()).toISODate()
}

/**
Convenience function to return current today's IsoDateString representation formatted with no hyphens, e.g `20240613`
*/
export function todayStringNoHyphens(): IsoDateString {
const date = new Date();
const ymd = date.toISOString().split('T')[0].split('-');
const date_formatted = `${ymd[0]}${ymd[1]}${ymd[2]}`
return date_formatted
}
Loading