corporate-nepali-calendar
A JavaScript/TypeScript utility library for converting between Gregorian (AD) and Nepali (BS) dates, calculating date differences, and managing date ranges. This library provides functions to handle common date operations specifically tailored to the Nepali calendar (Bikram Sambat).
Install the library via npm:
npm install corporate-nepali-calendar
Usage with Laravel or any other non-npm projects
<script src="https://cdn.jsdelivr.net/npm/corporate-nepali-calendar/dist/corporate-nepali-calendar.min.js"></script>
Once the script is loaded, users can access your functions through the global variable CorporateNepaliCalendar.
<script>
// Example usage
const bsDate = CorporateNepaliCalendar.convertToBs("2024-11-07");
console.log("BS Date:", bsDate);
</script>
Returns the number of days in a specified Gregorian (AD) month.
-
Parameters:
-
year
- The AD year (e.g.,2024
). -
month
- The month number (1-12
).
-
-
Returns: The number of days in the specified month.
Returns the number of days in a specified Nepali (BS) month in calendar year.
-
Parameters:
-
year
- The BS year (e.g.,2081
). -
month
- The month number (1-12
).
-
-
Returns: The number of days in the specified BS month.
Calculates the number of days in a specific BS quarter in calendar year.
-
Parameters:
-
year
- The BS year. -
quarter
- The quarter number (1-4
).
-
-
Returns: The number of days in the specified BS quarter.
Returns the number of days in a specified BS half-year period in calendar year.
-
Parameters:
-
year
- The BS year. -
half
- The half of the year (1
for the first half,2
for the second half).
-
-
Returns: The number of days in the specified half-year period.
Returns the total number of days in a given BS year in calendar year.
-
Parameters:
-
year
- The BS year.
-
-
Returns: The total number of days in the specified BS year.
Returns the end date of a specified BS month in YYYY-MM-DD
format.
-
Parameters:
-
year
- The BS year. -
month
- The BS month (1-12
).
-
-
Returns: The end date of the specified BS month as a string in
YYYY-MM-DD
format.
Returns the end date of a specified BS quarter in YYYY-MM-DD
format.
-
Parameters:
-
year
- The BS year. -
quarter
- The BS quarter (1-4
).
-
-
Returns: The end date of the specified BS quarter as a string in
YYYY-MM-DD
format.
Returns the end date of a specified BS year in YYYY-MM-DD
format.
-
Parameters:
-
year
- The BS year.
-
-
Returns: The end date of the specified BS year as a string in
YYYY-MM-DD
format.
Converts a Gregorian (AD) date to a Nepali (BS) date.
-
Parameters:
-
date
- ADate
object or a string inYYYY-MM-DD
format.
-
-
Returns: The corresponding BS date as a string in
YYYY-MM-DD
format.
Converts a Nepali (BS) date to a Gregorian (AD) date.
-
Parameters:
-
bsDate
- A BS date string inYYYY-MM-DD
format.
-
-
Returns: A
Date
object representing the corresponding AD date.
getDifferenceDaysBsDates(startDate: string, endDate: string, includeStartEndDates: boolean = true): number
Calculates the difference in days between two BS dates.
-
Parameters:
-
startDate
- The starting BS date inYYYY-MM-DD
format. -
endDate
- The ending BS date inYYYY-MM-DD
format. -
includeStartEndDates
- Optional. Whether to include both start and end dates in the count (default istrue
).
-
-
Returns: The number of days between the two BS dates.
Calculates the Gregorian (AD) date range for a specified BS month.
-
Parameters:
-
year
- The BS year. -
month
- The BS month (1-12
).
-
-
Returns: An object with
startDate
andendDate
inYYYY-MM-DD
format representing the corresponding AD date range.
Returns today's date in the Nepali (BS) calendar.
-
Returns: The current BS date as a string in
YYYY-MM-DD
format.
getPeriodEndDatesBs({ startDate: string, endDate: string, periodType: string, yearType?: string}): array<string>
Returns array of dates of period ends based on input from start date or end date
-
Parameters:
-
startDate
- The BS date in format 'YYYY-MM-DD' -
endDate
- The BS date in format 'YYYY-MM-DD' -
periodType
- quarter or half-year -
yearType
- calendar or financial. This is optional, by default it is set to calendar in functonal scope, with ability to set it globally.
-
-
Returns: The array of string of BS date in
YYYY-MM-DD
format with the period end dates starting from startDate and ending with endDate.
getPeriodEndDatesAd({ startDate: string, endDate: string, periodType: string, yearType?: string}): array<string>
Returns array of dates of period ends based on input from start date or end date
-
Parameters:
-
startDate
- The BS date in format 'YYYY-MM-DD' -
endDate
- The BS date in format 'YYYY-MM-DD' -
periodType
- quarter or half-year -
yearType
- calendar or financial. This is optional, by default it is set to calendar in functonal scope, with ability to set it globally.
-
-
Returns: The array of string of AD date in
YYYY-MM-DD
format with the period end dates starting from startDate converted to AD and ending with endDate converted to AD.
If you find this project helpful, please consider giving it a ⭐️ on GitHub. Your support helps others discover this library and motivates us to keep improving it.
This project is licensed under the MIT License. See the LICENSE file for more information.
We welcome contributions! Please feel free to submit issues, suggest new features, or create pull requests to improve this library.