nobelzsushank/nepali-date-converter
Composer 安装命令:
composer require nobelzsushank/nepali-date-converter
包简介
Laravel Nepali Date Converter (BS to AD and AD to BS) package with carbon like formatting and user-editable dataset.
关键字:
README 文档
README
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
- ✅ 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
- PHP 8.1+
- Laravel 9 / 10 / 11 / 12
nesbot/carbon^2 | ^3
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.phpstorage/app/bsad/bsad.json✅ (ACTIVE dataset file used at runtime)
Configuration
config/bsad.php options:
data_path– where the app reads the dataset
Default:storage/app/bsad/bsad.jsonupdate_url– dataset URL used bybs:update-data(optional)backup_on_update– keep backups when updating (default: true)locale– default locale:enornpnepali_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)
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.jsonmanually, or - point
bsad.data_pathto 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)
In config/bsad.php:
'data_path' => storage_path('app/bsad/custom-bsad.json'),
Quick Start
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
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)
BS → AD: bsToAd(...)
All of these are supported:
1) Integers (classic)
NepaliDateConverter::bsToAd(2082, 11, 14); NepaliDateConverter::bsToAdDateString(2082, 11, 14);
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
NepaliDateConverter::bsToAd([2082, 11, 14])->toDateString();
4) Associative array
NepaliDateConverter::bsToAd(['y' => 2082, 'm' => 11, 'd' => 14])->toDateString(); NepaliDateConverter::bsToAd(['year' => 2082, 'month' => 11, 'day' => 14])->toDateString();
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(...)
All of these are supported:
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
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
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)
1) Format BS date: BsDate::format(...)
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
$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
$ad = $bs->toAd(); echo $ad->toDateString();
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
The formatter supports these tokens (BS side and AD-localized side):
| Token | Meaning |
|---|---|
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:
\Yprints literalY.
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
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
MIT — see LICENSE.
Changelog
See CHANGELOG.md.
nobelzsushank/nepali-date-converter 适用场景与选型建议
nobelzsushank/nepali-date-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 82 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「ad」 「carbon」 「date-converter」 「nepali date converter」 「nepal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nobelzsushank/nepali-date-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nobelzsushank/nepali-date-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nobelzsushank/nepali-date-converter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nepali (Bikram Sambat) calendar utilities and BS ↔ AD date conversion for PHP.
Datetime helpers for timezone handling
The easiest way to determine calendar availability using Carbon.
An package for handling date ranges.
Nepali (BS) ↔ English (AD) Date Converter for Laravel — by Jeeven Lamichhane.
Package to convert carbon date to nepali date
统计信息
- 总下载量: 82
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-02