Time format in metaWeblog API: find the missing time zone
The time foramt in metaWeblog API is ISO8601, it is constructed by year, month, day, hour, minute and seconds of the time. Here's an example:
20070418T07:05:23It means 5 minutes and 23 seconds pass 7, April 18th, 2007.
The problem with this format is that it doesn't provide time zone info. The API doesn't specify which is the default time zone, so different implementations could have different definition on this issue. This could result in a serious problem when an application communicates with a server using this API and tries to get an accurate time info.
Most servers assume the time zone in the API is UTC, but that's not always the case, sometimes they use their local time zone as the default time zone.
This issue make it difficult for a tool that uses metaWeblog API to get accurate result on different servers. For example my BlogSync. Because you never know if your time info is understood correctly by the server.
However I figured out a solution, based on the following assumption:
- If no time info is specified in the parameter when calling posting article command, the server will use its local current time as the publish time of that article.
- The server will use the same standard to handle input time format and output time format. That is to say, when you send a time to the server, and fetch it back later, it should be the same with the one you send out earlier.
With these 2 assumptions in mind, we can imagine that if we send a command to create a new article without specifying time information, and then acquire the newly created article, read its publish time. The time should also be approximately the server local time, in its local time zone setting. We can then compare it with the time we send the first command, and find out exactly how many hours' difference these two times have.
With this information, we can finally calculate our goal -- the real time zone of the server, which enables us to reformat all time values we need to send to the server and expect them to be processed correctly by the server.
The procedure implemented in BlogSync is as follows:
- Call "blogger.newPost" method to create a new article without specifying publish time. And log the current time simultaneously.
- When the "newPost" method is executed successfully, log the postid server returns.
- Call "metaWeblog.getPost" using the postid we just received to fetch the article, read its publish time.
- Compare the time with the one we logged in the first step, it is the time difference between our local time and the server.
