@@ -27,6 +27,7 @@ import axios from 'axios';
2727import { API_BASE_URL } from '../utils/apiConfig.js' ;
2828import { getDeviceApiBase } from '../utils/deviceName.js' ;
2929import { shouldShowChoreToday , getTodayDateString , convertDaysToCrontab } from '../utils/choreHelpers.js' ;
30+ import { getServerTimezoneSync } from '../utils/timezone.js' ;
3031
3132const USERS_UPDATED_EVENT = 'homeglow:users-updated' ;
3233
@@ -93,6 +94,34 @@ const ChoreWidget = ({ transparentBackground, refreshInterval = 0 }) => {
9394 }
9495 } , [ refreshInterval ] ) ;
9596
97+ useEffect ( ( ) => {
98+ function getMsUntilServerMidnight ( ) {
99+ const tz = getServerTimezoneSync ( ) ;
100+ const now = new Date ( ) ;
101+ const formatter = new Intl . DateTimeFormat ( 'en-CA' , {
102+ timeZone : tz ,
103+ year : 'numeric' ,
104+ month : '2-digit' ,
105+ day : '2-digit' ,
106+ hour : '2-digit' ,
107+ minute : '2-digit' ,
108+ second : '2-digit' ,
109+ hour12 : false
110+ } ) ;
111+ const parts = formatter . formatToParts ( now ) ;
112+ const get = ( type ) => parseInt ( parts . find ( p => p . type === type ) . value , 10 ) ;
113+ const h = get ( 'hour' ) , m = get ( 'minute' ) , s = get ( 'second' ) ;
114+ const secondsUntilMidnight = ( 24 * 3600 ) - ( h * 3600 + m * 60 + s ) ;
115+ return secondsUntilMidnight * 1000 + 1000 ;
116+ }
117+
118+ const timerId = setTimeout ( ( ) => {
119+ fetchData ( ) ;
120+ } , getMsUntilServerMidnight ( ) ) ;
121+
122+ return ( ) => clearTimeout ( timerId ) ;
123+ } , [ history ] ) ;
124+
96125 useEffect ( ( ) => {
97126 if ( ! deviceSettingsLoaded ) {
98127 return ;
0 commit comments