/** * 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; }
/** * 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; }