@@ -8,8 +8,6 @@ import { SettingsDialog } from "./SettingsDialog";
88
99const USER_LOCALE = navigator . language || navigator . languages [ 0 ] ;
1010
11- // const IS_DEV = import.meta.env.DEV === true
12-
1311interface ChatMessage {
1412 id : number
1513 username : string
@@ -56,6 +54,32 @@ function useLocalStorage(key: string, initialValue: string) {
5654 return [ value , setValue ] as const ;
5755}
5856
57+ function getMilisecondsUntilBrazilianMidnight ( ) {
58+ const now = new Date ( ) ;
59+
60+ // current UTC time in ms
61+ const nowUtc = now . getTime ( ) + now . getTimezoneOffset ( ) * 60_000 ;
62+
63+ // offset for Brazil (UTC−3)
64+ const brazilOffsetMs = - 3 * 60 * 60 * 1000 ;
65+
66+ // current "Brazil time"
67+ const nowBrazil = new Date ( nowUtc + brazilOffsetMs ) ;
68+
69+ // next midnight in Brazil
70+ const nextMidnightBrazil = new Date ( nowBrazil ) ;
71+ nextMidnightBrazil . setHours ( 24 , 0 , 0 , 0 ) ;
72+
73+ // convert that Brazil midnight back to UTC
74+ const nextMidnightUtc =
75+ nextMidnightBrazil . getTime ( ) - brazilOffsetMs ;
76+
77+ // how long until then from now
78+ const msUntilMidnight = nextMidnightUtc - nowUtc ;
79+
80+ return msUntilMidnight
81+ }
82+
5983const MessageItem = ( { formattedMessage } : { formattedMessage : FormattedChatMessage } ) => {
6084 return (
6185 < div key = { formattedMessage . id } className = "p-2 text-gray-800 w-full" >
@@ -273,6 +297,16 @@ export const ChatHub = () => {
273297 }
274298 } , [ currentInput ] ) ; // runs whenever input changes
275299
300+ // MISCELANEOUS
301+ useEffect ( ( ) => {
302+ const msUntilMidnight = getMilisecondsUntilBrazilianMidnight ( )
303+ const timer = setTimeout ( ( ) => {
304+ window . location . reload ( ) ;
305+ } , msUntilMidnight ) ;
306+
307+ return ( ) => clearTimeout ( timer ) ;
308+ } , [ ] )
309+
276310
277311 return (
278312 < div >
@@ -331,8 +365,6 @@ export const ChatHub = () => {
331365 />
332366 < Emojis insertAtCursor = { insertAtCursor } > </ Emojis >
333367 </ div >
334-
335- { /* <CustomSnippetsInput></CustomSnippetsInput> */ }
336368 < button
337369 onClick = { handleSendMessage }
338370 className = "w-12 h-12 rounded-full bg-blue-500 text-white flex items-center justify-center hover:bg-blue-600 hover:cursor-pointer"
@@ -343,6 +375,11 @@ export const ChatHub = () => {
343375 </ div >
344376 </ div >
345377 </ div >
378+ < footer className = "py-4" >
379+ < div className = "max-w-7xl mx-auto px-4 text-center text-sm text-amber-600" >
380+ ⚠️ The Chat™ resets every day at midnight Brazilian Time (UTC -3).
381+ </ div >
382+ </ footer >
346383 </ div >
347384 ) ;
348385}
0 commit comments