Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: removed

Remove the arrows that stepped the date range back and forward a period.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ same window as an earlier one is dropped. Each option carries the resolved
**Returns:** `ComparisonOption[]` - Empty when the range is incomplete or
inverted

### Range Measurement and Stepping
### Range Measurement

#### `getDateRangeSpan( range? )`

Expand All @@ -215,22 +215,6 @@ A whole-month range stays in days below two months and only collapses into
years from two years up, so "Last 30 days" reads as 30 days and a
twelve-month window as 12 months.

#### `stepDateRange( range, direction )`

Shifts a range backward or forward (`'previous' | 'next'`) by its own length.
Steps move in calendar units, so a step across a DST boundary keeps the wall
clock; where a calendar step cannot be undone, it falls back to whole days.
Returns `undefined` when the range has no measurable span.

```typescript
stepDateRange( { from, to }, 'previous' ); // Last 7 days -> the 7 days before
```

#### `canStepForward( range, now )`

Whether the next window has already happened in full. Pass the site's `now`,
not the browser's.

## Types

### `DateRange`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { differenceInDays } from 'date-fns';
*/
import { getDateRangeSpan } from '../date-range-span';
import { COMPARISON_PRESETS, getComparisonRangeFromPreset } from '../get-comparison-range';
import { stepDateRange } from '../step-date-range';
import { createTZDateFromParts } from '../tz';

describe( 'getComparisonRangeFromPreset', () => {
Expand Down Expand Up @@ -389,8 +388,7 @@ describe( 'getComparisonRangeFromPreset', () => {
it( 'falls back to the day count where a month step will not reverse', () => {
// 31 January through 30 March measures as two months, but two months
// back from 31 January clamps to 30 November: 62 days against the
// reference's 59. The step arrows count days there, and a comparison
// naming a different window than the arrow would is a defect.
// reference's 59, so the comparison counts days instead.
const clamping = {
from: new Date( 2026, 0, 31, 0, 0, 0, 0 ),
to: new Date( 2026, 2, 30, 23, 59, 59, 999 ),
Expand All @@ -401,7 +399,6 @@ describe( 'getComparisonRangeFromPreset', () => {
};

expect( getComparisonRangeFromPreset( clamping, 'previous-period' ) ).toEqual( expected );
expect( stepDateRange( clamping, 'previous' ) ).toEqual( expected );
} );

it( 'ends the previous whole months on a month end, whatever day the reference ends on', () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TZDate } from '@date-fns/tz';
* Internal dependencies
*/
import { getDateRangeSpan } from '../date-range-span';
import { clampRangeEndToToday, completeToDateRange } from '../to-date-range';
import { completeToDateRange } from '../to-date-range';

/**
* A zone away from UTC, so a boundary computed on the wrong clock lands on a
Expand Down Expand Up @@ -92,47 +92,3 @@ describe( 'completeToDateRange', () => {
expect( completeToDateRange( open, 'last-12-months' ) ).toBe( open );
} );
} );

describe( 'clampRangeEndToToday', () => {
// Where a forward step out of "12 months" lands: the running month closed,
// which reaches eleven days past the day it was taken on.
const steppedForward = { from: at( 2025, 9, 1 ), to: endOf( 2026, 8, 31 ) };
const noon = new TZDate( 2026, 7, 20, 12, 0, 0, 0, TIMEZONE );

it( 'pulls a window ending after today back to the end of today', () => {
expect( clampRangeEndToToday( steppedForward, noon ) ).toEqual( {
from: at( 2025, 9, 1 ),
to: endOf( 2026, 8, 20 ),
} );
} );

it( 'closes the day on the window’s own clock', () => {
// 02:00 UTC is still the 26th in New York, so a clamp read on the
// browser's clock would leave the window a day long.
const clamped = clampRangeEndToToday(
steppedForward,
new Date( Date.UTC( 2026, 7, 27, 2, 0 ) )
);

expect( clamped.to ).toEqual( endOf( 2026, 8, 26 ) );
expect( clamped.to ).toBeInstanceOf( TZDate );
} );

it( 'leaves a window that already ends today where it is', () => {
const toDate = { from: at( 2025, 9, 1 ), to: endOf( 2026, 8, 20 ) };

expect( clampRangeEndToToday( toDate, noon ) ).toBe( toDate );
} );

it( 'leaves a window ending in the past where it is', () => {
const past = { from: at( 2024, 9, 1 ), to: endOf( 2025, 8, 31 ) };

expect( clampRangeEndToToday( past, noon ) ).toBe( past );
} );

it( 'returns a range without an end untouched', () => {
const open = { from: at( 2025, 9, 1 ) };

expect( clampRangeEndToToday( open, noon ) ).toBe( open );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function getInclusiveDayCount( from: Date, to: Date ): number {
* whole number of months. Detected by round trip against the day after the
* range ends, and again from the start stepped back by that count: a start a
* month step cannot undo (31 January two months back clamps to 30 November)
* measures in days, the way the step arrows measure it. Shared by the
* previous-period shift and its label, so both take the same branch; unlike
* measures in days instead. Shared by the previous-period shift and its
* label, so both take the same branch; unlike
* `getDateRangeSpan`, a single month counts.
*
* @param from - Range start.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export { INTERVAL_TYPES, isIntervalType, type IntervalType } from './interval';

export { getDateRangeSpan, type DateRangeSpan, type DateRangeSpanUnit } from './date-range-span';

export { stepDateRange, canStepForward, type StepDirection } from './step-date-range';
export { completeToDateRange, clampRangeEndToToday } from './to-date-range';

export { drillDateRange } from './drill-date-range';

export { toBucketStamp, resolveBucketStamp } from './bucket-stamp';
Expand Down
Loading
Loading