List of usage examples for org.joda.time MutableDateTime setZone
public void setZone(DateTimeZone newZone)
From source file:com.enonic.cms.core.search.ElasticSearchFormatter.java
License:Open Source License
public static ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) { if (DateTimeZone.UTC.equals(dateTime.getZone())) { return dateTime; }//from www.j a va 2s . c o m final MutableDateTime dateInUTC = dateTime.toMutableDateTime(); dateInUTC.setZone(DateTimeZone.UTC); return dateInUTC.toDateTime(); }
From source file:com.enonic.cms.core.search.query.factory.FilterQueryBuilderFactory.java
License:Open Source License
private ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) { if (DateTimeZone.UTC.equals(dateTime.getZone())) { return dateTime; }/*from w w w . j a va2 s . co m*/ final MutableDateTime dateInUTC = dateTime.toMutableDateTime(); dateInUTC.setZone(DateTimeZone.UTC); return dateInUTC.toDateTime(); }
From source file:com.foundationdb.server.types.mcompat.mfuncs.MConvertTZ.java
License:Open Source License
@Override protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {// ww w . jav a 2 s. c om long original = inputs.get(0).getInt64(); long[] ymd = MDateAndTime.decodeDateTime(original); if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR)) { output.putNull(); } else { try { DateTimeZone fromTz = MDateAndTime.parseTimeZone(inputs.get(1).getString()); DateTimeZone toTz = MDateAndTime.parseTimeZone(inputs.get(2).getString()); MutableDateTime date = MDateAndTime.toJodaDateTime(ymd, fromTz); // If the value falls out of the supported range of the TIMESTAMP // when converted from fromTz to UTC, no conversion occurs. date.setZone(DateTimeZone.UTC); final long converted; if (MDateAndTime.isValidTimestamp(date)) { date.setZone(toTz); converted = MDateAndTime.encodeDateTime(date); } else { converted = original; } output.putInt64(converted); } catch (InvalidDateFormatException e) { context.warnClient(e); output.putNull(); } } }
From source file:org.hippoecm.frontend.plugins.yui.datetime.YuiDateTimeField.java
License:Apache License
private void updateDateTime() { Date date = getDate();//from ww w .j av a 2s . c o m if (date != null) { MutableDateTime datetime = new MutableDateTime(date); try { TimeZone zone = getClientTimeZone(); if (zone != null) { datetime.setZone(DateTimeZone.forTimeZone(zone)); } Integer hours = getHours(); if (hours != null) { datetime.set(DateTimeFieldType.hourOfDay(), hours % 24); Integer minutes = getMinutes(); datetime.setMinuteOfHour(minutes != null ? minutes : 0); } // the date will be in the server's timezone setDate(datetime.toDate()); //setModelObject(datetime.toDate()); } catch (RuntimeException e) { error(e.getMessage()); invalid(); } } }
From source file:org.hippoecm.frontend.widgets.AjaxDateTimeField.java
License:Apache License
private void updateDateTime(Object datetime, Integer hours, Integer minutes, AjaxRequestTarget target) { MutableDateTime date = new MutableDateTime(datetime); try {/*from www .ja v a 2s . c o m*/ TimeZone zone = getClientTimeZone(); if (zone != null) { date.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { date.set(DateTimeFieldType.hourOfDay(), hours.intValue() % 24); date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); } // the date will be in the server's timezone setModelObject(date.toDate()); if (target != null) { target.add(this); } } catch (RuntimeException e) { error(e.getMessage()); invalid(); } }
From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java
License:Apache License
public T convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; }/*from ww w. j a v a2s . com*/ DateTimeFormatter format = formatProvider.getFormatter(); if (format == null) { throw new IllegalStateException("format must be not null"); } format = format.withLocale(locale).withPivotYear(pivotYear); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); // instantiate now/ current time MutableDateTime dt = new MutableDateTime(); if (zone != null) { // set time zone for client format = format.withZone(DateTimeZone.forTimeZone(zone)); dt.setZone(DateTimeZone.forTimeZone(zone)); } try { // parse date retaining the time of the submission int result = format.parseInto(dt, value, 0); if (result < 0) { throw new ConversionException(new ParseException("unable to parse date " + value, ~result)); } } catch (RuntimeException e) { throw new ConversionException(e); } // apply the server time zone to the parsed value dt.setZone(getServerTimeZone()); return translator.fromDateTime(dt.toDateTime()); } else { try { DateTime date = format.parseDateTime(value); return date == null ? null : translator.fromDateTime(date); } catch (RuntimeException e) { throw new ConversionException(e); } } }
From source file:org.wicketstuff.calendar.util.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String, * java.util.Locale)/*from www . ja va 2 s .co m*/ */ public Object convertToObject(String value, Locale locale) { DateTimeFormatter format = getFormat(); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); // instantiate now/ current time MutableDateTime dt = new MutableDateTime(); if (zone != null) { // set time zone for client format = format.withZone(DateTimeZone.forTimeZone(zone)); dt.setZone(DateTimeZone.forTimeZone(zone)); } // parse date retaining the time of the submission format.parseInto(dt, value, 0); // apply the server time zone to the parsed value dt.setZone(getTimeZone()); return dt.toDate(); } else { return format.parseDateTime(value).toDate(); } }
From source file:org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField.java
License:Apache License
/** * @see org.apache.wicket.Component#onBeforeRender() *///from ww w. j a v a2 s. co m @Override protected void onBeforeRender() { dateField.setRequired(isRequired()); hoursField.setRequired(isRequired()); minutesField.setRequired(isRequired()); boolean use12HourFormat = use12HourFormat(); amOrPmChoice.setVisible(use12HourFormat); Date modelObject = (Date) getDefaultModelObject(); if (modelObject == null) { date = null; hours = null; minutes = null; } else { MutableDateTime mDate = new MutableDateTime(modelObject); // convert date to the client's time zone if we have that info TimeZone zone = getClientTimeZone(); if (zone != null) { mDate.setZone(DateTimeZone.forTimeZone(zone)); } date = mDate.toDateTime().toLocalDate().toDate(); if (use12HourFormat) { int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday()); hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay; } else { hours = mDate.get(DateTimeFieldType.hourOfDay()); } amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM; minutes = mDate.getMinuteOfHour(); } super.onBeforeRender(); }
From source file:org.xmlcml.euclid.JodaDate.java
License:Apache License
public static DateTime parseDate(String s) { if (s.endsWith("Z")) { MutableDateTime dateTime = ZULU_FORMATTER.parseMutableDateTime(s); dateTime.setZone(DateTimeZone.UTC); return dateTime.toDateTime(); } else if (Character.isLetter(s.charAt(0))) { DateTime dateTime = JodaDate.parseQuietly(ALPHA_FORMATTER2, s); if (dateTime == null) { dateTime = JodaDate.parseQuietly(ALPHA_FORMATTER1, s); }// w w w. ja v a2 s. c om return dateTime; } else { return DATETIME_FORMATTER.parseDateTime(s); } }