-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#589 - added conversion from date-only string to local date
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
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,34 @@ | ||
import {createDate, getParsedDate} from '../src/utils'; | ||
import {describe, it, expect} from '@jest/globals'; | ||
|
||
|
||
describe('createDate', () => { | ||
it('should return date object if it receives one', () => { | ||
const date = new Date(); | ||
const createdDate = createDate(date); | ||
|
||
expect(date).toEqual(createdDate); | ||
}); | ||
it('should create date from string', () => { | ||
const dateString = '2024-03-01'; | ||
const createdDate = createDate(dateString); | ||
|
||
expect(createdDate).toBeInstanceOf(Date); | ||
|
||
const {fullDate, fullMonth, year} = getParsedDate(createdDate); | ||
const allEqual = year === 2024 && fullMonth === '03' && fullDate === '01'; | ||
|
||
expect(allEqual).toBeTruthy(); | ||
}); | ||
it('should create date from number', () => { | ||
const time = 1709241680707; | ||
const createdDate = createDate(time); | ||
|
||
expect(createdDate).toBeInstanceOf(Date); | ||
|
||
const {fullDate, fullMonth, year} = getParsedDate(createdDate); | ||
const allEqual = year === 2024 && fullMonth === '03' && fullDate === '01'; | ||
|
||
expect(allEqual).toBeTruthy(); | ||
}); | ||
}); |