List of usage examples for com.google.gwt.i18n.shared.impl DateRecord setTzOffset
public void setTzOffset(int tzOffset)
From source file:com.rnb.plategka.shared.DateTimeFormat.java
License:Apache License
/** * Method parses time zone offset.//from ww w . j a v a2 s.c om * * @param text * the time text to be parsed * @param pos * Parse position * @param cal * DateRecord object that holds parsed value * * @return <code>true</code> if parsing successful, otherwise * <code>false</code> */ private boolean parseTimeZoneOffset(String text, int[] pos, DateRecord cal) { if (pos[0] >= text.length()) { cal.setTzOffset(0); return true; } int sign; switch (text.charAt(pos[0])) { case '+': sign = 1; break; case '-': sign = -1; break; default: cal.setTzOffset(0); return true; } ++(pos[0]); // Look for hours:minutes or hhmm. int st = pos[0]; int value = parseInt(text, pos); if (value == 0 && pos[0] == st) { return false; } int offset; if (pos[0] < text.length() && text.charAt(pos[0]) == ':') { // This is the hours:minutes case. offset = value * MINUTES_PER_HOUR; ++(pos[0]); st = pos[0]; value = parseInt(text, pos); if (value == 0 && pos[0] == st) { return false; } offset += value; } else { // This is the hhmm case. offset = value; // Assume "-23".."+23" refers to hours. if (offset < 24 && (pos[0] - st) <= 2) { offset *= MINUTES_PER_HOUR; } else { offset = offset % 100 + offset / 100 * MINUTES_PER_HOUR; } } offset *= sign; cal.setTzOffset(-offset); return true; }