Skip to content

Commit c3ca003

Browse files
committed
Extract date components with UTC timezone instead of local timezone
1 parent e006901 commit c3ca003

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

WordPress/WordPressTest/BloggingPromptsServiceTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ final class BloggingPromptsServiceTests: XCTestCase {
77
private let siteID = 1
88
private let timeout: TimeInterval = 2
99

10+
private static let utcTimeZone = TimeZone(secondsFromGMT: 0)!
1011
private static var dateFormatter: DateFormatter = {
1112
let formatter = DateFormatter()
1213
formatter.dateFormat = "yyyy-MM-dd"
1314
formatter.locale = .init(identifier: "en_US_POSIX")
14-
formatter.timeZone = .init(secondsFromGMT: 0)
15+
formatter.timeZone = utcTimeZone
1516

1617
return formatter
1718
}()
@@ -66,7 +67,7 @@ final class BloggingPromptsServiceTests: XCTestCase {
6667
XCTAssertEqual(firstPrompt.content, "<!-- wp:pullquote -->\n<figure class=\"wp-block-pullquote\"><blockquote><p>Was there a toy or thing you always wanted as a child, during the holidays or on your birthday, but never received? Tell us about it.</p><cite>(courtesy of plinky.com)</cite></blockquote></figure>\n<!-- /wp:pullquote -->")
6768
XCTAssertEqual(firstPrompt.attribution, "dayone")
6869

69-
let firstDateComponents = firstPrompt.date.dateAndTimeComponents()
70+
let firstDateComponents = Calendar.current.dateComponents(in: Self.utcTimeZone, from: firstPrompt.date)
7071
XCTAssertEqual(firstDateComponents.year!, 2022)
7172
XCTAssertEqual(firstDateComponents.month!, 5)
7273
XCTAssertEqual(firstDateComponents.day!, 3)
@@ -83,7 +84,7 @@ final class BloggingPromptsServiceTests: XCTestCase {
8384
XCTAssertEqual(secondPrompt.content, "<!-- wp:pullquote -->\n<figure class=\"wp-block-pullquote\"><blockquote><p>Tell us about a time when you felt out of place.</p><cite>(courtesy of plinky.com)</cite></blockquote></figure>\n<!-- /wp:pullquote -->")
8485
XCTAssertTrue(secondPrompt.attribution.isEmpty)
8586

86-
let secondDateComponents = secondPrompt.date.dateAndTimeComponents()
87+
let secondDateComponents = Calendar.current.dateComponents(in: Self.utcTimeZone, from: secondPrompt.date)
8788
XCTAssertEqual(secondDateComponents.year!, 2021)
8889
XCTAssertEqual(secondDateComponents.month!, 9)
8990
XCTAssertEqual(secondDateComponents.day!, 12)
@@ -116,7 +117,7 @@ final class BloggingPromptsServiceTests: XCTestCase {
116117

117118
// Ensure that the date returned is more recent than the supplied date parameter.
118119
let firstPrompt = prompts.first!
119-
let firstDateComponents = firstPrompt.date.dateAndTimeComponents()
120+
let firstDateComponents = Calendar.current.dateComponents(in: Self.utcTimeZone, from: firstPrompt.date)
120121
XCTAssertEqual(firstDateComponents.year!, 2022)
121122
XCTAssertEqual(firstDateComponents.month!, 5)
122123
XCTAssertEqual(firstDateComponents.day!, 3)
@@ -155,7 +156,7 @@ final class BloggingPromptsServiceTests: XCTestCase {
155156

156157
XCTAssertNotNil(remote.passedDateParameter)
157158
let passedDate = remote.passedDateParameter!
158-
let differenceInHours = Calendar.autoupdatingCurrent.dateComponents([.hour], from: passedDate, to: Date()).hour!
159+
let differenceInHours = Calendar.current.dateComponents([.hour], from: passedDate, to: Date()).hour!
159160
XCTAssertEqual(differenceInHours, expectedDifferenceInHours)
160161

161162
XCTAssertNotNil(remote.passedNumberParameter)

0 commit comments

Comments
 (0)