Nepali DateNepali DateBikram Sambat Date Engine
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

ParameterTypeRequiredDescription
dateNepaliDateYesTarget NepaliDate instance to compare against.

Return Value

  • Type: boolean
  • Returns true if the current date and time precedes the provided date in absolute time; otherwise returns false.

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)); // false

Time-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)); // true

Advertisement

On this page