Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 51f0616

Browse files
committed
Convert rfc3339DateFormatter method to Swift
1 parent 50916f6 commit 51f0616

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

WordPressKit/NSDate+RFC3339.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@ import Foundation
22

33
extension NSDate {
44

5+
// TODO: Make `static let` after conversion since it's not used outside WordPressKit
6+
@objc
7+
static func rfc3339DateFormatter() -> DateFormatter {
8+
DateFormatter.rfc3339Formatter
9+
}
10+
511
@objc(WordPressComJSONString)
612
public func wordPressComJSONString() -> String {
713
NSDate.rfc3339DateFormatter().string(from: self as Date)
814
}
915
}
16+
17+
extension DateFormatter {
18+
19+
static let rfc3339Formatter: DateFormatter = {
20+
let formatter = DateFormatter()
21+
formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"
22+
formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) as TimeZone
23+
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale
24+
return formatter
25+
}()
26+
}

WordPressKit/NSDate+WordPressJSON.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
@interface NSDate (WordPressJSON)
44

5-
+ (NSDateFormatter *)rfc3339DateFormatter;
6-
75
/**
86
Parses a date string
97

WordPressKit/NSDate+WordPressJSON.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@implementation NSDate (WordPressJSON)
44

5+
// FIXME: This is here only for the benefit of dateWithWordPressComJSONString. Remove together with that.
56
+ (NSDateFormatter *)rfc3339DateFormatter {
67
static NSDateFormatter *rfc3339DateFormatter;
78
if (rfc3339DateFormatter == nil) {

0 commit comments

Comments
 (0)