Giter Club home page Giter Club logo

Comments (4)

getodk-bot avatar getodk-bot commented on June 12, 2024

Comment by meletis
Wednesday Jan 27, 2016 at 20:28 GMT


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.

from briefcase.

yanokwa avatar yanokwa commented on June 12, 2024

@dcbriccetti You've been poking around JavaRosa. Can you please try to reproduce this issue?

from briefcase.

dcbriccetti avatar dcbriccetti commented on June 12, 2024

Sure, when my cortisol levels are very low. πŸ˜€

from briefcase.

ggalmazor avatar ggalmazor commented on June 12, 2024

I can reproduce this error with this test:

CsvFieldMappersTest.java:

  @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.

DateUtils.java#351:

    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.

from briefcase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.