Skip to content

iOS: DateFormatter has no fixed locale, breaking non-Gregorian calendars #40

Description

@developerjamiu
// ios/smart_text_flutter/Sources/smart_text_flutter/NSDataDetectorExtension.swift:88-90
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"

A fixed format string combined with the user's locale produces wrong output under non-Gregorian calendars. A user whose device is set to the Buddhist or Japanese calendar gets a year like 2569 in the rawValue.

This is a well-known iOS pitfall: fixed-format DateFormatter must pin its locale.

Fix: set locale = Locale(identifier: "en_US_POSIX"), or use ISO8601DateFormatter, which is what the format string is imitating.

Found during the v0.4.0 codebase audit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplatform: iosAffects the iOS or macOS implementation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions