定制 anuzpandey/laravel-nepali-date 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anuzpandey/laravel-nepali-date

Composer 安装命令:

composer require anuzpandey/laravel-nepali-date

包简介

A Laravel Package to convert English Date (A.D.) to Nepali Date (B.S.) and vice-versa.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

LaravelNepaliDate is a Laravel package that simplifies the conversion of dates between the Gregorian (English) and Nepali (Bikram Sambat) calendars. This package is a handy tool for projects that require handling dates in both English and Nepali formats, such as websites and applications targeting users in Nepal.

Installation

You can install the package via composer:

composer require anuzpandey/laravel-nepali-date

Optionally, you can publish the config file with:

php artisan vendor:publish --tag="nepali-date-config"

Usage

$engDate = '1996-04-22';
LaravelNepaliDate::from($engDate)->toNepaliDate();
// Result: 2053-01-10

LaravelNepaliDate::from($engDate)->toNepaliDate(format: 'D, j F Y');
// Result: सोम, १० वैशाख २०५३

// Format Specifiers are supported and listed below
LaravelNepaliDate::from($engDate)->toNepaliDate(format: 'D, j F Y', locale: 'en');
// Result: Mon, 10 Baisakh 2053


$nepDate = '2053-01-10';
LaravelNepaliDate::from($nepDate)->toEnglishDate();
// Result: 1996-04-22

LaravelNepaliDate::from($nepDate)->toEnglishDate(format: 'l, jS F Y');
// Result: Sunday, 22nd April 1996

// Format Specifiers are supported and listed below
LaravelNepaliDate::from($nepDate)->toEnglishDate(format: 'l, j F Y', locale: 'np');
// Result: आइतबार, २२ बैशाख १९९६

// Get total days in a month of a year
use Anuzpandey\LaravelNepaliDate\Enums\NepaliMonth;
// month can be NepaliMonth::XXX or month number (1-12)
LaravelNepaliDate::daysInMonth(NepaliMonth::BAISAKH, 2053);
// Result: 31

// Get total days in a year
LaravelNepaliDate::daysInYear(2053);
// Result: 365

Format Specifiers

The following format specifiers are supported for formatting dates:

  • Y - Year in four digits
  • y - Year in two digits
  • m - Month in two digits with leading zero (01-12/०१-१२)
  • n - Month in one or two digits without leading zero (1-12/१-१२)
  • M - Month in three letters (Jan-Dec)
  • F - Month in full name (January-December/बैशाख-चैत्र)
  • d - Day in two digits with leading zero (01-31/०१-३२)
  • j - Day in one or two digits without leading zero (1-31/१-३२)
  • D - Day in three letters (Sun-Sat/आइत-शनि)
  • l - Day in full name (Sunday-Saturday/आइतबार-शनिबार)
  • S - Day in two letters (st, nd, rd, th)

Extending Carbon with NepaliDateMixin

Note: This feature has been deprecated as Carbon doesn't support the months having more than 31 days. This feature has been removed from version 2.0.0.

Helper function

// Convert English date to Nepali date (B.S.).
toNepaliDate("1996-04-22")
// Result: 2053-01-10

// Convert Nepali date to English date (A.D.).
toEnglishDate("2053-01-10")
// Result: 1996-04-22

Blade Directives

You can use the Blade directives directly in your views:

{{-- Convert English date to Nepali date --}}
@nepaliDate('1996-04-22')
{{-- Result: 2053-01-10 --}}

{{-- With format --}}
@nepaliDate('1996-04-22', 'l, d F Y')
{{-- Result: सोमबार, १० वैशाख २०५३ --}}

{{-- With format and locale --}}
@nepaliDate('1996-04-22', 'l, d F Y', 'en')
{{-- Result: Monday, 10 Baisakh 2053 --}}

{{-- Convert Nepali date to English date --}}
@englishDate('2053-01-10')
{{-- Result: 1996-04-22 --}}

{{-- With format --}}
@englishDate('2053-01-10', 'l, d F Y')
{{-- Result: सोमबार, २२ अप्रिल १९९६ --}}

{{-- With format and locale --}}
@englishDate('2053-01-10', 'l, d F Y', 'en')
{{-- Result: Monday, 22 April 1996 --}}

Artisan Commands

Run quick conversions from the CLI:

php artisan nepali-date:convert --from=1996-04-22 --to=np
php artisan nepali-date:today
php artisan nepali-date:range --from=2080-01-01 --until=2080-01-05 --calendar=np --to=en

Common options:

  • --format= Output format (defaults to config('nepali-date.default_format'))
  • --locale= Output locale en or np
  • --strict Enable stricter date validation
  • --json Emit JSON output
  • --timezone= Timezone for today

Getting Date as Array

You can get the date components as an array for more flexibility:

$engDate = '1996-04-22';
$dateArray = LaravelNepaliDate::from($engDate)->toNepaliDateArray();
// Returns NepaliDateArrayData object with:
// - year: '2053'
// - month: '01'
// - day: '10'
// - npYear: '२०५३'
// - npMonth: '०१'
// - npDay: '१०'
// - dayName: 'Monday'
// - monthName: 'Baisakh'
// - npDayName: 'सोमबार'
// - npMonthName: 'वैशाख'

$nepDate = '2053-01-10';
$dateArray = LaravelNepaliDate::from($nepDate)->toEnglishDateArray();
// Returns similar structure with English date data

Supported Date Ranges

Calendar From To
English (A.D.) 1944-01-01 2033-12-31
Nepali (B.S.) 2000-09-17 2099-12-30

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

anuzpandey/laravel-nepali-date 适用场景与选型建议

anuzpandey/laravel-nepali-date 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.12k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2023 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「nepali-date」 「anuzpandey」 「laravel-nepali-date」 「nepali-date-converter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 anuzpandey/laravel-nepali-date 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anuzpandey/laravel-nepali-date 我们能提供哪些服务?
定制开发 / 二次开发

基于 anuzpandey/laravel-nepali-date 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 1
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-24