-
-
Notifications
You must be signed in to change notification settings - Fork 135
Migrated NumberFormatter and DateFormatter to FormatStyle API #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request modernizes date and number formatting throughout the codebase by migrating from the legacy DateFormatter and NumberFormatter APIs to the modern FormatStyle API introduced in iOS 15.
- Replaces all
DateFormatterusage with.formatted()andDate.ISO8601FormatStyle - Replaces all
NumberFormatterusage withDouble/Int/Float(_, format:)for parsing and.formatted(.number...)for output - Removes the custom
DateFormatterExtension.swiftfile containingiso8601Fullformatter
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| openHABWatch/Views/LogsViewer.swift | Migrated log timestamp formatting to .formatted(.dateTime...) API |
| openHABWatch/Domain/UserData.swift | Minor whitespace cleanup (trailing space removed) |
| openHABTestsSwift/OpenHABWatchTests.swift | Updated date decoding strategy to use custom decoder with ISO8601FormatStyle |
| openHAB/SettingsView/ServerCertificatesView.swift | Replaced DateFormatter with inline .formatted(.dateTime...) for certificate dates |
| openHAB/ScreenSaver/ScreenSaverView.swift | Migrated time and date formatting functions to FormatStyle API |
| openHAB/NotificationsView.swift | Simplified date formatting using .formatted(date:time:) shorthand |
| openHAB/LoggerView.swift | Updated timestamp formatting to include fractional seconds with FormatStyle |
| openHAB/DatePickerUITableViewCell.swift | Migrated ISO8601 date parsing/formatting to ISO8601FormatStyle |
| OpenHABCore/Tests/OpenHABCoreTests/OpenHABJSONParserTests.swift | Updated test date decoding to custom strategy with ISO8601FormatStyle |
| OpenHABCore/Tests/OpenHABCoreTests/JSONParserTests.swift | Updated test date decoding to custom strategy with ISO8601FormatStyle |
| OpenHABCore/Sources/OpenHABCore/Util/StringExtension.swift | Migrated number parsing from NumberFormatter to Double/Int(_, format:) |
| OpenHABCore/Sources/OpenHABCore/Util/HTTPClient.swift | Updated notification date decoding to custom strategy with ISO8601FormatStyle |
| OpenHABCore/Sources/OpenHABCore/Util/DoubleExtension.swift | Migrated number formatting to .formatted(.number.precision(...)) |
| OpenHABCore/Sources/OpenHABCore/Util/DateFormatterExtension.swift | Removed legacy file containing custom ISO8601 DateFormatter |
| OpenHABCore/Sources/OpenHABCore/Model/CGFloatExtension.swift | Migrated number parsing to Float(_, format:) API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| formatter.decimalSeparator = "." | ||
| return formatter.number(from: filter("01234567890E.+-".contains)) | ||
| let filtered = filter("01234567890E.+-".contains) | ||
| if let value = try? Double(filtered, format: .number.notation(.scientific).locale(Locale(identifier: "en_US_POSIX"))) { |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number parsing format for scientific notation may not be correctly configured. The '.notation(.scientific)' option sets the output format, not the parsing format. Scientific notation strings like "1.5E+10" should be parseable, but this implementation may not handle them correctly. Consider testing with scientific notation inputs to ensure backward compatibility.
| if let value = try? Double(filtered, format: .number.notation(.scientific).locale(Locale(identifier: "en_US_POSIX"))) { | |
| if let value = Double(filtered) { |
openHABWatch/Views/LogsViewer.swift
Outdated
| try Task.checkCancellation() | ||
| if let log = entry as? OSLogEntryLog { | ||
| var attributedMessage = AttributedString(dateFormatter.string(from: entry.date)) | ||
| let dateString = entry.date.formatted(.dateTime.year().month().day().hour().minute().second()) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date formatting output differs from the original format. The original used "yyyy-MM-dd HH:mm:ss" (e.g., "2025-01-15 14:30:45"), but the new format will produce a localized format that may not match this pattern (e.g., "Jan 15, 2025 at 2:30:45 PM" in English US locale). Consider using a specific locale or format pattern to maintain the consistent date format.
| let formatter = DateFormatter() | ||
| formatter.dateStyle = .none | ||
| let amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle = configuration.uses24HourTime ? .omitted : .narrow | ||
| var formatStyle = Date.FormatStyle.dateTime.hour(.defaultDigits(amPM: amPM)).minute() |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The time formatting logic may produce incorrect output for 24-hour time. When using 24-hour format, the hour should use '.twoDigits' instead of '.defaultDigits' to ensure leading zeros (e.g., "09:30" instead of "9:30"). The original format used "H:mm:ss" which includes leading zeros for hours.
| var formatStyle = Date.FormatStyle.dateTime.hour(.defaultDigits(amPM: amPM)).minute() | |
| var formatStyle: Date.FormatStyle = configuration.uses24HourTime | |
| ? .dateTime.hour(.twoDigits(amPM: amPM)).minute() | |
| : .dateTime.hour(.defaultDigits(amPM: amPM)).minute() |
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
Signed-off-by: Tim Mueller-Seydlitz <[email protected]>
NumberFormatter → FormatStyle
DateFormatter → FormatStyle