Menu

Testing a daily puzzle date across New York's daylight-saving boundaries
📰

Testing a daily puzzle date across New York's daylight-saving boundaries

DEV Community: javascript·Leon·3 days ago
#tK1OedJH
#devtojavascript#devto#dev#date#instant
Long article (419 words) — no AI summary yet.
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.