Skip to content

Commit

Permalink
Stats: use today as shortcut ending date / default ending date (#97096)
Browse files Browse the repository at this point in the history
* use today as ending date

* fix start date calculation
  • Loading branch information
kangzj authored Dec 5, 2024
1 parent c7302c1 commit e36d212
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
20 changes: 9 additions & 11 deletions client/components/date-range/use-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down
10 changes: 3 additions & 7 deletions client/my-sites/stats/site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
};
}

Expand All @@ -358,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 );
}

Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit e36d212

Please sign in to comment.