Java Code Examples for java.util.Calendar#ZONE_OFFSET

The following examples show how to use java.util.Calendar#ZONE_OFFSET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastDateParser.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 * @param field The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale, Strategy> cache = getCache(field);
    Strategy strategy = cache.get(locale);
    if (strategy == null) {
        strategy = field == Calendar.ZONE_OFFSET 
                ? new TimeZoneStrategy(locale)
                : new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
        final Strategy inCache = cache.putIfAbsent(locale, strategy);
        if (inCache != null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 2
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void fieldFirst() {
	// If the user has opted to have the user be able to
	// change time zones then allow the next field to be the
	// time zone field
	if (this.allowedTimezones == null) {
		if (Calendar.ZONE_OFFSET == getCalendarField(field[0])) {
			setActiveField(1);
		} else {
			setActiveField(0);
		}
	} else {
		// allowed time zones have been set, so let the user edit it
		setActiveField(0);
	}
}
 
Example 3
Source File: FastDateParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 *
 * @param field            The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale, Strategy> cache = getCache(field);
    Strategy strategy = cache.get(locale);
    if (strategy == null) {
        strategy = field == Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        final Strategy inCache = cache.putIfAbsent(locale, strategy);
        if (inCache != null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 4
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void fieldLast() {
	// If the user has opted to have the user be able to change
	// time zones then allow the next field to be the time zone field
	if (this.allowedTimezones == null) {
		if (Calendar.ZONE_OFFSET == getCalendarField(
				field[field.length - 1])) {
			setActiveField(field.length - 2);
		} else {
			setActiveField(field.length - 1);
		}
	} else {
		// allowed time zones have been set, so let the user edit it
		setActiveField(field.length - 1);
	}
}
 
Example 5
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the active field to the next field; wraps if necessary and sets to
 * last field if there is no current active field
 * 
 * @param If
 *            true, the text update will be asynchronous (for changes to
 *            text selection)
 */
void fieldNext(boolean async) {
	if (activeField >= 0 && activeField < field.length - 1) {
		// If the user has opted to have the user be able to change
		// time zones then allow the next field to be the time zone field
		if (this.allowedTimezones == null) {
			if (Calendar.ZONE_OFFSET == getCalendarField(
					field[activeField + 1])) {
				if (activeField < field.length - 2) {
					setActiveField(activeField + 2);
				} else {
					setActiveField(0);
				}
			} else {
				setActiveField(activeField + 1);
			}
		} else {
			// allowed time zones have been set, so let the user edit it
			setActiveField(activeField + 1);
		}
	} else {
		// If the user has opted to have the user be able to change
		// time zones then allow the next field to be the time zone field
		if (this.allowedTimezones == null) {
			if (Calendar.ZONE_OFFSET == getCalendarField(field[0])) {
				setActiveField(1);
			} else {
				setActiveField(0);
			}
		} else {
			// allowed time zones have been set, so let the user edit it
			setActiveField(0);
		}
	}
	updateText(async);
}
 
Example 6
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the active field to the previous field; wraps if necessary and sets
 * to first field if there is no current active field
 * 
 * @param If
 *            true, the text update will be asynchronous (for changes to
 *            text selection)
 */
void fieldPrev(boolean async) {
	if (activeField > 0 && activeField < field.length) {
		// If the user has opted to have the user be able to change
		// time zones then allow the next field to be the time zone field
		if (this.allowedTimezones == null) {
			if (Calendar.ZONE_OFFSET == getCalendarField(
					field[activeField - 1])) {
				if (activeField > 1) {
					setActiveField(activeField - 2);
				} else {
					setActiveField(field.length - 1);
				}
			} else {
				setActiveField(activeField - 1);
			}
		} else {
			// allowed time zones have been set, so let the user edit it
			setActiveField(activeField - 1);
		}
	} else {
		// If the user has opted to have the user be able to change
		// time zones then allow the next field to be the time zone field
		if (this.allowedTimezones == null) {

			if (Calendar.ZONE_OFFSET == getCalendarField(
					field[field.length - 1])) {
				setActiveField(field.length - 2);
			} else {
				setActiveField(field.length - 1);
			}
		} else {
			// allowed time zones have been set, so let the user edit it
			setActiveField(field.length - 1);
		}
	}
	updateText(async);
}
 
Example 7
Source File: FastDateParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 *
 * @param field            The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale, Strategy> cache = getCache(field);
    Strategy strategy = cache.get(locale);
    if (strategy == null) {
        strategy = field == Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        final Strategy inCache = cache.putIfAbsent(locale, strategy);
        if (inCache != null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 8
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
int getCalendarField(Field field) {
	int cf = field.getCalendarField();
	if (cf < 0) {
		if (field.toString().indexOf("hour 1") > -1) { //$NON-NLS-1$
			cf = Calendar.HOUR;
		} else if (field.toString().contains("zone")) { //$NON-NLS-1$
			cf = Calendar.ZONE_OFFSET;
		} else if (field.toString().contains("hour of day 1")) { //$NON-NLS-1$
			cf = Calendar.HOUR_OF_DAY;
		}
	}
	return cf;
}
 
Example 9
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 * @param locale The Locale of the TimeZone to parse
 * @param field The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(int field, Calendar definingCalendar) {
	ConcurrentMap<Locale,Strategy> cache = getCache(field);
	Strategy strategy= cache.get(Integer.valueOf(field));
    if(strategy==null) {
    	strategy= field==Calendar.ZONE_OFFSET
    			? new TimeZoneStrategy(locale)
    			: new TextStrategy(field, definingCalendar, locale);
        Strategy inCache= cache.putIfAbsent(locale, strategy);
        if(inCache!=null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 10
Source File: FastDateParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 *
 * @param field            The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale, Strategy> cache = getCache(field);
    Strategy strategy = cache.get(locale);
    if (strategy == null) {
        strategy = field == Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        final Strategy inCache = cache.putIfAbsent(locale, strategy);
        if (inCache != null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 11
Source File: Bug370605.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Using traverse arrow keys, move through each field of the control
 *
 * Stop traversing if we have cycled back to the starting field, or we reach
 * the time zone field
 *
 * @return true, if the time zone field has been found. false otherwise.
 */
private boolean moveToTimeZoneField(int calendarFieldSelection) {
	CDateTime cdt = tester.getCDateTime();
	int initialField = cdt.getCalendarField();

	int currentField = -1;
	do {
		keyPress(SWT.ARROW_RIGHT);
		keyPress('\r');
		currentField = cdt.getCalendarField();
	} while (currentField != initialField
			&& currentField != calendarFieldSelection);

	return currentField != Calendar.ZONE_OFFSET;
}
 
Example 12
Source File: FastDateParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 *
 * @param field            The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale, Strategy> cache = getCache(field);
    Strategy strategy = cache.get(locale);
    if (strategy == null) {
        strategy = field == Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        final Strategy inCache = cache.putIfAbsent(locale, strategy);
        if (inCache != null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 13
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 * @param field The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
    final ConcurrentMap<Locale,Strategy> cache = getCache(field);
    Strategy strategy= cache.get(locale);
    if(strategy==null) {
        strategy= field==Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        final Strategy inCache= cache.putIfAbsent(locale, strategy);
        if(inCache!=null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 14
Source File: FastDateParser.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Strategy that parses a Text field
 * @param locale The Locale of the TimeZone to parse
 * @param field The Calendar field
 * @param definingCalendar The calendar to obtain the short and long values
 * @return a TextStrategy for the field and Locale
 */
private Strategy getLocaleSpecificStrategy(int field, Calendar definingCalendar) {
    ConcurrentMap<Locale,Strategy> cache = getCache(field);
    Strategy strategy= cache.get(Integer.valueOf(field));
    if(strategy==null) {
        strategy= field==Calendar.ZONE_OFFSET
                ? new TimeZoneStrategy(locale)
                : new TextStrategy(field, definingCalendar, locale);
        Strategy inCache= cache.putIfAbsent(locale, strategy);
        if(inCache!=null) {
            return inCache;
        }
    }
    return strategy;
}
 
Example 15
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Set the style of this CDateTime to work with dates and / or times as
 * determined by the given pattern. This will set the fields shown in the
 * text box and, if <code>DROP_DOWN</code> style is set, the fields of the
 * drop down component.<br>
 * This method is backed by an implementation of SimpleDateFormat, and as
 * such, any string pattern which is valid for SimpleDateFormat may be used.
 * Examples (US Locale):<br>
 * </code>setPattern("MM/dd/yyyy h:mm a");</code><br />
 * </code>setPattern("'Meeting @' h:mm a 'on' EEEE, MMM dd,
 * yyyy");</code><br />
 * 
 * @param pattern
 *            the pattern to use, if it is invalid, the original is restored
 * @throws IllegalArgumentException
 * @see SimpleDateFormat
 * @see #getPattern()
 * @see #setFormat(int)
 */
public void setPattern(String pattern) throws IllegalArgumentException {
	this.allowedTimezones = null;
	if (isOpen()) {
		setOpen(false);
	}
	df = new SimpleDateFormat(pattern, locale);
	df.setTimeZone(timezone);
	if (updateFields()) {
		this.pattern = pattern;
		this.format = -1;
		boolean wasDate = isDate;
		boolean wasTime = isTime;
		isDate = isTime = false;
		calendarFields = new int[field.length];
		for (int i = 0; i < calendarFields.length; i++) {
			calendarFields[i] = getCalendarField(field[i]);
			switch (calendarFields[i]) {
			case Calendar.AM_PM:
			case Calendar.HOUR:
			case Calendar.HOUR_OF_DAY:
			case Calendar.MILLISECOND:
			case Calendar.MINUTE:
			case Calendar.SECOND:
			case Calendar.ZONE_OFFSET:
				isTime = true;
				break;
			case Calendar.DAY_OF_MONTH:
			case Calendar.DAY_OF_WEEK:
			case Calendar.DAY_OF_WEEK_IN_MONTH:
			case Calendar.DAY_OF_YEAR:
			case Calendar.ERA:
			case Calendar.MONTH:
			case Calendar.WEEK_OF_MONTH:
			case Calendar.WEEK_OF_YEAR:
			case Calendar.YEAR:
				isDate = true;
				break;
			default:
				break;
			}
		}
		if (checkButton() && (isDate != wasDate || isTime != wasTime)) {
			if (defaultButtonImage) {
				if (isDate && isTime) {
					doSetButtonImage(Resources.getIconCalendarClock());
				} else if (isDate) {
					doSetButtonImage(Resources.getIconCalendar());
				} else {
					doSetButtonImage(Resources.getIconClock());
				}
			}
			updateNullText();
		}
		if (checkText()) {
			updateText();
		}
		if (isSimple()) {
			disposePicker();
			createPicker();
		}
	} else {
		throw new IllegalArgumentException(
				"Problem setting pattern: \"" + pattern + "\""); //$NON-NLS-1$ //$NON-NLS-2$
	}
}
 
Example 16
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The Travers event handler. Note that ARROW_UP and ARROW_DOWN are handled
 * in the <code>handleKey</code> method.
 * 
 * @param event
 *            the event
 */
void handleTraverse(Event event) {
	boolean allowTimeZoneEdit = this.allowedTimezones != null;

	switch (event.detail) {
	case SWT.TRAVERSE_ARROW_NEXT:
		if (event.keyCode == SWT.ARROW_RIGHT) {
			fieldNext();
		} else if (event.keyCode == SWT.ARROW_DOWN) {
			fieldAdjust(-1);
		}
		break;
	case SWT.TRAVERSE_ARROW_PREVIOUS:
		if (event.keyCode == SWT.ARROW_LEFT) {
			fieldPrev();
		} else if (event.keyCode == SWT.ARROW_UP) {
			fieldAdjust(1);
		}
		break;
	case SWT.CR:
		fieldNext();
		fireSelectionChanged();
		break;
	case SWT.TRAVERSE_TAB_NEXT:
		if (tabStops && hasSelection()) {
			// if we are at the last field, allow the tab out of the control
			// the last field is also considered to be the 2nd to last if
			// the last is a time zone
			// we now check if the control allows time zone editing
			if (activeField == field.length - 1
					|| activeField == field.length - 2
							&& Calendar.ZONE_OFFSET == getCalendarField(
									field[field.length - 1])
							&& !allowTimeZoneEdit) {
				event.doit = true;
			} else {
				event.doit = false;
				if (activeField < 0) {
					fieldPrev();
				} else {
					fieldNext();
				}
			}
		}
		break;
	case SWT.TRAVERSE_TAB_PREVIOUS:
		if (tabStops && hasSelection()) {
			// if we are at the 1st field, allow the tab out of the control
			// the 1st field is also considered to the the 2nd if the 1st
			// is a time zone
			if (activeField == 0 || activeField == 1
					&& Calendar.ZONE_OFFSET == getCalendarField(field[0])
					&& !allowTimeZoneEdit) {
				event.doit = true;
			} else {
				event.doit = false;
				if (activeField < 0) {
					fieldNext();
				} else {
					fieldPrev();
				}
			}
		}
		break;
	default:
	}
}
 
Example 17
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private boolean fieldRoll(final int calendarField, final int rollAmount,
		final int style) {
	if (!getEditable()) {
		return false;
	}

	long backup = calendar.getTimeInMillis();

	if (calendarField == Calendar.ZONE_OFFSET
			&& this.allowedTimezones != null) {
		boolean timeZoneSet = false;
		for (int idx = 0; idx < this.allowedTimezones.length; idx++) {
			TimeZone activeTimeZone = this.getTimeZone();
			if (activeTimeZone.getID() == this.allowedTimezones[idx]
					.getID()) {
				if (rollAmount < 0) {
					if (idx == 0) {
						this.setTimeZone(
								this.allowedTimezones[this.allowedTimezones.length
										- 1]);
					} else {
						this.setTimeZone(this.allowedTimezones[idx - 1]);
					}
				} else if (rollAmount > 0) {
					if (idx == this.allowedTimezones.length - 1) {
						this.setTimeZone(this.allowedTimezones[0]);
					} else {
						this.setTimeZone(this.allowedTimezones[idx + 1]);
					}
				}
				timeZoneSet = true;
				break;
			}
		}
		if (!timeZoneSet) {
			this.setTimeZone(this.allowedTimezones[0]);
		}
	} else {
		if ((this.style & CDT.ADD_ON_ROLL) != 0) {
			calendar.add(calendarField, rollAmount);
		} else {
			if (calendarField == Calendar.YEAR
					&& calendar.get(Calendar.YEAR) == 1 && rollAmount < 0) {
				return false;
			}
			calendar.roll(calendarField, rollAmount);
		}
	}

	if (!DatePicker.isValidDate(calendar, minDate, maxDate)) {
		calendar.setTimeInMillis(backup);
		return false;
	}
	if (selection.length > 0) {
		selection[0] = calendar.getTime();
	}
	updateText();
	updatePicker();
	fireSelectionChanged(calendarField);

	return true;
}
 
Example 18
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Sets the active field from the select of the text box
 */
void fieldFromTextSelection() {
	if (!hasSelection()) {
		// setActiveField(FIELD_ALL);
		fieldNext();
	} else {
		Point sel = text.getControl().getSelection();
		AttributedCharacterIterator aci = df
				.formatToCharacterIterator(calendar.getTime());
		if (sel.x > textSelectionOffset.x) {
			sel.x += textSelectionOffset.y;
		}
		aci.setIndex(sel.x);
		Object[] oa = aci.getAttributes().keySet().toArray();
		if (oa.length == 0 && sel.x > 0) {
			sel.x -= 1;
			aci.setIndex(sel.x);
			oa = aci.getAttributes().keySet().toArray();
		}
		if (oa.length > 0) {
			for (int i = 0; i < field.length; i++) {
				if (oa[0].equals(field[i])) {
					// If the user has opted to have the user be able to
					// change time zones then allow the next field to be the
					// time zone field
					if (this.allowedTimezones == null) {
						if (Calendar.ZONE_OFFSET != getCalendarField(
								field[i])) {
							setActiveField(i);
						}
					} else {
						// allowed time zones have been set, so let the user
						// edit it
						setActiveField(i);
					}
					break;
				}
			}
			updateText();
		}
	}
}
 
Example 19
Source File: DateHelper.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static int getCalendarTypeForString(String oneChar) {

		int calType = -1;

		switch (oneChar.charAt(0)) {
			case 'G':
				calType = Calendar.ERA;
				break;
			case 'y':
				calType = Calendar.YEAR;
				break;
			case 'M':
				calType = Calendar.MONTH;
				break;
			case 'd':
				calType = Calendar.DAY_OF_MONTH;
				break;
			case 'E':
				calType = Calendar.DAY_OF_WEEK;
				break;
			case 'D':
				calType = Calendar.DAY_OF_YEAR;
				break;
			case 'F':
				calType = Calendar.DATE;
				break;
			case 'h':
				calType = Calendar.HOUR;
				break;
			case 'm':
				calType = Calendar.MINUTE;
				break;
			case 's':
				calType = Calendar.SECOND;
				break;
			case 'S':
				calType = Calendar.MILLISECOND;
				break;
			case 'w':
				calType = Calendar.WEEK_OF_YEAR;
				break;
			case 'W':
				calType = Calendar.WEEK_OF_MONTH;
				break;
			case 'a':
				calType = Calendar.AM_PM;
				break;
			case 'k':
				calType = Calendar.HOUR_OF_DAY;
				break;
			case 'K':
				// ?
				break;
			case 'z':
				calType = Calendar.ZONE_OFFSET;
				break;
		}

		return calType;
	}
 
Example 20
Source File: DateTimeHelper.java    From uavstack with Apache License 2.0 3 votes vote down vote up
/**
 * 指定时间的秒数 指定时间零点的秒数加指定天数的秒数
 * 
 * @param time
 *            时间
 * @param range
 *            天
 * @return
 */
public static long getSpecifyTimeSec(long time, int range) {

    Date date = new Date((time * 1000 + (23 - Calendar.ZONE_OFFSET) * 3600000) / 86400000 * 86400000
            - (23 - Calendar.ZONE_OFFSET) * 3600000);
    long zeroTime = date.getTime() / 1000;
    long specifyTime = range * 24 * 3600;
    return (zeroTime + specifyTime);
}