Methods
date.startOfWeek()
Return a new NepaliDate instance set to the first day of the week on Sunday.
The startOfWeek method returns a new NepaliDate instance set to Sunday, the first day of the weekly cycle containing the current date. It serves as an anchor date for week based scheduling and calendar grids.
Import
import { NepaliDate } from "nepali-date-library";Signature
startOfWeek(startOfWeek?: number): NepaliDate;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
startOfWeek | number | No | 0 | Day of week index (0-6), where 0 is Sunday and 1 is Monday. |
Return Value
- Type:
NepaliDate - Returns a new
NepaliDateinstance set to the start of the week at midnight. The original instance is not modified.
Exceptions
Throws an Error if startOfWeek is not an integer between 0 and 6:
"startOfWeek must be an integer between 0 and 6"Examples
Default Week Start (Sunday)
import { NepaliDate } from "nepali-date-library";
// Suppose date falls on a Wednesday (day 3)
const date = new NepaliDate("2081-02-16");
const weekStart = date.startOfWeek();
console.log(weekStart.getDay()); // 0 (Sunday)
console.log(weekStart.getHours()); // 0
console.log(weekStart.format("YYYY-MM-DD"));Custom Week Start (Monday)
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-02-16");
// Week starts on Monday (1)
const mondayStart = date.startOfWeek(1);
console.log(mondayStart.getDay()); // 1 (Monday)Related
date.endOfWeek(): Return the end of the week.date.startOfDay(): Return the start of the day.date.getDay(): Get current day of week index (0-6).
Advertisement
date.endOfDay()
Return a new NepaliDate instance set to the final millisecond of the current day.
date.endOfWeek()
Return a new NepaliDate instance set to the final day of the current week on Saturday.