Skip to content

Commit 6f1b714

Browse files
committed
Update normalizeOrdinalDate()
1 parent b162da2 commit 6f1b714

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Mf2/Parser.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,16 @@ function convertTimeFormat($time) {
244244
* @return string
245245
*/
246246
function normalizeOrdinalDate($dtValue) {
247-
try {
248-
$parts = explode('-', $dtValue);
249-
250-
if ($parts[1] > 366) {
251-
throw new \Exception('Day of year can never be greater than 366');
252-
}
253-
247+
list($year, $day) = explode('-', $dtValue, 2);
248+
$day = intval($day);
249+
if ($day < 367 && $day > 0) {
254250
$date = \DateTime::createFromFormat('Y-z', $dtValue);
255251
$date->modify('-1 day'); # 'z' format is zero-based so need to adjust
256-
257-
if ($date->format('Y') != $parts[0]) {
258-
throw new \Exception('Day of year cannot be greater than 365 in non-leap years');
252+
if ($date->format('Y') === $year) {
253+
return $date->format('Y-m-d');
259254
}
260-
261-
return $date->format('Y-m-d');
262-
} catch (\Exception $e) {
263-
return '';
264255
}
256+
return '';
265257
}
266258

267259
/**

0 commit comments

Comments
 (0)