List of usage examples for org.joda.time Minutes getMinutes
public int getMinutes()
From source file:au.id.hazelwood.xmltvguidebuilder.mapper.XmltvMapper.java
License:Apache License
private Length createLength(Minutes duration) { Length length = OBJECT_FACTORY.createLength(); length.setUnits(LENGTH_UNITS);/*from www. ja va 2s . c o m*/ length.setvalue(String.valueOf(duration.getMinutes())); return length; }
From source file:ca.barrenechea.ticker.utils.TimeUtils.java
License:Apache License
public static TimeSpan getSpan(long start, long end) { if (end <= start) { return new TimeSpan(0, 0, 0); }/*from ww w .ja v a 2 s .com*/ Interval interval = new Interval(start, end); Days days = Days.daysIn(interval); Hours hours = Hours.hoursIn(interval).minus(days.toStandardHours()); Minutes minutes = Minutes.minutesIn(interval).minus(days.toStandardMinutes()) .minus(hours.toStandardMinutes()); return new TimeSpan(days.getDays(), hours.getHours(), minutes.getMinutes()); }
From source file:com.axelor.studio.service.wkf.WkfTrackingService.java
License:Open Source License
/** * Method add new WkfTrackingLine in WkfTracking for given status if that * status is not last status added.// ww w . j a v a 2 s . com * * @param wkfTracking * WkfTracking to update with new line. * @param status * Status to check for update. * @return WkfTrackingLine created or return null if status not changed. */ @Transactional public WkfTrackingLine updateTrackingLine(WkfTracking wkfTracking, String status) { WkfTrackingLine trackingLine = trackingLineRepo.all().filter("self.wkfTracking = ?1", wkfTracking) .fetchOne(); if (trackingLine == null || !trackingLine.getStatus().equals(status)) { LocalDateTime now = new LocalDateTime(); if (trackingLine != null) { oldStatus = trackingLine.getStatus(); LocalDateTime lastUpdated = trackingLine.getCreatedOn(); Minutes minutes = Minutes.minutesBetween(lastUpdated, now); log.debug("Minutes between {} and {} : {}", lastUpdated, now, minutes.getMinutes()); durationHrs = new BigDecimal(minutes.getMinutes()).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP); log.debug("Hours between {} and {} : {}", lastUpdated, now, durationHrs); trackingLine.setTimeSpent(durationHrs); trackingLineRepo.save(trackingLine); } trackingLine = new WkfTrackingLine(); trackingLine.setWkfTracking(wkfTracking); trackingLine.setStatus(status); trackingLine.setWkfTracking(wkfTracking); return trackingLineRepo.save(trackingLine); } return null; }
From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *//*from w w w .j ava 2 s . c om*/ public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { java.util.Date startDate = null; java.util.Date endDate = null; Calendar startCal = null; Calendar endCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; long dateLength = 0; try { result = null; if (inputValues[0] == null) { result = new Long(dateLength); return; } if (inputValues[1] == null) { result = new Long(dateLength); return; } if (inputValues[2] == null) { result = new Long(dateLength); return; } datePart = (String) inputValues[0]; startDate = (java.util.Date) inputValues[1]; startCal = Calendar.getInstance(); startCal.setTime(startDate); endDate = (java.util.Date) inputValues[2]; endCal = Calendar.getInstance(); endCal.setTime(endDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1, endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); if (datePart.equalsIgnoreCase("second")) { Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime); dateLength = seconds.getSeconds(); } if (datePart.equalsIgnoreCase("minute")) { Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime); dateLength = minutes.getMinutes(); } if (datePart.equalsIgnoreCase("hour")) { Hours hours = Hours.hoursBetween(startDateTime, endDateTime); dateLength = hours.getHours(); } if (datePart.equalsIgnoreCase("day")) { Days days = Days.daysBetween(startDateTime, endDateTime); dateLength = days.getDays(); } if (datePart.equalsIgnoreCase("week")) { Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime); dateLength = weeks.getWeeks(); } if (datePart.equalsIgnoreCase("month")) { Months months = Months.monthsBetween(startDateTime, endDateTime); dateLength = months.getMonths(); } if (datePart.equalsIgnoreCase("year")) { Years years = Years.yearsBetween(startDateTime, endDateTime); dateLength = years.getYears(); } result = new Long(dateLength); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *///w w w . j a v a2s . com public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { Timestamp startTimestamp = null; Timestamp endTimestamp = null; Calendar startCal = null; Calendar endCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; long dateLength = 0; try { result = null; if (inputValues[0] == null) { result = new Long(dateLength); return; } if (inputValues[1] == null) { result = new Long(dateLength); return; } if (inputValues[2] == null) { result = new Long(dateLength); return; } datePart = (String) inputValues[0]; startTimestamp = (Timestamp) inputValues[1]; // long startMilliseconds = startTimestamp.getTime() + // (startTimestamp.getNanos() / 1000000); long startMilliseconds = startTimestamp.getTime() + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0); startCal = Calendar.getInstance(); startCal.setTimeInMillis(startMilliseconds); endTimestamp = (Timestamp) inputValues[2]; // long endMilliseconds = endTimestamp.getTime() + // (endTimestamp.getNanos() / 1000000); long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0); endCal = Calendar.getInstance(); endCal.setTimeInMillis(endMilliseconds); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY), startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND), startCal.get(Calendar.MILLISECOND)); endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1, endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY), endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND)); Interval interval = new Interval(startDateTime, endDateTime); if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) { Seconds seconds = Seconds.secondsIn(interval); dateLength = seconds.getSeconds(); } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) { Minutes minutes = Minutes.minutesIn(interval); dateLength = minutes.getMinutes(); } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) { Hours hours = Hours.hoursIn(interval); dateLength = hours.getHours(); } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) { Days days = Days.daysIn(interval); dateLength = days.getDays(); } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) { Weeks weeks = Weeks.weeksIn(interval); dateLength = weeks.getWeeks(); } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) { Months months = Months.monthsIn(interval); dateLength = months.getMonths(); } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) { Years years = Years.yearsIn(interval); dateLength = years.getYears(); } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) { dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) { dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds * 1000000L // micros + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000 } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) { dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds * 1000000000L // nanos + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos } else { throw new IllegalArgumentException(datePart); } result = new Long(dateLength); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.google.android.apps.paco.EsmGenerator2.java
License:Open Source License
public List<DateTime> generateForSchedule(DateTime startDate, SignalSchedule schedule) { this.schedule = schedule; this.periodStartDate = adjustStartDateToBeginningOfPeriod(startDate); times = new ArrayList<DateTime>(); if (schedule.getEsmFrequency() == null || schedule.getEsmFrequency() == 0) { return times; }// w w w . ja v a2 s. com List<Integer> schedulableDays; switch (schedule.getEsmPeriodInDays()) { case SignalSchedule.ESM_PERIOD_DAY: if (!schedule.getEsmWeekends() && TimeUtil.isWeekend(periodStartDate)) { return times; } else { schedulableDays = Arrays.asList(1); } break; case SignalSchedule.ESM_PERIOD_WEEK: schedulableDays = getPeriodDaysForWeek(); break; case SignalSchedule.ESM_PERIOD_MONTH: schedulableDays = getPeriodDaysForMonthOf(periodStartDate); break; default: throw new IllegalStateException("Cannot get here."); } Minutes dayLengthIntervalInMinutes = Minutes .minutesIn(new Interval(schedule.getEsmStartHour(), schedule.getEsmEndHour())); Minutes totalMinutesInPeriod = dayLengthIntervalInMinutes.multipliedBy(schedulableDays.size()); Minutes sampleBlockTimeInMinutes = totalMinutesInPeriod.dividedBy(schedule.getEsmFrequency()); Minutes timeoutInMinutes = Minutes.minutes(schedule.getMinimumBuffer()); Random rand = new Random(); for (int signal = 0; signal < schedule.getEsmFrequency(); signal++) { int candidateTimeInBlock; DateTime candidateTime; int periodAttempts = 1000; do { candidateTimeInBlock = rand.nextInt(sampleBlockTimeInMinutes.getMinutes()); // map candidatePeriod and candidateTime back onto days of period // note, sometimes a candidate period will map across days in period // because start and end hours make for non-contiguous days int totalMinutesToAdd = sampleBlockTimeInMinutes.getMinutes() * signal + candidateTimeInBlock; int daysToAdd = totalMinutesToAdd / dayLengthIntervalInMinutes.getMinutes(); int minutesToAdd = 0; if (totalMinutesToAdd <= dayLengthIntervalInMinutes.getMinutes()) { // within one day minutesToAdd = totalMinutesToAdd; } else { minutesToAdd = totalMinutesToAdd % dayLengthIntervalInMinutes.getMinutes(); } DateTime plusDays = periodStartDate.plusDays(schedulableDays.get(daysToAdd) - 1); candidateTime = plusDays.withMillisOfDay(schedule.getEsmStartHour().intValue()) .plusMinutes(minutesToAdd); periodAttempts--; } while (periodAttempts > 0 && (!isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) || (!schedule.getEsmWeekends() && TimeUtil.isWeekend(candidateTime)))); if (isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) && (schedule.getEsmWeekends() || !TimeUtil.isWeekend(candidateTime))) { times.add(candidateTime); } } return times; }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
License:Open Source License
static void checkIfUpdateRequired(JMenuItem update_item) { // Get current date DateTime dT = new DateTime(); // Get stored date String updateTime = m_prefs.get("updateTime", dT.now().toString()); DateTime uT = new DateTime(updateTime); // Seconds diffSec = Seconds.secondsBetween(uT, dT); Minutes diffMin = Minutes.minutesBetween(uT, dT); // Do this only when the application is freshly installed int timeDiff = diffMin.getMinutes(); /*/* w w w . ja v a 2 s.c o m*/ if (timeDiff == 0) m_prefs.put("updateTime", dT.now().toString()); */ // First check if everything needs to be updated... switch (m_prefs.getInt("update", 0)) { case 0: // Manual // do nothing break; case 1: // Daily if (timeDiff > 60 * 24) { m_full_db_update = true; update_item.doClick(); } break; case 2: // Weekly if (timeDiff > 60 * 24 * 7) { m_full_db_update = true; update_item.doClick(); } break; case 3: // Monthly if (timeDiff > 60 * 24 * 30) { m_full_db_update = true; update_item.doClick(); } break; default: break; } // else proceed with the Preisvergleich-only update switch (m_prefs.getInt("update-comp", 0)) { case 0: // Manual // do nothing break; case 1: // Half-hourly if (timeDiff % 30 == 0) { m_full_db_update = false; update_item.doClick(); } break; case 2: // Hourly if (timeDiff % 60 == 0) { m_full_db_update = false; update_item.doClick(); } break; case 3: // Half-daily if (timeDiff % (4 * 60) == 0) { m_full_db_update = false; update_item.doClick(); } break; default: break; } }
From source file:com.pacoapp.paco.shared.scheduling.EsmGenerator2.java
License:Open Source License
public List<DateTime> generateForSchedule(DateTime startDate, Schedule schedule2) { this.schedule = schedule2; this.periodStartDate = adjustStartDateToBeginningOfPeriod(startDate); times = new ArrayList<DateTime>(); if (schedule2.getEsmFrequency() == null || schedule2.getEsmFrequency() == 0) { return times; }//from w w w .j av a2 s.c o m List<Integer> schedulableDays; switch (schedule2.getEsmPeriodInDays()) { case Schedule.ESM_PERIOD_DAY: if (!schedule2.getEsmWeekends() && TimeUtil.isWeekend(periodStartDate)) { return times; } else { schedulableDays = Arrays.asList(1); } break; case Schedule.ESM_PERIOD_WEEK: schedulableDays = getPeriodDaysForWeek(); break; case Schedule.ESM_PERIOD_MONTH: schedulableDays = getPeriodDaysForMonthOf(periodStartDate); break; default: throw new IllegalStateException("Cannot get here."); } Minutes dayLengthIntervalInMinutes = Minutes .minutesIn(new Interval(schedule2.getEsmStartHour(), schedule2.getEsmEndHour())); Minutes totalMinutesInPeriod = dayLengthIntervalInMinutes.multipliedBy(schedulableDays.size()); Minutes sampleBlockTimeInMinutes = totalMinutesInPeriod.dividedBy(schedule2.getEsmFrequency()); Minutes timeoutInMinutes = Minutes.minutes(schedule2.getMinimumBuffer()); Random rand = new Random(); for (int signal = 0; signal < schedule2.getEsmFrequency(); signal++) { int candidateTimeInBlock; DateTime candidateTime; int periodAttempts = 1000; do { candidateTimeInBlock = rand.nextInt(sampleBlockTimeInMinutes.getMinutes()); // map candidatePeriod and candidateTime back onto days of period // note, sometimes a candidate period will map across days in period // because start and end hours make for non-contiguous days int totalMinutesToAdd = sampleBlockTimeInMinutes.getMinutes() * signal + candidateTimeInBlock; int daysToAdd = totalMinutesToAdd / dayLengthIntervalInMinutes.getMinutes(); int minutesToAdd = 0; if (totalMinutesToAdd <= dayLengthIntervalInMinutes.getMinutes()) { // within one day minutesToAdd = totalMinutesToAdd; } else { minutesToAdd = totalMinutesToAdd % dayLengthIntervalInMinutes.getMinutes(); } DateTime plusDays = periodStartDate.plusDays(schedulableDays.get(daysToAdd) - 1); candidateTime = plusDays.withMillisOfDay(schedule2.getEsmStartHour().intValue()) .plusMinutes(minutesToAdd); periodAttempts--; } while (periodAttempts > 0 && (!isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) || (!schedule2.getEsmWeekends() && TimeUtil.isWeekend(candidateTime)))); if (isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) && (schedule2.getEsmWeekends() || !TimeUtil.isWeekend(candidateTime))) { times.add(candidateTime); } } return times; }
From source file:com.rapidminer.operator.GenerateDateSeries.java
License:Open Source License
private long calculateNumberOfExample(DateTime startTime, DateTime endTime) { // TODO Auto-generated method stub long valuetoReturn = 0; try {//from w ww .j a v a 2s .c om //getParameterAsString(key) switch (getParameterAsString(PARAMETER_INTERVALTYPE)) { case "YEAR": Years year = Years.yearsBetween(startTime, endTime); valuetoReturn = year.getYears() / getParameterAsInt(INTERVAL); break; case "MONTH": Months month = Months.monthsBetween(startTime, endTime); valuetoReturn = month.getMonths() / getParameterAsInt(INTERVAL); break; case "DAY": Days days = Days.daysBetween(startTime, endTime); valuetoReturn = days.getDays() / getParameterAsInt(INTERVAL); break; case "HOUR": Hours hours = Hours.hoursBetween(startTime, endTime); valuetoReturn = hours.getHours() / getParameterAsInt(INTERVAL); break; case "MINUTE": Minutes minute = Minutes.minutesBetween(startTime, endTime); valuetoReturn = minute.getMinutes() / getParameterAsInt(INTERVAL); break; case "SECOND": Seconds second = Seconds.secondsBetween(startTime, endTime); valuetoReturn = second.getSeconds() / getParameterAsInt(INTERVAL); break; case "MILLISECOND": // Milliseconds millisecond = milli long milli = endTime.getMillis() - startTime.getMillis(); valuetoReturn = milli / getParameterAsInt(INTERVAL); break; default: valuetoReturn = 0; } } catch (Exception e) { valuetoReturn = 0; } return valuetoReturn; }
From source file:com.rubenlaguna.en4j.sync.SyncAction.java
License:Open Source License
public void actionPerformed(ActionEvent e) { // TODO implement action body final SynchronizationService sservice = Lookup.getDefault().lookup(SynchronizationService.class); Runnable task = new Runnable() { public void run() { DateTime startTime = new DateTime(); StatusDisplayer.getDefault().setStatusText("Sync started at " + startTime.toString("HH:mm")); if (toolbarPresenter.startAnimator()) { //dont run if it was already running sservice.sync();//from w ww . j a va 2 s. c om toolbarPresenter.stopAnimator(); if (sservice.isSyncFailed()) { StatusDisplayer.getDefault().setStatusText("Sync failed."); } else { DateTime finishTime = new DateTime(); Duration dur = new Duration(startTime, finishTime); Minutes minutes = dur.toPeriod().toStandardMinutes(); Seconds seconds = dur.toPeriod().minus(minutes).toStandardSeconds(); final String message = "sync finished at " + finishTime.toString("HH:mm") + ". Sync took " + minutes.getMinutes() + " minutes and " + seconds.getSeconds() + " seconds."; final StatusDisplayer.Message sbMess = StatusDisplayer.getDefault().setStatusText(message, 1); RP.post(new Runnable() { public void run() { sbMess.clear(10000); } }); } } } }; RP.post(task); }