1 16 package org.joda.time.field; 17 18 import org.joda.time.DateTimeField; 19 20 31 public class LenientDateTimeField extends DelegatedDateTimeField { 32 33 private static final long serialVersionUID = 8714085824173290599L; 34 35 40 public static DateTimeField getInstance(DateTimeField field) { 41 if (field == null) { 42 return null; 43 } 44 if (field instanceof StrictDateTimeField) { 45 field = ((StrictDateTimeField)field).getWrappedField(); 46 } 47 if (field.isLenient()) { 48 return field; 49 } 50 return new LenientDateTimeField(field); 51 } 52 53 protected LenientDateTimeField(DateTimeField field) { 54 super(field); 55 } 56 57 public final boolean isLenient() { 58 return true; 59 } 60 61 66 public long set(long instant, int value) { 67 int min = getMinimumValue(instant); 68 if (value >= min && value < getMaximumValue(instant)) { 69 return super.set(instant, value); 70 } 71 return add(super.set(instant, min), value - min); 72 } 73 } 74 | Popular Tags |