@Override public final DayToSecond abs() { return new DayToSecond(days, hours, minutes, seconds, nano, false); }
@Override public final DayToSecond neg() { return new DayToSecond(days, hours, minutes, seconds, nano, !negative); }
@Override public final DayToSecond neg() { return new DayToSecond(days, hours, minutes, seconds, nano, !negative); }
@Override public final DayToSecond abs() { return new DayToSecond(days, hours, minutes, seconds, nano, false); }
/** * 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; }
/** * 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; }
/** * 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; }
int nano = Convert.convert(StringUtils.rightPad(matcher.group(6), 9, "0"), int.class); 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; }
/** * 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; }