@@ -183,6 +183,25 @@ class RFC822DateFormatter: PermissiveDateFormatter, @unchecked Sendable {
183
183
}
184
184
}
185
185
186
+ // MARK: - RFC1123 formatter
187
+
188
+ /// Formatter for RFC1123 date specification.
189
+ class RFC1123DateFormatter : PermissiveDateFormatter , @unchecked Sendable {
190
+ /// List of date formats supported for RFC1123.
191
+ override var dateFormats : [ String ] {
192
+ [
193
+ " EEE, dd MMM yyyy HH:mm:ss z "
194
+ ]
195
+ }
196
+
197
+ override var permissiveDateFormats : [ String ] {
198
+ [
199
+ // Omits the time and timezone
200
+ " EEE, dd MMM yyyy "
201
+ ]
202
+ }
203
+ }
204
+
186
205
// MARK: - DateSpec
187
206
188
207
/// Enum representing different date specifications.
@@ -193,8 +212,10 @@ enum DateSpec {
193
212
case rfc3339
194
213
/// RFC822 date format (e.g., Tue, 05 Dec 2024 10:30:00 GMT).
195
214
case rfc822
215
+ /// RFC1123 date format (e.g., Fri, 06 Sep 2024 12:34:56 GMT).
216
+ case rfc1123
196
217
/// Permissive mode which attempts to parse the date using multiple formats.
197
- /// It tries RFC822 first, then RFC3339, and finally ISO8601 in that order.
218
+ /// It tries RFC822 first, then RFC3339, RFC1123 and finally ISO8601 in that order.
198
219
case permissive
199
220
}
200
221
@@ -231,6 +252,9 @@ class FeedDateFormatter: DateFormatter, @unchecked Sendable {
231
252
/// RFC822 date formatter.
232
253
lazy var rfc822Formatter : RFC822DateFormatter = . init( )
233
254
255
+ /// RFC1123 date formatter.
256
+ lazy var rfc1123Formatter : RFC1123DateFormatter = . init( )
257
+
234
258
/// Converts a string to a Date based on the given date specification.
235
259
///
236
260
/// - Parameters:
@@ -244,10 +268,13 @@ class FeedDateFormatter: DateFormatter, @unchecked Sendable {
244
268
rfc3339Formatter. date ( from: string)
245
269
case . rfc822:
246
270
rfc822Formatter. date ( from: string)
271
+ case . rfc1123:
272
+ rfc1123Formatter. date ( from: string)
247
273
case . permissive:
248
274
rfc822Formatter. date ( from: string) ??
249
- rfc3339Formatter. date ( from: string) ??
250
- iso8601Formatter. date ( from: string)
275
+ rfc3339Formatter. date ( from: string) ??
276
+ rfc1123Formatter. date ( from: string) ??
277
+ iso8601Formatter. date ( from: string)
251
278
}
252
279
}
253
280
@@ -264,6 +291,8 @@ class FeedDateFormatter: DateFormatter, @unchecked Sendable {
264
291
rfc3339Formatter. string ( from: date)
265
292
case . rfc822:
266
293
rfc822Formatter. string ( from: date)
294
+ case . rfc1123:
295
+ rfc1123Formatter. string ( from: date)
267
296
case . permissive:
268
297
fatalError ( )
269
298
}
0 commit comments