Jeff VIP
Total posts: 745
14 Jul 2013 22:28

Hi,

I wonder if it's possible to change the output of the expiration date.

So, instead of showing

Expire date: 17 juli 2013

I'd like to show:

2 days before expiration

or 2 day left

And when a record has expired:

Expired

Best regards,

Jeff

Last Modified: 02 Mar 2014


Sergey
Total posts: 13,748
15 Jul 2013 06:43

Is this a date field or core record ctime column?

In date field there is formatter called age. But with core field you will need to edit template.


Jeff VIP
Total posts: 745
15 Jul 2013 06:58

Hi Sergey,

It is a core field.

I really don't know how to achieve this in the template, because this seems like a rather complex date calculation / conversion thing.

Personally I would prefer to use a normal datetime field to act like an expired field, but so far I have only seen the option to override the expiration date when saving. My only worry is when I change the expiration date with the core field, the datetime field won't reflect the change.

Best regards,

Jeff


Jeff VIP
Total posts: 745
15 Jul 2013 07:01

And what happens with a custom expiration field when someone prolongs a record? Does this field get updated automatically?


Sergey
Total posts: 13,748
15 Jul 2013 07:09

$time = $item->ctime->toUnix();

if($time < time())

{

echo '<span class="label label-danger">'.JText::_('Expired').'</span>';

}

else

{

$rest = ceil($time - time()) / 86400);

echo 'Another '.$rest.' days';

}


Jeff VIP
Total posts: 745
15 Jul 2013 10:36

Thanks Sergey,

but this doesn't work for me.

First:

I think there's a '(' missing in :

$rest = ceil($time - time()) / 86400); 

Second:

This code is using ctime. Since I've overridden ctime with dates that are way back in the past, all my records are expired. I need extime.


Jeff VIP
Total posts: 745
15 Jul 2013 11:48

This one works:

$time = strtotime("$item->extime");

if($time < time())

{

echo '<span class="label label-danger">'.JText::_('Expired').'</span>';

}

else

{

$rest = ceil(($time - time()) / 86400);

echo 'Another '.$rest.' days';

    echo $time;

}

But records that never expire will return also 'Expired' :(

I think it is because when a record is set never to expire, the output is 'never' instead of a real date

Correct?


Jeff VIP
Total posts: 745
15 Jul 2013 21:20

I worked till 3 AM last night trying to solve this.

This morning I figured it out: :)

<?php            

$time = strtotime("$item->extime");

if($time < time() && $time != NULL)

{

    echo '<span class="label label-important">'.JText::_('Expired').'</span>';

}

else if ($time < time() && $time = '-15902')

{

    echo '<span class="label label-success">VALID</span>';

}

else

{

$rest = ceil(($time - time()) / 86400);

    echo '<span class="label">'.$rest.' days remaining</span>';

}

?>

Sergey: Do you think this code can be optimized?

Best regards,

Jeff


Sergey
Total posts: 13,748
16 Jul 2013 04:42

If it works it looks ok.


Jeff VIP
Total posts: 745
16 Jul 2013 06:21

Great! Thanks for your help :)

Powered by Cobalt