diff options
author | Sven de Marothy <sven@physto.se> | 2005-05-18 00:52:32 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2005-05-18 00:52:32 +0000 |
commit | 552f0bd9646349b4a20564a0e0dc87af99f14995 (patch) | |
tree | 4b858f9a7a6a9e1c946d993f008303b135891b67 /java/text/SimpleDateFormat.java | |
parent | 932e7645a24c740de0a7d01954f16134dac19fd0 (diff) | |
download | classpath-552f0bd9646349b4a20564a0e0dc87af99f14995.tar.gz |
2005-05-18 Sven de Marothy <sven@physto.se>
* java/text/SimpleDateFormat.java
(computeOffset): Allow timezone to be first in the parsed String.
Diffstat (limited to 'java/text/SimpleDateFormat.java')
-rw-r--r-- | java/text/SimpleDateFormat.java | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/java/text/SimpleDateFormat.java b/java/text/SimpleDateFormat.java index 06275b628..84475fb1c 100644 --- a/java/text/SimpleDateFormat.java +++ b/java/text/SimpleDateFormat.java @@ -999,7 +999,7 @@ public class SimpleDateFormat extends DateFormat int zoneCount = zoneStrings.length; int index = pos.getIndex(); boolean found_zone = false; - simpleOffset = computeOffset(dateStr.substring(index)); + simpleOffset = computeOffset(dateStr.substring(index), pos); if (simpleOffset != null) { found_zone = true; @@ -1186,26 +1186,44 @@ public class SimpleDateFormat extends DateFormat * @return the parsed offset, or null if parsing * failed. */ - private Integer computeOffset(String zoneString) + private Integer computeOffset(String zoneString, ParsePosition pos) { - Pattern pattern = + Pattern pattern = Pattern.compile("(GMT)?([+-])([012])?([0-9]):?([0-9]{2})"); Matcher matcher = pattern.matcher(zoneString); - if (matcher.matches()) + + // Match from start, but ignore trailing parts + boolean hasAll = matcher.lookingAt(); + try + { + // Do we have at least the sign, hour and minute? + matcher.group(2); + matcher.group(4); + matcher.group(5); + } + catch (IllegalStateException ise) + { + hasAll = false; + } + if (hasAll) { int sign = matcher.group(2).equals("+") ? 1 : -1; - int hour = (Integer.parseInt(matcher.group(3)) * 10) - + Integer.parseInt(matcher.group(4)); + int hour = Integer.parseInt(matcher.group(4)); + if (!matcher.group(3).equals("")) + hour += (Integer.parseInt(matcher.group(3)) * 10); int minutes = Integer.parseInt(matcher.group(5)); if (hour > 23) return null; - int offset = sign * ((hour * 60) + minutes) * 60000; + + // advance the index + pos.setIndex(pos.getIndex() + matcher.end()); return new Integer(offset); } else if (zoneString.startsWith("GMT")) { + pos.setIndex(pos.getIndex() + 3); return new Integer(0); } return null; |