jenssegers / date Goto Github PK
View Code? Open in Web Editor NEW🗓 A library to help you work with dates in multiple languages, based on Carbon.
Home Page: https://jenssegers.com
License: MIT License
🗓 A library to help you work with dates in multiple languages, based on Carbon.
Home Page: https://jenssegers.com
License: MIT License
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?
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.
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.
Hi,
Larval uses Carbon to convert timestamps from the database (created_at, updated_at and custom ones) into a Carbon object. Is there a way to make Laravel use laravel-date instead?
thank you for your help
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
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
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.
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.
In README is: jenssegers/data , should be: jenssegers/date
'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',
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.
Thanks, for this project!
I was wondering, how I can translate Month names, and day of week names?
But I have multilingual site.
Any help would be appreciated. Thanks!
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?
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:
How do I make it show and use local time instead of UTC?
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!!
It would be cool if it was possible of using a shorter syntax like:
1s
1m
1h
1d
1y
or
1sec
1min
1hrs
1day
1yr
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.
Current date/time is set to client time instead of server time as expected.
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.
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?
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');
}
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 :)
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".
When i use Date::parse(43)->diffForHumans(); i get that error , but in ro lang exists
'year' => 'un an|:count ani',
as i see, if i put value <= 19 it works... : acum 19 ani
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!
composer.json:
"jenssegers/date": "2.0.21"
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?
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").
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
Unable to choose a translation for "1 dzień|:count dni" with locale "pl" for value "5". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %count% apples")
That strange because in polish we have:
1 dzień
2 dni
5 dni
1576352745 dni
so only "dzień" and "dni" but translator looking for... 5 ?
When I execute:
diffForHumans(new Date('2014-10-30')); ?>locale - output:
ja - 1日 前
zh - 1 天 之前
zh-TW - 1 天前
en - 4 days before
fr - 4 jours avant
Hi,
I've added a PR but would like to inform you about a small bug. When you select the Turkish language, you never reach plural forms.
Will do a PR myself if you guys don't have time.
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!
Is there any plan to support Laravel 5?
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!
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?
Hi Jens,
I got this error on my Laravel 5 install after updating your library through composer. Any ideas?
ErrorException in Date.php line 6: Declaration of Jenssegers\Date\Date::setTranslator() should be compatible with Carbon\Carbon::setTranslator(Symfony\Component\Translation\TranslatorInterface $translator)
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 ?
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
Im trying to set the package language to spanish but It doesn't detect the locale language, the diffForHumans() only show in english. And when I try to set the language manually with " Lang::setLocale('es'); " the diffForHumans() function return a empty string, without errors, or anything to track the issue.
Pd: The package looks great, I really want to see it working =)
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?
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?
I'm trying to implement this package in my project but after installation via composer and adding the provider, i get Call to undefined method Carbon\Carbon::timespan()
Can I know what I did wrong
Subject pretty much covers it but wondering if Japanese is in the works or a way create my own lang files. Much appreciated.
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?
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)
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',
What about adding PSR-2 and PSR-4 standards to this package? What do you think @jenssegers? I could help out with that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.