[Mono-dev] DateTime.Now gives a wrong time

2011-10-12 Thread k0l0b0k . void
Hello. I'm using Mono 2.6.7 (distro) on Debian squeezy, fully up to date, in 
my little enterprise environment.
Some days ago, I've noticed a strangest behavior - all my services, based on 
mono shows a wrong time on calling DateTime.Now (with a difference of 1 hour 
ago). Any other services (php and RoR-based) gives normal current time.

I've created simple test, and build it directly on server:

using System;

class Test
{
public static void Main()
{
Console.WriteLine("{0}", DateTime.Now);
}
}


and got next output:
user@server:~# ./test.exe 
10/12/2011 13:09:07
user@server:~# date
Wed Oct 12 14:09:10 FET 2011

i.e. local time handles correctly by all software except mono (local timezone 
is set correctly). May be it is Debian-specific (coz mono does not update 
recently, and some days ago all was fine)? Should I post it to Debian 
maintainers?

Thanks in advice, I need to fix it urgently, there are 3 servers with mono-
based services, and the same issue.

server:~# mono -V
Mono JIT compiler version 2.6.7 (Debian 2.6.7-5)
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
TLS:   __thread
GC:Included Boehm (with typed GC and Parallel Mark)
SIGSEGV:   altstack
Notifications: epoll
Architecture:  amd64
Disabled:  none
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] DateTime.Now gives a wrong time

2011-10-12 Thread Federico Di Gregorio
On 12/10/11 13:42, k0l0b0k.v...@gmail.com wrote:
> Hello. I'm using Mono 2.6.7 (distro) on Debian squeezy, fully up to date, in 
> my little enterprise environment.
> Some days ago, I've noticed a strangest behavior - all my services, based on 
> mono shows a wrong time on calling DateTime.Now (with a difference of 1 hour 
> ago). Any other services (php and RoR-based) gives normal current time.

On my Debian box (using debian packaged Mono) everything is fine.

fog@ania:~$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> Console.WriteLine("{0}", DateTime.Now);
12/10/2011 14:18:58
csharp>

fog@ania:~$ date
Wed Oct 12 14:19:04 CEST 2011

Can you show us your env?

federico

-- 
Federico Di Gregorio   f...@initd.org
 Ubuntu is an ancient African word meaning "I can't configure Debian".
 -- somewhere on IRC



signature.asc
Description: OpenPGP digital signature
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] DateTime.Now gives a wrong time

2011-10-12 Thread Robert Jordan
On 12.10.2011 13:42, k0l0b0k.v...@gmail.com wrote:

> user@server:~# date
> Wed Oct 12 14:09:10 FET 2011

FET? This is an interesting time zone:
http://en.wikipedia.org/wiki/Further-eastern_European_Time

It seems that Mono is thinking that you're now on EET
(Eastern Europe Time, UTC+2), your former time zone.

Either you don't have correct time zone files or there is
a bug in Mono's GetTimeZoneData.

Unlike other apps that only show the current time, Mono
needs valid time probes for the whole year, so you can
have invalid time zone info even if other apps seems to work.

Maybe it helps when I tell you that on 2012/01/01 the bug will
vanish on its own :)

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] DateTime.Now gives a wrong time

2011-10-12 Thread k0l0b0k . void
> On my Debian box (using debian packaged Mono) everything is fine.
> 
> fog@ania:~$ csharp
> Mono C# Shell, type "help;" for help
> Enter statements below.
> csharp> Console.WriteLine("{0}", DateTime.Now);
> 12/10/2011 14:18:58
> csharp>
> 
> fog@ania:~$ date
> Wed Oct 12 14:19:04 CEST 2011
> 
> Can you show us your env?
> 
> federico
> 
> > user@server:~# date
> > Wed Oct 12 14:09:10 FET 2011
> 
> FET? This is an interesting time zone:
> http://en.wikipedia.org/wiki/Further-eastern_European_Time
> 
> It seems that Mono is thinking that you're now on EET
> (Eastern Europe Time, UTC+2), your former time zone.
> 
> Either you don't have correct time zone files or there is
> a bug in Mono's GetTimeZoneData.
> 
> Unlike other apps that only show the current time, Mono
> needs valid time probes for the whole year, so you can
> have invalid time zone info even if other apps seems to work.
> 
> Maybe it helps when I tell you that on 2012/01/01 the bug will
> vanish on its own :)
> 
> Robert


Hello guys, thanks for your replies. I think, I've understand the situation. 
Some weeks ago, Ukraine and Belarus has timezone changes by law, and now we 
are FET timezone (GMT+3, without DST). As Robert pointed, I've look into 
TimeZone.* methods, and their native implementations, and found, that wrong 
GMT offset brings by glibc's mktime function. But, it is not mktime bug 
(however, I'm not sure), it is mono issue - code from icall.c:5931:

memset (&start, 0, sizeof (start));

start.tm_mday = 1;
start.tm_year = year-1900;

t = mktime (&start);

I've found, that setting only tm_year in start struct is insufficiently. At 
least tm_mon must be set too, to avoid this issue. Simple test:

#include 
#include 
#include 

int main(int argc, char *argv[])
{
struct tm t;
memset(&t, 0, sizeof(t));
t.tm_year = 111; // 2011
t.tm_mon = 10;   // wrong tm_gmtoff will received if comment out this line
mktime (&t);
printf("2011: %d\n", t.tm_gmtoff);

return 0;
}

this is 100% reproducible inaccuracy for FET timezone, on all my accessible 
machines: 
* Debian Squeeze + mono 2.6.7 up to date
* Ubuntu 11.10 + mono 2.10.5 up to date
* Arch Linux + mono 2.10.5 up to date

on one machine, with Ubuntu 11.04, which is not updated last weeks, and stay 
on EEST timezone - all works fine.

I'm vote for setting month value to "start" struct - today it happen with FET, 
tomorrow it can be happen with any other timezone - world is changing all the  
time...

Also, thanks God, I'm saving all times as UTC+0 in my server databases ;)
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] DateTime.Now gives a wrong time

2011-10-12 Thread Robert Jordan
On 12.10.2011 22:05, k0l0b0k.v...@gmail.com wrote:
> Hello guys, thanks for your replies. I think, I've understand the situation.
> Some weeks ago, Ukraine and Belarus has timezone changes by law, and now we
> are FET timezone (GMT+3, without DST). As Robert pointed, I've look into
> TimeZone.* methods, and their native implementations, and found, that wrong
> GMT offset brings by glibc's mktime function. But, it is not mktime bug
> (however, I'm not sure), it is mono issue - code from icall.c:5931:
>
>  memset (&start, 0, sizeof (start));
>
>  start.tm_mday = 1;
>  start.tm_year = year-1900;
>
>  t = mktime (&start);
>
> I've found, that setting only tm_year in start struct is insufficiently. At
> least tm_mon must be set too, to avoid this issue. Simple test:
>
> #include
> #include
> #include
>
> int main(int argc, char *argv[])
> {
>  struct tm t;
>  memset(&t, 0, sizeof(t));
>  t.tm_year = 111; // 2011
>  t.tm_mon = 10;   // wrong tm_gmtoff will received if comment out this 
> line

tm_mon = 0 means January 1st 2011. Back then, the offset was GMT+2,
Eastern Europe Time, so the call is correct.

The problem is not tm_mon = 0, because Mono does it on purpose
to get the first day of the year:

https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L6013

Then it starts looping to find out when the GMT offset is changing:

https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L6038

This probably happened at some date in March:

https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L6063

Then it loops further to find out when the GMT offset changes again.
But this second change is never happening, because FET remains
forever at GTM+3 => Mono thinks it's still on DST for the rest of
the year.


I believe the fix is to remove the if-statement at

https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L6076

because the code inside the if-statement must be executed
regardless of is_daylight's value.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list