Skip to content

Commit 6a28d0f

Browse files
author
denis.tikhonov
committed
fix seconds
1 parent a6602a1 commit 6a28d0f

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

src/Helpers/ExcelHelper.php

+9-36
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ public static function convertDateTime($dateInput)
2424
{
2525
$epoch = 1900;
2626
$norm = 300;
27-
$year = $month = $day = $offset = 0;
27+
$year = $month = $day = $offset = $seconds = 0;
2828
$dateTime = $dateInput;
2929
if (preg_match("/(\d{4})\-(\d{2})\-(\d{2})/", $dateTime, $matches)) {
3030
$year = $matches[1];
3131
$month = $matches[2];
3232
$day = $matches[3];
3333
}
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+
3539
if ("$year-$month-$day" == '1899-12-31' || "$year-$month-$day" == '1900-01-00') {
3640
return $seconds;
3741
}
@@ -42,9 +46,11 @@ public static function convertDateTime($dateInput)
4246
// check leapDay
4347
$leap = (new \DateTime($dateInput))->format('L');
4448
$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]) {
4651
return 0;
4752
}
53+
4854
$days = $day + ($range * 365) + array_sum(array_slice($mDays, 0, $month - 1));
4955
$days += intval(($range) / 4) - intval(($range + $offset) / 100);
5056
$days += intval(($range + $offset + $norm) / 400) - intval($leap);
@@ -55,23 +61,6 @@ public static function convertDateTime($dateInput)
5561
return $days + $seconds;
5662
}
5763

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-
7564
/**
7665
* @param $val
7766
*
@@ -151,20 +140,4 @@ public static function escapeCellFormat($cellFormat)
151140

152141
return $escaped;
153142
}
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-
}
170143
}

0 commit comments

Comments
 (0)