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

Advertisement

On this page