Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: use today as shortcut ending date / default ending date #97096

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading