Timedate Help

identicon
Timedate Help
hmmy Sunday 24th January 2016, 23:45:06

Hi,

Can you help me getting the following code to work?


public static function toDate($id, $pattern = 'j M \'y')
{
global $lang;
$timestamp = strtotime(substr($id, 0, 16));
$diff = time() - $timestamp;
if($pattern === 'j M \'y' && $diff < 2628000) //1 week
{
$periods = array(604800 => 'w', 86400 => 'd', 3600 => 'h', 60 => 'm', 1 => 's');
foreach($periods as $key => $value)
{
if($diff >= $key)
{
$num = (int) ($diff / $key);
return $num. '' .$value. '';
}
}
}
if (date('Y') == date('Y', $timestamp)) {
return date('j M', $timestamp);
}
else
return date($pattern, $timestamp);
}

Replies 7
identicon
hmmy  Monday 25th January 2016, 20:05:08

You might have to edit the post to view it; "Wink" is not part of the code. Think that's a smiley

Fred_4346f29d
Fred  Monday 25th January 2016, 21:59:46

Try this:

public static function toDate($id, $pattern = 'j M Y')
{
global $lang;
$timestamp = strtotime(substr($id, 0, 16));
$diff = time() - $timestamp;
if($pattern === 'j M Y' && $diff < 2628000) //1 week
{
$periods = array(604800 => 'w', 86400 => 'd', 3600 => 'h', 60 => 'm', 1 => 's');
foreach($periods as $key => $value)
{
if($diff >= $key)
{
$num = (int) ($diff / $key);
return $num.$value;
}
}
}
if (date('Y') == date('Y', $timestamp))
return date('j M', $timestamp);
else
return date($pattern, $timestamp);
}

Before ask a question, read the documentation.
Please like in alternativeto.net 👍🏻
╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!

Prétendre que votre droit à une sphère privée n'est pas important parce que vous n'avez rien à cacher n'est rien d'autre que dire que la liberté d'expression n'est pas essentielle car vous n'avez rien à dire.
-- E. Snowden

Fred_4346f29d
Fred  Monday 25th January 2016, 22:29:49

  The smilies is fixed for next version wink

Before ask a question, read the documentation.
Please like in alternativeto.net 👍🏻
╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!

Prétendre que votre droit à une sphère privée n'est pas important parce que vous n'avez rien à cacher n'est rien d'autre que dire que la liberté d'expression n'est pas essentielle car vous n'avez rien à dire.
-- E. Snowden

identicon
hmmy  Monday 25th January 2016, 23:39:47

  I was going to say!

> quotes need fixing too

I was going to ask when you'll add: ratings and quick reply

identicon
hmmy  Tuesday 26th January 2016, 02:37:44

  This still break. Doesn't show the days, mins, seconds ago in the formate provided. Just shows DAY MONTH.

Fred_4346f29d
Fred  Tuesday 26th January 2016, 09:31:32

Remove this on the $periods array():

, 3600 => 'h', 60 => 'm', 1 => 's'

Yes i don't understant what don't quote parsed... Work great in the [doc page](http://flatboard.free.fr/view.php/plugin/page/p/docs) plugin.
For the quick reply is ready no? The form appear in accordeon style with jQuery.

Before ask a question, read the documentation.
Please like in alternativeto.net 👍🏻
╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!

Prétendre que votre droit à une sphère privée n'est pas important parce que vous n'avez rien à cacher n'est rien d'autre que dire que la liberté d'expression n'est pas essentielle car vous n'avez rien à dire.
-- E. Snowden

identicon
23dd6  Friday 29th January 2016, 17:58:10

  do you think it has to do with the config?

Suggested Topics
identicon
705 12
Fred_4346f29d
373 1
Fred_4346f29d
1.7K 10
Want to read more? Browse all categories or view latest topics.