List of usage examples for org.joda.time DateTime withZoneRetainFields
public DateTime withZoneRetainFields(DateTimeZone newZone)
From source file:org.openmainframe.ade.ext.os.parser.LinuxSyslog3164ParserBase.java
License:Open Source License
/** * Retrieves the date parsed from the header of a log. Unless otherwise defined in the properties file, * we have to use some logic to figure out the year. After parsing the date, we need to correct the time-zone. * Then we set the dateTime to the current year. Now we need to check the dateTime and see if it's after today. * The logic is as follows:/*from www. ja v a2 s .c o m*/ * - If Log time-stamp < End of day of today * (comparing Month, Day, Hour, Minutes, Seconds, with year missing), * assume it's this year. * - If Log time-stamp > End of day of today * (comparing Month, Day, Hour, Minutes, Seconds, with year missing), * assume it's previous year. * * The following restrictions will be made to customer for BulkLoad: * - Cannot upload logs older than 11 months. * - Cannot upload logs that are continuous for more than 11 months. * * Note: END OF TODAY is purposely chosen instead of START OF TODAY in case a user bulk loads logs that * belongs to today. It's not possible/likely that a user would bulk load logs from last year of the * same day with the restriction we specified above. * @param source the source name string value. * @param s the date and time string value. * @return Date object with date/time-stamp of the Linux log. */ @Override public final Date toDate(String source, String s) { DateTime dt = null; for (DateTimeFormatter fmt : dt_formatters) { try { dt = fmt.parseDateTime(s); dt = dt.withZoneRetainFields(INPUT_TIME_ZONE); dt = dt.withZone(OUTPUT_TIME_ZONE); /* Year must be set after all the time is normalized to the timezone */ dt = dt.withYear(curYear); if (s_linuxAdeExtProperties.isYearDefined()) { yearSetter = LinuxSyslogYearSetter.getYearSetter(source); /* If years is defined, then, use the defined year as a starting year */ final int yearToUse = yearSetter.getDesiredYear(dt); dt = dt.withYear(yearToUse); } else if (dt.isAfter(END_OF_TODAY)) { /* Set DateTime to previous year */ dt = dt.withYear(curYear - 1); } else { dt = dt.withYear(curYear); } /* AdeCore will take the Java Date object, and convert * it to the output time-zone, then extract the hour. */ return dt.toDate(); } catch (IllegalArgumentException e) { /* This exception can occur normally when iterating * through the DateTimeFormatter objects. It is only * an error worth noting when the dt object is not null. */ if (dt != null) { s_logger.error("Invalid argument encountered.", e); } } } throw new IllegalArgumentException("Failed to parse date " + s); }
From source file:org.owasp.webscarab.plugin.openid.PAPEResponse.java
License:Open Source License
public void setAuthenticationTime(String authenticationTimeStr) { DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyy-MM-dd'T'HH:mm:ss'Z'"); DateTime dateTime = dateTimeFormatter.parseDateTime(authenticationTimeStr); this.authenticationTime = dateTime.withZoneRetainFields(DateTimeZone.UTC).toDate(); }
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)//from w ww.ja v a2 s . com */ @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:us.physion.ovation.ui.editor.DatePickers.java
License:Open Source License
public static DateTime zonedDate(DateTimePicker datePicker, javax.swing.JComboBox zonePicker) { // datePicker.getDate() is giving us in local zone, so convert back to UTC DateTime pickedDate = new DateTime(datePicker.getDate()); //.withZone(DateTimeZone.forID("UTC")); //User entered date in UTC, but we want it in given zone return pickedDate.withZoneRetainFields(DateTimeZone.forID((String) zonePicker.getSelectedItem())); }