momentnp
v1.0.3
Published
momentnp is a npm library that facilitates easy handling and formatting of dates, with special support for the Nepali calendar system. It provides methods for calculating time differences, formatting dates, converting dates to the Bikram Sambat (BS) calen
Downloads
3
Maintainers
Readme
momentnp
momentnp
is a node module that provides various utilities for handling dates, including formatting dates, calculating the time difference from the current time, and converting dates to Nepali formats.
Table of Contents
Installation
Simply paste the following code into the terminal to install momentnp
:
npm install momentnp
or
yarn add momentnp
Usage
To use momentnp
, create an instance of the function with a date string or a Date object. If no valid date is provided, it will use the current date.
const myDate = momentnp("2023-06-01");
fromNow
The fromNow
method calculates the difference from the provided date to the current date and returns the difference in Nepali format.
myDate.fromNow(); // Returns the difference in Nepali, e.g., 'केहि क्षण पहिले'
format
The format
method formats the date into different specified formats. Available formats are:
dmy-
: YYYY-MM-DDdmyt-
: YYYY-MM-DD HH:MM:SSdmy/
: YYYY/MM/DDdmyt/
: YYYY/MM/DD HH:MM:SSDDMMYY
: Dth Month, YYYYDDDDMMYY
: Day, Dth Month YYYYddDDMMYY
: Day, Dth Mon YYYYDDDDMMYYnp
: Nepali format with full day and month namesDDMMYYnp
: Nepali format with month nameYYMMDDDDnp
: Nepali format with year, month, and day namesdmytnp-
: Nepali format with dash separatordmynp-
: Nepali format with dash separator, date onlydmynp/
: Nepali format with slash separator, date onlydmytnp/
: Nepali format with slash separatorfullnp
: Full Nepali date with time
myDate.format("dmy-"); // Returns '2023-06-01'
myDate.format("fullnp"); // Returns full Nepali date with time
inBS
The inBS
method converts the date to the Bikram Sambat (BS) calendar and returns it in the specified format. Available formats are:
YYMMDD
: BS date in YYYY-MM-DDddmmyy
: BS date in Nepali format with month nameddmmyyfull
: BS date in full Nepali formatmmddyy
: BS date with month nameyymmdd
: BS date in YYYY/MM/DD
myDate.inBS("YYMMDD"); // Returns BS date in YYYY-MM-DD format
myDate.inBS("ddmmyyfull"); // Returns full Nepali formatted BS date
isPast
The isPast
method checks if the provided date is in the past.
myDate.isPast(); // Returns true if the date is in the past, otherwise false
Examples
const dateExample = momentnp("2023-05-21");
console.log(dateExample.fromNow()); // Outputs time difference in Nepali
console.log(dateExample.format("dmy-")); // Outputs '2023-05-21'
console.log(dateExample.format("fullnp")); // Outputs full Nepali formatted date and time
console.log(dateExample.inBS("YYMMDD")); // Outputs BS date in YYYY-MM-DD format
console.log(dateExample.isPast()); // Outputs true or false based on whether the date is in the past
By utilizing momentnp
, you can easily handle date manipulations and formatting in both English and Nepali contexts.