Skip to content

Commit

Permalink
Merge pull request #20387 from wordpress-mobile/fix/20334-fix-timezon…
Browse files Browse the repository at this point in the history
…e-issue-on-traffic-chart

Fix timezone issue on traffic chart
  • Loading branch information
irfano authored Mar 3, 2024
2 parents cb12a0f + 5c357cd commit a25f785
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.viewmodel.ResourceProvider
import java.util.Calendar
import java.util.Date
import javax.inject.Inject
import javax.inject.Named
Expand Down Expand Up @@ -110,19 +109,9 @@ class TrafficOverviewUseCase(
}

private fun getLastDate(model: VisitsAndViewsModel?): Date? {
selectedDateProvider.getSelectedDate(statsGranularity)?.let { return dateWithoutHour(it) }

selectedDateProvider.getSelectedDate(statsGranularity)?.let { return it }
val lastDateString = model?.dates?.lastOrNull()?.period
return lastDateString?.let { dateWithoutHour(statsDateFormatter.parseStatsDate(statsGranularity, it)) }
}

// Remove the hour and minute from the date to avoid fetching incorrect dates caused by timezone differences
private fun dateWithoutHour(date: Date): Date {
val calendar = Calendar.getInstance()
calendar.time = date
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
return calendar.time
return lastDateString?.let { statsDateFormatter.parseStatsDate(statsGranularity, it) }
}

override suspend fun fetchRemoteData(forced: Boolean): State<TrafficOverviewUiModel> {
Expand Down Expand Up @@ -180,7 +169,8 @@ class TrafficOverviewUseCase(
granularity,
LimitMode.Top(quantity),
date,
forced
forced,
false
)
} ?: visitsAndViewsStore.fetchVisits(
statsSiteProvider.siteModel,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext {
automatticTracksVersion = '3.4.0'
gutenbergMobileVersion = 'v1.114.0'
wordPressAztecVersion = 'v2.0'
wordPressFluxCVersion = 'trunk-8b930418a49b0d0846ed56ebf8fd8adad5011901'
wordPressFluxCVersion = 'trunk-cef238b9f77fbbdc7aff16c7f1623b3d89091968'
wordPressLoginVersion = '1.14.1'
wordPressPersistentEditTextVersion = '1.0.2'
wordPressUtilsVersion = '3.13.0'
Expand Down

0 comments on commit a25f785

Please sign in to comment.