-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: conversion from string date to string iso date (#1231)
* fix: conversion from string date to string iso date * fix: avoid trying to airdrop when badge spec upload went wrong * fix: use utc time for string conversion
- Loading branch information
Showing
4 changed files
with
45 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { toIsoStringDate } from './toIsoString' | ||
|
||
describe('convertToISO function', () => { | ||
it('should convert a valid date string to ISO format', () => { | ||
const dateStr = '2023-09-04' | ||
const isoDate = toIsoStringDate(dateStr) | ||
expect(isoDate).toEqual('2023-09-04T00:00:00.000Z') | ||
}) | ||
|
||
it('should throw an error for an invalid date string', () => { | ||
const invalidDateStr = 'invalid-date' | ||
expect(() => toIsoStringDate(invalidDateStr)).toThrow('Invalid date format') | ||
}) | ||
|
||
it('should not change the hours and minutes if they are already defined', () => { | ||
const dateStr = '2023-07-21T13:57:28.882Z' | ||
const isoDate = toIsoStringDate(dateStr) | ||
expect(isoDate).toEqual(dateStr) | ||
}) | ||
|
||
it('should add the missing part of the date string', () => { | ||
const dateStr = '2023-07-21T13:57' | ||
const isoDate = toIsoStringDate(dateStr) | ||
expect(isoDate).toEqual('2023-07-21T13:57:00.000Z') | ||
}) | ||
|
||
it('should not change the minutes and seconds if they are already defined', () => { | ||
const dateStr = '2023-09-30T23:59:59.999Z' | ||
const isoDate = toIsoStringDate(dateStr) | ||
expect(isoDate).toEqual('2023-09-30T23:59:59.999Z') | ||
}) | ||
}) |
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,9 @@ | ||
import Time from './Time' | ||
|
||
export function toIsoStringDate(dateStr: string) { | ||
const parsedDate = Time.utc(dateStr) | ||
if (!parsedDate.isValid()) { | ||
throw new Error('Invalid date format') | ||
} | ||
return parsedDate.toISOString() | ||
} |