1
1
import { make_reactive } from './utils.js' ;
2
2
3
+ const modified_date_to_compare = new Date ( ) ;
3
4
/**
4
5
* we have to create a new Date to compare, because setting `X` might or might not affect `Y`
5
6
* for instance calling `date.setMonth(55)` will also change the `date.getYear()`
@@ -12,57 +13,57 @@ import { make_reactive } from './utils.js';
12
13
* @return {boolean } - returns true if any changes happened
13
14
*/
14
15
const notify_datetime_changes = ( options , ...params ) => {
16
+ modified_date_to_compare . setTime ( options . value . getTime ( ) ) ;
17
+
15
18
let is_time_changed = false ;
16
19
let is_date_changed = false ;
17
20
18
- const new_datetime = new Date ( options . value ) ;
19
-
20
21
// @ts -ignore
21
- new_datetime [ options . property ] ( ...params ) ;
22
+ modified_date_to_compare [ options . property ] ( ...params ) ;
22
23
23
- if ( options . value . getFullYear ( ) !== new_datetime . getFullYear ( ) ) {
24
+ if ( options . value . getFullYear ( ) !== modified_date_to_compare . getFullYear ( ) ) {
24
25
options . notify_read_properties ( [ 'getFullYear' , 'getUTCFullYear' ] ) ;
25
26
is_date_changed = true ;
26
27
}
27
28
28
29
// @ts -expect-error
29
- if ( options . value . getYear && options . value . getYear ( ) !== new_datetime . getYear ( ) ) {
30
+ if ( options . value . getYear && options . value . getYear ( ) !== modified_date_to_compare . getYear ( ) ) {
30
31
// @ts -expect-error
31
32
options . notify_read_properties ( [ 'getYear' ] ) ;
32
33
is_date_changed = true ;
33
34
}
34
35
35
- if ( options . value . getMonth ( ) !== new_datetime . getMonth ( ) ) {
36
+ if ( options . value . getMonth ( ) !== modified_date_to_compare . getMonth ( ) ) {
36
37
options . notify_read_properties ( [ 'getMonth' , 'getUTCMonth' ] ) ;
37
38
is_date_changed = true ;
38
39
}
39
40
40
- if ( options . value . getDate ( ) !== new_datetime . getDate ( ) ) {
41
+ if ( options . value . getDate ( ) !== modified_date_to_compare . getDate ( ) ) {
41
42
options . notify_read_properties ( [ 'getDate' , 'getUTCDate' ] ) ;
42
43
is_date_changed = true ;
43
44
}
44
45
45
- if ( options . value . getDay ( ) !== new_datetime . getDay ( ) ) {
46
+ if ( options . value . getDay ( ) !== modified_date_to_compare . getDay ( ) ) {
46
47
options . notify_read_properties ( [ 'getDay' , 'getUTCDay' ] ) ;
47
48
is_date_changed = true ;
48
49
}
49
50
50
- if ( options . value . getHours ( ) !== new_datetime . getHours ( ) ) {
51
+ if ( options . value . getHours ( ) !== modified_date_to_compare . getHours ( ) ) {
51
52
options . notify_read_properties ( [ 'getHours' , 'getUTCHours' ] ) ;
52
53
is_time_changed = true ;
53
54
}
54
55
55
- if ( options . value . getMinutes ( ) !== new_datetime . getMinutes ( ) ) {
56
+ if ( options . value . getMinutes ( ) !== modified_date_to_compare . getMinutes ( ) ) {
56
57
options . notify_read_properties ( [ 'getMinutes' , 'getUTCMinutes' ] ) ;
57
58
is_time_changed = true ;
58
59
}
59
60
60
- if ( options . value . getSeconds ( ) !== new_datetime . getSeconds ( ) ) {
61
+ if ( options . value . getSeconds ( ) !== modified_date_to_compare . getSeconds ( ) ) {
61
62
options . notify_read_properties ( [ 'getSeconds' , 'getUTCSeconds' ] ) ;
62
63
is_time_changed = true ;
63
64
}
64
65
65
- if ( options . value . getMilliseconds ( ) !== new_datetime . getMilliseconds ( ) ) {
66
+ if ( options . value . getMilliseconds ( ) !== modified_date_to_compare . getMilliseconds ( ) ) {
66
67
options . notify_read_properties ( [ 'getMilliseconds' , 'getUTCMilliseconds' ] ) ;
67
68
is_time_changed = true ;
68
69
}
0 commit comments