@@ -24,14 +24,18 @@ public static function convertDateTime($dateInput)
24
24
{
25
25
$ epoch = 1900 ;
26
26
$ norm = 300 ;
27
- $ year = $ month = $ day = $ offset = 0 ;
27
+ $ year = $ month = $ day = $ offset = $ seconds = 0 ;
28
28
$ dateTime = $ dateInput ;
29
29
if (preg_match ("/(\d{4})\-(\d{2})\-(\d{2})/ " , $ dateTime , $ matches )) {
30
30
$ year = $ matches [1 ];
31
31
$ month = $ matches [2 ];
32
32
$ day = $ matches [3 ];
33
33
}
34
- $ seconds = self ::getSeconds ($ dateTime );
34
+
35
+ if (preg_match ("/(\d{2}):(\d{2}):(\d{2})/ " , $ dateTime , $ matches )) {
36
+ $ seconds = ($ matches [1 ] * 60 * 60 + $ matches [2 ] * 60 + $ matches [3 ]) / 86400 ;
37
+ }
38
+
35
39
if ("$ year- $ month- $ day " == '1899-12-31 ' || "$ year- $ month- $ day " == '1900-01-00 ' ) {
36
40
return $ seconds ;
37
41
}
@@ -42,9 +46,11 @@ public static function convertDateTime($dateInput)
42
46
// check leapDay
43
47
$ leap = (new \DateTime ($ dateInput ))->format ('L ' );
44
48
$ mDays = [31 , ($ leap ? 29 : 28 ), 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ];
45
- if (self ::checkEpoch ($ year , $ month , $ day , $ mDays [$ month - 1 ])) {
49
+
50
+ if (($ year < 1900 || $ year > 9999 ) || ($ month < 1 || $ month > 12 ) || $ day < 1 || $ day > $ mDays [$ month - 1 ]) {
46
51
return 0 ;
47
52
}
53
+
48
54
$ days = $ day + ($ range * 365 ) + array_sum (array_slice ($ mDays , 0 , $ month - 1 ));
49
55
$ days += intval (($ range ) / 4 ) - intval (($ range + $ offset ) / 100 );
50
56
$ days += intval (($ range + $ offset + $ norm ) / 400 ) - intval ($ leap );
@@ -55,23 +61,6 @@ public static function convertDateTime($dateInput)
55
61
return $ days + $ seconds ;
56
62
}
57
63
58
- /**
59
- * @param $year
60
- * @param $month
61
- * @param $day
62
- * @param $dayCheck
63
- *
64
- * @return bool
65
- */
66
- private function checkEpoch ($ year , $ month , $ day , $ dayCheck )
67
- {
68
- if (($ year < 1900 || $ year > 9999 ) || ($ month < 1 || $ month > 12 ) || $ day < 1 || $ day > $ dayCheck ) {
69
- return true ;
70
- }
71
-
72
- return false ;
73
- }
74
-
75
64
/**
76
65
* @param $val
77
66
*
@@ -151,20 +140,4 @@ public static function escapeCellFormat($cellFormat)
151
140
152
141
return $ escaped ;
153
142
}
154
-
155
- /**
156
- * @param $dateTime
157
- *
158
- * @return float|int
159
- */
160
- private function getSeconds ($ dateTime )
161
- {
162
- $ seconds = 0 ;
163
-
164
- if (preg_match ("/(\d{2}):(\d{2}):(\d{2})/ " , $ dateTime , $ matches )) {
165
- $ seconds = ($ matches [1 ] * 60 * 60 + $ matches [2 ] * 60 + $ matches [3 ]) / 86400 ;
166
- }
167
-
168
- return $ seconds ;
169
- }
170
143
}
0 commit comments