-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.php
More file actions
76 lines (64 loc) · 2.3 KB
/
Date.php
File metadata and controls
76 lines (64 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class WS_Date extends Zend_Date {
public static function today() {
$ZD = new Zend_Date();
return $ZD;
}
public static function adjustToDb($data) {
$test = explode('/', $data);
if (count($test) == 3):
$ZD = new Zend_Date($data, 'dd/MM/yyyy');
return $ZD->toString('yyyy-MM-dd');
else:
return false;
endif;
}
public static function adjustToView($data) {
if (!empty($data)):
$test = explode('-', $data);
if (count($test) == 3):
$ZD = new Zend_Date($data, 'yyyy-MM-dd');
return $ZD->toString('dd/MM/yyyy');
else:
return false;
endif;
endif;
}
public static function adjustToViewWithHour($data) {
if (!empty($data)):
$ZD = new Zend_Date($data);
return $ZD->toString('dd/MM/yyyy HH:mm:ss');
endif;
}
public static function adjustToDbWithHour($data) {
if (!empty($data)):
$ZD = new Zend_Date($data);
return $ZD->toString('yyyy-DD-dd HH:mm:ss');
endif;
}
public static function dateDifference($date1, $date2) {
$d1 = (is_string($date1) ? strtotime($date1) : $date1);
$d2 = (is_string($date2) ? strtotime($date2) : $date2);
$diff_secs = abs($d1 - $d2);
$base_year = min(date("Y", $d1), date("Y", $d2));
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
return array(
"years" => abs(substr(date('Ymd', $d1) - date('Ymd', $d2), 0, -4)),
"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
"months" => date("n", $diff) - 1,
"days_total" => floor($diff_secs / (3600 * 24)),
"days" => date("j", $diff) - 1,
"hours_total" => floor($diff_secs / 3600),
'horas' => $diff_secs / 3600,
"hours" => date("G", $diff),
"minutes_total" => floor($diff_secs / 60),
"minutes" => (int) date("i", $diff),
"seconds_total" => $diff_secs,
"seconds" => (int) date("s", $diff)
);
}
public static function minutesToHours($minutes) {
$retorno = number_format($minutes / 60, 2);
return $retorno;
}
}