Skip to content

Commit 95995ca

Browse files
authored
Merge pull request #8448 from woocommerce/fix/isSameYear-extension
[Analytics Hub] Use custom timezone in isSameYear Date extension
2 parents e1ef761 + dbd2978 commit 95995ca

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

WooCommerce/Classes/Extensions/Date+Woo.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ extension Date {
9797

9898
/// Returns `true` if `self` is in the same year as `other`.
9999
///
100-
func isSameYear(as otherDate: Date) -> Bool {
101-
let calendar = Calendar.current
100+
func isSameYear(as otherDate: Date, using calendar: Calendar = .current) -> Bool {
102101
guard let selfYear = calendar.dateComponents([.year], from: self).year,
103102
let otherYear = calendar.dateComponents([.year], from: otherDate).year else {
104103
return false

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/Time Range/AnalyticsHubTimeRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct AnalyticsHubTimeRange {
1010
}
1111

1212
let startDateDescription: String
13-
if start.isSameYear(as: end) {
13+
if start.isSameYear(as: end, using: calendar) {
1414
startDateDescription = DateFormatter.Stats.createAnalyticsHubDayMonthFormatter(timezone: timezone).string(from: start)
1515
} else {
1616
startDateDescription = DateFormatter.Stats.createAnalyticsHubDayMonthYearFormatter(timezone: timezone).string(from: start)

0 commit comments

Comments
 (0)