Java Code Examples for org.joda.time.DateTimeFieldType#year()

The following examples show how to use org.joda.time.DateTimeFieldType#year() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1_SkipDateTimeField.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public long set(long millis, int value) {
        FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
// start of generated patch
if(value<=iSkip){
if(value==iSkip){
throw new IllegalFieldValueException(DateTimeFieldType.year(),Integer.valueOf(value),null,null);
}
getMaximumValue();
}
// end of generated patch
/* start of original code
        if (value <= iSkip) {
            if (value == iSkip) {
                throw new IllegalFieldValueException
                    (DateTimeFieldType.year(), Integer.valueOf(value), null, null);
            }
            value++;
        }
 end of original code*/
        return super.set(millis, value);
    }
 
Example 2
Source File: TestISODateTimeFormat_Fields.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testForFields_calBased_YMD_duplicates() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
    };
    DateTimeFieldType[] dupFields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
            DateTimeFieldType.monthOfYear(),
    };
    int[] values = new int[] {2005, 6, 25};
    List types = new ArrayList(Arrays.asList(dupFields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    
    types = Arrays.asList(dupFields);
    f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(4, types.size());
}
 
Example 3
Source File: TestISODateTimeFormat_Fields.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testForFields_calBased_YMD_unmodifiable() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
    };
    int[] values = new int[] {2005, 6, 25};
    List types = Collections.unmodifiableList(new ArrayList(Arrays.asList(fields)));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(3, types.size());
    
    types = Arrays.asList(fields);
    f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(3, types.size());
}
 
Example 4
Source File: TestISODateTimeFormat_Fields.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testForFields_calBased_YMD_unmodifiable() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
    };
    int[] values = new int[] {2005, 6, 25};
    List types = Collections.unmodifiableList(new ArrayList(Arrays.asList(fields)));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(3, types.size());
    
    types = Arrays.asList(fields);
    f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(3, types.size());
}
 
Example 5
Source File: TestISODateTimeFormat_Fields.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testForFields_calBased_YMD_duplicates() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
    };
    DateTimeFieldType[] dupFields = new DateTimeFieldType[] {
            DateTimeFieldType.year(),
            DateTimeFieldType.monthOfYear(),
            DateTimeFieldType.dayOfMonth(),
            DateTimeFieldType.monthOfYear(),
    };
    int[] values = new int[] {2005, 6, 25};
    List types = new ArrayList(Arrays.asList(dupFields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    
    types = Arrays.asList(dupFields);
    f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(4, types.size());
}
 
Example 6
Source File: SkipDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long millis, int value) {
    FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
    if (value <= iSkip) {
        if (value == iSkip) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(value), null, null);
        }
        value++;
    }
    return super.set(millis, value);
}
 
Example 7
Source File: JulianChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static int adjustYearForSet(int year) {
    if (year <= 0) {
        if (year == 0) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(year), null, null);
        }
        year++;
    }
    return year;
}
 
Example 8
Source File: JulianChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static int adjustYearForSet(int year) {
    if (year <= 0) {
        if (year == 0) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(year), null, null);
        }
        year++;
    }
    return year;
}
 
Example 9
Source File: SkipDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long millis, int value) {
    FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
    if (value <= iSkip) {
        if (value == iSkip) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(value), null, null);
        }
        value++;
    }
    return super.set(millis, value);
}
 
Example 10
Source File: TestISODateTimeFormat.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testFormat_date_partial() {
    Partial dt = new Partial(
            new DateTimeFieldType[] {DateTimeFieldType.year(), DateTimeFieldType.monthOfYear(), DateTimeFieldType.dayOfMonth()},
            new int[] {2004, 6, 9});
    assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt));
}
 
Example 11
Source File: TestGJYearField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public TestGJYearField(TestGJChronology chrono) {
    super(DateTimeFieldType.year(), chrono.millisPerYear(), chrono);
}
 
Example 12
Source File: FixedYearLengthChronology.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public YearField(DurationField yearDuration) {
  super(DateTimeFieldType.year(), yearDuration);
}
 
Example 13
Source File: TestISODateTimeFormat.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testFormat_date_partial() {
    Partial dt = new Partial(
            new DateTimeFieldType[] {DateTimeFieldType.year(), DateTimeFieldType.monthOfYear(), DateTimeFieldType.dayOfMonth()},
            new int[] {2004, 6, 9});
    assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt));
}
 
Example 14
Source File: TestGJYearField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public TestGJYearField(TestGJChronology chrono) {
    super(DateTimeFieldType.year(), chrono.millisPerYear(), chrono);
}
 
Example 15
Source File: CalendarEntryBean.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Partial getPartialFromString(String date) {
    Integer month = Integer.valueOf(date.substring(0, 2));
    Integer year = Integer.valueOf(date.substring(2));
    return new Partial(new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.monthOfYear() }, new int[] {
            year.intValue(), month.intValue() });
}
 
Example 16
Source File: CalendarEntryBean.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Partial getPartialFromYearMonthDay(YearMonthDay day) {
    return new Partial(new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.monthOfYear() }, new int[] {
            day.getYear(), day.getMonthOfYear() });
}
 
Example 17
Source File: BasicYearDateTimeField.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Restricted constructor.
 * 
 * @param chronology  the chronology this field belogs to
 */
BasicYearDateTimeField(BasicChronology chronology) {
    super(DateTimeFieldType.year(), chronology.getAverageMillisPerYear());
    iChronology = chronology;
}
 
Example 18
Source File: BasicYearDateTimeField.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Restricted constructor.
 * 
 * @param chronology  the chronology this field belogs to
 */
BasicYearDateTimeField(BasicChronology chronology) {
    super(DateTimeFieldType.year(), chronology.getAverageMillisPerYear());
    iChronology = chronology;
}