fix GenericFormatter.parse ("time","timeoffset")

change: UTC offset internally expected in minutes
pull/65/head
reger 8 years ago
parent 27163af0e1
commit 774b3906a9

@ -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));
}
/**

Loading…
Cancel
Save