From 34174af2cabeef5a83ba87651958a27cdafe8fc2 Mon Sep 17 00:00:00 2001 From: Jasper Kang Date: Thu, 5 Dec 2024 14:14:42 +1300 Subject: [PATCH 1/2] use today as ending date --- client/components/date-range/use-shortcuts.ts | 20 +++++++++---------- client/my-sites/stats/site.jsx | 8 ++------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/client/components/date-range/use-shortcuts.ts b/client/components/date-range/use-shortcuts.ts index e0013c4191363d..29435c65f06cd7 100644 --- a/client/components/date-range/use-shortcuts.ts +++ b/client/components/date-range/use-shortcuts.ts @@ -29,38 +29,36 @@ export const getShortcuts = createSelector( const siteId = getSelectedSiteId( state ); const siteToday = getMomentSiteZone( state, siteId ); const siteTodayStr = siteToday.format( DATE_FORMAT ); - const siteYesterday = isNewDateFilteringEnabled - ? siteToday.clone().subtract( 1, 'days' ) - : siteToday.clone(); + const siteYesterday = siteToday.clone().subtract( 1, 'days' ); const yesterdayStr = siteYesterday.format( DATE_FORMAT ); const supportedShortcutList = [ { id: 'last_7_days', label: translateFunction( 'Last 7 Days' ), - startDate: siteYesterday.clone().subtract( 6, 'days' ).format( DATE_FORMAT ), - endDate: yesterdayStr, + startDate: siteToday.clone().subtract( 6, 'days' ).format( DATE_FORMAT ), + endDate: siteTodayStr, period: DATERANGE_PERIOD.DAY, }, { id: 'last_30_days', label: translateFunction( 'Last 30 Days' ), - startDate: siteYesterday.clone().subtract( 29, 'days' ).format( DATE_FORMAT ), - endDate: yesterdayStr, + startDate: siteToday.clone().subtract( 29, 'days' ).format( DATE_FORMAT ), + endDate: siteTodayStr, period: DATERANGE_PERIOD.DAY, }, { id: 'last_3_months', label: translateFunction( 'Last 90 Days' ), - startDate: siteYesterday.clone().subtract( 89, 'days' ).format( DATE_FORMAT ), - endDate: yesterdayStr, + startDate: siteToday.clone().subtract( 89, 'days' ).format( DATE_FORMAT ), + endDate: siteTodayStr, period: DATERANGE_PERIOD.WEEK, }, { id: 'last_year', label: translateFunction( 'Last Year' ), - startDate: siteYesterday.clone().subtract( 364, 'days' ).format( DATE_FORMAT ), - endDate: yesterdayStr, + startDate: siteToday.clone().subtract( 364, 'days' ).format( DATE_FORMAT ), + endDate: siteTodayStr, period: DATERANGE_PERIOD.MONTH, }, { diff --git a/client/my-sites/stats/site.jsx b/client/my-sites/stats/site.jsx index 1595f6d471f9b8..df7951f3f811df 100644 --- a/client/my-sites/stats/site.jsx +++ b/client/my-sites/stats/site.jsx @@ -338,9 +338,7 @@ class StatsSite extends Component { customChartRange = { chartEnd }; } else { customChartRange = { - chartEnd: isNewDateFilteringEnabled - ? momentSiteZone.clone().subtract( 1, 'days' ).format( DATE_FORMAT ) - : momentSiteZone.format( DATE_FORMAT ), + chartEnd: momentSiteZone.format( DATE_FORMAT ), }; } @@ -395,9 +393,7 @@ class StatsSite extends Component { // For StatsDateControl customChartRange.daysInRange = 7; - customChartRange.chartEnd = isNewDateFilteringEnabled - ? momentSiteZone.clone().subtract( 1, 'days' ).format( DATE_FORMAT ) - : momentSiteZone.format( DATE_FORMAT ); + customChartRange.chartEnd = momentSiteZone.format( DATE_FORMAT ); customChartRange.chartStart = moment( customChartRange.chartEnd ) .subtract( customChartRange.daysInRange - 1, 'days' ) .format( DATE_FORMAT ); From 97eb70325fe7c6e9c0d67fa0df85011788a9fb5d Mon Sep 17 00:00:00 2001 From: Jasper Kang Date: Thu, 5 Dec 2024 14:21:17 +1300 Subject: [PATCH 2/2] fix start date calculation --- client/my-sites/stats/site.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/my-sites/stats/site.jsx b/client/my-sites/stats/site.jsx index df7951f3f811df..138ca155c68939 100644 --- a/client/my-sites/stats/site.jsx +++ b/client/my-sites/stats/site.jsx @@ -356,7 +356,7 @@ class StatsSite extends Component { // (e.g. months defaulting to 30 days and showing one point) customChartRange.chartStart = momentSiteZone .clone() - .subtract( daysInRange, 'days' ) + .subtract( daysInRange - 1, 'days' ) .format( DATE_FORMAT ); }