Download the PHP package remls/hijri-date without Composer
On this page you can find all versions of the php package remls/hijri-date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download remls/hijri-date
More information about remls/hijri-date
Files in remls/hijri-date
Package hijri-date
Short Description Laravel helper package for Hijri dates.
License MIT
Informations about the package hijri-date
HijriDate
Laravel helper package for Hijri dates. Supports displaying dates in Arabic, Bengali, Dhivehi and English out of the box, with support for further customizations or adding a language of your choice.
- Installation
- Creating dates
- Customizing how dates are converted between Hijri and Gregorian
- Available methods
- Conversions
- Calculations
- Comparisons
- Formatting
- Casting
- Validation
- Localization
- Adding a language
- Migrating from v1 to v2
Installation
To publish configuration files:
Creating dates
All of the following methods return an instance of Remls\HijriDate\HijriDate
.
Customizing how dates are converted between Hijri and Gregorian
By default, the package uses an external map between Hijri and Gregorian dates in Maldives to convert between the two. This map is cached and reused for subsequent conversions.
You may customize for how long the map is cached by changing config/hijri.php
> conversion.cache_period
.
You may manually re-fetch data from the external source by running php artisan hijri:fetch
.
The package also comes with an alternative class for converting dates using calculations instead of a map. You may enable it by changing config/hijri.php
> conversion.converter
to \Remls\HijriDate\Converters\MaldivesEstimateG2HConverter::class
.
You may customize how dates are converted by:
- providing your own map in
config/hijri.php
>conversion.data_url
- providing your own custom converter class in
config/hijri.php
>conversion.converter
- The class must implement
\Remls\HijriDate\Converters\Contracts\GregorianToHijriConverter
.
- The class must implement
Available methods
Conversions
You may customise how the conversion works, as detailed here.
Calculations
Comparisons
You may compare two HijriDate objects $a
and $b
using the following methods:
Method | Description |
---|---|
$a->compareWith($b) |
Returns -1 if $a < $b. Returns 0 if $a == $b. Returns 1 if $a > $b. |
$a->equalTo($b) |
Returns true if $a == $b. |
$a->greaterThan($b) |
Returns true if $a > $b (a is after b). |
$a->lessThan($b) |
Returns true if $a < $b (a is before b). |
$a->greaterThanOrEqualTo($b) |
Returns true if $a >= $b (a is after or equal to b). |
$a->lessThanOrEqualTo($b) |
Returns true if $a <= $b (a is before or equal to b). |
Formatting
Each HijriDate object will have a set locale when it is created. This locale will be used for formatting.
The locale is 'dv'
by default, but you may customize it by:
- passing locale in constructor (eg:
new HijriDate(1443, 9, 1, 'en')
) - changing locale after creation (eg:
$date->setLocale('en')
) - changing
default_locale
in configuration, so all HijriDate objects are created using that default locale
The following options are supported with $date->format()
:
Option | Description | Example |
---|---|---|
d | Day of month (with leading zero) | 01 ... 30 |
D | Weekday (short) | Sun ... Sat |
j | Day of month (without leading zero) | 1 ... 30 |
l (lowercase L) |
Weekday | Sunday ... Saturday |
F | Month | Muharram ... Dhul-Hijja |
m | Month (number, with leading zero) | 01 ... 12 |
M | Month (short) | Mhr ... DhH |
n | Month (number, without leading zero) | 1 ... 12 |
Y | Year | 1000 ... 1999 |
y | Year (final two digits) | 00 ... 99 |
Casting
The field to be cast must be a string field on database.
This will automatically store data as Y-m-d
string in database, and cast to Remls\HijriDate\HijriDate
when accessing.
Validation
Any string that passes the following conditions is considered a valid Hijri date:
- in the format
Y-m-d
- year between 1000 and 1999 (This can be changed in config.)
- month between 1 and 12
- day between 1 and 30
Note that validation error messages will use app's locale (unlike formatting).
Localization
Publish translation files by using:
You may then customize strings as needed.
Adding a language
To add support for another language:
- Publish the configuration file. The file will be copied to
config/hijri.php
. - Publish the translation files. The files will be copied to
lang/vendor/hijri
. - Copy one of the existing translation folders, and rename it with the language code of your choice. Eg:
lang/vendor/hijri/es
- Change strings to their respective translations.
- Add the language code to
supported_locales
inconfig/hijri.php
. - (Optional) Change
default_locale
inconfig/hijri.php
to the new language code.
Migrating from v1 to v2
The package no longer uses estimates when converting from Hijri to Gregorian by default.
- New keys have been added to
config/hijri.php
. You may need to update your configuration file. - The function
getEstimateFromGregorian
has been REMOVED in favour ofcreateFromGregorian
.- To maintain the same behaviour as before:
- Change
config/hijri.php
>conversion.converter
to\Remls\HijriDate\Converters\MaldivesEstimateG2HConverter::class
. - Change all calls from
getEstimateFromGregorian
tocreateFromGregorian
.
- Change
- To maintain the same behaviour as before:
- The function
isEstimate
has been REMOVED. There is no more need to check if the date was made from an estimate, as you can now always just get the corresponding Gregorian date with a call togetGregorianDate
, regardless of how it was created. - The function
getEstimatedFrom
has been REMOVED in favour ofgetGregorianDate
. - The function
resetEstimation
has been REMOVED in favour ofresetGregorianDate
. - The functions
addDays
andsubDays
will now use the underlying Gregorian date by default for calculations.- To maintain the same behaviour as before, pass
false
to$useGregorian
parameter of these functions.
- To maintain the same behaviour as before, pass