Sfoglia il codice sorgente

Web scraping support date format epoch milliseconds (#8266)

fix https://github.com/FreshRSS/FreshRSS/discussions/8264
Auto detect whether a `U` date format should be in seconds or milliseconds.
Alexandre Alapetite 4 mesi fa
parent
commit
023cdf0d7a
2 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 4 0
      app/Models/Feed.php
  2. 4 0
      app/Utils/dotNotationUtil.php

+ 4 - 0
app/Models/Feed.php

@@ -1098,6 +1098,10 @@ class FreshRSS_Feed extends Minz_Model {
 				$item['author'] = $xPathItemAuthor == '' ? '' : $xpathEvaluateString($xPathItemAuthor, $node);
 				$item['timestamp'] = $xPathItemTimestamp == '' ? '' : $xpathEvaluateString($xPathItemTimestamp, $node);
 				if ($xPathItemTimeFormat != '') {
+					if ($xPathItemTimeFormat === 'U' && strlen($item['timestamp']) > 10) {
+						// Compatibility with Unix timestamp in milliseconds
+						$item['timestamp'] = substr($item['timestamp'], 0, -3);
+					}
 					$dateTime = DateTime::createFromFormat($xPathItemTimeFormat, $item['timestamp']);
 					if ($dateTime != false) {
 						$item['timestamp'] = $dateTime->format(DateTime::ATOM);

+ 4 - 0
app/Utils/dotNotationUtil.php

@@ -159,6 +159,10 @@ final class FreshRSS_dotNotation_Util
 				: $rssItem['content'];
 
 			if (isset($dotNotation['itemTimeFormat']) && is_string($dotNotation['itemTimeFormat'])) {
+				if ($dotNotation['itemTimeFormat'] === 'U' && strlen($rssItem['timestamp']) > 10) {
+					// Compatibility with Unix timestamp in milliseconds
+					$rssItem['timestamp'] = substr($rssItem['timestamp'], 0, -3);
+				}
 				$dateTime = DateTime::createFromFormat($dotNotation['itemTimeFormat'], $rssItem['timestamp']);
 				if ($dateTime != false) {
 					$rssItem['timestamp'] = $dateTime->format(DateTime::ATOM);