Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone error in XmlRpc #1758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 17 additions & 13 deletions var/IXR/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
*/
class Date
{
private int $year;
private string $year;

private int $month;
private string $month;

private int $day;
private string $day;

private int $hour;
private string $hour;

private int $minute;
private string $minute;

private int $second;
private string $second;

private string $timezone;

/**
* @param int|string $time
Expand All @@ -39,12 +41,13 @@ public function __construct($time)
*/
private function parseTimestamp(int $timestamp)
{
$this->year = intval(date('Y', $timestamp));
$this->month = intval(date('m', $timestamp));
$this->day = intval(date('d', $timestamp));
$this->hour = intval(date('H', $timestamp));
$this->minute = intval(date('i', $timestamp));
$this->second = intval(date('s', $timestamp));
$this->year = gmdate('Y', $timestamp);
$this->month = gmdate('m', $timestamp);
$this->day = gmdate('d', $timestamp);
$this->hour = gmdate('H', $timestamp);
$this->minute = gmdate('i', $timestamp);
$this->second = gmdate('s', $timestamp);
$this->timezone = '';
}

/**
Expand All @@ -58,14 +61,15 @@ private function parseIso(string $iso)
$this->hour = substr($iso, 9, 2);
$this->minute = substr($iso, 12, 2);
$this->second = substr($iso, 15, 2);
$this->timezone = substr($iso, 17);
}

/**
* @return string
*/
public function getIso(): string
{
return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second;
return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second . $this->timezone;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions var/Widget/XmlRpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public function wpGetPageList(int $blogId, string $userName, string $password):
while ($pages->next()) {
$pageStructs[] = [
'dateCreated' => new Date($this->options->timezone + $pages->created),
'date_created_gmt' => new Date($this->options->timezone + $pages->created),
'date_created_gmt' => new Date($pages->created),
'page_id' => $pages->cid,
'page_title' => $pages->title,
'page_parent_id' => '0',
Expand Down Expand Up @@ -945,7 +945,7 @@ public function wpGetComment(int $blogId, string $userName, string $password, in
}

return [
'date_created_gmt' => new Date($this->options->timezone + $comment->created),
'date_created_gmt' => new Date($comment->created),
'user_id' => $comment->authorId,
'comment_id' => $comment->coid,
'parent' => $comment->parent,
Expand Down Expand Up @@ -999,7 +999,7 @@ public function wpGetComments(int $blogId, string $userName, string $password, a

while ($comments->next()) {
$commentsStruct[] = [
'date_created_gmt' => new Date($this->options->timezone + $comments->created),
'date_created_gmt' => new Date($comments->created),
'user_id' => $comments->authorId,
'comment_id' => $comments->coid,
'parent' => $comments->parent,
Expand Down Expand Up @@ -1174,7 +1174,7 @@ public function wpGetMediaLibrary(int $blogId, string $userName, string $passwor
while ($attachments->next()) {
$attachmentsStruct[] = [
'attachment_id' => $attachments->cid,
'date_created_gmt' => new Date($this->options->timezone + $attachments->created),
'date_created_gmt' => new Date($attachments->created),
'parent' => $attachments->parent,
'link' => $attachments->attachment->url,
'title' => $attachments->title,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ public function wpGetMediaItem(int $blogId, string $userName, string $password,

return [
'attachment_id' => $attachment->cid,
'date_created_gmt' => new Date($this->options->timezone + $attachment->created),
'date_created_gmt' => new Date($attachment->created),
'parent' => $attachment->parent,
'link' => $attachment->attachment->url,
'title' => $attachment->title,
Expand Down Expand Up @@ -1417,7 +1417,7 @@ public function mtGetRecentPostTitles(int $blogId, string $userName, string $pas
'userid' => $posts->authorId,
'postid' => $posts->cid,
'title' => $posts->title,
'date_created_gmt' => new Date($this->options->timezone + $posts->created)
'date_created_gmt' => new Date($posts->created)
];
}

Expand Down