| 1: | <?php |
| 2: | |
| 3: | namespace nightmare; |
| 4: | |
| 5: | class date |
| 6: | { |
| 7: | /** |
| 8: | * @return int |
| 9: | */ |
| 10: | public static function now() |
| 11: | { |
| 12: | return time(); |
| 13: | } |
| 14: | |
| 15: | /** |
| 16: | * @param int $day |
| 17: | * @return int |
| 18: | */ |
| 19: | public static function start_day($day) |
| 20: | { |
| 21: | return mktime(00, 00, 00, (int) date('n'), $day); |
| 22: | } |
| 23: | |
| 24: | /** |
| 25: | * @param int $month |
| 26: | * @return int |
| 27: | */ |
| 28: | public static function start_month($month) |
| 29: | { |
| 30: | return mktime(00, 00, 00, $month); |
| 31: | } |
| 32: | |
| 33: | /** |
| 34: | * @return int |
| 35: | */ |
| 36: | public static function start_year() |
| 37: | { |
| 38: | return 0; |
| 39: | } |
| 40: | |
| 41: | /** |
| 42: | * @return string |
| 43: | */ |
| 44: | public static function current_day() |
| 45: | { |
| 46: | return date('d'); |
| 47: | } |
| 48: | |
| 49: | /** |
| 50: | * @return string |
| 51: | */ |
| 52: | public static function current_month() |
| 53: | { |
| 54: | return date('m'); |
| 55: | } |
| 56: | |
| 57: | /** |
| 58: | * @return string |
| 59: | */ |
| 60: | public static function current_year() |
| 61: | { |
| 62: | return date('Y'); |
| 63: | } |
| 64: | |
| 65: | /** |
| 66: | * @param int $time |
| 67: | * @return string |
| 68: | */ |
| 69: | public static function display_ago($time) |
| 70: | { |
| 71: | $times = time() - $time; |
| 72: | |
| 73: | if ($times < 1) { |
| 74: | $t = 'Vừa xong'; |
| 75: | } elseif ($times < 60) { |
| 76: | $t = $times . ' giây trước'; |
| 77: | } elseif ($times < 3600) { |
| 78: | $t = round($times / 60) . ' phút trước'; |
| 79: | } elseif ($times < 86400) { |
| 80: | $t = round($times / 3600) . ' giờ trước'; |
| 81: | } elseif ($times < 2_592_000) { |
| 82: | $t = round($times / 86400) . ' ngày trước'; |
| 83: | } elseif ($times < 31_536_000) { |
| 84: | $t = round($times / 2_592_000) . ' tháng trước'; |
| 85: | } else { |
| 86: | $t = round($times / 31_536_000) . ' năm trước'; |
| 87: | } |
| 88: | |
| 89: | return $t; |
| 90: | } |
| 91: | } |
| 92: |