1

I´m having trouble when working with dates in my Web MVC project. It is running in my local IIS. The problem is, I live in Brazil, Rio de Janeiro, so according to a this my TimeZone is

        E. South America Standard Time

That means Brasilia with GMT-3. And it is perfect and correct.

But when running my unit test in NCrunch, for the code above:

        System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();
        var zone = TimeZone.CurrentTimeZone;
        var time = zone.GetDaylightChanges(DateTime.Today.Year);
        var start = time.Start;
        var end = time.End;
        var offset = zone.GetUtcOffset(DateTime.Now);

I ´m receiving the following results:

        zone.DaylightName = "E. South America Daylight Time" (CORRECT)
        time.Start = {18/10/2014 23:59:59} (CORRECT FOR 2014)
        time.End = {15/02/2014 23:59:59} (CORRECT FOR 2014)
        offset = {-2:00:00} (WRONT, it is -3) -> it would be right if there was no daylight saving time
        TimeZone.IsDaylightSavingTime(DateTime.Now) = true

The problem is that when I send it to Postgres DB it saves as timestampZ so, it saves correct

        for example 01/01/01 01:01:01 -3

But then when retrieving from database, it comes the mistake, because of the wrong offset I get

        01/01/01 02:01:01 -3

It is runnin in local IIS but it should use the local computer time, right? If I go to my computer settings is is correct (Brasilia Time, GMT-3)

How should I proceed?

Thanks in regards,

Edit

Actually the problem is in my PostgresSQL. It is saving the current time with offset -3 instead of -2 and that is all the problem. When i get it back in server it adds one hour...

How do I enable DST in Postgres?!?

Community
  • 1
  • 1
Gabriel Bastos
  • 540
  • 1
  • 7
  • 16
  • 1
    -2 is correct for a timezone in DST for Brazil when the non-DST timezone is -3. http://www.timetemperature.com/samerica/brazil_time_zone.shtml – John Koerner Dec 21 '14 at 14:44
  • Ohhh yeah, you are right so probably the problem is at my postgresSQL.. Because it is saving the current time with offset -3... – Gabriel Bastos Dec 21 '14 at 16:42
  • 2
    Depending on what you're trying to achieve, you might want to consider storing date/times in the database in UTC? – Stephen Kennedy Dec 21 '14 at 17:21

0 Answers0