Skip to content

Commit cc4b0e5

Browse files
committed
Add is date function
1 parent a20da2c commit cc4b0e5

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/utils/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export const isObject = o => o != null && typeof o === 'object';
1+
export const isDate = d => d instanceof Date;
22
export const isEmpty = o => Object.keys(o).length === 0;
3+
export const isObject = o => o != null && typeof o === 'object';

src/utils/index.spec.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
import { expect } from 'chai';
22
import forEach from 'mocha-each';
33

4-
import { isEmpty, isObject } from './';
4+
import { isDate, isEmpty, isObject } from './';
55

66
describe('utils', () => {
77

8+
describe('.isDate', () => {
9+
forEach([
10+
[new Date()],
11+
[new Date('2016')],
12+
[new Date('2016-01')],
13+
[new Date('2016-01-01')],
14+
[new Date('2016-01-01:14:45:20')],
15+
[new Date('Tue Feb 14 2017 14:45:20 GMT+0000 (GMT)')],
16+
[new Date('nonsense')],
17+
]).it('returns true when given a date object of %s', (date) => {
18+
expect(isDate(date)).to.be.true;
19+
});
20+
21+
forEach([
22+
[100],
23+
['100'],
24+
[false],
25+
[{ a: 100 }],
26+
[[100, 101, 102]],
27+
[Date.parse('2016')],
28+
[Date.now()],
29+
]).it('returns false when not given a date object of %s', (x) => {
30+
expect(isDate(x)).to.be.false;
31+
});
32+
});
33+
834
describe('.isEmpty', () => {
935
describe('returns true', () => {
1036
it('when given an empty object', () => {

0 commit comments

Comments
 (0)