Bad dating in Blog Archive.

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
7/20/2008 8:13:51 PM
Gravatar
Total Posts 4
I'd take one Tommy Flowers over ten Alan Turings.

Bad dating in Blog Archive.

   I had a problem with the blog module in that when I clicked on the archive link for July it listed the posts correctly, but titled the section "Posts from January". This turned out to be because my server is using en-GB date format rather than en-US. I fixed the code by changing the line

this.litHeader.Text = Resource.BlogArchivesPrefixLabel
+ DateTime.Parse(month.ToString() + "/1/" + year.ToString()).ToString("MMMM, yyyy");

to

IFormatProvider culture = new CultureInfo("en-US", true);
this.litHeader.Text = Resource.BlogArchivesPrefixLabel
+ DateTime.Parse(month.ToString() + "/1/" + year.ToString(), culture).ToString("MMMM, yyyy");

in the BlogArchiveView.aspx.cs file.

    Regards,

       Cormac.

 

 

7/20/2008 11:11:57 PM
Gravatar
Total Posts 4
I'd take one Tommy Flowers over ten Alan Turings.

Re: Bad dating in Blog Archive.

Just noticed that

IFormatProvider culture = new CultureInfo("en-US", true);

Should probably read

IFormatProvider culture = new CultureInfo("en-US", false);

to prevent problems in cases where the server is en-US and someone has changed the servers default date format.

    Regards,

       Cormac.

7/21/2008 6:07:08 AM
Gravatar
Total Posts 18439

Re: Bad dating in Blog Archive.

Hi,

Thanks for letting me know. You are right that it is a bug as it was displaying the wrong month, but your solution is incorrect as it would only work for en-US and not other cultures.

The problem was occuring in DateTime.Parse because by default it will use the culture of the currently executing thread. The culture to use is determined by the browser language settings not the server, though the server can be configured to force a culture rather than use the browser culture.

If you look in Web.config you'll see this:

<globalization
culture="auto:en-US"
uiCulture="auto:en-US"
requestEncoding="utf-8"
responseEncoding="utf-8"
fileEncoding="iso-8859-15" />

The "auto:" part tells the server to use the preferred culture as determined by the browser, but if resources for that language are not available it will fall back to the default which is specified after the colon.

So, in this case, its was your browser set to en-GB, not the server. I was able to produce the same symptom on this site by changing my browser language to en-GB. So the DateTime.Parse was not correctly determining which part was the month because in en-GB its backwards from en-US.

I have made the correct fix here that respects the culture but displays the correct month in all cases.

DateTime selectedMonth = DateTime.Now;
try
{
selectedMonth = new DateTime(year, month, 1);
}
catch(Exception)
{}

this.litHeader.Text = Resource.BlogArchivesPrefixLabel
+ selectedMonth.ToString("MMMM, yyyy");

Using the constructor new DateTime(year, month, 1), there is no ambiguity which number is the month as with .Parse(...)

So this fixes the problem without forcing en-US

I will have this fix in svn trunk by tonight.

Best,

Joe

7/21/2008 8:07:35 AM
Gravatar
Total Posts 4
I'd take one Tommy Flowers over ten Alan Turings.

Re: Bad dating in Blog Archive.

Thanks for that. Fix works fine.

  Regards,

    Cormac.

You must sign in to post in the forums. This thread is closed to new posts.