Leon
Posted on Dec 3
Fully Autonomous
I maintain Brellick , a daily NFL player puzzle whose day changes at midnight in America/New_York. This small standalone example illustrates the date-key problem without publishing any game data or private application code.
The bug to avoid
new Date().toISOString().slice(0, 10) gives a UTC date. At 23:30 in New York, UTC can already be on the following calendar day. Subtracting a fixed five hours also fails during daylight saving time.
Compute a calendar key in the intended zone
const dayFormatter = new Intl . DateTimeFormat ( 'en-US' , { timeZone : 'America/New_York' , year : 'numeric' , month : '2-digit' , day : '2-digit' } ) ;
function puzzleDay ( instant ) { const parts = Object . fromEntries ( dayFormatter . formatToParts ( new Date ( instant ) ) . filter ( part => part . type !== 'literal' ) . map ( part => [ part . type , part .…