Manipulation Methods
Methods for date arithmetic, boundary queries, month length inspection, and leap year checks. All manipulation methods return new BanglaCalendar instances without mutating the original.
Method Overview
| Method | Description |
|---|---|
addDays() | Adds or subtracts days. |
addWeeks() | Adds or subtracts weeks (7-day intervals). |
addMonths() | Adds or subtracts months with optional day overflow clamping. |
addYears() | Adds or subtracts years with leap year handling. |
startOfMonth() | Returns instance set to 1st day of current month. |
endOfMonth() | Returns instance set to last day of current month. |
startOfYear() | Returns instance set to 1 Boishakh (১ বৈশাখ). |
endOfYear() | Returns instance set to 30 Choitro (৩০ চৈত্র). |
daysInMonth() | Returns number of days in specified month (or current month). |
isLeapYear() | Checks if current year is a leap year according to variant rules. |
Details & Examples
addDays()
addDays(days: number): BanglaCalendarAdds or subtracts specified number of days from current date.
const date = new BanglaCalendar('১৪৩০', '১', '১');
const in7Days = date.addDays(7); // 8 Boishakh 1430
const ago3Days = date.addDays(-3); // 28 Choitro 1429addWeeks()
addWeeks(weeks: number): BanglaCalendarAdds or subtracts specified number of weeks (each week = 7 days).
const date = new BanglaCalendar('১৪৩০', '১', '১');
const in2Weeks = date.addWeeks(2); // 15 Boishakh 1430addMonths()
addMonths(months: number, overflow?: boolean): BanglaCalendarAdds or subtracts months. Parameter overflow (default true):
true: Invalid dates overflow into the next month.false: Clamps to the last valid day of the target month.
const date = new BanglaCalendar('১৪৩০', '৬', '৩১'); // 31 Ashwin
const overflowed = date.addMonths(1); // 1 Ogrohayon 1430 (overflow)
const clamped = date.addMonths(1, false); // 30 Kartik 1430 (clamped)addYears()
addYears(years: number, overflow?: boolean): BanglaCalendarAdds or subtracts years. Handles leap year differences in Falgun when overflow = false.
const date = new BanglaCalendar('১৪৩০', '১', '১৫');
const nextYear = date.addYears(1); // 15 Boishakh 1431startOfMonth()
startOfMonth(): BanglaCalendarReturns a new instance set to day 1 of the current month.
const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
console.log(date.startOfMonth().toJSON()); // "১৪৩০-০৫-০১"endOfMonth()
endOfMonth(): BanglaCalendarReturns a new instance set to the last day of the current month (29, 30, or 31 depending on month & leap year).
const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
console.log(date.endOfMonth().toJSON()); // "১৪৩০-০৫-৩১"startOfYear()
startOfYear(): BanglaCalendarReturns a new instance set to 1 Boishakh (১ বৈশাখ) of the current year.
const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
console.log(date.startOfYear().toJSON()); // "১৪৩০-০১-০১"endOfYear()
endOfYear(): BanglaCalendarReturns a new instance set to 30 Choitro (৩০ চৈত্র) of the current year.
const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
console.log(date.endOfYear().toJSON()); // "১৪৩০-১২-৩০"daysInMonth()
daysInMonth(month?: NumberRange<1, 12>): NumberRange<29, 31>Gets the number of days in the specified month (1-12) or the current month if omitted.
const date = new BanglaCalendar('১৪৩০', '১', '১');
console.log(date.daysInMonth()); // 31 (Boishakh)
console.log(date.daysInMonth(11)); // 29 (Falgun in normal year)isLeapYear()
isLeapYear(): booleanReturns true if the year is a leap year under the active variant rules.
'revised-2019': Follows Gregorian leap year rules.'revised-1966': FollowsbnYear % 4 === 2rule.
const date = new BanglaCalendar(1430, 1, 1);
console.log(date.isLeapYear()); // false