Skip to content

Commit

Permalink
Update timestamp tests incl. test for tz -07:00
Browse files Browse the repository at this point in the history
fixes #63 Cannot build importer when host in timezone MST (-07:00)
  • Loading branch information
EHJ-52n committed Dec 12, 2016
1 parent 4090216 commit 38d20f0
Showing 1 changed file with 16 additions and 3 deletions.
Expand Up @@ -58,14 +58,27 @@ public void createTimestamp() throws Exception {

@Test public void
shouldSetAllValuesViaSetLong() {
shouldSetAllValuesViaSetLongUsingTimeZone(TimeZone.getDefault());
}

/*
* Test for Issue #63: Cannot build importer when host in timezone MST (-07:00)
*
* https://github.com/52North/sos-importer/issues/63
*/
@Test public void
shouldSetAllValuesViaSetLongUsingTimeZoneMST() {
timestamp.setTimezone((byte) -7);
shouldSetAllValuesViaSetLongUsingTimeZone(TimeZone.getTimeZone("MST"));
}

private void shouldSetAllValuesViaSetLongUsingTimeZone(final TimeZone tz) {
// given
final TimeZone tz = TimeZone.getDefault();
String sign = "-";
int rawOffset = tz.getRawOffset();
if (rawOffset>= 0) {
sign = "+";
}
rawOffset = Math.abs(rawOffset);
final int offsetInHours = rawOffset / millisPerHour;
final int hours = 12 + offsetInHours;
final int minutes = (rawOffset - (offsetInHours * millisPerHour)) / millisPerMinute;
Expand All @@ -74,7 +87,7 @@ public void createTimestamp() throws Exception {
// why minutes+1?
final int minutesTime = Integer.parseInt(minutesString)+1;
final String timeMinutesString = minutesTime < 10? "0"+minutesTime : Integer.toString(minutesTime);
final String offsetInHoursString = String.format("%02d", offsetInHours);
final String offsetInHoursString = String.format("%02d", Math.abs(offsetInHours));
final String asExpected = String.format("1970-01-01T%s:%s:00%s%s:%s",
hoursString,
timeMinutesString,
Expand Down

0 comments on commit 38d20f0

Please sign in to comment.