List of usage examples for org.joda.time DateTimeZone forTimeZone
public static DateTimeZone forTimeZone(TimeZone zone)
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 w ww .j ava 2s .c om*/ */ 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.calendar.util.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToString(java.lang.Object, * java.util.Locale)/*from w ww . ja v a 2 s. c o m*/ */ public String convertToString(Object value, Locale locale) { DateTime dt = new DateTime(((Date) value).getTime(), getTimeZone()); DateTimeFormatter format = getFormat(); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); if (zone != null) { // apply time zone to formatter format = format.withZone(DateTimeZone.forTimeZone(zone)); } } return format.print(dt); }
From source file:org.wicketstuff.datetime.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String, * java.util.Locale)// w ww. j a va2s .c om */ @Override public Date convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; } DateTimeFormatter format = getFormat(locale); if (format == null) { throw new IllegalStateException("format must be not null"); } if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); DateTime dateTime; // set time zone for client format = format.withZone(getTimeZone()); try { // parse date retaining the time of the submission dateTime = format.parseDateTime(value); } catch (RuntimeException e) { throw newConversionException(e, locale); } // apply the server time zone to the parsed value if (zone != null) { dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone)); } return dateTime.toDate(); } else { try { DateTime date = format.parseDateTime(value); return date.toDate(); } catch (RuntimeException e) { throw newConversionException(e, locale); } } }
From source file:org.wicketstuff.datetime.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToString(java.lang.Object, * java.util.Locale)// w w w .j av a2s .c om */ @Override public String convertToString(Date value, Locale locale) { DateTime dt = new DateTime(value.getTime(), getTimeZone()); DateTimeFormatter format = getFormat(locale); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); if (zone != null) { // apply time zone to formatter format = format.withZone(DateTimeZone.forTimeZone(zone)); } } return format.print(dt); }
From source file:org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField.java
License:Apache License
/** * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it. * <p>//from ww w .j av a 2 s . co m * Note that overriding this method is a better option than overriding {@link #updateModel()} * like the first versions of this class did. The reason for that is that this method can be * used by form validators without having to depend on the actual model being updated, and this * method is called by the default implementation of {@link #updateModel()} anyway (so we don't * have to override that anymore). */ @Override public void convertInput() { try { // Get the converted input values Date dateFieldInput = dateField.getConvertedInput(); Integer hoursInput = hoursField.getConvertedInput(); Integer minutesInput = minutesField.getConvertedInput(); AM_PM amOrPmInput = amOrPmChoice.getConvertedInput(); if (dateFieldInput == null) { return; } // Get year, month and day ignoring any timezone of the Date object Calendar cal = Calendar.getInstance(); cal.setTime(dateFieldInput); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hours = (hoursInput == null ? 0 : hoursInput % 24); int minutes = (minutesInput == null ? 0 : minutesInput); // Use the input to create a date object with proper timezone MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0, DateTimeZone.forTimeZone(getClientTimeZone())); // Adjust for halfday if needed if (use12HourFormat()) { int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0); date.set(DateTimeFieldType.halfdayOfDay(), halfday); date.set(DateTimeFieldType.hourOfHalfday(), hours % 12); } // The date will be in the server's timezone setConvertedInput(newDateInstance(date.getMillis())); } catch (RuntimeException e) { DateTimeField.this.error(e.getMessage()); invalid(); } }
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 a 2s .c o 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.wremja.launcher.Launcher.java
License:Open Source License
/** * Main method that starts the application. * @param arguments the command line arguments *//*from w w w. j a va 2s . co m*/ public static void main(final String[] arguments) { try { final Launcher mainInstance = new Launcher(); mainInstance.parseCommandLineArguments(arguments); mainInstance.initDir(); mainInstance.initLogger(); initUncaughtExceptionHandler(); initLookAndFeel(); initLockFile(); @SuppressWarnings("deprecation") IUserSettings settings = UserSettings.instance(); TimeZone tz = TimeZone.getTimeZone(settings.getTimeZone()); LOG.info("Using timezone: " + tz); TimeZone.setDefault(tz); DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz)); final PresentationModel model = initModel(settings); mainInstance.initMainFrame(model, settings); initTimer(model); initShutdownHook(model); mainInstance.checkForUpdates(); } catch (Throwable t) { LOG.error(t, t); JOptionPane.showMessageDialog(null, textBundle.textFor("Launcher.FatalError.Message", logFileName), //$NON-NLS-1$ textBundle.textFor("Launcher.FatalError.Title"), //$NON-NLS-1$ JOptionPane.ERROR_MESSAGE); System.exit(-1); } }
From source file:org.xbib.elasticsearch.jdbc.strategy.standard.StandardSource.java
License:Apache License
@Override public StandardSource<C> setTimeZone(TimeZone timezone) { this.timezone = timezone; TimeZone.setDefault(timezone); // for JDBC drivers internals if (locale == null) { locale = Locale.getDefault(); }//from w w w . j a va 2s .c o m this.calendar = Calendar.getInstance(timezone, locale); logger.debug("calendar timezone for JDBC timestamps = {}", calendar.getTimeZone().getDisplayName()); // for formatting fetched JDBC time values this.dateTimeZone = DateTimeZone.forTimeZone(timezone); return this; }
From source file:pl.edu.icm.coansys.statisticsgenerator.operationcomponents.DateRangesPartitioner.java
License:Open Source License
@Override public void setup(String... params) { List<Integer> numbers = new ArrayList<Integer>(); DateTime end = new DateTime(DateTimeZone.forTimeZone(timezone)).withMillisOfDay(0).plusDays(1); for (String param : params) { if (param.contains("=")) { int eqIndex = param.indexOf('='); String paramName = param.substring(0, eqIndex); String paramValue = param.substring(eqIndex + 1); if (paramName.equals("timezone")) { timezone = TimeZone.getTimeZone(paramValue); TimeZone.setDefault(timezone); } else if (paramName.equals("logsEnd")) { end = new DateTime(DatatypeConverter.parseTime(paramValue)).withMillisOfDay(0).plusDays(1); } else { throw new IllegalArgumentException("Unknown param name: " + paramName); }// w ww.ja v a 2s .co m } else { numbers.add(Integer.parseInt(param)); } } Collections.sort(numbers); timeBuckets = new ArrayList<TimeBucket>(); for (Integer period : numbers) { DateTime start = end.minusDays(period).withMillisOfDay(0); timeBuckets.add(new TimeBucket(start, period.toString() + " days")); } timeBuckets.add(new TimeBucket("all")); }
From source file:rapture.kernel.ScheduleApiImpl.java
License:Open Source License
private RaptureJob createJob(CallingContext context, String jobURI, String description, String executableURI, String cronExpression, String timeZone, Map<String, String> jobParams, Boolean autoActivate, JobType type, int maxRuntimeMinutes, String appStatusNamePattern) { RaptureJob job = new RaptureJob(); job.setCronSpec(cronExpression);/*from w w w . j a v a 2 s . c o m*/ // validate timezone DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZone)); if (!dateTimeZone.getID().equals(timeZone)) { throw RaptureExceptionFactory.create("Invalid TimeZone " + timeZone); } job.setTimeZone(timeZone); RaptureURI uri = new RaptureURI(jobURI, Scheme.JOB); job.setJobURI(uri.toString()); if (type == JobType.SCRIPT) { job.setScriptURI(executableURI); } else { job.setScriptURI(new RaptureURI(executableURI, Scheme.WORKFLOW).toString()); } job.setParams(jobParams); job.setDescription(description); job.setAutoActivate(autoActivate); if (autoActivate) { job.setActivated(true); } else { job.setActivated(false); } job.setJobType(type); job.setMaxRuntimeMinutes(maxRuntimeMinutes); if (appStatusNamePattern != null) { job.setAppStatusNamePattern(appStatusNamePattern); } RaptureJobStorage.add(uri, job, context.getUser(), Messages.getString("Schedule.createNew")); //$NON-NLS-1$ ScheduleManager.handleJobChanged(job, false, null, null); return job; }