[VkBridge] Make timestamps more accurate (#3325)

This commit is contained in:
Eugene Molotov 2023-03-23 00:32:15 +05:00 committed by GitHub
parent 9bb04ba848
commit c8af9f9055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -24,6 +24,7 @@ class VkBridge extends BridgeAbstract
]; ];
protected $pageName; protected $pageName;
protected $tz = 0;
public function getURI() public function getURI()
{ {
@ -50,6 +51,13 @@ class VkBridge extends BridgeAbstract
$text_html = iconv('windows-1251', 'utf-8//ignore', $text_html); $text_html = iconv('windows-1251', 'utf-8//ignore', $text_html);
$html = str_get_html($text_html); $html = str_get_html($text_html);
foreach ($html->find('script') as $script) {
preg_match('/tz: ([0-9]+)/', $script->outertext, $matches);
if (count($matches) > 0) {
$this->tz = intval($matches[1]);
break;
}
}
$pageName = $html->find('.page_name', 0); $pageName = $html->find('.page_name', 0);
if (is_object($pageName)) { if (is_object($pageName)) {
$pageName = $pageName->plaintext; $pageName = $pageName->plaintext;
@ -393,8 +401,9 @@ class VkBridge extends BridgeAbstract
private function getTime($post) private function getTime($post)
{ {
if ($time = $post->find('time.PostHeaderSubtitle__item', 0)->getAttribute('time')) { $accurateDateElement = $post->find('span.rel_date', 0);
return $time; if ($accurateDateElement) {
return $accurateDateElement->getAttribute('time');
} else { } else {
$strdate = $post->find('time.PostHeaderSubtitle__item', 0)->plaintext; $strdate = $post->find('time.PostHeaderSubtitle__item', 0)->plaintext;
$strdate = preg_replace('/[\x00-\x1F\x7F-\xFF]/', ' ', $strdate); $strdate = preg_replace('/[\x00-\x1F\x7F-\xFF]/', ' ', $strdate);
@ -417,7 +426,7 @@ class VkBridge extends BridgeAbstract
$date['hour'] = $date['minute'] = '00'; $date['hour'] = $date['minute'] = '00';
} }
return strtotime($date['day'] . '-' . $date['month'] . '-' . $date['year'] . ' ' . return strtotime($date['day'] . '-' . $date['month'] . '-' . $date['year'] . ' ' .
$date['hour'] . ':' . $date['minute']); $date['hour'] . ':' . $date['minute']) - $this->tz;
} }
} }