Skip to content

Zone offset without sign - should it be parseable or not? #502

@MenoData

Description

@MenoData

See also http://stackoverflow.com/questions/36911917/convert-java-lang-string-to-oracle-sql-timestamptz

My evaluation: It should only be parseable in lax mode where a missing sign might be interpreted as AHEAD_OF_UTC. Unfortunatley Time4J is a little bit too strict here. However, omitting the sign is not really smart because such text (like "8" or "8:00") could also be interpreted as anything else (trailing characters) but not a timezone offset. So the solution should be to allow a missing sign only in lax but not smart or strict mode.

Side note: If the sign was not omitted then a solution of given SO-question would look like

        ChronoFormatter<Moment> f =
            ChronoFormatter.setUp(Moment.axis(), Locale.ROOT)
                .addPattern("uuuu-MM-dd HH:mm:ss.", PatternType.CLDR)
                .addFraction(PlainTime.MILLI_OF_SECOND, 1, 3, false)
                .addPattern("[ XXX| VV]", PatternType.CLDR)
                .build()
                .withTimezone(ZonalOffset.UTC); // default timezone in effect if no tz-id or offset was found

        String[] input = {
            "2016-04-19 17:34:43.781 Asia/Calcutta",
            "2016-04-30 20:05:02.002 8:00",
            "2003-11-11 00:22:15.0 -7:00",
            "2003-01-01 02:00:00.0 -7:00",
            "2007-06-08 15:01:12.288 Asia/Bahrain",
            "2016-03-08 17:17:35.301 Asia/Calcutta",
            "1994-11-24 11:57:17.303"
        };

        List<Moment> moments = new ArrayList<Moment>();

        for (String s : input) {
// current hack for missing positive sign
/*
            int dot = s.indexOf('.');
            int space2 = s.indexOf(' ', dot);
            if (space2 != -1 && Character.isDigit(s.charAt(space2 + 1))) {
                s = s.substring(0, space2 + 1) + "+" + s.substring(space2 + 1);
            }
*/
            moments.add(f.parse(s));
        }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions