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