@Override public final DayToSecond abs() { return new DayToSecond(days, hours, minutes, seconds, nano, false); }
@Override public final float floatValue() { return (float) doubleValue(); }
/** * Convert a jOOQ <code>DAY TO SECOND</code> interval to a Postgres representation */ public static Object toPGInterval(DayToSecond interval) { return on("org.postgresql.util.PGInterval").create(0, 0, interval.getSign() * interval.getDays(), interval.getSign() * interval.getHours(), interval.getSign() * interval.getMinutes(), interval.getSign() * interval.getSeconds() + interval.getSign() * interval.getNano() / 1000000000.0).get(); }
/** * Load a {@link Double} representation of a * <code>INTERVAL DAY TO SECOND</code> by assuming standard 24 hour days and * 60 second minutes. * * @param milli The number of milliseconds as a fractional number * @return The loaded <code>INTERVAL DAY TO SECOND</code> object */ public static DayToSecond valueOf(double milli) { double abs = Math.abs(milli); int n = (int) ((abs % 1000) * 1000000.0); abs = Math.floor(abs / 1000); int s = (int) (abs % 60); abs = Math.floor(abs / 60); int m = (int) (abs % 60); abs = Math.floor(abs / 60); int h = (int) (abs % 24); abs = Math.floor(abs / 24); int d = (int) abs; DayToSecond result = new DayToSecond(d, h, m, s, n); if (milli < 0) result = result.neg(); return result; }
/** * Get the whole interval in days */ public final double getTotalDays() { return getSign() * ( nano / (24.0 * 3600.0 * 1000000000.0) + seconds / (24.0 * 3600.0) + minutes / (24.0 * 60.0) + hours / 24.0 + days); }
return valueOf(Double.valueOf(string)); int nano = Convert.convert(StringUtils.rightPad(matcher.group(6), 9, "0"), int.class); return new DayToSecond(days, hours, minutes, seconds, nano, negative); return DayToSecond.valueOf(Duration.parse(string));
@Override public final double doubleValue() { return getTotalMilli(); }
/** * Load a {@link Double} representation of a <code>INTERVAL DAY TO SECOND</code> * * @param milli The number of milliseconds as a fractional number * @return The loaded <code>INTERVAL DAY TO SECOND</code> object */ public static DayToSecond valueOf(double milli) { double abs = Math.abs(milli); int n = (int) ((abs % 1000) * 1000000.0); abs = Math.floor(abs / 1000); int s = (int) (abs % 60); abs = Math.floor(abs / 60); int m = (int) (abs % 60); abs = Math.floor(abs / 60); int h = (int) (abs % 24); abs = Math.floor(abs / 24); int d = (int) abs; DayToSecond result = new DayToSecond(d, h, m, s, n); if (milli < 0) { result = result.neg(); } return result; }
/** * Get the whole interval in minutes */ public final double getTotalMinutes() { return getSign() * ( nano / (60.0 * 1000000000.0) + seconds / 60.0 + minutes + 60.0 * hours + 60.0 * 24.0 * days); }
/** * Parse a string representation of a <code>INTERVAL DAY TO SECOND</code> * * @param string A string representation of the form * <code>[+|-][days] [hours]:[minutes]:[seconds].[fractional seconds]</code> * @return The parsed <code>INTERVAL DAY TO SECOND</code> object, or * <code>null</code> if the string could not be parsed. */ public static DayToSecond valueOf(String string) { if (string != null) { // Accept also doubles as the number of days try { return valueOf(Double.valueOf(string)); } catch (NumberFormatException e) { Matcher matcher = PATTERN.matcher(string); if (matcher.find()) { boolean negative = "-".equals(matcher.group(1)); int days = Convert.convert(matcher.group(2), int.class); int hours = Convert.convert(matcher.group(3), int.class); int minutes = Convert.convert(matcher.group(4), int.class); int seconds = Convert.convert(matcher.group(5), int.class); int nano = Convert.convert(StringUtils.rightPad(matcher.group(6), 9, "0"), int.class); return new DayToSecond(days, hours, minutes, seconds, nano, negative); } } } return null; }
@Override public final double doubleValue() { return getTotalMilli(); }
/** * Convert a jOOQ <code>DAY TO SECOND</code> interval to a Postgres representation */ public static Object toPGInterval(DayToSecond interval) { return on("org.postgresql.util.PGInterval").create(0, 0, interval.getSign() * interval.getDays(), interval.getSign() * interval.getHours(), interval.getSign() * interval.getMinutes(), interval.getSign() * interval.getSeconds() + interval.getSign() * interval.getNano() / 1000000000.0).get(); }
/** * Convert a Postgres interval to a jOOQ <code>DAY TO SECOND</code> interval */ public static DayToSecond toDayToSecond(Object pgInterval) { boolean negative = pgInterval.toString().contains("-"); Reflect i = on(pgInterval); if (negative) { i.call("scale", -1); } Double seconds = i.call("getSeconds").<Double>get(); DayToSecond result = new DayToSecond( i.call("getDays").<Integer>get(), i.call("getHours").<Integer>get(), i.call("getMinutes").<Integer>get(), seconds.intValue(), (int) (1000000000 * (seconds - seconds.intValue()))); if (negative) { result = result.neg(); } return result; }
/** * Get the whole interval in days */ public final double getTotalDays() { return getSign() * ( nano / (24.0 * 3600.0 * 1000000000.0) + seconds / (24.0 * 3600.0) + minutes / (24.0 * 60.0) + hours / 24.0 + days); }
@Override public final int intValue() { return (int) doubleValue(); }
@Override public final DayToSecond neg() { return new DayToSecond(days, hours, minutes, seconds, nano, !negative); }
/** * Convert a Postgres interval to a jOOQ <code>DAY TO SECOND</code> interval */ public static DayToSecond toDayToSecond(Object pgInterval) { boolean negative = pgInterval.toString().contains("-"); Reflect i = on(pgInterval); if (negative) { i.call("scale", -1); } Double seconds = i.call("getSeconds").<Double>get(); DayToSecond result = new DayToSecond( i.call("getDays").<Integer>get(), i.call("getHours").<Integer>get(), i.call("getMinutes").<Integer>get(), seconds.intValue(), (int) (1000000000 * (seconds - seconds.intValue()))); if (negative) { result = result.neg(); } return result; }
/** * Get the whole interval in milli-seconds */ public final double getTotalMilli() { return getSign() * ( nano / 1000000.0 + 1000.0 * seconds + 1000.0 * 60.0 * minutes + 1000.0 * 3600.0 * hours + 1000.0 * 3600.0 * 24.0 * days); }
@Override public final long longValue() { return (long) doubleValue(); }
@Override public final DayToSecond neg() { return new DayToSecond(days, hours, minutes, seconds, nano, !negative); }