Java Code Examples for org.joda.time.DurationFieldType#years()
The following examples show how to use
org.joda.time.DurationFieldType#years() .
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: OrgDateTimeUtils.java From org-java with GNU General Public License v3.0 | 6 votes |
public static DurationFieldType getDurationFieldType(OrgInterval.Unit unit) { switch (unit) { case HOUR: return DurationFieldType.hours(); case DAY: return DurationFieldType.days(); case WEEK: return DurationFieldType.weeks(); case MONTH: return DurationFieldType.months(); case YEAR: return DurationFieldType.years(); default: throw new IllegalArgumentException("Unknown unit " + unit); } }
Example 2
Source File: TestGJChronology.java From astor with GNU General Public License v2.0 | 6 votes |
private void testAdd(String start, DurationFieldType type, int amt, String end) { DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC)); DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC)); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC)); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC)); YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC)); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
Example 3
Source File: TestISOChronology.java From astor with GNU General Public License v2.0 | 6 votes |
private void testAdd(String start, DurationFieldType type, int amt, String end) { DateTime dtStart = new DateTime(start, ISOChronology.getInstanceUTC()); DateTime dtEnd = new DateTime(end, ISOChronology.getInstanceUTC()); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(ISOChronology.getInstanceUTC()); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { YearMonthDay ymdStart = new YearMonthDay(start, ISOChronology.getInstanceUTC()); YearMonthDay ymdEnd = new YearMonthDay(end, ISOChronology.getInstanceUTC()); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
Example 4
Source File: TestGJChronology.java From astor with GNU General Public License v2.0 | 6 votes |
private void testAdd(String start, DurationFieldType type, int amt, String end) { DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC)); DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC)); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC)); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC)); YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC)); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
Example 5
Source File: TestISOChronology.java From astor with GNU General Public License v2.0 | 6 votes |
private void testAdd(String start, DurationFieldType type, int amt, String end) { DateTime dtStart = new DateTime(start, ISOChronology.getInstanceUTC()); DateTime dtEnd = new DateTime(end, ISOChronology.getInstanceUTC()); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(ISOChronology.getInstanceUTC()); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { YearMonthDay ymdStart = new YearMonthDay(start, ISOChronology.getInstanceUTC()); YearMonthDay ymdEnd = new YearMonthDay(end, ISOChronology.getInstanceUTC()); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
Example 6
Source File: FixedYearLengthChronology.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param daysInYear The number of days in each year */ protected FixedYearLengthChronology(int daysInYear) { this.daysInYear = daysInYear; this.yearDuration = new PreciseDurationField(DurationFieldType.years(), daysInYear * dayDuration.getUnitMillis()); this.centuryDuration = new PreciseDurationField(DurationFieldType.centuries(), 100 * yearDuration.getUnitMillis()); this.dayOfYear = new OneBasedPreciseDateTimeField(DateTimeFieldType.dayOfYear(), dayDuration, this.yearDuration); this.yearOfCentury = new PreciseDateTimeField(DateTimeFieldType.yearOfCentury(), this.yearDuration, this.centuryDuration); this.year = new YearField(this.yearDuration); }
Example 7
Source File: QuarterOfYearDateTimeField.java From presto with Apache License 2.0 | 4 votes |
@Override public DurationFieldType getRangeDurationType() { return DurationFieldType.years(); }
Example 8
Source File: DateTruncTransformFunction.java From incubator-pinot with Apache License 2.0 | 4 votes |
@Override public DurationFieldType getRangeDurationType() { return DurationFieldType.years(); }
Example 9
Source File: Joda.java From crate with Apache License 2.0 | 4 votes |
@Override public DurationFieldType getRangeDurationType() { return DurationFieldType.years(); }