Skip to content
This repository
Browse code

datetime formatting fixes for unknown dates. fixes #83

  • Loading branch information...
commit b5b4ccd367bec72f675d48fc6383d934f6089c02 1 parent 711db6d
authored July 25, 2013

Showing 1 changed file with 32 additions and 16 deletions. Show diff stats Hide diff stats

  1. 48  classes/utility.php
48  classes/utility.php
@@ -254,30 +254,35 @@ public static function dayOfWeek($numeric_day)
254 254
 
255 255
 	public function newformatDate($date)
256 256
 	{
257  
-		$time = strtotime($date);
258  
-		return date("F j, Y, G:i", $time);	
259  
-		
  257
+	  if (strtotime($date) < 0)
  258
+		  return 'unknown';
  259
+		else
  260
+		  return date("F j, Y, G:i", strtotime($date));	
260 261
 	}
261 262
 
262 263
 
263 264
 	public function formatDate($date)
264 265
 	{
265  
-		$time = strtotime($date);
266  
-		
267  
-		//if (abs(time() - $time) > 86400)
268  
-			return date("M j, Y", $time);	
269  
-		//else
270  
-		//	return date("g:i a", $time);	
  266
+	  if (strtotime($date) < 0)
  267
+		  return 'unknown';
  268
+		else
  269
+			return date("M j, Y", strtotime($date));	
271 270
 	}
272 271
 
273 272
 	public function formatDateTime($date)
274 273
 	{
275  
-		return date("M j, Y // G:i", strtotime($date));	
  274
+		if (strtotime($date) < 0)
  275
+		  return 'unknown';
  276
+		else
  277
+		  return date("M j, Y // G:i", strtotime($date));	
276 278
 	}
277 279
 
278 280
 	public static function W3CDate($datetime) 
279 281
 	{
280  
-	    return date("Y-m-d\TH:i:sP", $datetime);
  282
+		if (strtotime($datetime) < 0)
  283
+		  return 'unknown';
  284
+		else
  285
+      return date("Y-m-d\TH:i:sP", $datetime);
281 286
 	}
282 287
 	
283 288
 	public static function relativeDays($datetime)
@@ -286,6 +291,9 @@ public static function relativeDays($datetime)
286 291
 		$elapsed = time() - strtotime($datetime);
287 292
 		$days = floor(abs($elapsed / Cache::TIME_ONE_DAY));
288 293
 		
  294
+		if (strtotime($datetime) < 0)
  295
+		  return 'unknown';
  296
+		
289 297
 		//special formatting...
290 298
 		if ($days == 0)
291 299
 			return "today";
@@ -342,7 +350,7 @@ public static function getHours($datediff)
342 350
 	public static function getTimeAgo($datetime)
343 351
 	{
344 352
 		if (trim($datetime) == "" || trim($datetime) == "0000-00-00 00:00:00")
345  
-			return false;
  353
+			return 'unknown';
346 354
 
347 355
 		$datediff = strtotime(date("Y-m-d H:i:s")) - strtotime($datetime);
348 356
 	
@@ -354,7 +362,9 @@ public static function getTimeAgo($datetime)
354 362
 		
355 363
 		//echo "$min $hours $days $months $years "; 
356 364
 		
357  
-		if ($datediff < 60) { // seconds
  365
+		if (strtotime($datetime) < 0) {
  366
+		  return 'unknown';
  367
+		} else if ($datediff < 60) { // seconds
358 368
 			if ($datediff == 0) return "just now";
359 369
 			return "$datediff second".self::pluralizer($datediff>1)." ago";
360 370
 		} else if ($min < 60) {
@@ -375,12 +385,15 @@ public static function getTimeAgo($datetime)
375 385
 	public static function relativeTime($datetime)
376 386
 	{
377 387
 		if (trim($datetime) == "")
378  
-			return false;
  388
+			return 'unknown';
379 389
 		
380 390
 		$from = strtotime(date("Y-m-d H:i:s"));
381 391
 		$to = strtotime($datetime);
382 392
 		$datediff = $from - $to;
383  
-	
  393
+
  394
+    if ($to < 0)
  395
+      return 'unknown';
  396
+		
384 397
 		$min = 	  round(abs($datediff) / (60));
385 398
 		$hours =  round(abs($datediff)  / (60 * 60));
386 399
 		$days =   round(abs($datediff)  / (60 * 60 * 24));
@@ -430,7 +443,7 @@ public static function relativeTime($datetime)
430 443
 	public static function relativeDate($datetime)
431 444
 	{
432 445
 		if (trim($datetime) == "")
433  
-			return false;
  446
+			return 'unknown';
434 447
 		
435 448
 		$from = strtotime(date("Y-m-d"));
436 449
 		$to = strtotime($datetime);
@@ -444,6 +457,9 @@ public static function relativeDate($datetime)
444 457
 		
445 458
     // Utility::log("$datetime datediff = $min $hours $days $months $years "); 
446 459
 		
  460
+    if ($to < 0)
  461
+      return 'unknown';
  462
+		
447 463
 		if ($datediff >= 0)
448 464
 		{
449 465
 			if ($days == 0)

0 notes on commit b5b4ccd

Please sign in to comment.
Something went wrong with that request. Please try again.