#339 open
Bernerd Schaefer

Windows UTF Offset

Reported by Bernerd Schaefer | June 3rd, 2008 @ 05:44 PM

Comments and changes to this ticket

  • Bernerd Schaefer

    Bernerd Schaefer June 3rd, 2008 @ 05:47 PM

    I looked into this a bit today. Here's the solution I came up with for do_postgres.

    It would be great for someone with Windows to see if this actually works. If so, we can clean it up and put in the other adapters.

  • Bernerd Schaefer

    Bernerd Schaefer June 11th, 2008 @ 11:45 AM

    • → State changed from “new” to “open”

    This should hopefully work better, now. It still remains to figure out how to handle daylight savings time, but I don't /think/ there should be windows problems. Do let me know.

  • Bernerd Schaefer

    Bernerd Schaefer June 5th, 2008 @ 10:49 AM

    • → Title changed from “Windows UTF Offset” to “Windows UTC Offset”
  • Luis Lavena

    Luis Lavena June 5th, 2008 @ 06:36 PM

    It seems to be working, and could be applied, but got this error from it:

    1)
    'DataObjects::Postgres::Reader should return DateTimes using the current locale's Time Zone for TIMESTAMP WITHOUT TIME ZONE fields' FAILED
    expected: "2008-06-06T01:33:04+02:00",
         got: "2008-06-06T01:33:04+01:00" (using ==)
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:198
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/spec_helper.rb:74:in `select'
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:197
    

    It seems is taking one hour away from the timezone information.

    Moving to a timezone with no offset got another round of failures:

    
    1)
    'DataObjects::Postgres::Reader should return DateTimes using the current locale's Time Zone for TIMESTAMP WITHOUT TIME ZONE fields' FAILED
    expected: "2008-06-06T00:34:20+01:00",
         got: "2008-06-06T00:34:20+00:00" (using ==)
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:198
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/spec_helper.rb:74:in `select'
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:197
    
    2)
    'DataObjects::Postgres::Reader should return DateTimes using the current locale's Time Zone TIMESTAMP WITH TIME ZONE fields' FAILED
    expected: "2008-06-06T00:34:20+01:00",
         got: "2008-06-06T01:34:20+02:00" (using ==)
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:207
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/spec_helper.rb:74:in `select'
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:206
    
    3)
    'DataObjects::Postgres::Reader should return DateTimes using the current locale's Time Zone if they were inserted using a different timezone' FAILED
    expected: "2008-06-06T00:34:20+01:00",
         got: "2008-06-06T01:34:20+02:00" (using ==)
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:228
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/spec_helper.rb:74:in `select'
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:226
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:223:in `each'
    D:/Users/Luis/projects/oss/datamapper/do/do_postgres/spec/do_postgres_spec.rb:223
    
    
  • Bernerd Schaefer

    Bernerd Schaefer June 9th, 2008 @ 12:05 PM

    Luis,

    I think I have resolved all of these timezone issues for do_postgres.

    http://github.com/sam/do/commit/...

    If you can confirm that this does work for windows, I'll port it to do_mysql and do_sqlite, and we'll be set.

    Thanks,

    Bernerd

  • Luis Lavena

    Luis Lavena June 9th, 2008 @ 01:34 PM

    Close, only when timezone < 0:

    UTC-3 (Buenos Aires, my default timezone) works without issues,

    With Timezone set +1 (Paris), instead:

    
    1)
    'DataObjects::Postgres::Reader should return DateTimes using the current locale's Time Zone for TIMESTAMP WITHOUT TIME ZONE fields' FAILED
    expected: "2008-06-09T20:26:51+02:00",
         got: "2008-06-09T20:26:51+03:00" (using ==)
    
    

    I'm looking at it right now, I'll jump into #irc in a minute.

  • Bernerd Schaefer

    Bernerd Schaefer June 9th, 2008 @ 03:55 PM

    Luis, is this on Windows? How are you changing the timezone? Do you know how the local timezone is calculated?

    I ask because I wrote a script to run the specs with every timezone in the zoneinfo database on my OS X box, and all pass except Asia/Riyadh87-9 and Mideast/Riyadh87-9.

  • Luis Lavena

    Luis Lavena June 9th, 2008 @ 04:46 PM

    Yes.

    Tried specs with timezone -3 (Buenos Aires), changed from Timezone in Regional Settings.

    Tried also with timezone +1, added some debug information:

    
    		// Get localtime
    		time(&rawtime);
    		timeinfo = localtime(&rawtime);
    
    		fprintf(stderr, "localtime->tm_isdst = %d\n", timeinfo->tm_isdst);
    		is_dst = timeinfo->tm_isdst * 3600;
    
    		// Reset to GM Time
    		timeinfo = gmtime(&rawtime);
    
    		fprintf(stderr, "gmtime->tm_isdst = %d\n", timeinfo->tm_isdst);
    		gmt_offset = mktime(timeinfo) - rawtime;
    
    		fprintf(stderr, "(before) gmt_offset = %d\n", gmt_offset);
    
    		if ( is_dst > 0 )
    			gmt_offset -= is_dst;
    
    		fprintf(stderr, "(after) gmt_offset = %d\n", gmt_offset);
    
    

    Those are the results:

    
    localtime->tm_isdst = 1
    gmtime->tm_isdst = 0
    (before) gmt_offset = -3600
    (after) gmt_offset = -7200
    
    
  • Bernerd Schaefer

    Bernerd Schaefer June 10th, 2008 @ 09:37 AM

    You said this was for Paris, right? Because +2 is actually correct, since there is currently daylight savings time in Central Europe.

    http://www.timeanddate.com/libra...

  • Luis Lavena

    Luis Lavena June 10th, 2008 @ 10:14 AM

    Yes, you're correct, but:

    http://www.timeanddate.com/world...

    
    UTC/GMT Offset	
    Standard time zone:	UTC/GMT +1 hour
    Daylight saving time:	+1 hour
    Current time zone offset:	UTC/GMT +2 hours
    
    

    But now, check the following IRB output:

    
    irb(main):001:0> Time.now
    => Tue Jun 10 17:10:50 +0200 2008
    irb(main):002:0> Time.now.utc
    => Tue Jun 10 15:11:00 UTC 2008
    
    

    The expected value is correct, but the returned value from do_postgres is not, all due the increment of hour in is_dst condition.

    Sorry I cannot take a deeper look at it until weekend, been extremely busy the past days :-(

  • Luis Lavena

    Luis Lavena June 21st, 2008 @ 08:23 AM

    • → Title changed from “Windows UTC Offset” to “Windows UTF Offset”

    Thank you Bernerd for you hard work, but after extlib (new Pooling being merged) I can no longer run specs for do_postgres:

    
    

    deadlock 0x28b5580: sleep:- (main) - D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-111/lib/ruby/gems/1.8/gems/extlib-0.9.2/lib/extlib/pooling.rb:57

    deadlock 0x2d14898: sleep:- - D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-111/lib/ruby/gems/1.8/gems/extlib-0.9.2/lib/extlib/pooling.rb:35

    Too bad since they looked good, except, as we discussed the DST (daylight saving) issue.

    Please let me know when those changes will be part of the other adapters (sqlite3 and mysql).

    Thanks.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Attachments