count = Hours.hoursIn(interval).getHours(); if (past) { if (abbrevRelative) {
private static String getHoursCron(Period p) { Integer hrs = p.getHours(); Hours h = p.toStandardHours(); Integer hours = h.getHours(); String str = "0" + (hrs > 0 ? "/" + hrs : ""); if (hours > 24) { str = hrs + ""; } return str; }
assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(baseDateTime, TIMESTAMP).getSeconds()); assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) minutesBetween(baseDateTime, TIMESTAMP).getMinutes()); assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(baseDateTime, TIMESTAMP).getHours()); assertFunction("date_diff('day', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) daysBetween(baseDateTime, TIMESTAMP).getDays()); assertFunction("date_diff('week', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) weeksBetween(baseDateTime, TIMESTAMP).getWeeks()); assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getHours()); assertFunction("date_diff('day', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT,
Hours h = Hours.hoursBetween(date1, date2); int hours = h.getHours();
Hours hours = Hours.hoursBetween(introDateTimeSaved, introTodaysDate); System.out.println(hours); // PT119H System.out.println(hours.getHours() / 24); // 4 (should be 5)
@Override public int numIn(ReadableInterval interval) { return Hours.hoursIn(interval).getHours(); } },
@Override public int numIn(ReadableInterval interval) { return Hours.hoursIn(interval).getHours(); }
@Override public long getDiff(Interval interval) { return Hours.hoursIn(interval).getHours(); } },
@Override public int numIn(ReadableInterval interval) { return Hours.hoursIn(interval).getHours(); }
@Override public int numIn(ReadableInterval interval) { return Hours.hoursIn(interval).getHours() / 6; }
@Override public int numIn(ReadableInterval interval) { return Hours.hoursIn(interval).getHours() / 6; }
/** * Returns a {@link String} instance representing the configuration parameter's {@literal value}. * * @param value The configuration parameter's {@link org.joda.time.Hours} value * @return A {@link String} instance representing the configuration parameter's typed value */ @Override public String convertTo(Hours value) { if (value == null) { throw new ParameterException("Couldn't convert \"null\" to String."); } return String.valueOf(value.getHours()); } }
/** * isSameHours 判断两个日期是否在同一小时 * @param dateTime1 日期1 * @param dateTime2 日期2 * @return */ public static boolean isSameHours(DateTime dateTime1, DateTime dateTime2) { boolean res = false; int intervalHours = Hours.hoursBetween(dateTime1, dateTime2).getHours(); if (intervalHours == 0) { res = true; } return res; }
/** * Converts seconds to hours. * * @param seconds to be converted. * @return hours equivalent of seconds */ public static int SECONDS_TO_HOURS(int seconds) { Period period = new Period(Seconds.seconds(seconds)); return period.toStandardHours().getHours(); }
private static String getHoursCron(Period p) { Integer hrs = p.getHours(); Hours h = p.toStandardHours(); Integer hours = h.getHours(); String str = "0" + (hrs > 0 ? "/" + hrs : ""); if (hours > 24) { str = hrs + ""; } return str; }
private void formatHours(DateTime now, DateTime then, StringBuilder text) { int hoursBetween = Hours.hoursBetween(now.toLocalTime(), then.toLocalTime()).getHours(); if (hoursBetween == 0) { if (hasFormat(MINUTES)) { formatMinutes(now, then, text); } else { text.append(context.getString(R.string.now)); } } else if (hoursBetween > 0) { // in N hours text.append(context.getResources().getQuantityString(R.plurals.carbon_inHours, hoursBetween, hoursBetween)); } else { // N hours ago text.append(context.getResources().getQuantityString(R.plurals.carbon_hoursAgo, -hoursBetween, -hoursBetween)); } }
private static List<Interval> selectRandomHours(Interval interval, int n) { Hours hours = interval.toDuration().toStandardHours(); List<Interval> result = new ArrayList<Interval>(); Random random = new Random(); for (int i = 0; i < n; i++) { int begOffset = random.nextInt(hours.getHours()); DateTime start = interval.getStart().plusHours(begOffset); DateTime end = start.plusHours(1); result.add(new Interval(start, end)); } return result; } }
private static List<Interval> selectRandomHours(Interval interval, int n) { Hours hours = interval.toDuration().toStandardHours(); List<Interval> result = new ArrayList<Interval>(); Random random = new Random(); for (int i = 0; i < n; i++) { int begOffset = random.nextInt(hours.getHours()); DateTime start = interval.getStart().plusHours(begOffset); DateTime end = start.plusHours(1); result.add(new Interval(start, end)); } return result; } }
public int getHours() { return Hours.hoursIn(interval).getHours(); }
public DateIterator(DateTime end, DateTime start, Duration interval){ this.end = end ; this.start = start ; this.interval = interval ; // inclusive this.cur = this.start ; this.duration = new Duration(this.start, this.end); years = Years.yearsBetween(start,end).getYears(); months = Months.monthsBetween(start, end).getMonths(); weeks = Weeks.weeksBetween(start, end).getWeeks(); days = Days.daysBetween(start, end).getDays(); hours = Hours.hoursBetween(start, end).getHours(); minutes = Minutes.minutesBetween(start, end).getMinutes(); seconds = Seconds.secondsBetween(start, end).getSeconds(); weekDays = weekDays( start.toDate(), end.toDate()); stringRep = String.format("%s : %s : %s", start.toDate(), end.toDate(), interval); hashCode = ( 31* (( 31 * end.hashCode() ) + start.hashCode()) + interval.hashCode()); }