Changeset 2656
- Timestamp:
- 05/07/08 11:59:30 (3 months ago)
- Files:
-
- trunk/system/helpers/date.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/system/helpers/date.php
r2655 r2656 355 355 } 356 356 357 /** 358 * Returns time difference between two timestamps, in the format: 359 * N year, N months, N weeks, N days, N hours, N minutes, and N seconds ago 360 * 361 * @param integer timestamp 362 * @param integer timestamp, defaults to the current time 363 * @param string formatting string 364 * @return string 365 */ 357 366 public static function timespan_string($time1, $time2 = NULL, $output = 'years,months,weeks,days,hours,minutes,seconds') 358 367 { 359 368 if ($difference = date::timespan($time1, $time2, $output) AND is_array($difference)) 360 369 { 361 $key = end($difference); 362 $key = key($difference); 363 364 echo Kohana::debug($key, $difference);exit; 370 // Determine the key of the last item in the array 371 $last = end($difference); 372 $last = key($difference); 365 373 366 374 $span = array(); 367 375 foreach ($difference as $name => $amount) 368 376 { 369 if ($amount === 1) 377 if ($name !== $last AND $amount === 0) 378 { 379 // Skip empty amounts 380 continue; 381 } 382 elseif ($amount === 1) 370 383 { 371 384 // Make the name singualr … … 373 386 } 374 387 388 if ($name === $last) 389 { 390 // Add "and" 391 $amount = 'and '.$amount; 392 } 393 394 // Add the amount to the span 375 395 $span[] = $amount.' '.$name; 376 396 } 377 397 378 $ span = array_splice()379 380 $span = trim($span).' ago'; 381 }398 $difference = implode(', ', $span).' ago'; 399 } 400 401 return $difference; 382 402 } 383 403
