Skip to content

Commit f799020

Browse files
committed
Make ISO8601DateFormatter.Options static properties immutable.
Fixes swiftlang#4703. [`ISO8601DateFormatter.Options`](https://github.com/apple/swift-corelibs-foundation/blob/7504fdfa4529ac01b77ab83bfee51a5f06e3e6d1/Sources/Foundation/ISO8601DateFormatter.swift#L14) currently uses `var` for its static properties. The properties should instead be declared using `let` to prevent accidental mutation and to let the compiler know that these properties are concurrency-safe. Regarding the latter point, the following is an example error caused by this issue: > error: reference to static property 'withInternetDateTime' is not concurrency-safe because it involves shared mutable state
1 parent f3f3a73 commit f799020

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Sources/Foundation/ISO8601DateFormatter.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@ extension ISO8601DateFormatter {
1717

1818
public init(rawValue: UInt) { self.rawValue = rawValue }
1919

20-
public static var withYear = ISO8601DateFormatter.Options(rawValue: 1 << 0)
20+
public static let withYear = ISO8601DateFormatter.Options(rawValue: 1 << 0)
2121

22-
public static var withMonth = ISO8601DateFormatter.Options(rawValue: 1 << 1)
22+
public static let withMonth = ISO8601DateFormatter.Options(rawValue: 1 << 1)
2323

24-
public static var withWeekOfYear = ISO8601DateFormatter.Options(rawValue: 1 << 2)
24+
public static let withWeekOfYear = ISO8601DateFormatter.Options(rawValue: 1 << 2)
2525

26-
public static var withDay = ISO8601DateFormatter.Options(rawValue: 1 << 4)
26+
public static let withDay = ISO8601DateFormatter.Options(rawValue: 1 << 4)
2727

28-
public static var withTime = ISO8601DateFormatter.Options(rawValue: 1 << 5)
28+
public static let withTime = ISO8601DateFormatter.Options(rawValue: 1 << 5)
2929

30-
public static var withTimeZone = ISO8601DateFormatter.Options(rawValue: 1 << 6)
30+
public static let withTimeZone = ISO8601DateFormatter.Options(rawValue: 1 << 6)
3131

32-
public static var withSpaceBetweenDateAndTime = ISO8601DateFormatter.Options(rawValue: 1 << 7)
32+
public static let withSpaceBetweenDateAndTime = ISO8601DateFormatter.Options(rawValue: 1 << 7)
3333

34-
public static var withDashSeparatorInDate = ISO8601DateFormatter.Options(rawValue: 1 << 8)
34+
public static let withDashSeparatorInDate = ISO8601DateFormatter.Options(rawValue: 1 << 8)
3535

36-
public static var withColonSeparatorInTime = ISO8601DateFormatter.Options(rawValue: 1 << 9)
36+
public static let withColonSeparatorInTime = ISO8601DateFormatter.Options(rawValue: 1 << 9)
3737

38-
public static var withColonSeparatorInTimeZone = ISO8601DateFormatter.Options(rawValue: 1 << 10)
38+
public static let withColonSeparatorInTimeZone = ISO8601DateFormatter.Options(rawValue: 1 << 10)
3939

40-
public static var withFractionalSeconds = ISO8601DateFormatter.Options(rawValue: 1 << 11)
40+
public static let withFractionalSeconds = ISO8601DateFormatter.Options(rawValue: 1 << 11)
4141

42-
public static var withFullDate = ISO8601DateFormatter.Options(rawValue: withYear.rawValue + withMonth.rawValue + withDay.rawValue + withDashSeparatorInDate.rawValue)
42+
public static let withFullDate = ISO8601DateFormatter.Options(rawValue: withYear.rawValue + withMonth.rawValue + withDay.rawValue + withDashSeparatorInDate.rawValue)
4343

44-
public static var withFullTime = ISO8601DateFormatter.Options(rawValue: withTime.rawValue + withTimeZone.rawValue + withColonSeparatorInTime.rawValue + withColonSeparatorInTimeZone.rawValue)
44+
public static let withFullTime = ISO8601DateFormatter.Options(rawValue: withTime.rawValue + withTimeZone.rawValue + withColonSeparatorInTime.rawValue + withColonSeparatorInTimeZone.rawValue)
4545

46-
public static var withInternetDateTime = ISO8601DateFormatter.Options(rawValue: withFullDate.rawValue + withFullTime.rawValue)
46+
public static let withInternetDateTime = ISO8601DateFormatter.Options(rawValue: withFullDate.rawValue + withFullTime.rawValue)
4747
}
4848

4949
}

0 commit comments

Comments
 (0)