Java Code Examples for org.dmfs.rfc5545.DateTime#getYear()
The following examples show how to use
org.dmfs.rfc5545.DateTime#getYear() .
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: InstancesMatcher.java From lib-recur with Apache License 2.0 | 6 votes |
@Override protected boolean matchesSafely(RecurrenceRule recurrenceRule, Description mismatchDescription) { int count = 0; RecurrenceRuleIterator it = recurrenceRule.iterator(mStart); while (it.hasNext()) { count++; DateTime instance = it.nextDateTime(); if (!mInstancesMatcher.matches(instance)) { mismatchDescription.appendText(String.format("instance %s ", instance.toString())); mInstancesMatcher.describeMismatch(instance, mismatchDescription); return false; } if (count == MAX_ITERATIONS || instance.getYear() > 9000) { break; } } return true; }
Example 2
Source File: IncreasingMatcher.java From lib-recur with Apache License 2.0 | 5 votes |
@Override protected boolean matchesSafely(RecurrenceRule recurrenceRule, Description mismatchDescription) { // no instance should be before start DateTime lastInstance = mStart.addDuration(mStart.isAllDay() ? new Duration(-1, 1, 0) : new Duration(-1, 0, 1)); int count = 0; RecurrenceRuleIterator it = recurrenceRule.iterator(mStart); while (it.hasNext()) { count++; DateTime instance = it.nextDateTime(); if (!lastInstance.before(instance)) { mismatchDescription.appendText( String.format(Locale.ENGLISH, "instance number %d (%s) of rule %s was before the previous instance (%s)", count, instance.toString(), recurrenceRule.toString(), lastInstance.toString())); return false; } lastInstance = instance; if (count == MAX_ITERATIONS || instance.getYear() > 9000) { break; } } return true; }
Example 3
Source File: DateTimeToTimeConversionTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Contains the definition/requirement of when a {@link DateTime} and {@link Time} is considered equivalent in this project. */ private boolean isEquivalentDateTimeAndTime(DateTime dateTime, Time time) { // android.text.Time doesn't seem to store in millis precision, there is a 1000 multiplier used there internally // when calculating millis, so we can only compare in this precision: boolean millisMatch = dateTime.getTimestamp() / 1000 == time.toMillis(false) / 1000; boolean yearMatch = dateTime.getYear() == time.year; boolean monthMatch = dateTime.getMonth() == time.month; boolean dayMatch = dateTime.getDayOfMonth() == time.monthDay; boolean hourMatch = dateTime.getHours() == time.hour; boolean minuteMatch = dateTime.getMinutes() == time.minute; boolean secondsMatch = dateTime.getSeconds() == time.second; boolean allDaysMatch = time.allDay == dateTime.isAllDay(); boolean timeZoneMatch = (dateTime.isFloating() && dateTime.isAllDay() && time.timezone.equals("UTC")) || // This is the regular case with non-floating DateTime (dateTime.getTimeZone() != null && time.timezone.equals(dateTime.getTimeZone().getID())); return millisMatch && yearMatch && monthMatch && dayMatch && hourMatch && minuteMatch && secondsMatch && allDaysMatch && timeZoneMatch; }
Example 4
Source File: WalkingStartMatcher.java From lib-recur with Apache License 2.0 | 4 votes |
@Override protected boolean matchesSafely(RecurrenceRule recurrenceRule, Description mismatchDescription) { DateTime lastInstance = new DateTime(0, 0, 0, 0, 0, 0); List<RecurrenceRuleIterator> instanceIterators = new LinkedList<RecurrenceRuleIterator>(); if (recurrenceRule.getSkip() != RecurrenceRule.Skip.OMIT) { // walking start doesn't work with SKIP, since that might change the order throw new IllegalArgumentException("Can't test walking start with SKIP value other than OMIT"); } RecurrenceRuleIterator mainIterator = recurrenceRule.iterator(mStart); if (!mainIterator.hasNext()) { return true; } int count = 1; while (mainIterator.hasNext() && count < MAX_ITERATIONS && lastInstance.getYear() < 9000) { lastInstance = mainIterator.nextDateTime(); count++; RecurrenceRuleIterator i2 = recurrenceRule.iterator(lastInstance); instanceIterators.add(i2); if (instanceIterators.size() > MAX_BUFFER) { instanceIterators.remove(0); } for (RecurrenceRuleIterator iter : instanceIterators) { if (!iter.hasNext()) { //("Expected another instance! rule=" + rule.rule + " lastInstance=" + lastInstance); return false; } DateTime upcoming = iter.nextDateTime(); if (!lastInstance.equals(upcoming)) { return false; } } } return true; }
Example 5
Source File: YearMatcher.java From lib-recur with Apache License 2.0 | 4 votes |
@Override protected Integer featureValueOf(DateTime actual) { return actual.getYear(); }