mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-24 06:22:45 +08:00
test(datetime): add unit tests for parseDate()
This commit is contained in:

committed by
Manu MA

parent
aa9d0d4282
commit
e75618e82f
@ -1,4 +1,4 @@
|
||||
import { convertDataToISO } from './datetime-util';
|
||||
import { convertDataToISO, parseDate } from './datetime-util';
|
||||
|
||||
describe('datetime-util', () => {
|
||||
describe('convertDataToISO', () => {
|
||||
@ -207,4 +207,70 @@ describe('datetime-util', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseDate', () => {
|
||||
it('should parse a single year', () => {
|
||||
const date = parseDate('1000');
|
||||
expect(date).toEqual({
|
||||
"day": undefined,
|
||||
"hour": undefined,
|
||||
"millisecond": undefined,
|
||||
"minute": undefined,
|
||||
"month": undefined,
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": 1000,
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse a time', () => {
|
||||
const date = parseDate('12:20');
|
||||
expect(date).toEqual({
|
||||
"day": undefined,
|
||||
"hour": 12,
|
||||
"millisecond": undefined,
|
||||
"minute": 20,
|
||||
"month": undefined,
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse a full ISO date', () => {
|
||||
const date = parseDate('1994-12-15T13:47:20Z');
|
||||
expect(date).toEqual({
|
||||
"day": 15,
|
||||
"hour": 13,
|
||||
"millisecond": undefined,
|
||||
"minute": 47,
|
||||
"month": 12,
|
||||
"second": 20,
|
||||
"tzOffset": 0,
|
||||
"year": 1994,
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse a partial ISO date', () => {
|
||||
const date = parseDate('2018-01-02');
|
||||
expect(date).toEqual({
|
||||
"day": 2,
|
||||
"hour": undefined,
|
||||
"millisecond": undefined,
|
||||
"minute": undefined,
|
||||
"month": 1,
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": 2018,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should return undefined', () => {
|
||||
expect(parseDate(null)).toBeUndefined();
|
||||
expect(parseDate(undefined)).toBeUndefined();
|
||||
expect(parseDate('')).toBeUndefined();
|
||||
expect(parseDate('3432-12-12-234')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user