[solved] Problem with && in UDT

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
squarefrog
New Member
New Member
Posts: 6
Joined: Fri Apr 23, 2010 9:20 am

[solved] Problem with && in UDT

Post by squarefrog »

I'm having difficulty with one of my UDT's. I use the tag to compare 2 unix timestamps, and return XX minutes ago, or XX seconds ago. I got it working using simple > rules, but I'd quite like to include && so I can say "1 hour ago" rather than "1 hours ago".

Code: Select all

if($params['time']){

$postedTime =  $params['time'];
$timediff = time() - $postedTime;

	switch (TRUE)
	{
		case ($timediff > 60):
		return round($timediff / 60) . ' minutes ago';
 		break;
 	
		case ($timediff >= 3600 && < 7200):
		return '1 hour ago';
  		break;

		case ($timediff >= 7200):
 		return round($timediff / 3600) . ' hours ago';
  		break;
  	
		case ($timediff >= 86400 && < 172800):
		return '1 day ago';
  		break;
  		
  		case ($timediff >= 172800):
		return round($timediff / 86400) . ' days ago';
  		break;
  	
		default:
   		return $timediff . ' seconds ago';
	} 

}
Any suggestions?
Last edited by squarefrog on Thu May 13, 2010 10:00 am, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: Problem with && in UDT

Post by Jos »

Change it to this:

Code: Select all

case ($timediff >= 3600 && $timediff < 7200):
edit:
and don't forget to add a max timediff here: case ($timediff >= 7200):
Last edited by Jos on Thu May 13, 2010 9:57 am, edited 1 time in total.
squarefrog
New Member
New Member
Posts: 6
Joined: Fri Apr 23, 2010 9:20 am

Re: Problem with && in UDT

Post by squarefrog »

Literally just figured it out as the reply came in. Good point about the max timediff. Needed one here too case ($timediff > 60):

Thanks for your help Jos!
Post Reply

Return to “Modules/Add-Ons”