Methods
date.isBefore()
Check whether the current date occurs chronologically before another specified date.
The isBefore method evaluates whether the current NepaliDate instance occurs earlier in time than another provided date. It takes into account both date and time components down to millisecond accuracy.
Import
import { NepaliDate } from "nepali-date-library";Signature
isBefore(date: NepaliDate): boolean;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
date | NepaliDate | Yes | Target NepaliDate instance to compare against. |
Return Value
- Type:
boolean - Returns
trueif the current date and time precedes the provideddatein absolute time; otherwise returnsfalse.
Precision
Comparison is evaluated down to the exact millisecond using the underlying Unix timestamp:
this.timestamp.getTime() < date.timestamp.getTime()Examples
Chronological Comparison
import { NepaliDate } from "nepali-date-library";
const date1 = new NepaliDate("2081-01-15");
const date2 = new NepaliDate("2081-01-20");
console.log(date1.isBefore(date2)); // true
console.log(date2.isBefore(date1)); // falseTime-Level Comparison
import { NepaliDate } from "nepali-date-library";
const morning = new NepaliDate("2081-01-15").startOfDay();
const evening = new NepaliDate("2081-01-15").endOfDay();
console.log(morning.isBefore(evening)); // trueRelated
date.isAfter(): Check if a date succeeds another.date.isEqual(): Check if calendar dates are identical.date.isSame(): Check equality by specific unit (year, month, day).
Advertisement
date.endOfYear()
Return a new NepaliDate instance set to the final day of the Bikram Sambat year on the last day of Chaitra.
date.isAfter()
Check whether the current date occurs chronologically after another specified date.