Over-clocking as in "More clocks per post".
Figure 1: Flying saucer landing on Lake Forggensee Germany
In the past I ran into a bunch of issues that were caused by BlogEngine.NET's implementation of storing and retrieving time stamps of posts. During the submission of new posts the "pubTime" is treated as the local time of the publisher's computer and stored in this format. Once the post is being served, an offset is calculated based on the "Server time offset" parameter.
Note: The following discussion also applies to the posting of pages and the commenting system.
Figure 2: BlogEngine.NET basic settings web form showing "Server time offset" parameter
In this post I am discussing an in my opinion better approach of dealing with time zones and time stamps.
BlogEngine users and their requirements
Here is how BlogEngine users care about time stamps.
Blog Post Publisher
The publisher usually considers the following circumstances before pushing the "Publish" button:
"Do I want to publish the post right away or do I want to schedule the post to be published some time in the future?"
"While I am traveling across time zones, do I want the post to be published with the local time of my current time zone or the local time of my home town?" If the post publisher prefers to publish using the local time during cross-time-zone travel, she also might be looking for a way to specify the locality or place that is associated with this local time.
For example my home town is Mission Viejo, CA, USA. California has Pacific Standard Time (GMT -8). Lets say I am traveling to Germany to visit my relatives. Here the time zone is (GMT+1). The clocks in Germany are 9 hours ahead of the clocks in California. At 3 PM (1500) I am blogging about an event that happened just minutes ago. I witnessed the landing of an UFO. I published a post called "UFO sighting in Germany". A few weeks later I am curious about the UFO sighting and hope that the blog post that resulted in the sighting would help me remembering when and where I saw the UFO. Lucky me, my blog post tells me straight away that the UFO was sighted at 3 PM in Germany.
Blog Post Reader
The reader on the other hand might be interested in the following pieces of information:
- Where was the post published?
- What time was it here in my time zone?
- What time was it in the time zone of the post publisher when the post was submitted?
Figure 3: Drawing on napkin with banana showing globe with local time displays
Changes to the way how blog posts are stored, published and rendered are necessary to meet these requirements. Of course these changes should be as transparent to the user as possible.
The pubTime needs to be stored as UTC time. Time comparisons on the server should be based on UTC time as well and not based on local time. Just assume that the server is located on a spaceship and circles around our planet. Its clock is using UTC time. As a consequence for BlogEngine.NET the "Server time offset" parameter needs to be removed.
Blog publishing apps
Publish as UTC time
The applications that are being used to publish blog posts should use UTC time for posts that are set to be published some time in the future. If the pubTime is not explicitly specified, then the server should use UTC time to set this value at the time when the post is submitted. All processing is done based on UTC time. Windows Live Writer for example is sending explicit publish time values as UTC time already.
Add time zone information to blog post
The time zone from which the post was published needs to be stored together with the post itself. This is the only way to restore later the publishers local time.
Here are two challenges: First we need to find the time zone where the post writer is publishing from and then we have to add the time zone information to the blog post record. Here is a list of possible approaches to retrieve the time zone from the blog publisher:
- Ask the blog author to enter the time zone manually during the editing of the post
- Ask the blog author to enter geo coordinates as latitude and longitude values during the editing of the post
- Ask the blog author to enter a geo location as a place during the editing of a post
- Ask the blog author to enter a nick name for a location that gets mapped into a time zone based on a pre-configured list
- Infer the time zone from the geo location information provided by the blog author
- Infer the time zone from the ip address of the client connection during the post submission
- Use a default time zone setting on the server to specify the desired publishing time zone
How the time zone inference should be implemented depends on the traveling habits of the publisher. I hardly leave my time zone. Using a default time zone would do the trick in 95 percent of all cases. And for the other 5 percent I could imagine using a list similar to the QuickLinks. Somebody who travels a lot to different places might appreciate an automatic time zone inference based on the IP address. I am considering a layered approach that covers a wide variety of usage scenarios. This could be implemented as a BlogEngine extension.
The second challenge is to store the inferred information. Ideally a pubTimeZone field would be nice in the post, page and comment records. As an alternative embedding this information in the Microformats way would be an option as well.
Blog reader apps
Figure 4: Blog posts time and location data
Getting the time stamps and time zones right is straight forward. There are many options. Making it transparent to the user is an interesting challenge. It will require some plumbing changes in the core on top of a BlogEngine extension.
Mads Kristensen's Time Zone Trouble post
Codeplex Issue: WLW sends publish date in UTC time
Getting the Time Zone from a Web Browser
Get longitude and latitude of a place
Location lookup based on IP address