nisshan/nepali-calendar

It converts date from english to nepali and vice-versa

1.0.0 2022-01-23 16:11 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is a laravel package that converts English date to Nepali and vice versa.

Installation

You can install the package via composer:

composer require nisshan/nepali-calendar

You can publish the config file with:

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

This is the contents of the published config file:

return [
    'date-format' => 'Y m, d is default format',
    
    'nepali-dates' => 'array of nepali dates'
];

Usage

toNepaliDate('2022-1-17'); => '2078 10, 03'

toNepaliDate('2022-1-17', 'Y, m d, D'); => '2078, 10 03, Monday'

to convert to Nepali Date from English and

toEnglishDate('2078-10-03'); => '2022 1, 17'

toEnglishDate('2078-10-03', 'Y, m d, D'); => '2022, 1 17, Monday'

to convert to English from Nepali date. The date Format parameter is optional which format the date if not passed will be used from configuration file. The above two implements shows how you can pass the english date to the function with or without a separator that changes helps in separating the date using Helper file or you can also convert the date as

use Nisshan\NepaliCalendar\DateConversion;

$nepaliDate = DateConversion::convert('2022-1-17')->toNepali();
$nepaliDateWithFormat = DateConversion::convert('2022-1-17','Y, m d, D')->toNepali();


$englishDate = DateConversion::convert('2078-10-03')->toNepali();
$englishWithFormat = DateConversion::convert('2078-10-03','Y, m d, D')->toNepali();

It will give same output as helper function.

Format that you can use

currently, I have used ['Y','M','D','d','m','y'] as date formatter you can use any combination of the following to output formatted date.

  'Y','y'  => 'Year',
  'M'      => 'Month Name',
  'm'      => 'month'
  'D'      => 'Name of Week Day',
  'd'      => 'date',

Thank you note

If you are here by any chance and using my package I would like to thank you and would love to accept PR on improvement of code or new features. Thank you.

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.