Argh… this is annoying. I was mucking around with a Callback function in Anthem that's sending back a date from JavaScript. Anthem allows making JSON page method calls to the server, but it doesn't provide two way JSON support so any data passed from the client passes values as strings.
Well, dates come back in a really fucked up toString() format that is a pain to parse.
JavaScript has Date.toUTCString() and Date.toGTMString(), but these are returning different things for different browsers. IE basically returns UTC strings while Mozilla returns GMT strings – the only difference between the two really is the UTC or GMT designator.
So on the client I ended up with this code:
Anthem_InvokePageMethod('RefreshMessages',
[ChatId,LastOn.toUTCString()],
RefreshMessagesCallback);
Which in turns calls a method that looks like this:
public string RefreshMessages(string ChatId, string LastOn)
{
// *** IE returns UTC - Mozilla returns GMT
LastOn.Replace("UTC", "GMT");
string[] fmt = {"r","R","ddd, dd MMM yyyy HH:mm:ss"};
DateTime Time;
if (!DateTime.TryParseExact(LastOn, fmt, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out Time))
return "";
string MessagesHtml = Message.GetMessagesHtml(Time, this.txtChatId.Text);
return MessagesHtml;
}
The r format allows for GMT formatting and it looks like it works. I don't think it works for date time strings that have timezone offsets, but the toUTCString() function doesn't set that luckily.
This is one place where Anthem is lacking a little. A two way JSON parser would really make life easier. I've built a beginning parser into wwHoverPanel and it skirts this issue.
This is a little thing but I wasted probably a half an hour on this plus now another 10 minutes on this post <g>... Hope this helps somebody out.
Other Posts you might also like