List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime(Chronology chronology)
this
if possible. From source file:ch.icclab.cyclops.util.DateInterval.java
License:Open Source License
/** * Will determine when was the last entry point (pull from Ceilometer), or even if there was any * * @return date object of the last commit, or epoch if there was none *///from w w w . j av a2 s . c o m private DateTime whenWasLastPull() { DateTime last; LatestPullORM pull = (LatestPullORM) HibernateClient.getInstance().getObject(LatestPullORM.class, 1l); if (pull == null) { last = new DateTime(0); } else { last = new DateTime(pull.getTimeStamp()); } logger.trace("Getting the last pull date " + last.toString()); // get date specified by admin String date = Loader.getSettings().getOpenStackSettings().getFirstImport(); if (date != null && !date.isEmpty()) { try { logger.trace("Admin provided us with import date preference " + date); DateTime selection = Time.getDateForTime(date); // if we are first time starting and having Epoch, change it to admin's selection // otherwise skip admin's selection and continue from the last DB entry time if (last.getMillis() == 0) { logger.debug("Setting first import date as configuration file dictates."); last = selection; } } catch (Exception ignored) { // ignoring configuration preference, as admin didn't provide correct format logger.debug("Import date selection for Ceilometer ignored - use yyyy-MM-dd'T'HH:mm:ssZ format"); } } DateTime dateTime = last.toDateTime(DateTimeZone.UTC); return dateTime; }
From source file:com.boxedfolder.carrot.domain.util.DateTimeSerializer.java
License:Open Source License
@Override public void serialize(DateTime value, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException { generator.writeString(formatter.print(value.toDateTime(DateTimeZone.UTC))); }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Parses the to utc calendar.//from w ww .j a v a2 s. c o m * * @param timestamp the timestamp * @param pattern the pattern * @return the calendar */ public static Calendar parseToUTCCalendar(String timestamp, String pattern) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); DateTime dt = fmt.parseDateTime(timestamp); dt = dt.toDateTime(DateTimeZone.UTC); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.confighub.core.utils.DateTimeUtils.java
License:Open Source License
public static Date parseISO8601Date(String dateString, Date cutoff) throws ConfigException { if (Utils.isBlank(dateString)) return null; try {//w w w .j a va 2s.c o m DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ"); DateTime dt = parser.parseDateTime(dateString); dt = dt.toDateTime(DateTimeZone.UTC); Date date = dt.toDate(); if (null != cutoff && date.before(cutoff)) return cutoff; return date; } catch (Exception e) { throw new ConfigException(Error.Code.DATE_API_FORMAT_ERROR); } }
From source file:com.digi.wva.internal.Hardware.java
License:Mozilla Public License
/** * Underlying implementation of {@link com.digi.wva.WVA#setTime(DateTime, WvaCallback)} * * @throws JSONException if an error occurs while creating the request *//*from ww w . java 2s. c om*/ public void setTime(final DateTime newTime, final WvaCallback<DateTime> cb) throws JSONException { JSONObject time = new JSONObject(); final DateTime newTimeUTC = newTime.toDateTime(DateTimeZone.UTC); final String timestamp = format.print(newTimeUTC); Log.i(TAG, "Sending timestamp down: " + timestamp); time.put("time", timestamp); httpClient.put(TIME_BASE, time, new HttpClient.ExpectEmptyCallback() { @Override public void onSuccess() { if (cb != null) { cb.onResponse(null, newTimeUTC); } } @Override public void onBodyNotEmpty(String body) { Log.e(TAG, "setTime got unexpected response body content:\n" + body); onFailure(new Exception("Unexpected response body: " + body)); } @Override public void onFailure(Throwable error) { Log.e(TAG, "Failed to set WVA device time to " + timestamp, error); if (cb != null) { cb.onResponse(error, newTimeUTC); } } }); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Parses the to zone calendar./*from w w w.j a v a 2 s. com*/ * @param timestamp the timestamp * @param pattern the pattern * @param timeZone the time zone * @return the calendar */ public static Calendar parseToZoneCalendar(String timestamp, String pattern, String timeZone) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); DateTime dt = fmt.parseDateTime(timestamp); dt = dt.toDateTime(DateTimeZone.forID(timeZone)); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.enitalk.configs.DateCache.java
public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) { ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>(); Iterator<JsonNode> els = tree.elements(); DateTimeZone dz = DateTimeZone.forID(tz); DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz); DateTime today = DateTime.now().millisOfDay().setCopy(0); while (els.hasNext()) { JsonNode el = els.next();//w w w. j av a 2s. c o m String day = el.path("day").asText(); boolean plus = today.getDayOfWeek() > days.get(day); if (el.has("start") && el.has("end")) { DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); Hours hours = Hours.hoursBetween(start, end); int hh = hours.getHours() + 1; while (hh-- > 0) { dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC)); } } else { List<String> datesAv = jackson.convertValue(el.path("times"), List.class); logger.info("Array of dates {} {}", datesAv, day); datesAv.forEach((String dd) -> { DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear() .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear()) .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); dates.add(date.toDateTime(DateTimeZone.UTC)); }); } } final TreeSet<DateTime> addWeek = new TreeSet<>(); for (int i = 1; i < 2; i++) { for (DateTime e : dates) { addWeek.add(e.plusWeeks(i)); } } dates.addAll(addWeek); DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC); nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2)); NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true); return ss; }
From source file:com.esofthead.mycollab.vaadin.web.ui.field.DateTimeOptionField.java
License:Open Source License
@Override public void setPropertyDataSource(Property newDataSource) { Date value = (Date) newDataSource.getValue(); if (value != null) { DateTime jodaTime = new DateTime(value); jodaTime = jodaTime.toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())); int hrs = jodaTime.getHourOfDay(); int min = jodaTime.getMinuteOfHour(); String timeFormat = "AM"; if (hrs > 12) { hrs -= 12;/*from ww w . j a va 2s. co m*/ timeFormat = "PM"; } if ((hrs > 0 || min > 0) && hideTimeOption) { toggleHideTimeOption(false); } popupDateField.setPropertyDataSource(new ObjectProperty(jodaTime.toDate())); if (!hideTimeOption) { hourPickerComboBox.setPropertyDataSource(new ObjectProperty((hrs < 10) ? "0" + hrs : "" + hrs)); minutePickerComboBox.setPropertyDataSource(new ObjectProperty((min < 10) ? "0" + min : "" + min)); timeFormatComboBox.setPropertyDataSource(new ObjectProperty(timeFormat)); } } super.setPropertyDataSource(newDataSource); }
From source file:com.harpatec.examples.converter.DateTimeWriteConverter.java
License:Apache License
@Override public DBObject convert(DateTime source) { DBObject dbo = new BasicDBObject(); dbo.put("millis", source.getMillis()); dbo.put("formatted", source.toDateTime(DateTimeZone.UTC).toString()); return dbo;/*from w ww. jav a 2 s . c o m*/ }
From source file:com.mastfrog.acteur.headers.Headers.java
License:Open Source License
public static String toISO2822Date(DateTime dt) { dt = new DateTime(dt.getMillis(), DateTimeZone.UTC); return dt.toDateTime(DateTimeZone.UTC).toDateTimeISO().toString(ISO2822DateFormat); }