Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Sources/SkipFoundation/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ public struct Date : Hashable, CustomStringConvertible, Comparable, Codable, Kot

public func ISO8601Format(_ style: Date.ISO8601FormatStyle = .iso8601) -> String {
// TODO: use the style parameters
// local time zone specific
// return java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", java.util.Locale.getDefault()).format(platformValue)
var dateFormat = java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.getDefault())
var dateFormat = java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.ROOT)
dateFormat.timeZone = java.util.TimeZone.getTimeZone("GMT")
return dateFormat.format(platformValue)
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/SkipFoundationTests/Foundation/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ final class DateTests: XCTestCase {
XCTAssertEqual("4001-01-01T00:00:00Z", Date.distantFuture.ISO8601Format())
}

func testISO8601FormattingIsLocaleIndependent() throws {
let date = Date(timeIntervalSince1970: 1_783_042_560)

#if SKIP
// Simulates a device configured with Eastern Arabic numerals (0-9 -> ٠-٩).
// This replicates the OS-level system settings that would distort technical
// string formatting when relying on `Locale.getDefault()`.
let originalLocale = java.util.Locale.getDefault()
let arabicNumbersLocale = java.util.Locale.Builder()
.setLanguage("ar")
.setExtension(java.util.Locale.UNICODE_LOCALE_EXTENSION, "nu-arab")
.build()

java.util.Locale.setDefault(arabicNumbersLocale)
defer { java.util.Locale.setDefault(originalLocale) }
#endif

XCTAssertEqual("2026-07-03T01:36:00Z", date.ISO8601Format())
}

func testDateFormatting() throws {
func fmt(_ format: String, _ date: Date) -> String {
let fmt = DateFormatter()
Expand Down
Loading