List of usage examples for org.joda.time Hours getHours
public int getHours()
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 w w w. j a va2s .co m 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.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. */// w w w . j av a2s . 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 av a2 s .co m*/ 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.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();/*from w w w . j a v a 2 s. 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.rapidminer.operator.GenerateDateSeries.java
License:Open Source License
private long calculateNumberOfExample(DateTime startTime, DateTime endTime) { // TODO Auto-generated method stub long valuetoReturn = 0; try {//w w w. j av a2s . 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.superrent.modules.Return.java
public int getNumberofhours(Date pickupdt, Date returndt) { Calendar pickup = Calendar.getInstance(); Calendar dropoff = Calendar.getInstance(); pickup.setTime(pickupdt);//from w w w .j ava 2 s . c o m dropoff.setTime(returndt); DateTime start = new DateTime(pickup.get(Calendar.YEAR), pickup.get(Calendar.MONTH) + 1, pickup.get(Calendar.DATE), pickup.get(Calendar.HOUR), pickup.get(Calendar.MINUTE), 0, 0); DateTime end = new DateTime(dropoff.get(Calendar.YEAR), dropoff.get(Calendar.MONTH) + 1, dropoff.get(Calendar.DATE), dropoff.get(Calendar.HOUR), dropoff.get(Calendar.MINUTE), 0, 0); Hours hours = Hours.hoursBetween(start, end); return hours.getHours(); }
From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java
License:Apache License
private static String getHoursCron(Period p) { Integer hrs = p.getHours();/*from w w w . ja va 2 s. c o m*/ Hours h = p.toStandardHours(); Integer hours = h.getHours(); String str = "0" + (hrs > 0 ? "/" + hrs : ""); if (hours > 24) { str = hrs + ""; } return str; }
From source file:influent.server.utilities.DateRangeBuilder.java
License:MIT License
public static int determineInterval(DateTime date, DateTime startDate, FL_DateInterval interval, int numIntervalsPerBin) { switch (interval) { case SECONDS: Seconds seconds = Seconds.secondsBetween(startDate, date); return seconds.getSeconds() / numIntervalsPerBin; case HOURS://from ww w . jav a 2s . c o m Hours hours = Hours.hoursBetween(startDate, date); return hours.getHours() / numIntervalsPerBin; case DAYS: Days days = Days.daysBetween(startDate, date); return days.getDays() / numIntervalsPerBin; case WEEKS: Weeks weeks = Weeks.weeksBetween(startDate, date); return weeks.getWeeks() / numIntervalsPerBin; case MONTHS: Months months = Months.monthsBetween(startDate, date); return months.getMonths() / numIntervalsPerBin; case QUARTERS: months = Months.monthsBetween(startDate, date); return months.getMonths() / 3 / numIntervalsPerBin; case YEARS: Years years = Years.yearsBetween(startDate, date); return years.getYears() / numIntervalsPerBin; } return 0; }
From source file:net.technicpack.launcher.ui.components.news.AuthorshipWidget.java
License:Open Source License
private String getDateText(Date date) { LocalDate posted = new LocalDate(date.getTime()); LocalDate now = new LocalDate(); Years yearsSince = Years.yearsBetween(posted, now); Months monthsSince = Months.monthsBetween(posted, now); Days daysSince = Days.daysBetween(posted, now); Hours hoursSince = Hours.hoursBetween(posted, now); Minutes minutesSince = Minutes.minutesBetween(posted, now); if (yearsSince.getYears() > 1) return resources.getString("time.years", Integer.toString(yearsSince.getYears())); else if (yearsSince.getYears() == 1) return resources.getString("time.year"); else if (monthsSince.getMonths() > 1) return resources.getString("time.months", Integer.toString(monthsSince.getMonths())); else if (monthsSince.getMonths() == 1) return resources.getString("time.month"); else if (daysSince.getDays() > 1) return resources.getString("time.days", Integer.toString(daysSince.getDays())); else if (daysSince.getDays() == 1) return resources.getString("time.day"); else if (hoursSince.getHours() > 1) return resources.getString("time.hours", Integer.toString(hoursSince.getHours())); else if (hoursSince.getHours() == 1) return resources.getString("time.hour"); else if (minutesSince.getMinutes() > 1) return resources.getString("time.minutes", Integer.toString(minutesSince.getMinutes())); else/*w w w . j a v a2s .c o m*/ return resources.getString("time.minute"); }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOHoursBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//w w w. ja v a2 s .c om // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Hours h = Hours.hoursBetween(endDate, startDate); long hours = h.getHours(); return hours; }