Methods
date.parse()
Parse a formatted Bikram Sambat date string and update the current date instance in place.
The parse method parses a Bikram Sambat date string and updates the coordinates of the current NepaliDate instance in place. It supports various delimiter styles including slashes, dots, and hyphens, recalculating the underlying timestamp upon successful parsing.
Import
import { NepaliDate } from "nepali-date-library";Signature
parse(dateString: string): void;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
dateString | string | Yes | Date string formatted as YYYY-MM-DD, YYYY/MM/DD, or YYYY.MM.DD. |
Return Value
- Type:
void - Mutates the current
NepaliDateinstance in place.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Invalid date | Thrown if string segments are non-numeric. |
Nepal year out of range | Thrown if the parsed year is outside 1976 to 2100 BS. |
Invalid nepali month must be between 1 - 12 | Thrown if month is outside 1 to 12. |
Invalid nepali date must be between 1 - <max> in <year> <month> | Thrown if day exceeds the month's verified length. |
Example
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate();
// Mutate instance from string
date.parse("2081-07-15");
console.log(date.format("YYYY-MM-DD")); // "2081-07-15"
// Delimiters with slash or period are supported
date.parse("2082/01/01");
console.log(date.format("YYYY-MM-DD")); // "2082-01-01"Related
new NepaliDate(string): Construct a new instance directly from a string.date.set(): Set coordinates using numeric values.
Advertisement
date.setDate()
Set the day of the month on a NepaliDate instance and recalculate its timestamp.
date.addDays()
Add or subtract a specified number of days to a NepaliDate instance with automatic month and year rollover.