Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Formatting Timer Readouts with Intl.DurationFormat: What It Does and What It Leaves to You

Most timer readouts are built from padStart(2, "0") and a colon. That works until you want localized digits, or a spoken-friendly string like "25 minutes". Intl.DurationFormat covers both, and MDN labels it Baseline 2025: "Since March 2025, this feature works across the latest devices and browser versions." I tried it on a timer readout and found four places where it does less than you might…

The article discusses the capabilities and limitations of the Intl.DurationFormat API when formatting timer readouts. The API allows for localized digits and spoken-friendly strings, but has four areas where it falls short and one engine difference observed.

Firstly, the format does not carry a passed value of seconds, resulting in a format like 00:125 instead of 02:05. This is why a helper function, splitMs, is required to properly format the data. Second, the formatter displays milliseconds when they are nonzero. If the display only shows seconds, the milliseconds value should be truncated first.

Third, the formatter truncates values instead of rounding them. This means that for a stopwatch, 1.9 seconds would be displayed as 00:01, while for a countdown, 0.9 seconds remaining would display as 00:00, as the last second is truncated.

Fourth, the format requires consistent signs for each field, and only integers are allowed. If mixed signs are provided, a RangeError will be thrown. For example, { minutes: 1, seconds: -5 } will cause an error. To handle overtime, the signs of all fields must be negated, as demonstrated by formatRemaining(-1500).

Lastly, the fractional digits option can be set from 0 to 9, but discrepancies were observed across different engines when setting values between 0 and 3. Chrome 156 showed no mismatches at 0 and 1 digit fractional values, while Node 24.22.1 showed 21 mismatches at 2 digits and 396 mismatches at 3 digits. This inconsistency could lead to unexpected formatting results, making it crucial to test targets or build the fraction manually if displaying hundredths.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

The message that retried hundreds of times: a retry loop with no exit

I'm Eric Gitangu. I work on backend systems for a mobility/fintech platform. This is the story of one text message that was retried hundreds of times, and what it took to teach the code to take no for…

  • Retry loop with no exit led to hundreds of SMS message retries
  • Three small decisions caused the issue: no catch, error thrown, progress saved prematurely
  • Catch per recipient, exponential backoff, and "not before" stamp resolved the problem

Test browser profile isolation after attaching Playwright over CDP

When Playwright attaches to Chrome over CDP, it can see the browser's existing context. A script that opens a new tab there inherits that context's first-party storage for the origin.

  • Playwright can inspect browser contexts via CDP
  • New tab inherits context's first-party storage
  • Separate contexts prevent request collisions

My Framework Said Any: How a Pyrefly Error Led Me to Fix Typing in SwiftPY

I build SwiftPY , a Python web framework with an async Active Record ORM. Last week I opened one of my own repositories in VS Code and saw this: class DocRepository : model = Doc async def get_doc (…

  • Pyrefly error caused Any return instead of "Doc" type
  • SwiftPY fixed type chain gaps in version 0.3.8
  • Pyrefly silent import fix added in version 0.3.9

Exporting Qwen2-VL the official way: 4 dead ends and 1 error that doesn't exist on the internet

You do everything by the book. The vendor's own toolkit, the vendor's own guide, a model the toolkit claims to support. Three hundred and seventy-one build steps scroll past, all green — and then it…

  • Error "mropesection" persists across hardware and configurations
  • Qwen3-VL-2B optimization completes successfully without error
  • Qwen2-VL export issue unique to older model, no public fix

More from Friday 27 November →