npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bs-ad-date-converter

v3.0.0

Published

A JavaScript package to convert dates between Bikram Sambat (BS) and Gregorian (AD) calendars.

Readme

BS-AD Date Converter

A versatile JavaScript/TypeScript package to convert dates between Bikram Sambat (BS) and Gregorian (AD) calendars, along with utilities for age calculation, date difference, and getting current dates. Supports dates in YYYY-MM-DD format.

Features

  • Date Conversion: Convert AD to BS and BS to AD.
  • TypeScript Support: Fully written in TypeScript with type definitions included.
  • Date Utilities:
    • Calculate age in years, months, and days.
    • Find the difference between two dates.
    • Get the current date in both AD and BS formats.
  • Validation: Robust validation for dates within the supported range.

Installation

npm install bs-ad-date-converter

Usage

Import

import { 
  bsToAd, 
  adToBs, 
  ageCalculater, 
  dateDifference, 
  getTodayDate 
} from 'bs-ad-date-converter';

Date Conversion

Convert BS to AD

const adDate = bsToAd('2078-01-01');
console.log(adDate); // Output: "2021-04-14"

Convert AD to BS

const bsDate = adToBs('2021-04-14');
console.log(bsDate); // Output: "2078-01-01"

Utilities

Get Current Date

Returns the current date in both AD and BS formats.

const { todayAdDate, todayBSDate } = getTodayDate();
console.log(`Today: ${todayBSDate} (BS) / ${todayAdDate} (AD)`);

Calculate Age

Calculate age from a birth date. You can specify the input date type ('AD' or 'BS').

// From AD DOB
const ageAD = ageCalculater('2000-01-01', 'AD');
console.log(ageAD); 
// Output: { years: 25, months: 0, days: 8 } (results vary based on current date)

// From BS DOB
const ageBS = ageCalculater('2056-09-17', 'BS');
console.log(ageBS);

Date Difference

Calculate the number of days between two dates. Both dates must be of the same type ('AD' or 'BS').

// Difference between two AD dates
const diffAD = dateDifference('2022-01-01', '2022-01-10', 'AD');
console.log(diffAD); // Output: 9

// Difference between two BS dates
const diffBS = dateDifference('2078-01-01', '2078-01-10', 'BS');
console.log(diffBS); // Output: 9

API Reference

bsToAd(bsDateStr: string): string

Converts a BS date string (YYYY-MM-DD) to AD. Throws an error if invalid.

adToBs(adDateStr: string): string

Converts an AD date string (YYYY-MM-DD) to BS. Throws an error if invalid or out of range.

getTodayDate(): { todayAdDate: string, todayBSDate: string }

Returns the current system date converted to both AD and BS strings.

ageCalculater(date: string, dateType: 'AD' | 'BS'): { years: number, months: number, days: number }

Calculates the age based on the provided date of birth. defaults dateType to 'AD'.

dateDifference(date1: string, date2: string, dateType: 'AD' | 'BS'): number

Calculates the absolute difference in days between date1 and date2. defaults dateType to 'AD'.

Supported Date Range

| Calendar | Start Date | End Date | | -------- | ---------- | ---------- | | BS | 1970-01-01 | 2099-12-30 | | AD | 1913-04-13 | 2043-04-13 |

Error Handling

Errors are thrown for invalid formats or dates outside the supported range.

try {
  bsToAd('2100-01-01');
} catch (e) {
  console.error(e.message); // "Invalid BS date" or range error
}

License

MIT © Nischal Dhakal

Author