Skip to content

Commit 432ad85

Browse files
author
Martijn Swaagman
committed
[fix] add files
1 parent dde96db commit 432ad85

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Convert a Date to a timestamp.
3+
*/
4+
export function toMilliseconds(options: Options, ...keys: Array<string>) {
5+
keys.forEach(function each(key) {
6+
const value = options[key];
7+
8+
// Is it a Date object?
9+
if (typeof value === 'object' && typeof value.getMonth === 'function') {
10+
options[key] = value.getTime();
11+
}
12+
});
13+
}

test/constants.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as constants from '../src/constants.js';
2+
3+
describe('constants', function (){
4+
it('exports mode values', () => {
5+
expect(constants).toHaveProperty('MODE_DATE', 'date');
6+
expect(constants).toHaveProperty('MODE_TIME', 'time');
7+
expect(constants).toHaveProperty('MODE_DATETIME', 'datetime');
8+
});
9+
10+
it('exports display values', () => {
11+
expect(constants).toHaveProperty('DISPLAY_DEFAULT', 'default');
12+
expect(constants).toHaveProperty('DISPLAY_SPINNER', 'spinner');
13+
expect(constants).toHaveProperty('DISPLAY_CLOCK', 'clock');
14+
expect(constants).toHaveProperty('DISPLAY_CALENDAR', 'calendar');
15+
});
16+
});

test/utils.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { toMilliseconds} from '../src/utils.js';
2+
3+
describe('utils', function (){
4+
describe('toMilliseconds', () => {
5+
it('converts Date values by key to milliseconds', () => {
6+
const options = {
7+
value: new Date('2020-12-12'),
8+
minimumDate: new Date('1950-01-01'),
9+
maximumDate: new Date('2050-12-31'),
10+
};
11+
12+
toMilliseconds(options, 'value');
13+
expect(options).toHaveProperty('value', 1607731200000);
14+
15+
toMilliseconds(options, 'minimumDate', 'maximumDate');
16+
expect(options).toHaveProperty('minimumDate', -631152000000);
17+
expect(options).toHaveProperty('maximumDate', 2556057600000);
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)