PostDate/UserTime and Timezone for Blog Posts

This post has 16 Replies | 7 Followers

Not Ranked
Posts 1
Points 35
JRoppert Posted: Mon, May 21 2007 8:34 AM

 Wow, the Blog Post Timestamp drives me crazy. I'm in Germany (Timezone CET, +1) and my server is located in (PST, -8). In Date/Time Settings, timezone is set to the servrs timezone and in the users profiles, timezone is set to the local (CET) timezone. In a default installation of CommunityServer 2006 the behaviour is as follows.

 (Assuming the writing and reading users have Timezone CET, +1 set)

- I write a post at 12 pm (CET)

- Posts table in database: PostDate = 3 am / UserTime = 12 pm (ok, so far)

- I am logged in and i read the posting, i see the posting timestamp is 9 pm. Ough, that's in the future. Bad stuff.

I figured out that i have to change all of the themes (post.aspx, postlist.aspx and taglist.aspx) to use PostDate instead of UserTime. That works so far. As a logged in user i see the correct posting timestamp of 12 pm.

Next problem: I want the anonymous users to see the timestamp according to my CET timezone. Quick try unveils that anonymous users always get the server time (PST). I changed the web.config in a way that the timezone default value in the profile definition is "1" which means CET. Does not work. Still PST times for anonymous users.

My next thought: Oh, we have a user "Anonymous" in the membership. Would be nice if i could define the default timezone of anonymous users in the profile of the user named "Anonymous". I set his timezone to +1 (CET). Hmpf, does not work. Still the PST times.

As i figured out, the problem is in User.cs, Method GetTimezone(DateTime date, bool isUTC) where Timezone calculation is skipped for anonymous users:

 

            if (IsAnonymous) return tmpDate;
            return tmpDate.AddHours(Profile.Timezone - CSContext.Current.SiteSettings.TimezoneOffset);

 

Why that? Is there any good reason to do so. I want timezone calculation even for anonymous users! (You can take that as a change request for the next release.)

So, how to get CET timestamps for anonymous users??? Any good ideas?

 

Next problem: I always get the timestamps in 12-hour format. Iwnat them in 24-hour format. The Parameter in Date/Time Settings has no effect, at least in blog postings. In most of the themes, there is a Format of hh:mm... hardcoded. Sounds like i have to change all the themes once more, right?

All in all, the timezone handling in CS (at least for blogs) is -beep- (i want to say the word with the B and the S but i assume that is on the blacklist Party Hat )  and must be strongly revised.

 
Summary:

  1. Is there an easier way to get non-server-timezone timestamps for blog posts than changing all the theme files?
  2. How to have anonymous users to see non-server-timezone timestamps for blog posts?
  3. Is there an easier way to get 24-hour format timestamps for blog posts than changing all the theme files?

 



 


 

Top 500 Contributor
Posts 84
Points 1,170
muro1 replied on Tue, Jul 31 2007 4:40 PM

I'm surprised that nobody, especially from Telligent, has answered this post.

I'm having the same problems even after many tests and double checks of my settings, I can't get something reliable. There is even a difference of time between forums posts and posts blogs. Here is my last test:

I'm in France, my local is GMT+1 (with daylight savings, that gives GMT+2 at this time), my user profile is set to GMT+1.

My web and database servers are in Arizona (Crystaltech), which is MST (GMT-7).

I write a blog post at 10:20 PM, on July 31 (that's 1:20 PM on July 1 in Arizona). This post appears for me as being posted on August 1 at 9:20 AM (!!!) and of course, I won't be able to see it before tomorrow morning Angry.

One minute later , I write a forum post. My local time in France is 10:21 PM, July 31. It appears as beeing posted at 9:21 PM July 31.

That is :

1 - Inconsistent
2 - Really annoying

Conclusion: host your CS site in the same time zone as where most of your users live or choose another community solution.

Telligent, do you have another solution? 

Thank you. 


 

 

 

  • | Post Points: 35
Not Ranked
Posts 8
Points 115
fabrikater replied on Sun, Dec 30 2007 11:34 AM

Same here, servers are in GMT-5, I am in GMT+1 and want the server to behave as if its located in GMT+1.

So Telligent, what about an anwser from your side?

Thanks in advance!

 

  • | Post Points: 5
Not Ranked
Posts 8
Points 115
fabrikater replied on Sun, Dec 30 2007 12:16 PM

Additional questions.

Why is it that CSBlog:WeblogPostData switches between PostDate and UserTime when loging on and off?

Why are you not saving the UTC DateTime to the database, wouldn't that prevented these problems?

 

Please help us!

  • | Post Points: 5
Not Ranked
Posts 8
Points 115

I also found that User.GetTimezone adds hours also to DateTime objects that are already correct.

Example:

In the default theme the following code prints the time (GMT+1 due to my profile setting) on which I wrote the post underneith each post.

<CSBlog:WeblogPostData Property="UserTime" LinkTo="Post" FormatString="MMM dd yyyy, hh:mm tt" runat="server" />

For the anonymous user this works but as soon as I logon *** happens in the User class:

tmpDate.AddHours(Profile.Timezone - CSContext.Current.SiteSettings.TimezoneOffset);

My server is in GMT-5 so this line results in 6 hours being added to an already correct DateTime.

  • | Post Points: 5
Not Ranked
Posts 8
Points 115

I also noticed that anonymous comments are added with UserTime and PostData set to DateTime.Now, which imo is incorrect.

I believe UserTime should be set to DateTime.Now.AddHours( timezone setting in web.config )

 

You should really save all dates as UTC/GMT and let the profile settings determine the value displayed.

Please change it!!!

  • | Post Points: 5
Top 50 Contributor
Posts 404
Points 5,890
TelligentSupportTeam
ryhoward replied on Wed, Jan 2 2008 11:41 AM

For the timezone differences on the posts...Have you tried going into the control panel's date / time settings, and setting your default value there?

 

 

Ryhoward.com - Community Server from the Support Side of things. Technical tips and ideas for CS users.

  • | Post Points: 20
Not Ranked
Posts 8
Points 115

Hi, thanks for your reply!

The date/time setting is set to the timezone in which the database server resides (GMT-5 in my case). That is what is should be set to, right? 

  • | Post Points: 20
Top 50 Contributor
Posts 404
Points 5,890
TelligentSupportTeam
ryhoward replied on Fri, Jan 4 2008 10:04 AM

 Yes, there is that setting in the control panel for the site itself, then there is the option to set the time zone per user on each user's profile. Is that not working for you?

Ryhoward.com - Community Server from the Support Side of things. Technical tips and ideas for CS users.

  • | Post Points: 20
Not Ranked
Posts 8
Points 115

No, unfortunately it is not working for me.

 

My settings are as follows:

  • Configuration panel: GMT-5 (should be set to same time zone as the database server)
  • Web.config: GMT+1 (This should make sure the anonymous user sees any DateTime as my local DateTime)
  • My account profile: GMT+1 (Where I am)

 

Now, when I am logged on and create a blog post, the control panel's "All Posts" overview shows the GMT+1 DateTime. (Correct)

 

However, when I view the blog post while still logged on, it shows the post's UserTime which is my GMT+1, but with .AddHours(Profile.Timezone - CSContext.Current.SiteSettings.TimezoneOffset). (Incorrect, result is GMT+7)

 

When I next logoff, and thus become the anonymous user, the blog post shows the GMT+1 DateTime. (Correct, UserTime is displayed, for the anonymous user the CS code does not adjust the DateTime. Which, on itself is still weird, I would expect the anonymous profile to correct a UTC/GMT DateTime to GMT+1 per the web.config setting)

 

When I next comment on the blog post, as the anonymous user, the comment displays the GMT-5 DateTime. (Incorrect, the same DateTime is saved to both UserTime and PostDate, I'd expect it to display GMT+1 per the web.config setting)

 

When I logon again and view the same comment, it displays the GMT+1 DateTime. (Correct, here there are also 6 hours added to the DateTime retrieved from the database)

 

The blog post itself shows the post's UserTime (GMT+1) but with .AddHours(Profile.Timezone - CSContext.Current.SiteSettings.TimezoneOffset), so in my case the code adds 6 hours to an already GMT+1 DateTime (1 - (-5) = 6).

This results in a blog post that I used for testing at the time of this writing, January 4th, 2008 6:19PM (GMT+1), displaying January 5th, 2008 12:19AM. (Incorrect)

 

I think that in some cases you save the wrong DateTime to the database, and in some cases you perform time zone adjustments that should not be done.

 

At this moment, for blog posts, you are saving to the database a UserTime GMT+1, and a PostDate GMT-5.

Wouldn't this all be solved if you would save only a single UTC/GMT DateTime to the database and let only the user profile setting determine what should be displayed?

 

I hope this reply explains what the problem is and is not confusing. I am looking forward to you reply.

  • | Post Points: 35
Top 50 Contributor
Posts 404
Points 5,890
TelligentSupportTeam

I believe I see what the issue is. Are you running your SQL Server and Windows Server as one? Or are they on seperate boxes?

Thanks,
Ryan Howard

Ryhoward.com - Community Server from the Support Side of things. Technical tips and ideas for CS users.

  • | Post Points: 20
Not Ranked
Posts 8
Points 115
Hi,
 
Yes, it were two separate boxes, I stopped using Community Server 2007.
If I can be of any assistance to help you resolve the issue for other customers then please let me know.
I'd be glad to answer any questions!
 
Thanks,
 
Kris

---

I believe I see what the issue is. Are you running your SQL SQL and Windows Server as one? Or are they on seperate boxes?

Thanks,
Ryan Howard




  • | Post Points: 20
Top 50 Contributor
Posts 404
Points 5,890
TelligentSupportTeam
ryhoward replied on Mon, Jan 14 2008 9:26 AM

Well it sounds like the problem is a mismatch on the time zones, meaning the server and sql box are in two different time zones. So when a post is made the sql box uses it's current time to stamp the post with. Then on the forums that's what you see.

 

Thanks,
Ryan

Ryhoward.com - Community Server from the Support Side of things. Technical tips and ideas for CS users.

  • | Post Points: 20
Not Ranked
Posts 8
Points 115
fabrikater replied on Mon, Jan 14 2008 10:21 AM

Let me see if I got some spare time and I will try to reproduce the issue on a single virtual server installation.
Then we'll know for sure!
 
Keep you updated!
 
Cheers,
 
Kris





Well it sounds like the problem is a mismatch on the time zones, meaning the server and sql box are in two different time zones. So when a post is made the sql box uses it's current time to stamp the post with. Then on the forums that's what you see.
 
Thanks,
Ryan




  • | Post Points: 20
Top 10 Contributor
Posts 3,564
Points 53,835
TelligentSupportTeam

One problem I've found is that hosts often tend to leave their servers set up to use -8GMT time, regardless if they're in a Pacific Time Region, Europe etc, and often they apply those rules to some servers, and not others, which might cause problems if your database server is on a different one to your webserver.

Community Server Documentation please rate articles you read

Nintendo Wiikly | My Blog

  • | Post Points: 5
Page 1 of 2 (17 items) 1 2 Next > | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com