Urgent.News

What's breaking now, across thousands of outlets.

Tech

new Date('2026-03-01') is 28 February if your user is in California

We build a tool that turns a few form fields into a finished resignation or notice letter. The single most important string in that output is a date. A resignation letter states your last working day, and that date is the thing your employer acts on. So the date formatting code is four lines and it is the most dangerous four lines in the feature. function formatDate ( value ) { if ( ! value .…

A powerful tool for generating resignation or notice letters relies on a simple date formatting function. The function relies on converting a date string into a Date object, which then formats the date according to the user's locale. However, this seemingly innocuous piece of code harbors a dangerous bug.

When the function receives a date string in the format YYYY-MM-DD, it converts it into a Date object using new Date(). This conversion assumes the string represents a UTC date. When parsed as UTC, the date 2026-03-01 becomes midnight on 28 February in California, which leads to the incorrect letter stating the last working day as 28 February instead of the correct date, 1 March.

The bug stems from ECMAScript's specification that date-only ISO strings are parsed as UTC. This means that any date string not following the date-only ISO format, such as 2026/03/01 or 2026-02-31, is parsed as local time, which can lead to incorrect results. The function's Number.isNaN guard is supposed to catch parsing errors, but it fails to detect overflow dates like 30 February, which silently rolls forward to the next month.

Moreover, the function does not handle daylight-saving time transitions properly. For instance, adding two weeks to 25 October 2026 in Los Angeles yields either 7 or 8 November, depending on the arithmetic used. This inconsistency can cause significant issues in a notice-period feature, where adding two weeks should always result in a precise date.

To avoid these problems, the function should stop parsing strings as dates and avoid using UTC in calendar calculations. Instead, it should convert the input string into a Date object using the local construction, perform calendar calculations using days instead of milliseconds, and return the formatted date using the user's locale settings. By taking these precautions, the tool can reliably generate accurate resignation and notice letters without confusing the user or compromising the integrity of the process.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Go GC Pauses in an RTB Bidder: Mark Assist, Deadlines, and the Rust Decision

A bidder that loses auctions on timeout while its average looks healthy is being described by the wrong number. The deadline belongs to the exchange and covers the network in both directions.

  • RTB bidder performance depends on exchange deadline and auction timeouts
  • Round trip time includes latency, connection setup, queue time, deserialization
  • Garbage collection concurrently impacts single connection performance

More from Thursday 10 September →