Giter Site home page Giter Site logo

jenssegers / date Goto Github PK

View Code? Open in Web Editor NEW
1.8K 48.0 244.0 530 KB

🗓 A library to help you work with dates in multiple languages, based on Carbon.

Home Page: https://jenssegers.com

License: MIT License

PHP 100.00%
i18n carbon dates internationalization internationalisation

date's People

Contributors

abhimanyu003 avatar aiiro avatar akalongman avatar albert221 avatar asd-lt avatar atofighi avatar balping avatar grahamcampbell avatar janbolat avatar jenssegers avatar kerryusry avatar kylekatarnls avatar limenet avatar martijnthomas avatar matthewnessworthy avatar meigwilym avatar mmestrovic avatar oscarotero avatar propaganistas avatar romanbican avatar scif avatar sendoa avatar sineld avatar siomkin avatar thangngoc89 avatar thujohn avatar topzar avatar unrulynatives avatar vinkla avatar vokomarov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

date's Issues

Drop PHP 5.3 support

Since you have integrated this with Laravel PHP 5.3 can't be supported. Laravel >=4.0 requires at least PHP ~5.4.7. Either we create separate packages for core and Laravel or remove PHP 5.3 support in this package.

This will help us create tests for the Laravel integration as well. We currently can't do that since the tests will fail due to the missing illuminate/support package.

What do you think about this @jenssegers?

Doesn't show translations for timestamps retrieved from database

How exactly is laravel-date supposed to work here? I don't seem to get the correct translations in from the database retrieved timestamps.

<?php
        use Jenssegers\Date\Date;
    // This returns 'vor 0 Sekunden' in German, which I do want.
    echo Date::now()->diffForHumans();
    echo '<br/>';
    // This returns '1 day ago'. It is in English, but I need it in German.
    echo $orders->find(1)->created_at->diffForHumans();
?>

I opened the case also here: http://stackoverflow.com/questions/29659683/laravel-5-jenssegers-laravel-date-doesnt-show-correct-translation-how-do-i-us

because I didn't found a tag for this package in stackoverflow, I also openend this issue here, so that I get your attention on this topic.

Thank you in advance.

Laravel 5 support breaking Laravel 4 support

Just reporting feedback for commit #3696417

While you updated the support to Laravel 5 and tried to not break the Laravel 4 support, you unfortunately did it, explaining what you did :

if (starts_with($this->app->version(), '5'))
{
    $this->loadTranslationsFrom($this->app->basePath() . '/vendor/jenssegers/date/src/lang', 'date');
}
// Laravel 4 package registration
else
{
    $this->package('jenssegers/date');
}

But in Laravel 4 $this->app->version() method doesn't exist at all and will throw a beautiful Call to undefined method Illuminate\Foundation\Application::version(), so how we fix it, just checking if the method exists before calling it for version check :

if (method_exists($this->app, 'version') && starts_with($this->app->version(), '5'))
{
    $this->loadTranslationsFrom($this->app->basePath() . '/vendor/jenssegers/date/src/lang', 'date');
}

Please review this PR #78, tested on L5 and L4 as working, also with Travis CI.

Multi-byte substr

Hi, great package, thx for a work.
I found an issue in format() method with 'M' format character (for short month name) for russian locale. You should consider, that russian characters are 2-bytes per symbol, so expression $translated = substr($translated, 0, 3); is incorrect. So preferred to use $translated = mb_substr($translated, 0, 3);

Maybe, it's also preferred to change any string methods to mb_ equivalent for correctly work with multibyte strings. Referenced to http://php.net/manual/en/ref.mbstring.php

Regards

Dutch pluralization incorrect

I just noticed that there is an error in the Dutch pluralization forms of year and hour.

It might sound wierd but in the Dutch language we don't use the plural form in time indications. So '2 years ago' should not be translated to '2 jaren geleden' but to '2 jaar geleden' (in English '2 year ago').

The same accounts for '2 hours ago', this should be translated to '2 uur geleden' (2 hour ago) and not '2 uren geleden'.

I tried to find an English source but could not find one. Here you have an advice (in Dutch) from 'het Genootschap Onze Taal' an organization specialized in the Dutch language: https://onzetaal.nl/taaladvies/advies/twintig-jaar-jaren

Standardization of months/days' name.

Hi,

I don't know if you consider it an issue, but I think that all the names of the months and days of the week should follow the same convention. Either start with a lower case or an upper case letter.

Latest Update 2.0.12 gave lang error

Just wanted to inform you, that your latest update caused an error for the language output in laravel 4.

If anyone else is having the same problem, work with 2.0.11 so far.

please! support Vietnamses lang

'ago'       => ':time trước',
'from_now'  => ':time từ bây giờ',
'after'     => ':time sau',
'before'    => ':time trước',
'year'      => '1 năm|:count năm',
'month'     => '1 tháng|:count tháng',
'week'      => '1 tuần|:count tuần',
'day'       => '1 ngày|:count ngày',
'hour'      => '1 giờ|:count giờ',
'minute'    => '1 phút|:count phút',
'second'    => '1 giây|:count giây',

'january'   => 'Tháng một',
'february'  => 'Tháng hai',
'march'     => 'Tháng ba',
'april'     => 'Tháng tư',
'may'       => 'Tháng năm',
'june'      => 'Tháng sáu',
'july'      => 'Tháng bảy',
'august'    => 'Tháng tám',
'september' => 'Tháng chín',
'october'   => 'Tháng mười',
'november'  => 'Tháng mười một',
'december'  => 'Tháng mười hai',

'monday'    => 'Thứ hai',
'tuesday'   => 'Thứ ba',
'wednesday' => 'Thứ tư',
'thursday'  => 'Thứ năm',
'friday'    => 'Thứ sáu',
'saturday'  => 'Thứ bảy',
'sunday'    => 'Chủ nhật',

composer require rule issue

hi

after adding "require" entry I got:
Problem 1
- The requested package jenssegers/date could not be found in any version, there may be a typo in the package name.

Laravel 5

Hi!
I would love an implementation ready for Laravel 5.

Cause it seems like it doesnt work for Laravel 5 as it is right now at least?

ErrorException after updating

  • Removing jenssegers/date (dev-master 0077c51)
  • Installing jenssegers/date (dev-master cab9999)
    Downloading: 100%

Writing lock file
Generating autoload files

[ErrorException]

Declaration of Jenssegers\Date\Date::setTranslator() should be compatible with Carbon\Carbon::setTranslator(Symfony\Component\Translation\TranslatorInterface $translator)

Script php artisan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException]
Error Output:

Date::parse() bug

Date::parse() accepts timestamps, Carbon doen't.
This is cool but the timezone is wrong, always is "+00:00", you can simply use Date::createFromTimestamp() and all works as expected but this made me crazy for a while...

Thankyou!!

Can't run composer update : Jenssegers\Date\Date::diffForHumans() should be compatible with Carbon\Carbon::diffForHumans(...)

When I run composer update on my project, I have this issue :

exception 'ErrorException' with message 'Declaration of Jenssegers\Date\Date::diffForHumans() should be compatible with Carbon\Carbon::diffForHumans(Carbon\Carbon $other = NULL, $absolute = false)'

I tried on master and last tag. I think it's because any version of carbon is required "nesbot/Carbon": "*", in Jenssegers/Date's composer.json, and Carbon was released 4 hours ago.

Encoding problem

When using the format function for french locale, some strings containing special chars are not displayed correctly (Ex: Août). My encoding seems correct. I can print some strings correctly in other section on my website. This only happens when using the 'format' method. I use UTF-8.

diffForHumans returning ":date.ago" and ":date.from_now"

Using Laravel 4.2 I'm getting the output ":date.ago" and ":date.from_now" from diffForHumans(). Locale doesn't seem to matter, and neither does the preceding method-calls. E.g.:

Date::createFromFormat('Y-m-d', '2015-12-01')->diffForHumans(); // :date.from_now
Date::tomorrow()->diffForHumans(); // :date.from_now
Date::yesterday()->diffForHumans() // :date.ago

Tried with both dev-master and 2.0.12, but no cigar.

Am I just being an idiot and missing something very obvious?

The class dont load the locale config from laravel

I was testing it and by default the class doesn't load the locale config from laravel. I can't see the code that load this config from laravel.

I fix it by putting this code on translator.php
public function __construct()
{

    if (class_exists('Illuminate\Support\Facades\Config'))
        $this->locale =\Illuminate\Support\Facades\Config::get('app.locale');

}

Idea: Change on fly display of language

In english is:
Written 1 hour ago
in PL is:
Napisano 1 godzinę temu
but singular form of hour is godzina but when you want to display properly you need to change lang on the fly. You can add this :)

How to perform declension of a date in Russian?

I am using the ->format() method to output the date in Russian language. But what I need is to perform declension at first. Because without it the date looks like this: "9 Март 2015", which is wrong according to Russian grammar. It is supposed to be "9 Марта 2015".

German translation correction

Hey, i really like your package, but as a german i have some minor issues with the diffForHuman translation:

'from_now' => ':time von jetzt', should be from_now' => 'in :time',
Example: 3 Tag_e_ von jetzt should be: in 3 Tage_n_ ( notice the pluralization )
As far as i can think of, the pluralization of from_now is the same as in *_ago

I don't really know how to produce the after and before triggers, but i suspect them to be incorrect as well. (but this should be verified)
'after' => ':time nach' -> 'after' => 'nach :time' (pluralization same as *_ago)
'before' => ':time vor' -> 'before' => 'vor :time' (pluralization same as *_ago)

Thanks!

Solution

composer.json:

"jenssegers/date": "2.0.21"

Feedback: rename GitHub repo

I feel like I should rename the repository to php-date instead of laravel-date as it is not limited to be used with Laravel only. What do you guys think?

ErrorException in MessageSelector.php line 85:

Hello there. Still have this error

Unable to choose a translation for "o secunda|:count secunde" with locale "ro" for value "31". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %count% apples").

How do i ouput time ago?

Sorry im a beginner.

I dont know how to output ago with this package

In carbon i use

$post->created_at->diffForHumans()

But what every i try here it just throws me an error

Hide empty date types in timespan

Is there a way to hide parts of a timespan that don't add a lot of value?

For example I have a timespan:
0 years, 0 months, 0 weeks, 0 days, 0 hours, 5 minutes, 19 seconds

I'd prefer to show it as:
5 minutes, 19 seconds

Is this possible @jenssegers? Great package by the way!

Default use in Laravel Eloquent model

Is it possible to use this library instead of Carbon as default for timestamp fields in Laravel Eloquent models?

So one could use $post->active_at->ago() instead of Date::parse($post->active_at)->ago() in a template

Thanks!

issue of zh-TW diffForHumans

in my situation is after i set Locale to zh-TW, it still show english version like 18 hours ago.
Date::setLocale('zh-TW');
$obj->created_at->diffForHumans();

but if i change $obj->created_at->diffForHumans() to Date::parse('-1 day')->diffForHumans();
it will work fine and shows '一天前'

is that a bug?? or i miss something?

Where should I put new languages files in Laravel ?

Hi !

I'm trying to add a new language file to display 'min' instead of 'minute', etc...

I've created app/lang/altitude/date.php and tried to use Date::setLocale('altitude') or App::setLocale('altitude') but it does not seem to work.

Any idea ?

Error after updating project

I run php composer.phar update and I've got:

Declaration of Jenssegers\Date\Date::setTranslator() should be compatible with Carbon\Carbon::setTranslator

L5, update from 5.0.18 -> 5.0.21

Is it possible to extend laravel-date?

Hi,

I tried extending laravel-date today but failed. (got plently of errors due to laravel-date not being correctly initialized)

Is it possible to extend laravel-date package?

Would it be possible to parse a localized date?

This will create an error, but it would be nice if it would just work.

Date::setLocale('nl');
$d = Date::parse('-1 day')->format('l j F Y H:i:s'); // $d = 'zondag 22 februari 2015 09:37:23'
Date::createFromFormat('l j F Y H:i:s', $d)->toDateTimeString()

The error is, of course:

InvalidArgumentException in Carbon.php line 385:
A textual day could not be found
A textual month could not be found

Would it be possible to get this to work?

[Discussion] day and month translations

In the current version, the library uses strftime to convert days and months based on the locale that is set with setlocale. It checks the format string for certain translatable characters and replaces the original date result with a translation from strftime. But this requires you set your locale.

Laravel's App::setLocale('es'); does not change the locale using setlocale, and there might be a good reason why it does not do this.

One possible solution would be to get the Laravel locale, convert it to a setlocale valid argument and set it in the service provider. A different solution would be to completely dump the strftime, and add manual translations for days an months in the language files.

Can I get some opinions on this? Maybe @tamplan or @briannesbitt?

v2.0.12 not compatible with L4

Hi,

First of all, thank you for your great library :)

It's just to say that last version (v2.0.12) is no compatible with L4:
laravel-date-issue

For the moment i had to downgrade my version to v2.0.11

Error after installation

Hi,

after composer installation and adding the ServiceProvider i get the following error message:

ErrorException in Date.php line 6:
Declaration of Jenssegers\Date\Date::setTranslator() should be compatible with Carbon\Carbon::setTranslator(Symfony\Component\Translation\TranslatorInterface $translator)

What i made wrong?

(Using Laravel 5)

In German "ago" has to include an "n" at the end

Hey guys,

I just started using your package and like it so far, but I noticed a slight issue when using diffForHumans():
"vor 10 Monate" - this is grammatically wrong, it should be:
"vor 10 Monaten"

I fixed it by editing the de.php in the lang folder:

'ago'   => 'vor :timen',

PSR-2 and PSR-4

What about adding PSR-2 and PSR-4 standards to this package? What do you think @jenssegers? I could help out with that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.