List of usage examples for org.joda.time DateTime withMinuteOfHour
public DateTime withMinuteOfHour(int minute)
From source file:org.jvyamlb.SafeConstructorImpl.java
public static Object constructYamlTimestamp(final Constructor ctor, final Node node) { Matcher match = YMD_REGEXP.matcher(node.getValue().toString()); if (match.matches()) { final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); }//w ww . j a va 2s .co m if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } return new Object[] { dt }; } match = TIMESTAMP_REGEXP.matcher(node.getValue().toString()); if (!match.matches()) { return new Object[] { ctor.constructPrivateType(node) }; } final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); final String hour_s = match.group(4); final String min_s = match.group(5); final String sec_s = match.group(6); final String fract_s = match.group(7); final String utc = match.group(8); final String timezoneh_s = match.group(9); final String timezonem_s = match.group(10); int usec = 0; if (fract_s != null) { usec = Integer.parseInt(fract_s); if (usec != 0) { while (10 * usec < 1000) { usec *= 10; } } } DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if ("Z".equalsIgnoreCase(utc)) { dt = dt.withZone(DateTimeZone.forID("Etc/GMT")); } else { if (timezoneh_s != null || timezonem_s != null) { int zone = 0; int sign = +1; if (timezoneh_s != null) { if (timezoneh_s.startsWith("-")) { sign = -1; } zone += Integer.parseInt(timezoneh_s.substring(1)) * 3600000; } if (timezonem_s != null) { zone += Integer.parseInt(timezonem_s) * 60000; } dt = dt.withZone(DateTimeZone.forOffsetMillis(sign * zone)); } } if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); } if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } if (hour_s != null) { dt = dt.withHourOfDay(Integer.parseInt(hour_s)); } if (min_s != null) { dt = dt.withMinuteOfHour(Integer.parseInt(min_s)); } if (sec_s != null) { dt = dt.withSecondOfMinute(Integer.parseInt(sec_s)); } dt = dt.withMillisOfSecond(usec / 1000); return new Object[] { dt, new Integer(usec % 1000) }; }
From source file:org.kairosdb.core.aggregator.RangeAggregator.java
License:Apache License
/** For YEARS, MONTHS, WEEKS, DAYS://from ww w. j av a 2s. c om Computes the timestamp of the first millisecond of the day of the timestamp. For HOURS, Computes the timestamp of the first millisecond of the hour of the timestamp. For MINUTES, Computes the timestamp of the first millisecond of the minute of the timestamp. For SECONDS, Computes the timestamp of the first millisecond of the second of the timestamp. For MILLISECONDS, returns the timestamp @param timestamp @return */ private long alignRangeBoundary(long timestamp) { DateTime dt = new DateTime(timestamp, m_timeZone); TimeUnit tu = m_sampling.getUnit(); switch (tu) { case YEARS: dt = dt.withDayOfYear(1).withMillisOfDay(0); break; case MONTHS: dt = dt.withDayOfMonth(1).withMillisOfDay(0); break; case WEEKS: dt = dt.withDayOfWeek(1).withMillisOfDay(0); break; case DAYS: case HOURS: case MINUTES: case SECONDS: dt = dt.withHourOfDay(0); dt = dt.withMinuteOfHour(0); dt = dt.withSecondOfMinute(0); default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:org.kitesdk.apps.spi.oozie.CronConverter.java
License:Apache License
public static Instant nextInstant(String cronSchedule, Instant current) { DateTime currentTime = new DateTime(current, DateTimeZone.UTC).withSecondOfMinute(0).withMillisOfSecond(0); validate(cronSchedule);// w w w . j a va 2 s .co m String[] splits = cronSchedule.split(" "); String minutePart = splits[0]; String hourPart = splits[1]; String dayPart = splits[2]; // TODO: fold these together like the hour. if (isWildCard(minutePart)) { return currentTime.plusMinutes(1).toInstant(); } if (isInterval(minutePart)) { // Roll minutes forward until we hit a start time // that matches the cron interval. int interval = getInterval(minutePart); DateTime next = currentTime.withSecondOfMinute(0).plusMinutes(1); while (!(next.getMinuteOfHour() % interval == 0)) { next = next.plusMinutes(1); } return next.toInstant(); } assert (isConstant(minutePart)); // The minute part must be a constant, so // simply get the value. int minute = Integer.parseInt(minutePart); // The schedule is based on hours. if (!isConstant(hourPart)) { int hourModulus = isWildCard(hourPart) ? 1 : getInterval(hourPart); DateTime next = currentTime.withMinuteOfHour(minute); while (next.isBefore(current) || !(next.getHourOfDay() % hourModulus == 0)) { next = next.plusHours(1); } return next.toInstant(); } int hour = Integer.parseInt(hourPart); // The schedule is based on days, and therfore the day cannot // be a constant. This is is checked in validation as well. assert (!isConstant(dayPart)); DateTime next = currentTime.withMinuteOfHour(minute).withHourOfDay(hour); while (next.isBefore(current)) { next = next.plusDays(1); } return next.toInstant(); }
From source file:org.kuali.kpme.tklm.time.rules.graceperiod.service.GracePeriodServiceImpl.java
License:Educational Community License
public DateTime processGracePeriodRule(DateTime actualDateTime, LocalDate asOfDate) { DateTime gracePeriodDateTime = actualDateTime; GracePeriodRule gracePeriodRule = getGracePeriodRule(asOfDate); if (gracePeriodRule != null) { //go ahead and round off seconds gracePeriodDateTime = gracePeriodDateTime.withSecondOfMinute(0); BigDecimal minuteIncrement = gracePeriodRule.getHourFactor(); BigDecimal minutes = new BigDecimal(gracePeriodDateTime.getMinuteOfHour()); int bottomIntervalFactor = minutes.divide(minuteIncrement, 0, BigDecimal.ROUND_FLOOR).intValue(); BigDecimal bottomInterval = new BigDecimal(bottomIntervalFactor).multiply(minuteIncrement); BigDecimal topInterval = new BigDecimal(bottomIntervalFactor + 1).multiply(minuteIncrement); if (bottomInterval.subtract(minutes).abs().intValue() < topInterval.subtract(minutes).abs() .intValue()) {//from w w w . ja v a 2s .c o m gracePeriodDateTime = gracePeriodDateTime .withMinuteOfHour(bottomInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); } else { if (topInterval.equals(new BigDecimal(60))) { gracePeriodDateTime = gracePeriodDateTime.withHourOfDay(gracePeriodDateTime.getHourOfDay() + 1) .withMinuteOfHour(0); } else { gracePeriodDateTime = gracePeriodDateTime .withMinuteOfHour(topInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); } } } return gracePeriodDateTime; }
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. j a va 2s. c o 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// ww w . j a va2s . c om * 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//from www .j ava 2 s. c om * 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.opensextant.extractors.xtemporal.DateNormalization.java
License:Apache License
/** * For now this reports only DATE and standard TIME fields. Timezone is * still TODO.//from w w w. j a v a 2 s . c o m * * TODO: throw NormalizationException * * @param elements pattern fields * @param dt found date * @throws ParseException the parse exception */ public static void normalize_date(java.util.Map<String, String> elements, DateMatch dt) throws ParseException { // Parse years. int year = normalize_year(elements); if (year == INVALID_DATE) { return; } if (year > MAXIMUM_YEAR) { // HHMM can look like a year, e.g., 2100h or 2300 PM return; } dt.resolution = DateMatch.TimeResolution.YEAR; int month = normalize_month(elements); if (month == INVALID_DATE) { month = normalize_month_name(elements); } if (month == INVALID_DATE) { return; } DateTime _cal = new DateTime(year, month, 1, 0, 0, DateTimeZone.UTC); dt.resolution = DateMatch.TimeResolution.MONTH; int dom = normalize_day(elements); // If you got this far, then assume Day of Month is 1 (first of the month) if (dom == INVALID_DATE) { // No date found, resolution is month dom = 1; } else if (dom == 0) { return; } else { dt.resolution = DateMatch.TimeResolution.DAY; } // Normalize Time fields found, H, M, s.SSS, etc. // _cal = _cal.withDayOfMonth(dom); // For normal M/D/Y patterns, set the default time to noon, UTC // Overall, we want to ensure that the general yyyy-mm-dd form is not impacted // by time zone and default hour of 00:00; -- this generally would yield a date format a day early for ALL US timezones. // // Time res: the presence of a field, hh, mm, or ss means the pattern has that level of resolution. // So even if time is 00:00:00Z -- all zeroes -- the resolution is still SECONDS. // int hour = normalize_time(elements, "hh"); if (hour >= 0) { // Only if HH:MM... is present do we try to detect TZ. // DateTimeZone tz = normalize_tz(elements); if (tz != null) { _cal = _cal.withZone(tz); } // NON-zero hour. dt.resolution = DateMatch.TimeResolution.HOUR; int min = normalize_time(elements, "mm"); if (min >= 0) { dt.resolution = DateMatch.TimeResolution.MINUTE; // NON-zero minutes _cal = _cal.withHourOfDay(hour); _cal = _cal.withMinuteOfHour(min); } else { // No minutes _cal = _cal.withHourOfDay(hour); } } else { // No hour; default is 12:00 UTC. _cal = _cal.withHourOfDay(12); } dt.datenorm = new Date(_cal.getMillis()); }
From source file:org.openvpms.web.workspace.workflow.appointment.FreeAppointmentSlotQuery.java
License:Open Source License
/** * Returns the next slot nearest to the specified time. * * @param time the slot time/* w w w .ja v a 2 s. c o m*/ * @return the next nearest slot */ private Date getNextSlot(Date time) { Date from; int slotSize = 15; DateTime dt = new DateTime(time); int min = (dt.getMinuteOfHour() / slotSize) * slotSize; if (dt.getMinuteOfHour() % slotSize != 0) { min += slotSize; if (min >= 60) { dt = dt.plusHours(1); min = 0; } } from = dt.withMinuteOfHour(min).minuteOfDay().roundFloorCopy().toDate(); return from; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Strips an org.joda.time.DateTime of its minutes, seconds, and millis * respecting time zone of original DateTime instance. * * @param dateTime/*w ww . j a v a 2s. com*/ * a DateTime instance * @return DateTime with only date and hour. */ public static DateTime dateTimeToDateHour(final DateTime dateTime) { // Assumes the caller has set the preferred time zone return dateTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }