/www/protected/pages/utils/DateUtils.php
PHP | 81 lines | 60 code | 8 blank | 13 comment | 16 complexity | e4c234591db84ec9d7aab5ac3219bbe3 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- /*
- * Created on 16 ??.?. 2009
- *
- * To change the template for this generated file go to
- * Window - Preferences - PHPeclipse - PHP - Code Templates
- */
- class DateUtils
- {
- public static function process_datetime($date)
- {
- $dateNow = date("Y/m/d H:i:s");
- // echo "<br /> dateNow " . $dateNow;
- // echo "<br /> dateToBeDiff " . $date;
-
- $sec = strtotime($dateNow) - strtotime($date);
- // echo "\nnum secs : " . $sec;
- if($sec < 0)
- return "Error ";
- else if($sec < 60)
- return "now";
- else if($sec < 60*60) // 1 minute - 59 minute
- return DateUtils::getMinutesDiff($sec);
- else if($sec < 60*60*24) // 1 hr - 23 hr
- return DateUtils::getHoursDiff($sec);
- else if($sec < 60*60*24*30) // 1 day - 29 day
- return DateUtils::getDayDiff($sec);
- else if($sec < 60*60*24*30*12) // 1 month - 11 months
- return DateUtils::getMonthDiff($sec);
- else
- return DateUtils::getYearDiff($sec);
-
- }
-
-
- public static function getMinutesDiff($sec)
- { // number of sec in a minute
- return ceil( $sec / 60) . " minutes ago ";
- }
-
- public static function getHoursDiff($sec)
- {
- // number of sec in an hour
- $hour = floor( $sec / (60*60));
- if($hour <= 1)
- return "an hour ago ";
- else
- return $hour. " hours ago ";
- }
-
- public static function getDayDiff($sec)
- {
- // number of sec in a day
- $day = floor( $sec / (60*60*24));
- if($day <= 1)
- return "a day ago ";
- else
- return $day. " days ago ";
- }
-
- public static function getMonthDiff($sec)
- {
- // number of sec in a month
- $month = floor( $sec / (60*60*24*30));
- if($month <= 1)
- return "a month ago ";
- else
- return $month. " months ago ";
- }
-
- public static function getYearDiff($sec)
- {
- // number of sec in a year
- $year = floor( $sec / (60*60*24*30*12));
- if($year <= 1)
- return "a month ago ";
- else
- return $year. " years ago ";
- }
- }
- ?>