pandas-tspandas-ts
npm

API reference

tseries.offsets

Date offset classes for arithmetic on dates. All offsets have apply(date), rollforward(date) and rollback(date) methods.

NameSummary
BusinessDayA business-day offset. Skips Saturday and Sunday.
MonthEndAn offset corresponding to the last business day of the month.
MonthBeginAn offset corresponding to the first calendar day of the month.
YearEndAn offset for the last day of the year.
YearBeginAn offset for the first day of the year.
QuarterEndDateOffset increments between Quarter end dates.
QuarterBeginDateOffset increments between Quarter start dates.
WeekA week offset.
DayA calendar day offset.
HourAn hour offset.
MinuteA minute offset.
SecondA second offset.
BusinessHourDateOffset subclass representing possibly n business hours. Default business hou

BusinessDay

#
new BusinessDay(n?)

A business-day offset. Skips Saturday and Sunday.

Parameters

nnumber
Number of business days. Default 1.

Returns

BusinessDay

Example

TypeScript
import { BusinessDay } from 'pandas-ts';
const bd = new BusinessDay(1);
bd.apply(new Date('2024-01-05')).toDateString();    // Friday -> Monday: 'Mon Jan 08 2024'

MonthEnd

#
new MonthEnd(n?)

An offset corresponding to the last business day of the month.

Returns

MonthEnd

Example

TypeScript
import { MonthEnd } from 'pandas-ts';
new MonthEnd(1).apply(new Date('2024-01-15')).getDate();    // => 31

MonthBegin

#
new MonthBegin(n?)

An offset corresponding to the first calendar day of the month.

Returns

MonthBegin

Example

TypeScript
new MonthBegin(1).apply(new Date('2024-01-15')).getDate();    // => 1

YearEnd

#
new YearEnd(n?, month?)

An offset for the last day of the year.

Returns

YearEnd

Example

TypeScript
new YearEnd(1).apply(new Date('2024-06-01')).toISOString().slice(0,10);    // => '2024-12-31'

YearBegin

#
new YearBegin(n?)

An offset for the first day of the year.

Returns

YearBegin

Example

TypeScript
new YearBegin(1).apply(new Date('2024-06-01')).toISOString().slice(0,10);    // => '2025-01-01'

QuarterEnd

#
new QuarterEnd(n?, startingMonth?)

DateOffset increments between Quarter end dates.

Returns

QuarterEnd

Example

TypeScript
new QuarterEnd(1).apply(new Date('2024-01-15')).toISOString().slice(0,10);    // => '2024-03-31'

QuarterBegin

#
new QuarterBegin(n?, startingMonth?)

DateOffset increments between Quarter start dates.

Returns

QuarterBegin

Example

TypeScript
new QuarterBegin(1).apply(new Date('2024-02-15')).toISOString().slice(0,10);    // => '2024-04-01'

Week

#
new Week(n?, weekday?)

A week offset.

Returns

Week

Example

TypeScript
new Week(2).apply(new Date('2024-01-01')).getDate();    // => 15

Day

#
new Day(n?)

A calendar day offset.

Returns

Day

Example

TypeScript
new Day(7).apply(new Date('2024-01-01')).getDate();    // => 8

Hour

#
new Hour(n?)

An hour offset.

Returns

Hour

Example

TypeScript
new Hour(6).apply(new Date('2024-01-01T00:00:00')).getHours();    // => 6

Minute

#
new Minute(n?)

A minute offset.

Returns

Minute

Example

TypeScript
new Minute(30).apply(new Date('2024-01-01T10:00:00')).getMinutes();    // => 30

Second

#
new Second(n?)

A second offset.

Returns

Second

Example

TypeScript
new Second(45).apply(new Date('2024-01-01T10:00:00')).getSeconds();    // => 45

BusinessHour

#
new BusinessHour(n?, start?, end?)

DateOffset subclass representing possibly n business hours. Default business hours: 09:00–17:00.

Returns

BusinessHour

Example

TypeScript
import { BusinessHour } from 'pandas-ts';
// Advancing from end of business hours rolls to next morning
const bh = new BusinessHour(1);
bh.rollforward(new Date('2024-01-05T18:00:00')).getHours();    // => 9