jimmiw / php-time-ago Goto Github PK
View Code? Open in Web Editor NEWSimple module, that displays the date in a "time ago" format.
Simple module, that displays the date in a "time ago" format.
There's a typo here https://github.com/jimmiw/php-time-ago/blob/master/src/Westsworld/TimeAgo.php#L67
DateTme should be DateTime
FYI, for more recent version 3.1.0, I get this deprecation notice when adding "jimmiw/php-time-ago": "^3.1.0"
:
to
composer.json`:
Deprecation Notice: Class Westsworld\TimeAgo\Translations\Zh_Tw located in ./wp-content/plugins/composer-libs/jimmiw/php-time-ago/src/Westsworld/TimeAgo/Translations/Zh_TW.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///home/yuvilio/apps/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
$ composer --version
Composer version 1.10.5 2020-04-10 11:44:22
$ php --version
PHP 7.4.4 (cli) (built: Apr 27 2020 00:25:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
$
I used
require_once ('include/Westsworld/TimeAgo.php'); $timeZone = null; $timeAgo = new Westsworld\TimeAgo( $timeZone, 'De');
But throws the error:
Got error 'PHP message: PHP Fatal error: Uncaught Error: Class 'Westsworld\\TimeAgo\\Translations\\En' not found in
Why not do the following instead?
$date = new DateTime();
$time_ago = new TimeAgo($date);
$time_ago->inWords();
Hi Jimmi great class, good job! I've created the catalan translation. I attach the file in case you want to add it. Thanks.
ca.txt
It would be great to add support for other languages. (i18n)
$timeAgo = new TimeAgo('es');
How would i set Swedish language?
Danish translation seems to work:
$filter = new Twig_SimpleFilter('timeago', function ($datetime) {
$timeago = new Westsworld\TimeAgo( new \Westsworld\TimeAgo\Translations\Da() );
return $timeago->inWords( new DateTime( $datetime ) );
});
But not Swedish (or any other translation class with underscore in its class name):
$filter = new Twig_SimpleFilter('timeago', function ($datetime) {
$timeago = new Westsworld\TimeAgo( new \Westsworld\TimeAgo\Translations\Sv_SE() );
return $timeago->inWords( new DateTime( $datetime ) );
});
What am i doing wrong? @jimmiw
6% of all methods have more than 50 lines. This violation is raised when more than 5% methods are too long.
Posted from SensioLabsInsight
Looks the same as the issue fixed in 0.4.3 "Added a fix for “about 1 hour ago”, which would yield “1 hours ago” if the time was 1hour 30minutes. Giving a pluralization error."
The same occurs for minutes, where it renders the text '1 minutes ago'.
I've translated the lang file to hebrew for one of my projects. Attached.
Cheers.
he.php.zip
I've just discovered php-time-ago and think its just great! There's just one thing:
In my opinion, 'about 1 hour ago' is a bit to long in some cases, so it would be great if you could add something like a shorter English language-class like this:
` 0 <-> 29 secs # => <1m
30 secs <-> 1 min, 29 secs # => 1m
1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] m
44 mins, 30 secs <-> 89 mins, 29 secs # => ~1h
89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => ~ [2..24] h
23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1d
47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] d
29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => ~1M
59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] M
1 yr <-> 2 yrs minus 1 secs # => 1y
2 yrs <-> max time or date # => >[2..X] y`
Hi there,
There seems to be a problem with the output of this code when the time of the date object is between 23:00 (11PM) and 00:00 (12 PM).
When this happens, it says that it is "46 years ago".
I want to add it.php
translation file, I know I can do this by simply adding the file in the translations directory, but that does not seem like an ideal solution to me.
Is it possible to have a function that loads language from an array? (This way I can store translations in my production code and not the vendor directory)
DateInterval dump:
y => 0
m => 0
d => 0
h => 1
i => 50
s => 25
f => 0.90637199999999996
but rule 5 is used => about 1 hours
not working using timestamp
Hi Jimmi,
could you please make me a contributor? I have a pull request with sk language translation.
Thanks,
Franta
Hi,
I was wondering if it would be easy to add short versions of the times like instead of "2 days ago" something like "2d".
Thanks
sorry i did not see the other only one issue :D somehow you can close this
Allow the ability to transform further dates
It would be better to include ago
in all the translation messages (i.e. about 1 hour ago
), because:
ago
?about 1 hour
would be translated by etwa eine Stunde
, whereas about 1 hour ago
would be translated by vor etwa eineR Stunde
(please notice the r
). So I can't just prepend vor
(ago
) to the translations of this library.Do you see what I mean?
/**
* TimeAgo constructor.
* @param null|DateTimeZone $timezone the timezone to use (uses system if none is given)
* @param string $language the language to use (defaults to 'en' for english)
*/
public function __construct(Language $language = null)
{
$this->language = $language;
}
@param null|DateTimeZone $timezone the timezone to use (uses system if none is given)
Where ??
The logic for the time ago calculations is currently entirely in the Language class, which, given its name, seems odd; shouldn't it only do the translations? Wouldn't the processing have a better place in either the TimeAgo class or another one dedicated to that task?
I get:
PHP Parse error: syntax error, unexpected ':', expecting ';' or '{'
in vendor/jimmiw/php-time-ago/src/Westsworld/TimeAgo.php on line 56?
Please fix this inside isLessThan44Min29Secs:
return $timeDifference->i < 45 &&
$timeDifference->s < 30 &&
...
as soon the $timeDifference->s >= 30 it gives a wrong result back.
["years"]=> int(0) ["months"]=> int(0) ["days"]=> int(0) ["hours"]=> int(0) ["minutes"]=> int(36) ["seconds"]=> int(58)
about 1 hour ago -> wrong
3 seconds later:
["years"]=> int(0) ["months"]=> int(0) ["days"]=> int(0) ["hours"]=> int(0) ["minutes"]=> int(37) ["seconds"]=> int(1)
37 minutes ago -> correct
Hey Jimmi,
Great library! I was hoping to use it in one of my projects. Would you be able to include a license in the readme so I am legally allowed to include it?
Something like this would work, if you agree with the license terms: https://github.com/themattharris/PHP-Blowfish/#the-mit-license
Thanks!
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.