The following sample illustrates a broken primitiveSystemOffset when DST is in action. I live in GMT+1 timezone.
- Code: Select all
DateAndTime year: 2008 month: 2 day: 14 hour: 13 minute: 30 second: 0
displays 2008-02-14T13:30:00+01:00
DateAndTime year: 2008 month: 4 day: 14 hour: 13 minute: 30 second: 0
displays 2008-04-14T13:30:00+01:00
This is wrong. On February 14, DST is not action so system offset is correct with +01:00.
However, on April 14th, DST is in action so system offset is WRONG, it should be +02:00.
Someone here once suggested using the following code for primitiveSystemOffset
- Code: Select all
primitiveSystemOffset
"Answer an <Integer> representing the westward displacement of system local time
from UTC in seconds. The value can be betwen 0 and 86400 minutes."
| daylightSavingInAction baseOffset dstOffset timezoneInformation |
timezoneInformation := OSTimeZoneInformation calloc: 1.
daylightSavingInAction := timezoneInformation getTimeZoneInformation.
baseOffset := timezoneInformation Bias.
dstOffset := timezoneInformation DaylightBias.
timezoneInformation free.
^(baseOffset + (daylightSavingInAction = PlatformConstants::TimeZoneIdDaylight ifTrue: [
dstOffset]
ifFalse: [0])) * 60
While this is nice, it just moves the problem, because now I get the following result
- Code: Select all
DateAndTime year: 2008 month: 2 day: 14 hour: 13 minute: 30 second: 0
displays: 2008-02-14T13:30:00+02:00
DateAndTime year: 2008 month: 4 day: 14 hour: 13 minute: 30 second: 0
displays: 2008-04-14T13:30:00+02:00
So my offset for April 14 is correct, but the offset for February 14 is wrong.
When using the following java code:
- Code: Select all
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = format.parse("2008-02-14T13:30:00");
Date date2 = format.parse("2008-04-14T13:30:00");
System.out.println(date);
System.out.println(date2);
Gives the following output:
Thu Feb 14 13:30:00 CET 2008
Mon Apr 14 13:30:00 CEST 2008
Any suggestions on how to fix this?