2017 © Pedro Peláez
 

library date

A date library to help you work with dates in different languages

image

haiquang9994/date

A date library to help you work with dates in different languages

  • Friday, May 4, 2018
  • by haiquang9994
  • Repository
  • 1 Watchers
  • 0 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 212 Forks
  • 0 Open issues
  • 62 Versions
  • 0 % Grown

The README.md

Date

Latest Stable Version Total Downloads Build Status Coverage Status Donate, (*1)

This date library extends Carbon with multi-language support. Methods such as format, diffForHumans, parse, createFromFormat and the new timespan, will now be translated based on your locale., (*2)

Installation

Install using composer:, (*3)

composer require jenssegers/date

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:, (*4)

'Jenssegers\Date\DateServiceProvider',

You can also add it as a Facade in config/app.php:, (*5)

'Date' => Jenssegers\Date\Date::class,

Languages

This package contains language files for the following languages:, (*6)

  • Albanian
  • Arabic
  • Azerbaijani
  • Bangla
  • Basque
  • Brazilian Portuguese
  • Bulgarian
  • Catalan
  • Croatian
  • Chinese Simplified
  • Chinese Traditional
  • Czech
  • Danish
  • Dutch
  • English
  • Esperanto
  • Estonian
  • Finnish
  • French
  • Galician
  • Georgian
  • German
  • Greek
  • Hebrew
  • Hindi
  • Hungarian
  • Icelandic
  • Indonesian
  • Italian
  • Japanese
  • Kazakh
  • Korean
  • Latvian
  • Lithuanian
  • Macedonian
  • Malay
  • Norwegian
  • Nepali (नेपाली)
  • Polish
  • Portuguese
  • Persian (Farsi)
  • Romanian
  • Russian
  • Thai
  • Serbian (latin)
  • Serbian (cyrillic)
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Turkish
  • Turkmen
  • Ukrainian
  • Uzbek
  • Vietnamese
  • Welsh

Usage

The Date class extends the Carbon methods such as format and diffForHumansn and translates them based on your locale:, (*7)

use Jenssegers\Date\Date;

Date::setLocale('nl');

echo Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16

echo Date::parse('-1 day')->diffForHumans(); // 1 dag geleden

The Date class also added some aliases and additional methods such as: ago which is an alias for diffForHumans, and the timespan method:, (*8)

echo $date->timespan(); // 3 months, 1 week, 1 day, 3 hours, 20 minutes

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:, (*9)

$date = Date::createFromFormat('l d F Y', 'zaterdag 21 maart 2015');

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:, (*10)

Creating dates

You can create Date objects just like the DateTime object (http://www.php.net/manual/en/datetime.construct.php):, (*11)

$date = new Date();
$date = new Date('2000-01-31');
$date = new Date('2000-01-31 12:00:00');

// With time zone
$date = new Date('2000-01-31', new DateTimeZone('Europe/Brussels'));

You can skip the creation of a DateTimeZone object:, (*12)

$date = new Date('2000-01-31', 'Europe/Brussels');

Create Date objects from a relative format (http://www.php.net/manual/en/datetime.formats.relative.php):, (*13)

$date = new Date('now');
$date = new Date('today');
$date = new Date('+1 hour');
$date = new Date('next monday');

This is also available using these static methods:, (*14)

$date = Date::parse('now');
$date = Date::now();

Creating a Date from a timestamp:, (*15)

$date = new Date(1367186296);

Or from an existing date or time:, (*16)

$date = Date::createFromDate(2000, 1, 31);
$date = Date::createFromTime(12, 0, 0);
$date = Date::create(2000, 1, 31, 12, 0, 0);

Formatting Dates

You can format a Date object like the DateTime object (http://www.php.net/manual/en/function.date.php):, (*17)

echo Date::now()->format('Y-m-d'); // 2000-01-31

The Date object can be cast to a string:, (*18)

echo Date::now(); // 2000-01-31 12:00:00

Get a human readable output (alias for diffForHumans):, (*19)

echo $date->ago(); // 5 days ago

Calculate a timespan:, (*20)

$date = new Date('+1000 days');
echo Date::now()->timespan($date);
// 2 years, 8 months, 3 weeks, 5 days

// or even
echo Date::now()->timespan('+1000 days');

Get years since date:, (*21)

$date = new Date('-10 years');
echo $date->age; // 10

$date = new Date('+10 years');
echo $date->age; // -10

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):, (*22)

$yesterday = Date::now()->sub('1 day');
$tomorrow  = Date::now()->add('1 day');

// ISO 8601
$date = Date::now()->add('P2Y4DT6H8M');

You can access and modify all date attributes as an object:, (*23)

$date->year = 2013:
$date->month = 1;
$date->day = 31;

$date->hour = 12;
$date->minute = 0;
$date->second = 0;

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:, (*24)

'hour'      => '1 hour|:count hours',
'minute'    => '1 minute|:count minutes',
'second'    => '1 second|:count seconds',

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:, (*25)

'year'          => '1 Jahr|:count Jahre',
'year_ago'      => '1 Jahr|:count Jahren',

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:, (*26)

php generator.php nl_NL

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, (*27)

License

Laravel Date is licensed under The MIT License (MIT)., (*28)

The Versions

04/05 2018

dev-master

9999999-dev https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nguyen Hai Quang

laravel date carbon translation time i18n datetime

04/05 2018

v3.3.2

3.3.2.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nguyen Hai Quang

laravel date carbon translation time i18n datetime

01/03 2018

v3.3.1

3.3.1.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

01/03 2018

v3.3.0

3.3.0.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

09/12 2017

v3.2.13

3.2.13.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nguyen Hai Quang

laravel date carbon translation time i18n datetime

08/12 2017

dev-patch-1

dev-patch-1 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

30/06 2017

v3.2.12

3.2.12.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

06/06 2017

v3.2.11

3.2.11.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

20/04 2017

v3.2.10

3.2.10.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

12/03 2017

v3.2.9

3.2.9.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

02/01 2017

v3.2.8

3.2.8.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

21/10 2016

v3.2.7

3.2.7.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

06/10 2016

v3.2.6

3.2.6.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

14/09 2016

v3.2.5

3.2.5.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

31/08 2016

v3.2.4

3.2.4.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

16/08 2016

v3.2.3

3.2.3.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

05/06 2016

v3.2.2

3.2.2.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

07/04 2016

v3.2.1

3.2.1.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

21/02 2016

v3.2.0

3.2.0.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

03/02 2016

v3.1.1

3.1.1.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

11/12 2015

2.0.x-dev

2.0.9999999.9999999-dev

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

11/12 2015

v3.1.0

3.1.0.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

01/12 2015

v3.0.13

3.0.13.0 https://github.com/jenssegers/date

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

26/10 2015

v3.0.12

3.0.12.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

18/10 2015

v3.0.11

3.0.11.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

24/09 2015

v3.0.10

3.0.10.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

16/09 2015

v3.0.9

3.0.9.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

10/08 2015

v3.0.8

3.0.8.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

25/07 2015

v3.0.7

3.0.7.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

04/07 2015

v2.0.22

2.0.22.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

13/06 2015

v3.0.6

3.0.6.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

04/06 2015

v3.0.5

3.0.5.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

23/05 2015

v3.0.4

3.0.4.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

17/05 2015

v3.0.3

3.0.3.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

09/05 2015

v3.0.2

3.0.2.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

30/04 2015

3.0.1

3.0.1.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

16/04 2015

v3.0.0

3.0.0.0

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

26/03 2015

v2.0.21

2.0.21.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

26/03 2015

v3.0.0-beta.2

3.0.0.0-beta2

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date carbon translation time i18n datetime

21/03 2015

v3.0.0-beta

3.0.0.0-beta

A date library to help you work with dates in different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date translation time i18n datetime

14/03 2015

v2.0.20

2.0.20.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

12/03 2015

v2.0.19

2.0.19.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

02/03 2015

v2.0.18

2.0.18.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

25/02 2015

v2.0.17

2.0.17.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

22/02 2015

v2.0.16

2.0.16.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

08/02 2015

v2.0.15

2.0.15.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

06/02 2015

v2.0.14

2.0.14.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

01/02 2015

v2.0.13

2.0.13.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

01/02 2015

v2.0.12

2.0.12.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

12/01 2015

v2.0.11

2.0.11.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

01/01 2015

v2.0.10

2.0.10.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

14/12 2014

v2.0.9

2.0.9.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

11/10 2014

v2.0.8

2.0.8.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

14/08 2014

v2.0.7

2.0.7.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

27/07 2014

v2.0.6

2.0.6.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel date time datetime

02/07 2014

v2.0.5

2.0.5.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

01/07 2014

v2.0.4

2.0.4.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

30/06 2014

v2.0.3

2.0.3.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

28/06 2014

v2.0.2

2.0.2.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

26/06 2014

v2.0.1

2.0.1.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

25/06 2014

v2.0.0

2.0.0.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

 

laravel date time datetime

10/05 2014

v1.0.0

1.0.0.0

A date library to help you work with dates

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

laravel date time datetime