Mapper { TimeZone convertTimeZone(String timeZone) { String[] timeZoneTokens = timeZone.split(":"); int hours = 0; int minutes = 0; if (!timeZone.startsWith("Z") && !timeZone.startsWith("z")) { if (timeZoneTokens.length > 0) { hours = Integer.parseInt(timeZoneTokens[0]); } if (timeZoneTokens.length > 1) { minutes = Integer.parseInt(timeZoneTokens[1]); if (timeZone.startsWith("-")) { minutes = minutes * -1; } } } int timeZoneOffsetMilliSeconds = ((hours * 60) + minutes) * 1000; return new SimpleTimeZone(timeZoneOffsetMilliSeconds, ""); } Mapper(); String convertDateTime(Date date); Date convertDateTime(String isodate);  }
@Test @Parameters({ " 00:00, 0, 0", "+00:00, 0, 0", "-00:00, -0, 0", " 00:30, 0, 30", "+00:30, 0, 30", "-00:30, 0, -30", " 05:00, 5, 0", "+05:00, 5, 0", "-05:00, -5, 0", " 05:30, 5, 30", "+05:30, 5, 30", "-05:30, -5, -30", " 00, 0, 0", "+00, 0, 0", "-00, 0, 0", "+05, 5, 0", "-05, -5, 0", }) public void testConvertTimeZone(String isoTimeZone, int expectedHours, int expectedMinutes) { TimeZone timeZone = mapper.convertTimeZone(isoTimeZone); int actualOffsetMinutes = timeZone.getRawOffset() / 1000; int actualHours = actualOffsetMinutes / 60; int actualMinutes = actualOffsetMinutes % 60; assertEquals(expectedHours, actualHours); assertEquals(expectedMinutes, actualMinutes); }