@Override public final YearToMonth neg() { return new YearToMonth(years, months, !negative); }
@Override public final YearToMonth abs() { return new YearToMonth(years, months, false); }
@Override public final YearToMonth neg() { return new YearToMonth(years, months, !negative); }
@Override public final YearToMonth abs() { return new YearToMonth(years, months, false); }
/** * Parse a string representation of a <code>INTERVAL YEAR TO MONTH</code> * * @param string A string representation of the form * <code>[+|-][years]-[months]</code> * @return The parsed <code>YEAR TO MONTH</code> object, or * <code>null</code> if the string could not be parsed. */ public static YearToMonth valueOf(String string) { if (string != null) { Matcher matcher = PATTERN.matcher(string); if (matcher.find()) { boolean negative = "-".equals(matcher.group(1)); int years = Integer.parseInt(matcher.group(2)); int months = Integer.parseInt(matcher.group(3)); return new YearToMonth(years, months, negative); } } return null; }
/** * Parse a string representation of a <code>INTERVAL YEAR TO MONTH</code> * * @param string A string representation of the form * <code>[+|-][years]-[months]</code> * @return The parsed <code>YEAR TO MONTH</code> object, or * <code>null</code> if the string could not be parsed. */ public static YearToMonth valueOf(String string) { if (string != null) { Matcher matcher; if ((matcher = PATTERN_SQL.matcher(string)).find()) { boolean negative = "-".equals(matcher.group(1)); int years = Integer.parseInt(matcher.group(2)); int months = Integer.parseInt(matcher.group(3)); return new YearToMonth(years, months, negative); } if ((matcher = PATTERN_ISO.matcher(string)).find()) { boolean negative = "-".equals(matcher.group(1)); String group2 = matcher.group(2); String group3 = matcher.group(3); int years = group2 == null ? 0 : Integer.parseInt(group2); int months = group3 == null ? 0 : Integer.parseInt(group3); return new YearToMonth(years, months, negative); } } return null; }
/** * Convert a Postgres interval to a jOOQ <code>YEAR TO MONTH</code> interval */ public static YearToMonth toYearToMonth(Object pgInterval) { boolean negative = pgInterval.toString().contains("-"); Reflect i = on(pgInterval); if (negative) { i.call("scale", -1); } YearToMonth result = new YearToMonth( i.call("getYears").<Integer>get(), i.call("getMonths").<Integer>get()); if (negative) { result = result.neg(); } return result; }
/** * Convert a Postgres interval to a jOOQ <code>YEAR TO MONTH</code> interval */ public static YearToMonth toYearToMonth(Object pgInterval) { boolean negative = pgInterval.toString().contains("-"); Reflect i = on(pgInterval); if (negative) { i.call("scale", -1); } YearToMonth result = new YearToMonth( i.call("getYears").<Integer>get(), i.call("getMonths").<Integer>get()); if (negative) { result = result.neg(); } return result; }