File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments