class_mcDate.inc.php
1.74 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
<?php
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;
}
}
}
?>