Reduces a date range to full years, full months, and days between two dates.
Using npm, npm i date-range-compressor
.
Using yarn, yarn add date-range-compressor
.
Using import
import { compressDateRange } from 'date-range-compressor';
const compressedRange = compressDateRange('20191230', '20210203');
// compressedRange is {years: ['2020'], months: ['202101'], days: ['20191230', '20191231', '20210201', '20210202', '20210203']}
In a CommonJS environment
const { compressDateRange } = require('date-range-compressor');
const compressedRange = compressDateRange('20191230', '20210203');
// compressedRange is {years: ['2020'], months: ['202101'], days: ['20191230', '20191231', '20210201', '20210202', '20210203']}
▸ compressDateRange(start
, end
): CompressedDateRange
Compresses a date range between two days expressed as string date expressions
Export
Link
https://day.js.org/docs/en/parse/string-format Possible date formats
Name | Type | Description |
---|---|---|
start |
string |
Starting day as any valid date string |
end |
string |
End day as any valid date string |
The full years, full months and days included in that range
▸ getDaysInRange(start
, end
, excludedMonths?
, excludedYears?
): string
[]
Gets the days in range between to days
Export
Name | Type | Default value | Description |
---|---|---|---|
start |
string |
undefined |
YYYYMMDD to start the range |
end |
string |
undefined |
YYYYMMDD to end the range |
excludedMonths? |
string [] |
[] |
The months to exclude in range YYYYMM |
excludedYears? |
string [] |
[] |
The years to exclude in range YYYY |
string
[]
The days range
▸ getMonthsInRange(start
, end
, excludedYears?
): string
[]
Gets all full months between two dates
Export
Name | Type | Default value | Description |
---|---|---|---|
start |
string |
undefined |
The start date as YYYYMMDD |
end |
string |
undefined |
The end date as YYYYMMDD |
excludedYears? |
string [] |
[] |
The list of years to exclude for checking as YYYY |
string
[]
The list of full months included in the range
▸ getYearsInRange(start
, end
): string
[]
Gets full years in date range
Export
Name | Type | Description |
---|---|---|
start |
string |
The starting date YYYYMMDD |
end |
string |
The end date YYYYMMDD |
string
[]
Full years between start and end
• Optional
days: string
[]
• Optional
months: string
[]
• Optional
years: string
[]