From 774b3906a97c8cf12d5482d49029c2dd6a38b147 Mon Sep 17 00:00:00 2001 From: reger Date: Tue, 19 Jul 2016 02:57:41 +0200 Subject: [PATCH] fix GenericFormatter.parse ("time","timeoffset") change: UTC offset internally expected in minutes --- source/net/yacy/cora/date/GenericFormatter.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/net/yacy/cora/date/GenericFormatter.java b/source/net/yacy/cora/date/GenericFormatter.java index 16c6084d2..663c95f6c 100644 --- a/source/net/yacy/cora/date/GenericFormatter.java +++ b/source/net/yacy/cora/date/GenericFormatter.java @@ -137,14 +137,18 @@ public class GenericFormatter extends AbstractFormatter implements DateFormatter * @throws ParseException */ public Calendar parse(final String timeString, final String UTCOffset) throws ParseException { - // FIXME: This method returns an incorrect date, check callers! - // ex: de.anomic.server.serverDate.parseShortSecond("20070101120000", "+0200").toGMTString() - // => 1 Jan 2007 13:00:00 GMT if (timeString == null || timeString.isEmpty()) { return Calendar.getInstance(UTCtimeZone); } if (UTCOffset == null || UTCOffset.isEmpty()) { return Calendar.getInstance(UTCtimeZone); } - return parse(timeString, UTCDiff(UTCOffset)); + return parse(timeString, UTCDiff(UTCOffset)); // offset expected in min } + /** + * Calculates the time offset in minutes given as timezoneoffsetstring (diffString) + * e.g. "+0300" returns 180 + * + * @param diffString with fixed timezone format + * @return parsed timezone string in minutes + */ private static int UTCDiff(final String diffString) { if (diffString.length() != 5) throw new IllegalArgumentException("UTC String malformed (wrong size):" + diffString); boolean ahead = true; @@ -153,7 +157,7 @@ public class GenericFormatter extends AbstractFormatter implements DateFormatter else throw new IllegalArgumentException("UTC String malformed (wrong sign):" + diffString); final int oh = NumberTools.parseIntDecSubstring(diffString, 1, 3); final int om = NumberTools.parseIntDecSubstring(diffString, 3); - return (int) ((ahead) ? 1 : -1 * (oh * AbstractFormatter.hourMillis + om * AbstractFormatter.minuteMillis)); + return (int) ( ((ahead) ? 1 : -1) * (oh * 60 + om)); } /**