When a CommonTS is constructed with positive gmtOffset, depending on the default timezone and the date the question the CommonTS.getValueAsCalendar() method returns a Calendar that is off by one or more hours. The attached test cased highlights the problems.
The testcases construct CommonTS objects using the setValue(Calendar) and when I'm in the following talking about the tested timezone, it means the timezone this Calendar is initialized with.
The culprit is the CommonTM.getValueAsCalendar method which constructs a Calendar implicitly based on the default timezone. The testcases reveals three problems. :
Some examples:
Default timezone: Europe/Copenhagen (GMT+01:00 AND uses daylight savings)
Tested timezone: GMT+01:00
Date tested: 2015-06-01, i.e DST is active
Returned Calendar is off by one hour as it has been constructed with default timezone which has DST.
Default timezone: Europe/Copenhagen (GMT+01:00 AND uses daylight savings)
Tested timezone: Europe/London (GMT AND uses daylight savings)
Date tested: 2015-06-01, i.e DST is active
Returned Calendar is off by one hour as it has been constructed with default timezone which has DST.
Default timezone: Europe/London (GMT AND uses daylight savings)
Tested timezone: Europe/London (GMT AND uses daylight savings)
Date tested: 2015-06-01, i.e DST is active
The returned Calendar is off one by as we enter the if-block but the constructed ZoneID is invalid.
A final note: when I'm comparing calendars, I'm actually comparing the Date returned by Calendar.getTime().
Great input.
Obviously, fixing the Timezone string for positive offsets makes most of your test configurations run.
The default calendar timezone is somewhat harder to tackle; mostly due to the dumb fact that HL7 allows plain TMs together with (implicit) timezone information. And it's impossible to derive DST from just having a time and not a full date.
Any ideas?
Last edit: Christian Ohr 2015-07-13
Thank you for the answer and for looking at this issue.
I have an idea, but I need to make some further investigations. I'll return shortly.
Instead of starting with Calendar.getInstance(), construct a Calendar based on gmtOffset and only use a default constructed Calendar as a fallback; see suggested code below.
In the below I have also slightly modified the timezone ID generation logic:
The following makes both the existing tests and my attached tests run without errors:
.
Unrelated to this particularly issue: the .classpath file for both the hapi-base and hapi-test Eclipse projects references some slf4j jar files in version 1.6.6. These entries must be removed in order for Eclipse to work. Additionally hapi-test references velocity-1.6.3.jar which also must removed from the .classpath file.
Last edit: Rolf Thorup 2015-07-28
Oh cool. I will look into this.
The .project files should probably not checked in at all
Verfied and comitted your fix except that I chose to construct the time zone string using string formatter. I hope it's ok that I added your test cases as well to prevent regressions.
Thanks again for your effort!