List of usage examples for org.joda.time DateTime withSecondOfMinute
public DateTime withSecondOfMinute(int second)
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period/*from ww w . ja v a 2 s .co m*/ * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ static DateTime getCurrentStartTime(Opt<DCMIPeriod> period) { DateTime currentStartTime = new DateTime(); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withHourOfDay(0); currentStartTime = currentStartTime.withMinuteOfHour(0); currentStartTime = currentStartTime.withSecondOfMinute(0); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay()); currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour()); currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute()); } return currentStartTime; }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Sets the start date in a dublin core catalog to the right value and keeps the start time and duration the same. * * @param dc/*from w w w. j a v a2s . c o m*/ * The dublin core catalog to adjust * @param field * The metadata field that contains the start date. * @param ename * The EName in the catalog to identify the property that has the dublin core period. */ static void setTemporalStartDate(DublinCoreCatalog dc, MetadataField<?> field, EName ename) { if (field.getValue().isNone() || (field.getValue().get() instanceof String && StringUtils.isBlank(field.getValue().get().toString()))) { logger.debug("No value was set for metadata field with dublin core id '{}' and json id '{}'", field.getInputID(), field.getOutputID()); return; } try { // Get the current date SimpleDateFormat dateFormat = MetadataField.getSimpleDateFormatter(field.getPattern().get()); Date startDate = dateFormat.parse((String) field.getValue().get()); // Get the current period Opt<DCMIPeriod> period = getPeriodFromCatalog(dc, ename); // Get the current duration Long duration = getDuration(period); // Get the current start time hours, minutes and seconds DateTime currentStartTime = getCurrentStartTime(period); // Setup the new start time DateTime startDateTime = new DateTime(startDate.getTime()); startDateTime = startDateTime.withZone(DateTimeZone.UTC); startDateTime = startDateTime.withHourOfDay(currentStartTime.getHourOfDay()); startDateTime = startDateTime.withMinuteOfHour(currentStartTime.getMinuteOfHour()); startDateTime = startDateTime.withSecondOfMinute(currentStartTime.getSecondOfMinute()); // Get the current end date based on new date and duration. DateTime endDate = new DateTime(startDateTime.toDate().getTime() + duration); dc.set(ename, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(startDateTime.toDate(), endDate.toDate()), Precision.Second)); } catch (ParseException e) { logger.error("Not able to parse date {} to update the dublin core because: {}", field.getValue(), ExceptionUtils.getStackTrace(e)); } }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period/* w w w . j a v a2 s . com*/ * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ private static DateTime getCurrentStartDateTime(Opt<DCMIPeriod> period) { DateTime currentStartTime = new DateTime(); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(2001); currentStartTime = currentStartTime.withMonthOfYear(1); currentStartTime = currentStartTime.withDayOfMonth(1); currentStartTime = currentStartTime.withHourOfDay(0); currentStartTime = currentStartTime.withMinuteOfHour(0); currentStartTime = currentStartTime.withSecondOfMinute(0); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(fromDC.getYear()); currentStartTime = currentStartTime.withMonthOfYear(fromDC.getMonthOfYear()); currentStartTime = currentStartTime.withDayOfMonth(fromDC.getDayOfMonth()); currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay()); currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour()); currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute()); } return currentStartTime; }
From source file:org.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateTickValues(double length, Object range) { LinkedList<Long> ticks = new LinkedList<Long>(); DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int majorInterval; if ((majorInterval = (origin.getSecondOfMinute() / 15) + 1) < 4) { origin = origin.withSecondOfMinute(majorInterval * 15); } else {// ww w . j a v a 2 s . c o m origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { ticks.add(origin.getMillis()); origin = origin.plusSeconds(15); } return ticks; }
From source file:org.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateMinorTickMarks() { LinkedList<Long> ticks = new LinkedList<Long>(); Object range = getRange();//ww w . j av a 2 s .c o m DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int minorInterval; if ((minorInterval = (origin.getSecondOfMinute() / 5) + 1) < 12) { origin = origin.withSecondOfMinute(minorInterval * 5); } else { origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { if ((origin.getSecondOfMinute() % 15) != 0) { ticks.add(origin.getMillis()); } origin = origin.plusSeconds(5); } return ticks; }