Elektrine lite

← Feed

@ashfurrow@tenforward.social

Post #2226263

2026-04-21 21:19 UTC

This is a long shot, but... Has anyone seen an issue where a Swift DateFormatter will *mostly* correctly parses dates with the wrong number of milliseconds, but won't under specific device configurations? I have a date formatter with "yyyy'-'MM'-'dd'T'HH:mm:ss.SSSZ" as its format string (which expects three millisecond digits). iOS will correctly parse a date string with only two digits, eg "2026-04-21T19:29:15.11Z", which, that's fine. But I have reports of an intermittent error in parsing dates, and they all have only two millisecond digits. So I'm wondering if there is some combination of locale/date settings that cause this to fail. Does this ring a bell to anyone?

Replies (3)

  • @ashfurrow@tenforward.social 2026-04-24 11:52

    Switching to ISO8601DateFormatter resolved the bug (the differing behaviour I was seeing with plain DateFormatter). I never found a root cause of why it failed to parse the same dates on different users’ devices, which means I can’t guard against the bug except by avoiding DateFormatter. Thanks to everyone who responded!

    Open ##2686025

  • @brunoph@breakpoint.cafe 2026-04-21 21:20

    @ashfurrow@tenforward.social I recall having issues with date strings that would sometimes have fractional milliseconds and sometimes not, and the same formatter wouldn't be able to decode both, so I had to have a fallback to handle the opposite case. It's been a long while tho, so details are hazy in my memory.

    Open ##2686026

  • @ashfurrow@tenforward.social any particular reason you're not using this guy since that looks to me like an ISO8601 compliant date? https://developer.apple.com/documentation/foundation/iso8601dateformatter

    Open ##2686032