-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom format function
- Loading branch information
1 parent
f5dc133
commit c801516
Showing
7 changed files
with
66 additions
and
82 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
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 |
---|---|---|
@@ -1,29 +1,18 @@ | ||
import { transformDate, transformDateRange } from '../src/utils/transform' | ||
import { transformDate } from '../src/utils/transform' | ||
|
||
const time = new Date(2019, 1, 3) | ||
const timestamp = time.getTime() | ||
const format = 'MM-DD-YYYY' | ||
const text = '02-03-2019' | ||
|
||
const testfn = ({ type, value, date, err = null, range = false }) => it(`${type}}`, () => { | ||
const obj = range ? transformDateRange : transformDate | ||
const testfn = ({ type, value, date, err = null }) => it(`${type}}`, () => { | ||
const obj = transformDate | ||
const typeObj = obj[type] | ||
expect(typeObj.value2date(err, format)).toEqual(err) | ||
expect(typeObj.value2date(value, format)).toEqual(date) | ||
expect(typeObj.date2value(err, format)).toEqual(err) | ||
expect(typeObj.date2value(date, format)).toEqual(value) | ||
expect(typeObj.value2date(err)).toEqual(err) | ||
expect(typeObj.value2date(value)).toEqual(date) | ||
expect(typeObj.date2value(err)).toEqual(err) | ||
expect(typeObj.date2value(date)).toEqual(value) | ||
}) | ||
|
||
describe('transformDate', () => { | ||
testfn({ type: 'date', value: time, date: time }) | ||
testfn({ type: 'format', value: text, date: time }) | ||
testfn({ type: 'timestamp', value: timestamp, date: time }) | ||
}) | ||
|
||
describe('transformDateRange', () => { | ||
const err = [null, null] | ||
const date = [time, time] | ||
testfn({ type: 'date', value: [time, time], date, err, range: true }) | ||
testfn({ type: 'format', value: [text, text], date, err, range: true }) | ||
testfn({ type: 'timestamp', value: [timestamp, timestamp], date, err, range: true }) | ||
}) |