PHPackages                             nobelzsushank/nepali-date-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nobelzsushank/nepali-date-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nobelzsushank/nepali-date-converter
===================================

Laravel Nepali Date Converter (BS to AD and AD to BS) package with carbon like formatting and user-editable dataset.

v1.0.0(2mo ago)217MITPHPPHP ^8.1

Since Feb 26Pushed 2mo agoCompare

[ Source](https://github.com/NobelzSushank/nepali-date-converter)[ Packagist](https://packagist.org/packages/nobelzsushank/nepali-date-converter)[ Docs](https://github.com/NobelzSushank/nepali-date-converter)[ RSS](/packages/nobelzsushank-nepali-date-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

Laravel Nepali Date Converter (BS ↔ AD)
=======================================

[](#laravel-nepali-date-converter-bs--ad)

A Laravel Nepali date converter for Bikram Sambat (BS) ↔ Gregorian (AD), with Carbon-like formatting, Nepali/English month names, and a user-editable dataset.

This package is built so your application uses a **local dataset file in `storage/`** (not inside `vendor/`).
That means **your app can patch/update the calendar data manually** at any time — **without updating the package** — and your changes **won’t be overwritten** by `composer update`.

---

Highlights
----------

[](#highlights)

- ✅ Convert **BS → AD** and **AD → BS**
- ✅ **Flexible inputs** for both directions (ints, arrays, strings, `Carbon`, `DateTime`, `BsDate`)
- ✅ **Dataset is user‑editable** at `storage/app/bsad/bsad.json`
    - No vendor edits required
    - Composer updates won’t overwrite your dataset
- ✅ **Carbon‑like formatting**
    - `NepaliDateConverter::format('Y F d, l', 'np', true)`
- ✅ Output in **English or Nepali** (month names + weekday names)
- ✅ Optional **Nepali digits** output
- ✅ Clean API designed to be easy to extend (more tokens/locales later)

---

Requirements
------------

[](#requirements)

- PHP **8.1+**
- Laravel **9 / 10 / 11 / 12**
- `nesbot/carbon` **^2 | ^3**

---

Installation (Packagist)
------------------------

[](#installation-packagist)

```
composer require nobelzsushank/nepali-date-converter
```

Publish config + dataset:

```
php artisan vendor:publish --tag=bsad-config
php artisan vendor:publish --tag=bsad-data
```

This creates:

- `config/bsad.php`
- `storage/app/bsad/bsad.json` ✅ (**ACTIVE dataset file used at runtime**)

---

Configuration
-------------

[](#configuration)

`config/bsad.php` options:

- `data_path` – where the app reads the dataset
    Default: `storage/app/bsad/bsad.json`
- `update_url` – dataset URL used by `bs:update-data` (optional)
- `backup_on_update` – keep backups when updating (default: true)
- `locale` – default locale: `en` or `np`
- `nepali_digits` – output digits in Nepali (true/false)

Example `.env` (optional updater):

```
BSAD_UPDATE_URL=https://example.com/bsad.json
```

---

How dataset updates work (no vendor edits)
------------------------------------------

[](#how-dataset-updates-work-no-vendor-edits)

Your app reads BS month‑day data from:

```
storage/app/bsad/bsad.json

```

So if you need to fix/extend the calendar (e.g., the package author hasn’t updated data yet), you can:

- **edit `storage/app/bsad/bsad.json` manually**, or
- point `bsad.data_path` to another file you manage.

✅ These changes stay in your app — **Composer updates do not touch your `storage/` files**.

### Point to a custom dataset file (optional)

[](#point-to-a-custom-dataset-file-optional)

In `config/bsad.php`:

```
'data_path' => storage_path('app/bsad/custom-bsad.json'),
```

---

Quick Start
-----------

[](#quick-start)

### AD → BS (including today)

[](#ad--bs-including-today)

```
use NobelzSushank\Bsad\Facades\NepaliDateConverter;

$bsToday = NepaliDateConverter::adToBs(now('Asia/Kathmandu'));

echo (string) $bsToday;   // "2082-11-12" (example)
echo $bsToday->year;      // 2082
echo $bsToday->month;     // 11
echo $bsToday->day;       // 12
```

### BS → AD

[](#bs--ad)

```
use NobelzSushank\Bsad\Facades\NepaliDateConverter;

$ad = NepaliDateConverter::bsToAd(2082, 11, 14);     // CarbonImmutable
echo $ad->toDateString();             // 2026-02-26

echo NepaliDateConverter::bsToAdDateString(2082, 11, 14); // 2026-02-26
```

> ⚠️ Blade tip: BS date strings must be quoted
> `NepaliDateConverter::bsToAd(2082-11-14)` is math in PHP. Use `'2082-11-14'`.

---

Flexible Inputs (All Supported)
-------------------------------

[](#flexible-inputs-all-supported)

### BS → AD: `bsToAd(...)`

[](#bs--ad-bstoad)

All of these are supported:

#### 1) Integers (classic)

[](#1-integers-classic)

```
NepaliDateConverter::bsToAd(2082, 11, 14);
NepaliDateConverter::bsToAdDateString(2082, 11, 14);
```

#### 2) String “YYYY-MM-DD” (also accepts `/`, `.`, spaces)

[](#2-string-yyyy-mm-dd-also-accepts---spaces)

```
NepaliDateConverter::bsToAd('2082-11-14')->toDateString();
NepaliDateConverter::bsToAd('2082/11/14')->toDateString();
NepaliDateConverter::bsToAd('2082.11.14')->toDateString();
NepaliDateConverter::bsToAd('2082 11 14')->toDateString();
```

#### 3) List array

[](#3-list-array)

```
NepaliDateConverter::bsToAd([2082, 11, 14])->toDateString();
```

#### 4) Associative array

[](#4-associative-array)

```
NepaliDateConverter::bsToAd(['y' => 2082, 'm' => 11, 'd' => 14])->toDateString();
NepaliDateConverter::bsToAd(['year' => 2082, 'month' => 11, 'day' => 14])->toDateString();
```

#### 5) `BsDate` object

[](#5-bsdate-object)

```
use NobelzSushank\Bsad\ValueObjects\BsDate;

NepaliDateConverter::bsToAd(new BsDate(2082, 11, 14))->toDateString();
```

✅ `bsToAd()` returns a **CarbonImmutable** in timezone `Asia/Kathmandu` (from dataset meta).

---

### AD → BS: `adToBs(...)`

[](#ad--bs-adtobs)

All of these are supported:

#### 1) Any Carbon-parseable string

[](#1-any-carbon-parseable-string)

```
NepaliDateConverter::adToBs('2026-02-26');                  // -> BsDate
NepaliDateConverter::adToBs('2026-02-26 10:30:00');         // time ignored (startOfDay)
NepaliDateConverter::adToBs('next monday');                 // Carbon parsing rules apply
NepaliDateConverter::adToBsString('2026-02-26');            // -> "YYYY-MM-DD" (BS)
```

#### 2) Carbon / DateTimeInterface

[](#2-carbon--datetimeinterface)

```
NepaliDateConverter::adToBs(now('Asia/Kathmandu'));         // 2082-11-14
NepaliDateConverter::adToBs(now()->toImmutable());          // 2082-11-14
NepaliDateConverter::adToBs(new DateTime('2026-02-26'));    // 2082-11-14
```

#### 3) Integers or arrays

[](#3-integers-or-arrays)

```
NepaliDateConverter::adToBs(2026, 2, 26);
NepaliDateConverter::adToBs([2026, 2, 26]);
NepaliDateConverter::adToBs(['y' => 2026, 'm' => 2, 'd' => 26]);
NepaliDateConverter::adToBs(['year' => 2026, 'month' => 2, 'day' => 26]);
```

✅ `adToBs()` returns a **BsDate** value object (`year`, `month`, `day`).

---

Carbon-like Formatting (Nepali + English)
-----------------------------------------

[](#carbon-like-formatting-nepali--english)

### 1) Format BS date: `BsDate::format(...)`

[](#1-format-bs-date-bsdateformat)

`adToBs()` returns a `BsDate` which supports:

```
$bs = NepaliDateConverter::adToBs(now('Asia/Kathmandu'));

// Nepali month + weekday + Nepali digits
echo $bs->format('Y F d, l', 'np', true);

// English month + weekday
echo $bs->format('Y F d, l', 'en', false);

// Default format
echo $bs->format(); // "YYYY-MM-DD"
```

### 2) BS helpers: month/weekday names

[](#2-bs-helpers-monthweekday-names)

```
$bs = NepaliDateConverter::adToBs(now('Asia/Kathmandu'));

echo $bs->monthName('np');     // e.g. "फाल्गुण"
echo $bs->monthName('en');     // e.g. "Falgun"

echo $bs->weekdayName('np');   // e.g. "बिहीबार"
echo $bs->weekdayName('en');   // e.g. "Thursday"
```

### 3) Convert BS back to AD easily

[](#3-convert-bs-back-to-ad-easily)

```
$ad = $bs->toAd();
echo $ad->toDateString();
```

---

Carbon Macros (AD side)
-----------------------

[](#carbon-macros-ad-side)

Carbon’s built-in `format()` only accepts **one** argument, so the package adds macros:

```
$ad = now('Asia/Kathmandu');

$bs = $ad->toBs(); // -> BsDate

echo $ad->formatBs('Y F d, l', 'np', true);           // AD -> BS -> formatted
echo $ad->formatAdLocalized('Y F d, l', 'np', true);  // AD formatting w/ NP month+weekday + Nepali digits
```

---

Supported Format Tokens
-----------------------

[](#supported-format-tokens)

The formatter supports these tokens (BS side and AD-localized side):

TokenMeaning`Y`4-digit year`y`2-digit year`m`2-digit month (`01`–`12`)`n`month number (`1`–`12`)`d`2-digit day`j`day number`F`month name (locale-aware)`l`weekday name (locale-aware)> Escaping is supported: `\Y` prints literal `Y`.

---

Dataset Format (JSON)
---------------------

[](#dataset-format-json)

Your `storage/app/bsad/bsad.json` must contain:

```
{
  "meta": {
    "tz": "Asia/Kathmandu",
    "ad_anchor": "1943-04-14",
    "bs_anchor": { "y": 2000, "m": 1, "d": 1 }
  },
  "years": {
    "2000": [30,32,31,32,31,30,30,30,29,30,29,31]
  }
}
```

If you see:

> `BSAD dataset meta.bs_anchor invalid`

it means the JSON does not match the expected schema (missing `bs_anchor`, wrong keys, etc.).

---

Supported Range
---------------

[](#supported-range)

This package is **data-driven**, so supported years depend on your dataset.

If you try to convert a BS year not present in `years`, you’ll get:

> Unsupported BS year XXXX. Dataset supports YYYY–ZZZZ.

To extend support, update the dataset JSON.

---

License
-------

[](#license)

MIT — see `LICENSE`.

---

Changelog
---------

[](#changelog)

See `CHANGELOG.md`.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance86

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

72d ago

Major Versions

v0.2.2 → v1.0.02026-03-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/88c6b6c78edce9c80c3884d04b0f7aefabca08b98f9b165a1cfe8ccb1b7ff32b?d=identicon)[Nobelz](/maintainers/Nobelz)

---

Top Contributors

[![NobelzSushank](https://avatars.githubusercontent.com/u/24863886?v=4)](https://github.com/NobelzSushank "NobelzSushank (8 commits)")

---

Tags

laravelcarbonadnepalnepali-datelaravel-nepali-datenepali-date-converterdate-converterbikram-sambatBSbs-to-adad-to-bsnobelzsushankbsToAdasToBsbsad

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nobelzsushank-nepali-date-converter/health.svg)

```
[![Health](https://phpackages.com/badges/nobelzsushank-nepali-date-converter/health.svg)](https://phpackages.com/packages/nobelzsushank-nepali-date-converter)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[wnx/laravel-stats

Get insights about your Laravel Project

1.8k1.8M7](/packages/wnx-laravel-stats)[livewire/flux

The official UI component library for Livewire.

9385.0M86](/packages/livewire-flux)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
