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

Strange time stamp problem #80

Open
hiromi3 opened this issue Mar 15, 2018 · 5 comments
Open

Strange time stamp problem #80

hiromi3 opened this issue Mar 15, 2018 · 5 comments

Comments

@hiromi3
Copy link

hiromi3 commented Mar 15, 2018

Hello,
I am using WordPressSharp with VS2017 on Windows10.
When I posted a new post with the following settings,
post.PublishDateTime = DateTime.Now;
post.Status = "publish";

I could successfully post.
However, I found a problem.

The Date/Time of the post is 9 hours future in edit window of the post.
But, the Date/Time of the post is 1 minutes before in posts list window.(Good)

My local time is UTC+9.

Then I changed post parameter as below and posted.
post.PublishDateTime = UTC time

The Date/Time of the post is 1 minutes before in edit window of the post.(Good)
But, the Date/Time of the post is 9 hours before in posts list window.

I tried many things but I could not solve the 9 hours difference.
If the post has this strange time stamp,
the client.GetPosts() fails with the following error message.

'response contains invalid dateTime value [response : array mapped to type Post[] : element 0 : struct mapped to type Post : member FeaturedImage mapped to type Object : struct mapped to XmlRpcStruct : member date_created_gmt : dateTime]'

If you know the solution, please let me know.

@Blackcat156
Copy link

Blackcat156 commented Mar 16, 2018

Hello, I got the problem by adjusting the time setting of WordPress.
default

I use GetPost () in a different time; I won't make a mistake.
If you don't want to adjust the time of WordPress, you can choose

GetPost.PublishDateTime.AddHours(-9);

Now these two methods are enough to solve the problem, and if there is a better way to tell me

@hiromi3
Copy link
Author

hiromi3 commented Mar 16, 2018

Thank you for your reply.
I know the WordPress Timezone setting menu in your captured image and I am setting it UTC+9 .
I could subtract nine hours by your suggested AddHours() method.

But, my simple question is why these time stamps have different values.

The Date/Time of the post is 9 hours future in edit window of the post.
But, the Date/Time of the post is 1 minutes before in posts list window.(Good)

When I post WordPress content manually without using C#,
these time stamps are exactly same value.

Have you ever experienced a time stamp problem that I reported, when you posted by using C# with WordPressSharp library?

@Blackcat156
Copy link

Hello, I now understand the reason for this problem.
I grabbed the content sent to the server
The time parameters are as follows:
<member> <name>post_date</name> <value> <dateTime.iso8601>20170413T07:21:04</dateTime.iso8601> </value> </member> <member> <name>post_modified</name> <value> <dateTime.iso8601>20170413T07:21:04</dateTime.iso8601> </value> </member>
As you can see, time is using dateTime. iso8601
But most of the time, servers are UTC World Standard Time.
This time is eight hours apart from UTC time.
So should
DateTime dateTime = post.PublishDateTime.AddHours(-8);
I don't know if you and I have the same problem. I can only tell you what I found.

The following is a complete send request

<?xml version="1.0"?> <methodCall> <methodName>wp.editPost</methodName> <params> <param> <value> <i4>1</i4> </value> </param> <param> <value> <string>username</string> </value> </param> <param> <value> <string>pass</string> </value> </param> <param> <value> <i4>userid</i4> </value> </param> <param> <value> <struct> <member> <name>post_id</name> <value> <string>post_id</string> </value> </member> <member> <name>post_type</name> <value> <string>post</string> </value> </member> <member> <name>post_title</name> <value> <string>title</string> </value> </member> <member> <name>post_status</name> <value> <string>publish</string> </value> </member> <member> <name>post_date</name> <value> <dateTime.iso8601>20170413T07:21:04</dateTime.iso8601> </value> </member> <member> <name>post_modified</name> <value> <dateTime.iso8601>20170413T07:21:04</dateTime.iso8601> </value> </member> <member> <name>post_content</name> <value> <string>content</string> </value> </member> <member> <name>post_author</name> <value> <string>56767</string> </value> </member> <member> <name>post_name</name> <value> <string>162445</string> </value> </member> <member> <name>link</name> <value> <string>https://acg12.com/162445/</string> </value> </member> <member> <name>custom_fields</name> <value> <array> <data /> </array> </value> </member> <member> <name>post_parent</name> <value> <string>0</string> </value> </member> <member> <name>terms</name> <value> <struct> <member> <name>category</name> <value> <array> <data> <value> <string>5977</string> </value> <value> <string>5978</string> </value> </data> </array> </value> </member> </struct> </value> </member> <member> <name>post_excerpt</name> <value> <string /> </value> </member> <member> <name>comment_status</name> <value> <string>open</string> </value> </member> </struct> </value> </param> </params> </methodCall>

@Blackcat156
Copy link

I know that the difference between UTC time and ISO8601 is the way of expression.
Simply put. Iso8601 is a UTC time representation
I don't know why time has to be reduced by eight hours, but I can only do that.

@hiromi3
Copy link
Author

hiromi3 commented Jan 11, 2019

Hi,
Thank you for your reply to the time stamp problem.
Currently, I am not using WordPressSharp, because I am doing JavaScript programming mainly.
So, if I return to Csharp programming again, I want to test again by following your report.
I think that the WordPressSharp is a great tool, so I hope you continue to develop and improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants