Skip to content

Commit

Permalink
Merge pull request #12363 from wordpress-mobile/fix/stats-timezone
Browse files Browse the repository at this point in the history
[Stats Refresh] Fix formatted date when timezone is different
  • Loading branch information
danielebogo committed Aug 23, 2019
2 parents 1ad7020 + 1a95e33 commit c6e5cfc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Expand Up @@ -6,7 +6,8 @@
* Account Settings: added the ability to change the username.
* Stats: added File Downloads to period stats.
* Stats Periods: Fixed an issue that made the Post stats title button unable.
* Adds a Publish Now action to posts in the posts list.
* Adds a Publish Now action to posts in the posts list.
* Stats Periods: Fixed a bug that affected the header date when the site and the device timezones were different.

13.0
-----
Expand Down
15 changes: 3 additions & 12 deletions WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift
Expand Up @@ -166,18 +166,9 @@ private extension StatsDataHelper {
extension Date {

func normalizedForSite() -> Date {
var calendar = StatsDataHelper.calendarForSite

let flags: NSCalendar.Unit = [.day, .month, .year]
let components = (calendar as NSCalendar).components(flags, from: self)

var normalized = DateComponents()
normalized.day = components.day
normalized.month = components.month
normalized.year = components.year

calendar.timeZone = .autoupdatingCurrent
return calendar.date(from: normalized) ?? self
let calendar = StatsDataHelper.calendar
let components = calendar.dateComponents([.day, .month, .year], from: self)
return calendar.date(from: components) ?? self
}

func relativeStringInPast() -> String {
Expand Down
Expand Up @@ -47,7 +47,7 @@ class StatsPeriodHelper {

switch period {
case .day:
return date < currentDate
return date < currentDate.normalizedDate()
case .week:
let week = weekIncludingDate(date)
guard let weekEnd = week?.weekEnd,
Expand Down
Expand Up @@ -142,7 +142,7 @@ private extension SiteStatsDashboardViewController {
animated: false)
}

periodTableViewController.selectedDate = periodDate ?? StatsDataHelper.currentDateForSite().normalizedForSite()
periodTableViewController.selectedDate = periodDate ?? StatsDataHelper.currentDateForSite()
let selectedPeriod = StatsPeriodUnit(rawValue: currentSelectedPeriod.rawValue - 1) ?? .day
periodTableViewController.selectedPeriod = selectedPeriod
}
Expand Down

0 comments on commit c6e5cfc

Please sign in to comment.