Refine search
private static Hours hoursBetween(ReadableInstant start, ReadableInstant end) { return Hours.hoursBetween(start, end); }
return MIN_VALUE; default: return new Hours(hours);
/** * Returns a new instance with the specified number of hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative, null means zero * @return the new period plus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours plus(Hours hours) { if (hours == null) { return this; } return plus(hours.getValue()); }
/** * Returns a new instance with the specified number of hours taken away. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to take away, may be negative, null means zero * @return the new period minus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours minus(Hours hours) { if (hours == null) { return this; } return minus(hours.getValue()); }
private static String dateToAge(String createdAt, DateTime now) { if (createdAt == null) { return ""; } DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_FORMAT); try { DateTime created = dtf.parseDateTime(createdAt); if (Seconds.secondsBetween(created, now).getSeconds() < 60) { return Seconds.secondsBetween(created, now).getSeconds() + "s"; } else if (Minutes.minutesBetween(created, now).getMinutes() < 60) { return Minutes.minutesBetween(created, now).getMinutes() + "m"; } else if (Hours.hoursBetween(created, now).getHours() < 24) { return Hours.hoursBetween(created, now).getHours() + "h"; } else { return Days.daysBetween(created, now).getDays() + "d"; } } catch (IllegalArgumentException e) { return ""; } } }
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('month', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) monthsBetween(baseDateTime, TIMESTAMP).getMonths()); assertFunction("date_diff('quarter', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) monthsBetween(baseDateTime, TIMESTAMP).getMonths() / 3); assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getSeconds()); assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) minutesBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getMinutes()); assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getHours()); assertFunction("date_diff('day', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) daysBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getDays()); assertFunction("date_diff('week', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) weeksBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getWeeks()); assertFunction("date_diff('month', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT,
if (Minutes.minutesIn(interval).isLessThan(Minutes.ONE)) { count = Seconds.secondsIn(interval).getSeconds(); if (past) { if (abbrevRelative) { else if (Hours.hoursIn(interval).isLessThan(Hours.ONE)) { count = Minutes.minutesIn(interval).getMinutes(); if (past) { if (abbrevRelative) { else if (Days.daysIn(interval).isLessThan(Days.ONE)) { count = Hours.hoursIn(interval).getHours(); if (past) { if (abbrevRelative) { else if (Weeks.weeksIn(interval).isLessThan(Weeks.ONE)) { count = Days.daysIn(interval).getDays(); if (past) { if (abbrevRelative) {
@Test public void testDateDiffTime() { DateTime baseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, DATE_TIME_ZONE); String baseDateTimeLiteral = "TIME '07:02:09.678'"; assertFunction("date_diff('millisecond', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, millisBetween(baseDateTime, TIME)); assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, secondsBetween(baseDateTime, TIME).getSeconds()); assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, minutesBetween(baseDateTime, TIME).getMinutes()); assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, hoursBetween(baseDateTime, TIME).getHours()); DateTime weirdBaseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, WEIRD_ZONE); String weirdBaseDateTimeLiteral = "TIME '07:02:09.678 +07:09'"; assertFunction("date_diff('millisecond', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, millisBetween(weirdBaseDateTime, WEIRD_TIME)); assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, secondsBetween(weirdBaseDateTime, WEIRD_TIME).getSeconds()); assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, minutesBetween(weirdBaseDateTime, WEIRD_TIME).getMinutes()); assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, hoursBetween(weirdBaseDateTime, WEIRD_TIME).getHours()); }
/** * Converts this period in hours to a period in seconds assuming a * 60 minute hour and 60 second minute. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all hours are * 60 minutes long and all minutes are 60 seconds long. * This may not be true for some unusual chronologies. However, it is included * as it is a useful operation for many applications and business rules. * * @return a period representing the number of seconds for this number of hours * @throws ArithmeticException if the number of seconds is too large to be represented */ public Seconds toStandardSeconds() { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), DateTimeConstants.SECONDS_PER_HOUR)); }
/** * Converts this period in hours to a period in minutes assuming a * 60 minute hour. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all hours are 60 minutes long. * This may not be true for some unusual chronologies. However, it is included * as it is a useful operation for many applications and business rules. * * @return a period representing the number of minutes for this number of hours * @throws ArithmeticException if the number of minutes is too large to be represented */ public Minutes toStandardMinutes() { return Minutes.minutes(FieldUtils.safeMultiply(getValue(), DateTimeConstants.MINUTES_PER_HOUR)); }
/** * 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 this period in days to a period in hours assuming a * 24 hour day. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all days are 24 hours long. * This is not true when daylight savings is considered and may also not * be true for some unusual chronologies. However, it is included * as it is a useful operation for many applications and business rules. * * @return a period representing the number of hours for this number of days * @throws ArithmeticException if the number of hours is too large to be represented */ public Hours toStandardHours() { return Hours.hours(FieldUtils.safeMultiply(getValue(), DateTimeConstants.HOURS_PER_DAY)); }
/** * Converts this period in weeks to a period in hours assuming a * 7 day week and 24 hour day. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all weeks are * 7 days long and all days are 24 hours long. * This is not true when daylight savings is considered and may also not * be true for some unusual chronologies. However, it is included * as it is a useful operation for many applications and business rules. * * @return a period representing the number of hours for this number of weeks * @throws ArithmeticException if the number of hours is too large to be represented */ public Hours toStandardHours() { return Hours.hours(FieldUtils.safeMultiply(getValue(), DateTimeConstants.HOURS_PER_WEEK)); }
/** * Converts this period in hours to a period in days assuming a * 24 hour day. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all days are 24 hours long. * This is not true when daylight savings time is considered, and may also * not be true for some unusual chronologies. However, it is included as it * is a useful operation for many applications and business rules. * * @return a period representing the number of whole days for this number of hours */ public Days toStandardDays() { return Days.days(getValue() / DateTimeConstants.HOURS_PER_DAY); }
/** * Returns a new instance with the hours value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Hours negated() { return Hours.hours(FieldUtils.safeNegate(getValue())); }
/** * Returns a new instance with the hours multiplied by the specified scalar. * <p> * This instance is immutable and unaffected by this method call. * * @param scalar the amount to multiply by, may be negative * @return the new period multiplied by the specified scalar * @throws ArithmeticException if the result overflows an int */ public Hours multipliedBy(int scalar) { return Hours.hours(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the specified number of hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative * @return the new period plus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours plus(int hours) { if (hours == 0) { return this; } return Hours.hours(FieldUtils.safeAdd(getValue(), hours)); }