generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from dineshuprety/helperfunction
Add Helper Function `toNepaliDate()` and `toEnglishDate()`.
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Anuzpandey\LaravelNepaliDate\LaravelNepaliDate; | ||
|
||
if (!function_exists('toNepaliDate')) { | ||
/** | ||
* The function converts a given date to the Nepali date format | ||
* | ||
* @param string date The date parameter is a string that represents the date in the Gregorian | ||
* calendar format. It should be in the format "YYYY-MM-DD" or "YYYY/MM/DD". | ||
* @param string|null format The format parameter is used to specify the desired format of the Nepali | ||
* date. It is an optional parameter and if not provided, the default format will be used. | ||
* @param string|null locale The "locale" parameter is used to specify the language and region | ||
* @return string Nepali date converted from the given date. | ||
*/ | ||
function toNepaliDate($date, $format = 'Y-m-d', $locale = 'en'): string | ||
{ | ||
return LaravelNepaliDate::from($date) | ||
->toNepaliDate($format, $locale); | ||
} | ||
} | ||
|
||
|
||
if (!function_exists('toEnglishDate')) { | ||
/** | ||
* The function converts a given date from Nepali (Bikram Sambat) to English format | ||
* | ||
* @param string date The date parameter is a string that represents the date in the Gregorian | ||
* calendar format. It should be in the format "YYYY-MM-DD" or "YYYY/MM/DD". | ||
* @param string|null format The format parameter is used to specify the desired format of the English | ||
* date. It is an optional parameter and if not provided, the default format will be used. | ||
* @param string|null locale The "locale" parameter is used to specify the language and region | ||
* @return string English date converted from the given Nepali Date. | ||
*/ | ||
function toEnglishDate($date, $format = 'Y-m-d', $locale = 'en'): string | ||
{ | ||
return LaravelNepaliDate::from($date) | ||
->toEnglishDate($format, $locale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters