Skip to content

Conversation

@timbms
Copy link
Contributor

@timbms timbms commented Dec 15, 2025

NumberFormatter → FormatStyle

  • CGFloatExtension.swift - Now uses Float(string, format: .number.locale(...))
  • StringExtension.swift - Parsing with Double/Int(self, format: .number...)
  • DoubleExtension.swift - Formatting with .formatted(.number.precision(...))

DateFormatter → FormatStyle

  • DateFormatterExtension.swift - Replaced with Date.ISO8601FormatStyle(includingFractionalSeconds: true)
  • UI Views - All date/time formatting now uses .formatted(.dateTime...)
  • Eliminated custom .iso8601Full for standardized approach

Copy link
Contributor

Copilot AI left a 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 DateFormatter usage with .formatted() and Date.ISO8601FormatStyle
  • Replaces all NumberFormatter usage with Double/Int/Float(_, format:) for parsing and .formatted(.number...) for output
  • Removes the custom DateFormatterExtension.swift file containing iso8601Full formatter

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.

Copy link
Contributor

Copilot AI left a 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"))) {
Copy link

Copilot AI Dec 20, 2025

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.

Suggested change
if let value = try? Double(filtered, format: .number.notation(.scientific).locale(Locale(identifier: "en_US_POSIX"))) {
if let value = Double(filtered) {

Copilot uses AI. Check for mistakes.
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())
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
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()
Copy link

Copilot AI Dec 20, 2025

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.

Suggested change
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()

Copilot uses AI. Check for mistakes.
timbms and others added 8 commits December 21, 2025 08:04
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants