-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPM Prep - Convert "WordPress JSON date" logic from Objective-C to Swift #758
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
360a0a2
Add tests for the `NSDate` extension implementing RFC3339
mokagio 50916f6
Convert `-(NSString *)WordPressComJSONString` method to Swift
mokagio 51f0616
Convert `rfc3339DateFormatter` method to Swift
mokagio 71fa951
Convert `dateWithWordPressComJSONString:` to Swift
mokagio b0e6dcf
Delete unused `NSDate+WordPressJSON` Objective-C file
mokagio b0ed585
Make new Swift `rfc3339DateFormatter` a `static let` instead of `func`
mokagio 5686c93
Restore `rfc3339DateFormatter()` method for backwards compatibility
mokagio 31292ae
Bump version to 15.0.0-beta.1 because of breaking change in `NSDate` API
mokagio f3bc0a0
Breaking change – Remove deprecated `rfc3339DateFormatter()`
mokagio ca4b342
Extract `DateFormatter` RFC-3339 to file and rename to `wordPressCom`
mokagio e4f8fba
Breaking change – Move `NSDate` WordPress.com implementation to `Date`
mokagio 2a90451
Breaking change – Modernize `NSDate` and `Date` WP.com extensions (#759)
mokagio 4ab30ee
Add `CHANGELOG` entry for reworked WP.com `NSDate` conversion
mokagio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
extension Date { | ||
|
||
/// Parses a date string | ||
/// | ||
/// Dates in the format specified in http://www.w3.org/TR/NOTE-datetime should be OK. | ||
/// The kind of dates returned by the REST API should match that format, even if the doc promises ISO 8601. | ||
/// | ||
/// Parsing the full ISO 8601, or even RFC 3339 is more complex than this, and makes no sense right now. | ||
/// | ||
/// - SeeAlso: [WordPress.com REST API docs](https://developer.wordpress.com/docs/api/) | ||
/// - Warning: This method doesn't support fractional seconds or dates with leap seconds (23:59:60 turns into 23:59:00) | ||
static func with(wordPressComJSONString jsonString: String) -> Date? { | ||
DateFormatter.wordPressCom.date(from: jsonString) | ||
} | ||
|
||
var wordPressComJSONString: String { | ||
DateFormatter.wordPressCom.string(from: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
extension DateFormatter { | ||
|
||
/// A `DateFormatter` configured to manage dates compatible with the WordPress.com API. | ||
/// | ||
/// - SeeAlso: [https://developer.wordpress.com/docs/api/](https://developer.wordpress.com/docs/api/) | ||
static let wordPressCom: DateFormatter = { | ||
let formatter = DateFormatter() | ||
formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ" | ||
formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) as TimeZone | ||
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale | ||
return formatter | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
|
||
// This `NSDate` extension wraps the `Date` implementation. | ||
// | ||
// It's done in two types because we cannot expose the `Date` methods to Objective-C, since `Date` is not a class: | ||
// | ||
// `@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes` | ||
extension NSDate { | ||
|
||
/// Parses a date string | ||
/// | ||
/// Dates in the format specified in http://www.w3.org/TR/NOTE-datetime should be OK. | ||
/// The kind of dates returned by the REST API should match that format, even if the doc promises ISO 8601. | ||
/// | ||
/// Parsing the full ISO 8601, or even RFC 3339 is more complex than this, and makes no sense right now. | ||
/// | ||
/// - SeeAlso: [WordPress.com REST API docs](https://developer.wordpress.com/docs/api/) | ||
/// - Warning: This method doesn't support fractional seconds or dates with leap seconds (23:59:60 turns into 23:59:00) | ||
// | ||
// Needs to be `public` because of the usages in the Objective-C code. | ||
@objc(dateWithWordPressComJSONString:) | ||
public static func with(wordPressComJSONString jsonString: String) -> Date? { | ||
Date.with(wordPressComJSONString: jsonString) | ||
} | ||
|
||
@objc(WordPressComJSONString) | ||
public func wordPressComJSONString() -> String { | ||
(self as Date).wordPressComJSONString | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we make version change in a dedicated PR along side with moving changelog content. Do you intend to make a release once this PR is merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. I just wanted to put a line in the sand for the breaking change.