Download the PHP package andhikamaheva/date without Composer
On this page you can find all versions of the php package andhikamaheva/date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andhikamaheva/date
More information about andhikamaheva/date
Files in andhikamaheva/date
Package date
Short Description A date library to help you work with dates in different languages
License MIT
Homepage https://github.com/andhikamaheva/date
Informations about the package date
Date
This date library extends Carbon with multi-language supports. Methods such as format
, diffForHumans
, parse
, createFromFormat
and the new timespan
, will now be translated based on your locale.
Installation
Install using composer:
Laravel
There is a service provider included for integration with the Laravel framework. This provider will get the application locale setting and use this for translations. To register the service provider, add the following to the providers array in config/app.php
:
You can also add it as a Facade in aliases array config/app.php
:
Languages
This package contains language files for the following languages:
- Albanian
- Arabic
- Azerbaijani
- Basque
- Brazilian Portuguese
- Bulgarian
- Catalan
- Croatian
- Chinese Simplified
- Chinese Traditional
- Czech
- Danish
- Dutch
- English
- Esperanto
- Estonian
- Finnish
- French
- Georgian
- German
- Greek
- Hebrew
- Hindi
- Hungarian
- Icelandic
- Indonesian
- Italian
- Japanese
- Korean
- Latvian
- Lithuanian
- Macedonian
- Malay
- Norwegian
- Polish
- Portuguese
- Persian (Farsi)
- Romanian
- Russian
- Thai
- Serbian
- Slovak
- Slovenian
- Spanish
- Swedish
- Turkish
- Turkmen
- Ukrainian
- Vietnamese
- Welsh
Usage
The Date class extends the Carbon methods such as format
and diffForHumans
n and translates them based on your locale:
The Date class also added some aliases and additional methods such as: ago
which is an alias for diffForHumans
, and the timespan
method:
Methods such as parse
and createFromFormat
also support "reverse translations". When calling these methods with translated input, it will try to translate it to English before passing it to DateTime:
Carbon
Carbon is the library the Date class is based on. All of the original Carbon operations are still available, check out https://github.com/briannesbitt/Carbon for more information. Here are some of the available methods:
Creating dates
You can create Date objects just like the DateTime object (http://www.php.net/manual/en/datetime.construct.php):
You can skip the creation of a DateTimeZone object:
Create Date objects from a relative format (http://www.php.net/manual/en/datetime.formats.relative.php):
This is also available using these static methods:
Creating a Date from a timestamp:
Or from an existing date or time:
Formatting Dates
You can format a Date object like the DateTime object (http://www.php.net/manual/en/function.date.php):
The Date object can be cast to a string:
Get a human readable output (alias for diffForHumans):
Calculate a timespan:
Get years since date:
Manipulating Dates
You can manipulate by using the add and sub methods, with relative intervals (http://www.php.net/manual/en/datetime.formats.relative.php):
You can access and modify all date attributes as an object:
Contributing
You can easily add new languages by adding a new language file to the lang directory. These language entries support pluralization. By using a "pipe" character, you may separate the singular and plural forms of a string:
Some languages have a different unit translation when they are used in combination with a suffix like 'ago'. For those situations you can add additional translations by adding the suffix to the unit as a key:
There is also a generator.php
script that can be used to quickly output day and month translations for a specific locale. If you want to add a new language, this can speed up the process:
NOTE! If you are adding languages, please check the rules about the capitalization of month and day names: http://meta.wikimedia.org/wiki/Capitalization_of_Wiktionary_pages#Capitalization_of_month_names
License
Laravel Date is licensed under The MIT License (MIT).