nicko       2004/08/19 15:30:58

  Modified:    src/Layout XmlLayoutSchemaLog4j.cs
               src/Layout/Pattern RelativeTimePatternConverter.cs
  Log:
  Fixed DateTime handling, convert to UTC before any math operations involving 
2 DateTimes.
  
  Revision  Changes    Path
  1.6       +9 -1      logging-log4net/src/Layout/XmlLayoutSchemaLog4j.cs
  
  Index: XmlLayoutSchemaLog4j.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Layout/XmlLayoutSchemaLog4j.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XmlLayoutSchemaLog4j.cs   2 Aug 2004 09:44:11 -0000       1.5
  +++ XmlLayoutSchemaLog4j.cs   19 Aug 2004 22:30:57 -0000      1.6
  @@ -39,6 +39,9 @@
        {
                #region Static Members
   
  +             /// <summary>
  +             /// The 1st of January 1970 in UTC
  +             /// </summary>
                private static readonly DateTime s_date1970 = new 
DateTime(1970, 1, 1);
   
                #endregion
  @@ -174,7 +177,12 @@
                        writer.WriteAttributeString("logger", 
loggingEvent.LoggerName);
   
                        // Calculate the timestamp as the number of 
milliseconds since january 1970
  -                     TimeSpan timeSince1970 = loggingEvent.TimeStamp - 
s_date1970;
  +                     // 
  +                     // We must convert the TimeStamp to UTC before 
performing any mathematical
  +                     // operations. This allows use to take into account 
discontinuities
  +                     // caused by daylight savings time transitions.
  +                     TimeSpan timeSince1970 = 
loggingEvent.TimeStamp.ToUniversalTime() - s_date1970;
  +
                        writer.WriteAttributeString("timestamp", 
XmlConvert.ToString((long)timeSince1970.TotalMilliseconds));
                        writer.WriteAttributeString("level", 
loggingEvent.Level.ToString());
                        writer.WriteAttributeString("thread", 
loggingEvent.ThreadName);
  
  
  
  1.3       +6 -3      
logging-log4net/src/Layout/Pattern/RelativeTimePatternConverter.cs
  
  Index: RelativeTimePatternConverter.cs
  ===================================================================
  RCS file: 
/home/cvs/logging-log4net/src/Layout/Pattern/RelativeTimePatternConverter.cs,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RelativeTimePatternConverter.cs   16 Feb 2004 02:10:53 -0000      1.2
  +++ RelativeTimePatternConverter.cs   19 Aug 2004 22:30:57 -0000      1.3
  @@ -44,12 +44,15 @@
                /// <summary>
                /// Internal method to get the time difference between two 
DateTime objects
                /// </summary>
  -             /// <param name="start">start time</param>
  -             /// <param name="end">end time</param>
  +             /// <param name="start">start time (in the current local time 
zone)</param>
  +             /// <param name="end">end time (in the current local time 
zone)</param>
                /// <returns>the time difference in milliseconds</returns>
                private static long TimeDifferenceInMillis(DateTime start, 
DateTime end)
                {
  -                     return ((end.Ticks - start.Ticks) / 
TimeSpan.TicksPerMillisecond);
  +                     // We must convert all times to UTC before performing 
any mathematical
  +                     // operations on them. This allows use to take into 
account discontinuities
  +                     // caused by daylight savings time transitions.
  +                     return (long)(end.ToUniversalTime() - 
start.ToUniversalTime()).TotalMilliseconds;
                }
        }
   }
  
  
  

Reply via email to