MailMessage renderer patch (time/date format)
- From: Kevin Godby <godbyk yahoo com>
- To: dashboard-hackers gnome org
- Subject: MailMessage renderer patch (time/date format)
- Date: Fri, 27 Feb 2004 03:11:37 -0600
Hello.
I've attached a patch for the MailMessage renderer that should fix the
date/time formatting issues for non-US locales. <crosses fingers>
It appears that there's a bug in either mono 0.30.1 or icu that was
causing this to crash originally. But I've found that mono 0.30.2 and
icu version 2.6 or above seems to fix it.
I'd appreciate it if a couple non-en-US folks could try the new version
of mono/icu and this patch to see if it works okay for you.
The patch also displays the time/date in the current time zone (whereas
previously they were in UTC).
If this works okay, it may be added to cvs.
----
Kevin Godby <godbyk yahoo com>
--- dashboard-pristine/renderers/MailMessageMatchRenderer.cs 2004-02-19 19:44:02.000000000 -0600
+++ dashboard/renderers/MailMessageMatchRenderer.cs 2004-02-27 02:57:45.000000000 -0600
@@ -13,6 +13,7 @@
using System.Collections;
using System.IO;
using System.Xml;
+using System.Globalization;
namespace Dashboard {
@@ -25,6 +26,8 @@
public override string HTMLRenderMatches (ArrayList matches)
{
+ DateTime StartExec = DateTime.Now;
+
StringWriter sw = new StringWriter ();
XmlWriter xw = new XmlTextWriter (sw);
@@ -42,13 +45,13 @@
xw.WriteAttributeString ("width", "100%");
// Sort results by date (newest first)
- IComparer matchcomparer = new MatchComparer ();
- matches.Sort (matchcomparer);
+ IComparer mailmessagedatecomparer = new MailMessageDateComparer ();
+ matches.Sort (mailmessagedatecomparer);
bool color_band = true;
foreach (Match m in matches) {
- xw.WriteRaw (HTMLRenderSingleMailMessage (m, color_band));
+ HTMLRenderSingleMailMessage (m, color_band, xw);
color_band = ! color_band;
}
@@ -58,10 +61,12 @@
// close the xhtml doc
xw.Close ();
+ Console.WriteLine ("..Renderer: MailMessage.. elapsed time {0}", DateTime.Now - StartExec);
+
return sw.ToString ();
}
- private string HTMLRenderSingleMailMessage (Match m, bool color_band)
+ private void HTMLRenderSingleMailMessage (Match m, bool color_band, XmlWriter xw)
{
// Make the date look pretty
string maildate = Convert.ToString (m ["SentDate"]);
@@ -70,11 +75,8 @@
Message msg = new Message ();
msg.Initialize (m);
- Console.WriteLine ("To: {0}\nFrom: {1}\nSubject: {2}\nDate: {3}",
- msg.Recipient, msg.Sender, msg.Subject, msg.SentDate);
-
- StringWriter sw = new StringWriter ();
- XmlWriter xw = new XmlTextWriter (sw);
+ // Console.WriteLine ("To: {0}\nFrom: {1}\nSubject: {2}\nDate: {3}",
+ // msg.Recipient, msg.Sender, msg.Subject, msg.SentDate);
xw.WriteStartElement ("tr");
@@ -151,29 +153,29 @@
xw.WriteEndElement (); // td
xw.WriteEndElement (); // tr
-
- return sw.ToString ();
}
private string ParseMailDate (string maildate)
{
- // I don't know if the date format returned by the EvoMail backend
- // is always the same or if it is dependent upon the locale.
- // Assuming en-US throughout.
+ // The dates returned by these functions are UTC
DateTime ParsedDate = DateTime.Parse (maildate);
DateTime today = DateTime.Today;
+ // Display in the current time zone
+ TimeZone localZone = TimeZone.CurrentTimeZone;
+ ParsedDate = localZone.ToLocalTime (ParsedDate);
- // FIXME: Terrible, horrible, no good, very bad hack
+ // Let's see if we can't use the proper date and time formats here...
+ CultureInfo ci = new CultureInfo (CultureInfo.CurrentCulture.Name);
if (today.Date == ParsedDate.Date) {
// Display the time only
- return ParsedDate.ToShortTimeString ();
+ return ParsedDate.ToString ("t", ci);
}
if (today.Year != ParsedDate.Year) {
// Show the year mm/dd/yyyy or dd/mm/yyyy
- return ParsedDate.ToShortDateString ();
+ return ParsedDate.ToString ("d", ci);
}
return ParsedDate.ToString ("ddd, MMM d");
@@ -389,7 +391,7 @@
Descending
}
- public class MatchComparer : IComparer {
+ public class MailMessageDateComparer : IComparer {
// Reverse-sort -- newest messages first
private SortDirection m_direction = SortDirection.Descending;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]