@Override public boolean test(GregorianDate context) { int month = context.getMonth(); return (this.getValue() == ((month - 1) / 3) + 1); }
/** * <p>Outputs this instance as a String in CLDR-format "uuuu-'Q'Q" (like "2016-Q1"). </p> * * @return String */ /*[deutsch] * <p>Gibt diese Instanz als String im CLDR-Format "uuuu-'Q'Q" (wie "2016-Q1") aus. </p> * * @return String */ @Override public String toString() { StringBuilder sb = new StringBuilder(); formatYear(sb, this.year); sb.append("-Q"); sb.append(this.quarter.getValue()); return sb.toString(); }
@Override public PlainDate withValue( PlainDate context, V value, boolean lenient ) { if (value == null) { throw new IllegalArgumentException("Missing element value."); } switch (this.index) { case EnumElement.MONTH: return context.withMonth(Month.class.cast(value).getValue()); case EnumElement.DAY_OF_WEEK: return context.withDayOfWeek(Weekday.class.cast(value)); case EnumElement.QUARTER_OF_YEAR: int q1 = ((context.month - 1) / 3) + 1; int q2 = Quarter.class.cast(value).getValue(); return context.plus((q2 - q1), CalendarUnit.QUARTERS); default: throw new UnsupportedOperationException(this.name); } }
CalendarQuarter cq = (CalendarQuarter) this.obj; out.writeInt(cq.getYear()); out.writeInt(cq.getQuarter().getValue()); break; case MONTH_TYPE:
/** * <p>Adds given quarter years to this quarter year. </p> * * @param quarters the count of quarter years to be added * @return result of addition */ /*[deutsch] * <p>Addiert die angegebenen Quartale zu diesem Kalenderquartal. </p> * * @param quarters the count of quarter years to be added * @return result of addition */ public CalendarQuarter plus(Quarters quarters) { if (quarters.isEmpty()) { return this; } long value = this.year * 4L + this.quarter.getValue() - 1 + quarters.getAmount(); int y = MathUtils.safeCast(MathUtils.floorDivide(value, 4)); Quarter q = Quarter.valueOf(MathUtils.floorModulo(value, 4) + 1); return CalendarQuarter.of(y, q); }
/** * <p>Subtracts given quarter years from this quarter year. </p> * * @param quarters the count of quarter years to be subtracted * @return result of subtraction */ /*[deutsch] * <p>Subtrahiert die angegebenen Quartale von diesem Kalenderquartal. </p> * * @param quarters the count of quarter years to be subtracted * @return result of subtraction */ public CalendarQuarter minus(Quarters quarters) { if (quarters.isEmpty()) { return this; } long value = this.year * 4L + this.quarter.getValue() - 1 - quarters.getAmount(); int y = MathUtils.safeCast(MathUtils.floorDivide(value, 4)); Quarter q = Quarter.valueOf(MathUtils.floorModulo(value, 4) + 1); return CalendarQuarter.of(y, q); }