List of usage examples for org.joda.time DateTime withSecondOfMinute
public DateTime withSecondOfMinute(int second)
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
License:Apache License
/** * Based on the given interval, create a "floor" value relative to the * given date. This basically means zero'ing out certain fields (different * fields based on the interval type) and returning the modified date. * @param date//from w w w. j av a 2 s .c om * @param interval */ protected static DateTime floor(DateTime date, HistogramIntervalType interval) { DateTime rval = date.withMillisOfSecond(0); switch (interval) { case day: rval = rval.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case hour: rval = rval.withMinuteOfHour(0).withSecondOfMinute(0); break; case minute: rval = rval.withSecondOfMinute(0); break; case month: rval = rval.withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case week: rval = rval.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); break; } return rval; }
From source file:org.egov.eventnotification.service.ScheduleService.java
License:Open Source License
@Transactional public Schedule saveSchedule(Schedule notificationSchedule, String fullURL) { DateTime sd = startOfGivenDate(new DateTime(notificationSchedule.getDetails().getStartDt())) .withHourOfDay(Integer.parseInt(notificationSchedule.getDetails().getStartHH())) .withMinuteOfHour(Integer.parseInt(notificationSchedule.getDetails().getStartMM())); sd = sd.withSecondOfMinute(00); Drafts draft = draftRepository.findOne(notificationSchedule.getDetails().getDraftId()); notificationSchedule.setStartDate(sd.toDate()); notificationSchedule.setStatus("scheduled"); notificationSchedule.setUrl(draft.getUrl()); notificationSchedule.setMethod(draft.getMethod()); scheduleRepository.save(notificationSchedule); scheduleDetailsService.executeScheduler(notificationSchedule, fullURL); return notificationSchedule; }
From source file:org.everit.jira.settings.dto.TimeTrackerUserSettings.java
License:Apache License
/** * Gets the default start time./*from w w w . j ava 2 s . c om*/ */ public String getDefaultStartTime() { String savedDefaultStartTime = pluginSettingsKeyValues.get(UserSettingKey.DEFAULT_START_TIME); if (savedDefaultStartTime == null) { DateTime dateTime = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); dateTime = dateTime.withHourOfDay(DateTimeConverterUtil.HOUR_EIGHT); dateTime = dateTime.withMinuteOfHour(0); dateTime = dateTime.withSecondOfMinute(0); return DateTimeConverterUtil.dateTimeToString(DateTimeConverterUtil.convertDateTimeToDate(dateTime)); } Date date; try { date = DateTimeConverterUtil.stringTimeToDateTimeWithFixFormat(savedDefaultStartTime); } catch (ParseException e) { // we save defautl start time with HH:mm format. We parse with this format at now. Not // possible to throw exception. throw new RuntimeException("Cannot be parse default start time."); } return DateTimeConverterUtil.dateTimeToString(date); }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Return a Calendar with time set by the start of the given day. * * @param date/* w w w . java 2 s . co m*/ * The time to set the calendar * @return The calendar which represents the start of the day */ public static DateTime setDateToDayStart(final DateTime date) { DateTime dateStartOfTheDay = date.withHourOfDay(0); dateStartOfTheDay = dateStartOfTheDay.withMinuteOfHour(0); dateStartOfTheDay = dateStartOfTheDay.withSecondOfMinute(0); dateStartOfTheDay = dateStartOfTheDay.withMillisOfSecond(0); return dateStartOfTheDay; }
From source file:org.jruby.CompatVersion.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime(); DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes = null; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); }/*from w w w .java 2s . co m*/ int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L + s); } else { p &= ~(1 << 31); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); dt = dt.withZone(getLocalTimeZone(runtime)); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); return time; }
From source file:org.jruby.RubyTime.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime();/*from www . ja v a 2 s . com*/ DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); } int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } boolean utc = false; if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L); time.setUSec((s & 0xFFFFF) % 1000); } else { p &= ~(1 << 31); utc = ((p >>> 30 & 0x1) == 0x1); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); if (!utc) time.localtime(); from.getInstanceVariables().copyInstanceVariablesInto(time); // pull out nanos, offset, zone IRubyObject nano_num = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_num"); IRubyObject nano_den = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_den"); IRubyObject offsetVar = (IRubyObject) from.getInternalVariables().getInternalVariable("offset"); IRubyObject zoneVar = (IRubyObject) from.getInternalVariables().getInternalVariable("zone"); if (nano_num != null && nano_den != null) { long nanos = nano_num.convertToInteger().getLongValue() / nano_den.convertToInteger().getLongValue(); time.nsec += nanos; } int offset = 0; if (offsetVar != null && offsetVar.respondsTo("to_int")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { offset = offsetVar.convertToInteger().getIntValue() * 1000; } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } String zone = ""; if (zoneVar != null && zoneVar.respondsTo("to_str")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { zone = zoneVar.convertToString().toString(); } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } time.dt = dt.withZone(getTimeZoneWithOffset(runtime, zone, offset)); return time; }
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 w w. j a v a 2 s. 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:/* w w w .j av a 2 s .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 ww .ja va 2s .c om*/ 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()) {/* w w w. j a v a2 s.c om*/ 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; }