dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]DateTime.Now is WRONG :)


From: David Logan
Subject: Re: [DotGNU]DateTime.Now is WRONG :)
Date: Wed, 30 Jun 2004 22:00:50 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040316

David Logan wrote:

Hey guys, anyone know how come the DateTime class Now property returns the wrong time?

David Logan

address@hidden temp]$ cscc -o tt.exe tt.cs
address@hidden temp]$ ilrun tt.exe;date
6/30/04 10:37:46 PM -5
Wed Jun 30 21:37:47 MDT 2004
address@hidden temp]$ cat tt.cs
class Test
{
  static void Main()
  {
                       System.Console.WriteLine(DateTime.Now);
  }
}
address@hidden temp]$
_______________________________________________
Developers mailing list
address@hidden
http://dotgnu.org/mailman/listinfo/developers


Looking at the problem, it is in pnet/support/time.c in function ILGetTimeZoneAdjust. As shown below, it calls localtime(), and then modifies the returned timezone offset hours by one hour if the "isdst" variable is set. In my case, I my timezone is GMT-7. The returned timezone from the call is "GMT-6" and isdst=1. So this function modifies it by another hour and returns GMT-5.

The documentation for localtime and the tm struct is unclear. It seems that isdst=1 means that the returned timezone has already been modified for daylight savings. Is this correct? Should I inquire on the Unix newsgroup?

David Logan

ILInt32 ILGetTimeZoneAdjust(void)
{
#if !defined(__palmos__)
       static int initialized = 0;
       static int isdst = 0;
#ifdef HAVE_TM_GMTOFF
   static long timezone = 0;
#endif
       if(!initialized)
       {
/* Call "localtime", which will set the global "timezone" for us */
               time_t temp = time(0);
               struct tm *tms = localtime(&temp);
               isdst = tms->tm_isdst;
#ifdef HAVE_TM_GMTOFF
               timezone = -(tms->tm_gmtoff);
#endif
               initialized = 1;
       }
       return (ILInt32)(timezone - (isdst ? 3600 : 0));
#else
       /* TODO */
       return 0;
#endif
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]