Methods
date.clone()
Create an independent deep clone of an existing NepaliDate instance.
The clone method creates and returns an independent duplicate of the current NepaliDate instance. Because several library arithmetic and mutation methods alter instances in place, creating a clone allows you to perform calculations without modifying the original date object.
Import
import { NepaliDate } from "nepali-date-library";Signature
clone(): NepaliDate;Parameters
This method does not take any parameters.
Return Value
- Type:
NepaliDate - Returns a new independent
NepaliDateinstance initialized with the exact state of the current instance.
Examples
Creating an Independent Duplicate
import { NepaliDate } from "nepali-date-library";
const original = new NepaliDate("2081-01-15");
const duplicate = original.clone();
// Mutating duplicate does not impact original
duplicate.setDate(20);
console.log(original.format("YYYY-MM-DD")); // "2081-01-15"
console.log(duplicate.format("YYYY-MM-DD")); // "2081-01-20"Related
new NepaliDate(): Class constructor supporting copy-construction from another instance.date.format(): Format instance to string.
Advertisement
date.toString()
Return the default string representation of a NepaliDate instance in standard year, month, and day format.
NepaliDate.isValid()
Static validation function to verify whether a given year, month, and day combination forms a valid Bikram Sambat date.