Over-clocking BlogEngine.NET

by Klaus Graefensteiner 8. April 2008 00:50

Over-clocking as in "More clocks per post".

Flying saucer landing in lake Forggensee

Figure 1: Flying saucer landing on Lake Forggensee Germany

Introduction

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.

BlogEngine.NET basic settings web form showing server time offset parameter

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:

  1. Where was the post published?
  2. What time was it here in my time zone?
  3. What time was it in the time zone of the post publisher when the post was submitted?

Implementation

Drawing on napkin with banana showing globe with local time displays

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.

Server changes

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:

  1. Ask the blog author to enter the time zone manually during the editing of the post
  2. Ask the blog author to enter geo coordinates as latitude and longitude values during the editing of the post
  3. Ask the blog author to enter a geo location as a place during the editing of a post
  4. 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
  5. Infer the time zone from the geo location information provided by the blog author
  6. Infer the time zone from the ip address of the client connection during the post submission
  7. 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

Blog post time stamp and location data

Figure 4: Blog posts time and location data

The location and time information "Published at:", "Published from:" and "Geo;" displayed in figure 4 is for all readers identical no matter where they are when they are reading the blog. The "In your time:" is specific to the readers time zone. Implementing this feature requires also Time Zone inference. In this case it could be fairly easy. JavaScript provides an option to get the offset to GMT, which could be used to convert the pubTime from UTC to local time. There is a little issue though, if the reader is traveling, and doesn't change the time zones on his portable computer. In this case the time zone could be either selectable by the reader or again inferred using the http client's IP address.

Summary

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.

Related links

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

kick it on DotNetKicks.com

Tags: , , , ,

BlogEngine.NET | Photoshop

Comments

4/17/2008 1:14:48 AM #

Nanny Paloni

Thanks for pushing this.

Nanny Paloni United States |

4/17/2008 1:56:15 AM #

Scott

I now know where you live. muhahah.  Good article and thanks.  P.S. Nice lake near your house.

Scott United States |

5/7/2008 8:25:54 PM #

Andre Tagesgeld

Nice article, thanks. As I still use dasBlog on some of my sites (but not satisfied with it), this was a good introduction in tweaking BlogEngine.NET

Andre Tagesgeld Germany |

6/12/2008 5:42:18 AM #

Daniel

gracias por su valiosa información

Daniel Mexico |

6/20/2008 2:16:07 AM #

Mike Borozdin

I've come up with a JavaScript solution that basically converts the server time (not the server time actually, but the time that comes from BlogEngine.NET) that is set to GMT (just correct the time zone offset in the settings) and converts it to the local time of the user.

Here is the code:
www.mikeborozdin.com/.../...-Local-Time-Zones.aspx

Mike Borozdin Russia |

Comments are closed

About Klaus Graefensteiner

I like the programming of machines.

Add to Google Reader or Homepage

LinkedIn FacebookTwitter View Klaus Graefensteiner's profile on Technorati
Klaus Graefensteiner

Klaus Graefensteiner
works as Developer In Test and is founder of the PowerShell Unit Testing Framework PSUnit. More...

Open Source Projects

PSUnit is a Unit Testing framwork for PowerShell. It is designed for simplicity and hosted by Codeplex.
BlogShell is The tool for lazy developers who like to automate the composition of blog content during the writing of a blog post. It is hosted by CodePlex.

Administration

About

Powered by:
BlogEngine.Net
Version: 1.6.1.0

License:
Creative Commons License

Copyright:
© Copyright 2014, Klaus Graefensteiner.

Disclaimer:
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Theme design:
This blog theme was designed and is copyrighted 2014 by Klaus Graefensteiner

Rendertime:
Page rendered at 11/26/2014 10:19:51 AM (PST Pacific Standard Time UTC DST -7)