-
Notifications
You must be signed in to change notification settings - Fork 156
Briefcase is not respecting the daylight savings time offset when exporting (date-) time fields. #19
Comments
Okay, the solution seems to be somewhere else, please ignore the "additional information" in the issue description above. This is the line 412 in DateUtils.java c.setTime(new Date(DateUtils.getDate(f, "UTC").getTime() + (((60 * timeOffset.hour) + timeOffset.minute) * 60 * 1000) + dstOffset)); ...and this is how we think it can be solved... long dstOffset = TimeZone.getDefault().inDaylightTime(new Date()) ? TimeZone.getDefault().getDSTSavings() : 0L;
c.setTime(new Date(DateUtils.getDate(f, "UTC").getTime() + (((60 * timeOffset.hour) + timeOffset.minute) * 60 * 1000) + dstOffset)); This is a test case that fails without the above change: public void testParseTime_with_DST() throws Exception {
Locale.setDefault(Locale.US);
TimeZone backupZone = TimeZone.getDefault();
// this is a timezone that operates DST every day of the year!
SimpleTimeZone dstTimezone = new SimpleTimeZone(
7200000,
"Europe/Athens",
Calendar.JANUARY, 1, -Calendar.SUNDAY,
0, SimpleTimeZone.UTC_TIME,
Calendar.DECEMBER, 31, -Calendar.SUNDAY,
3600 * 24, SimpleTimeZone.UTC_TIME,
3600000);
TimeZone.setDefault(dstTimezone);
String time = "12:03:05.000Z";
Date date = DateUtils.parseTime(time);
DateFormat formatter = DateFormat.getTimeInstance();
String formatted = formatter.format(date);
// It should shift 3 hours, 2 for the zone and 1 for DST.
assertEquals("3:03:05 PM", formatted);
TimeZone.setDefault(backupZone);
} Please note that if that change is adopted, then the first call of "testCycle()" in the "testParity" test in DateUtilsTests.java will start failing when DST will become effective for the building workstation. |
@dcbriccetti You've been poking around JavaRosa. Can you please try to reproduce this issue? |
Sure, when my cortisol levels are very low. 😀 |
I can reproduce this error with this test:
@Test
public void time_parsing_on_plus_2_daylight_saving_time_zone() {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Madrid"));
scenario = nonGroup(DataType.TIME);
List<Pair<String, String>> output = scenario.mapSimpleValue("07:00:00.000Z");
assertThat(output.get(0).getRight(), is("10:00 AM"));
} I think this would be a JR bug, not a Briefcase bug.
public static Date parseTime (String str) {
DateFields fields = getFields(new Date());
fields.second = 0;
fields.secTicks = 0;
if (!parseTime(str, fields)) {
return null;
}
// time zone may wrap time across midnight. Clear that.
fields.year = 1970;
fields.month = 1;
fields.day = 1;
return getDate(fields);
} Maybe using the current date for the date fields would make it work. |
Thursday Jul 09, 2015 at 19:44 GMT
Originally opened as getodk/getodk#1075 (1 comment(s))
Originally reported on Google Code with ID 1074
Reported by
meletis@surveycto.com
on 2014-10-17 11:12:23The text was updated successfully, but these errors were encountered: