private static Date _parseGlobalDateTime()

in myfaces-html5-core/src/main/java/org/apache/myfaces/html5/renderkit/input/util/Html5DateTimeFormatUtils.java [151:208]


    private static Date _parseGlobalDateTime(String value) throws ParseException
    {
        if (value == null || value.length() == 0)
            return null;

        boolean utcDateTime = value.charAt(value.length() - 1) == 'Z';

        if (!utcDateTime)
        {
            /*
             * TimeZoned datetime values of Html5 have to define the time zone with colon, but that is not applicable
             * with SimpleDateFormat. SimpleDateFormat is unable to use a pattern like "yyyy-MM-dd'T'HH:mm:ZZ:ZZ". It
             * doesn't like the last colon, since it breaks the timezone. Since it is unable to parse a value like
             * "1992-01-01T02:09+02:00" using "yyyy-MM-dd'T'HH:mm:ZZZZ" pattern, we're removing the last comma of the
             * value to convert it to "1992-01-01T02:09+0200"
             */
            value = _deleteLastColonOfGlobalNonUTCDateTime(value);
        }

        boolean hasMillis = value.indexOf('.') != -1;

        int lastIndexOfT = value.lastIndexOf('T');
        if (lastIndexOfT == -1)
            throw new ParseException("Value has no time information, since it does not have 'T' symbol : " + value, 0);

        boolean doesntHaveMillisButHasSeconds = _hasSeconds(value.substring(lastIndexOfT));

        if (utcDateTime)
        {
            if (hasMillis)
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_UTC_PATTERN_WITH_MILLIS).parse(value);
            }
            else if (doesntHaveMillisButHasSeconds)
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_UTC_PATTERN_WITH_SECONDS).parse(value);
            }
            else
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_UTC_PATTERN).parse(value);
            }
        }
        else
        {
            if (hasMillis)
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_NONUTC_PATTERN_WITH_MILLIS).parse(value);
            }
            else if (doesntHaveMillisButHasSeconds)
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_NONUTC_PATTERN_WITH_SECONDS).parse(value);
            }
            else
            {
                return new SimpleDateFormat(GLOBAL_DATETIME_NONUTC_PATTERN).parse(value);
            }
        }
    }