Exemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param field the field to wrap, like "year()".
  * @param offset offset to add to field values
  * @throws IllegalArgumentException if offset is zero
  */
 public OffsetDateTimeField(DateTimeField field, int offset) {
   this(
       field,
       (field == null ? null : field.getType()),
       offset,
       Integer.MIN_VALUE,
       Integer.MAX_VALUE);
 }
Exemplo n.º 2
0
  /**
   * Constructor.
   *
   * @param field the field to wrap, like "year()".
   * @param type the field type this field actually uses
   * @param offset offset to add to field values
   * @param minValue minimum allowed value
   * @param maxValue maximum allowed value
   * @throws IllegalArgumentException if offset is zero
   */
  public OffsetDateTimeField(
      DateTimeField field, DateTimeFieldType type, int offset, int minValue, int maxValue) {
    super(field, type);

    if (offset == 0) {
      throw new IllegalArgumentException("The offset cannot be zero");
    }

    iOffset = offset;

    if (minValue < (field.getMinimumValue() + offset)) {
      iMin = field.getMinimumValue() + offset;
    } else {
      iMin = minValue;
    }
    if (maxValue > (field.getMaximumValue() + offset)) {
      iMax = field.getMaximumValue() + offset;
    } else {
      iMax = maxValue;
    }
  }
Exemplo n.º 3
0
 /**
  * Get the value of one of the fields of a datetime.
  *
  * <p>This could be used to get a field using a different Chronology. For example:
  *
  * <pre>
  * Instant dt = new Instant();
  * int gjYear = dt.get(Chronology.getCoptic().year());
  * </pre>
  *
  * @param field the DateTimeField to use, not null
  * @return the value
  * @throws IllegalArgumentException if the field is null
  */
 public int get(DateTimeField field) {
   if (field == null) {
     throw new IllegalArgumentException("The DateTimeField must not be null");
   }
   return field.get(getMillis());
 }