class_mcDate.inc.php
2.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcDate {
/**
* check if the format is like this yyyy-mm-dd
*/
public static function check8601Date($param_date) {
$datumfalsch = 0;
$pruefjahr = substr($param_date, 0, 4);
$pruefstrich1 = substr($param_date, 4, 1);
$pruefmonat = substr($param_date, 5, 2);
$pruefstrich2 = substr($param_date, 7, 1);
$prueftag = substr($param_date, 8, 2);
if (!eregi("^[0-9]+$", $pruefjahr))
$datumfalsch = 1;
if ($pruefstrich1 != "-")
$datumfalsch = 1;;
if ($pruefstrich2 != "-")
$datumfalsch = 1;;
if ($pruefmonat < 01 || $pruefmonat > 12)
$datumfalsch = 1;
if ($prueftag < 01)
$datumfalsch = 1;
if ($datumfalsch == 0 && !checkdate($pruefmonat, $prueftag, $pruefjahr)) {
$datumfalsch = 1;
}
if($datumfalsch==1) {
return false;
} else {
return true;
}
}
/**
* wants http://en.wikipedia.org/wiki/ISO_8601 format for a date
*/
public static function format8601Date($param_date) {
if($param_date == '0000-00-00') {
return '';
} else {
$pruefjahr = substr($param_date, 0, 4);
$pruefmonat = substr($param_date, 5, 2);
$prueftag = substr($param_date, 8, 2);
return $prueftag.'.'.$pruefmonat.'.'.$pruefjahr;
}
}
public static function checkIfFirstIsBefore($param_DateBefore, $param_DateAfter) {
if(mcDate::check8601Date($param_DateBefore) && mcDate::check8601Date($param_DateAfter)) {
$DateBefore = mktime(null, null, null, substr($param_DateBefore, 5, 2), substr($param_DateBefore, 8, 2), substr($param_DateBefore, 0, 4));
$DateAfter = mktime(null, null, null, substr($param_DateAfter, 5, 2), substr($param_DateAfter, 8, 2), substr($param_DateAfter, 0, 4));
if($DateBefore <= $DateAfter) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public static function getNowAsDatetime() {
$return = date('o-m-d H:i:s');
return $return;
}
/**
*
* @param array $param_date
* @return type
*/
private static function transformToDatetime(array $param_date) {
return ''.$param_date['Y'].'-'.$param_date['m'].'-'.$param_date['d'].' '.$param_date['H'].':'.$param_date['i'].':'.$param_date['s'].'';
}
public static function transformToArrayDatetime($param_date=null) {
if($param_date) {
if(is_array($param_date)) {
$tmp_date = mcDate::transformToDatetime($param_date);
} else {
$tmp_date = $param_date;
}
} else {
$tmp_date = mcDate::getNowAsDatetime();
}
return $tmp_date;
}
}
?>