File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ jest.mock("../../hass");
77const setDatetimeServiceFactoryMock = setDatetimeServiceFactory as jest . MockedFunction < typeof setDatetimeServiceFactory >
88
99describe ( "datetime" , ( ) => {
10- const yesterday = new Date ( Date . now ( ) - 24 * 60 * 60 * 1000 ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
11- const tenDaysAgo = new Date ( Date . now ( ) - 10 * 24 * 60 * 60 * 1000 ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
10+ const tzOffset = new Date ( ) . getTimezoneOffset ( ) * 60000 ;
11+ const localDateTime = Date . now ( ) - tzOffset ;
12+ const yesterday = new Date ( localDateTime - 24 * 60 * 60 * 1000 ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
13+ const tenDaysAgo = new Date ( localDateTime - 10 * 24 * 60 * 60 * 1000 ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
1214
1315 [
1416 { hass : undefined , entity : undefined , expected : 0 } ,
Original file line number Diff line number Diff line change @@ -4,20 +4,24 @@ import { setDatetimeServiceFactory } from "../hass";
44const MS_IN_A_DAY = 1000 * 60 * 60 * 24 ;
55
66function getState ( hass : IHass , entity : IEntity ) : number {
7- const date = Date . parse ( hass ?. states ?. [ entity ?. id ] ?. state ) || Date . now ( ) ;
8- return Math . floor ( ( Date . now ( ) - date ) / MS_IN_A_DAY ) ;
7+ const tzOffset = new Date ( ) . getTimezoneOffset ( ) * 60000 ;
8+ const localDateTime = Date . now ( ) - tzOffset ;
9+ const date = Date . parse ( hass ?. states ?. [ entity ?. id ] ?. state ) || localDateTime ;
10+ return Math . floor ( ( localDateTime - date ) / MS_IN_A_DAY ) ;
911}
1012
1113function resetDate ( $event : Event , hass : IHass , entity : IEntity ) : void {
1214 const friendly_name = hass . states [ entity . id ] . attributes . friendly_name ;
1315 const entity_id = entity . id ;
14- const date = new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
16+ const tzOffset = new Date ( ) . getTimezoneOffset ( ) * 60000 ;
17+ const localDateTime = new Date ( Date . now ( ) - tzOffset ) ;
18+ const localDate = localDateTime . toISOString ( ) . split ( "T" ) [ 0 ] ;
1519 const confirmation = `Do you want to reset ${ friendly_name } ?` ;
1620 const element = setDatetimeServiceFactory (
1721 hass ,
1822 confirmation ,
1923 entity_id ,
20- date
24+ localDate
2125 ) ;
2226 ( < any > $event . target ) . appendChild ( element ) ;
2327 ( < any > element ) . buttonTapped ( ) ;
You can’t perform that action at this time.
0 commit comments