Java Code Examples for org.joda.time.DateTime#isEqual()

The following examples show how to use org.joda.time.DateTime#isEqual() . These examples are extracted from open source projects. 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 Project: winter   File: EventDateEvaluationRule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEqual(Event record1, Event record2, Attribute attribute) {
    if(record1.getDates().size()==0 && record2.getDates().size()==0)
        return true;
    else if(record1.getDates().size()==0 ^ record2.getDates().size()==0)
        return false;
    else {//compare all dates
        for (DateTime r1Date : record1.getDates()) {
            for (DateTime r2Date : record2.getDates()) {
                if (r1Date.isEqual(r2Date)) {
                    return true;//record1.getDates().getYear() == record2.getDates().getYear();
                }
            }
        }
        return false;
    }
}
 
Example 2
Source Project: elasticsearch-sql   File: QueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void dateBetweenSearch() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
	DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);

	DateTime dateLimit1 = new DateTime(2014, 8, 18, 0, 0, 0);
	DateTime dateLimit2 = new DateTime(2014, 8, 21, 0, 0, 0);

	SearchHits response = query(String.format("SELECT insert_time FROM %s/online WHERE insert_time BETWEEN '2014-08-18' AND '2014-08-21' LIMIT 3", TEST_INDEX_ONLINE));
	SearchHit[] hits = response.getHits();
	for(SearchHit hit : hits) {
		Map<String, Object> source = hit.getSourceAsMap();
		DateTime insertTime = formatter.parseDateTime((String) source.get("insert_time"));

		boolean isBetween =
				(insertTime.isAfter(dateLimit1) || insertTime.isEqual(dateLimit1)) &&
				(insertTime.isBefore(dateLimit2) || insertTime.isEqual(dateLimit2));

		Assert.assertTrue("insert_time must be between 2014-08-18 and 2014-08-21", isBetween);
	}
}
 
Example 3
/**
 * Converts this period to a list of year periods.  Partial years will not be
 * included.  For example, a period of "2009-2010" will return a list
 * of 2 years - one for 2009 and one for 2010.  On the other hand, a period
 * of "January 2009" would return an empty list since partial
 * years are not included.
 * @return A list of year periods contained within this period
 */
public List<DateTimePeriod> toYears() {
    ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>();

    // default "current" year to start datetime
    DateTime currentStart = getStart();
    // calculate "next" year
    DateTime nextStart = currentStart.plusYears(1);
    // continue adding until we've reached the end
    while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) {
        // its okay to add the current
        list.add(new DateTimeYear(currentStart, nextStart));
        // increment both
        currentStart = nextStart;
        nextStart = currentStart.plusYears(1);
    }

    return list;
}
 
Example 4
/**
 * Check that the current time is within the specified range.
 *
 * @param notBefore
 *            - can be null to skip before check
 * @param notOnOrAfter
 *            - can be null to skip after check
 *
 * @return true if in range, false otherwise
 */
private boolean isTimeInRange(String notBefore, String notOnOrAfter) {
    DateTime currentTime = new DateTime(DateTimeZone.UTC);

    if (notBefore != null) {
        DateTime calNotBefore = DateTime.parse(notBefore);
        if (currentTime.isBefore(calNotBefore)) {
            LOG.debug("{} is before {}.", currentTime, calNotBefore);
            return false;
        }
    }

    if (notOnOrAfter != null) {
        DateTime calNotOnOrAfter = DateTime.parse(notOnOrAfter);
        if (currentTime.isAfter(calNotOnOrAfter) || currentTime.isEqual(calNotOnOrAfter)) {
            LOG.debug("{} is on or after {}.", currentTime, calNotOnOrAfter);
            return false;
        }
    }
    return true;
}
 
Example 5
@Override
public boolean accept(File file) {
    // parse out the date contained within the filename
    DateTime d = null;

    try {
        d = DateTimeUtil.parseEmbedded(file.getName(), pattern, zone);
    } catch (Exception e) {
        // ignore for matching
        return false;
    }

    logger.trace("Filename '" + file.getName() + "' contained an embedded date of " + d);

    // does the cutoff date occurr before or equal
    if (d.isBefore(cutoffDate) || d.isEqual(cutoffDate)) {
        logger.trace("Filename '" + file.getName() + "' embedded date of " + d + " occurred beforeOrEquals " + d.isBefore(cutoffDate));
        return true;
    }

    // if we get here, then the date wasn't right
    logger.trace("Skipping filename '" + file.getName() + "' since its embedded date of " + d + " occurred after " + cutoffDate);
    return false;
}
 
Example 6
/**
 * Converts this period to a list of five minute periods.  Partial five minute periods will not be
 * included.  For example, a period of "January 20, 2009 7 to 8 AM" will return a list
 * of 12 five minute periods - one for each 5 minute block of time 0, 5, 10, 15, etc.
 * On the other hand, a period of "January 20, 2009 at 13:04" would return an empty list since partial
 * five minute periods are not included.
 * @return A list of five minute periods contained within this period
 */
public List<DateTimePeriod> toFiveMinutes() {
    ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>();

    // default "current" five minutes to start datetime
    DateTime currentStart = getStart();
    // calculate "next" five minutes
    DateTime nextStart = currentStart.plusMinutes(5);
    // continue adding until we've reached the end
    while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) {
        // its okay to add the current
        list.add(new DateTimeFiveMinutes(currentStart, nextStart));
        // increment both
        currentStart = nextStart;
        nextStart = currentStart.plusMinutes(5);
    }

    return list;
}
 
Example 7
/**
 * Converts this period to a list of hour periods.  Partial hours will not be
 * included.  For example, a period of "January 20, 2009" will return a list
 * of 24 hours - one for each hour on January 20, 2009.  On the other hand,
 * a period of "January 20, 2009 13:10" would return an empty list since partial
 * hours are not included.
 * @return A list of hour periods contained within this period
 */
public List<DateTimePeriod> toHours() {
    ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>();

    // default "current" hour to start datetime
    DateTime currentStart = getStart();
    // calculate "next" hour
    DateTime nextStart = currentStart.plusHours(1);
    // continue adding until we've reached the end
    while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) {
        // its okay to add the current
        list.add(new DateTimeHour(currentStart, nextStart));
        // increment both
        currentStart = nextStart;
        nextStart = currentStart.plusHours(1);
    }

    return list;
}
 
Example 8
/**
 * Converts this period to a list of day periods.  Partial days will not be
 * included.  For example, a period of "January 2009" will return a list
 * of 31 days - one for each day in January.  On the other hand, a period
 * of "January 20, 2009 13:00-59" would return an empty list since partial
 * days are not included.
 * @return A list of day periods contained within this period
 */
public List<DateTimePeriod> toDays() {
    ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>();

    // default "current" day to start datetime
    DateTime currentStart = getStart();
    // calculate "next" day
    DateTime nextStart = currentStart.plusDays(1);
    // continue adding until we've reached the end
    while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) {
        // its okay to add the current
        list.add(new DateTimeDay(currentStart, nextStart));
        // increment both
        currentStart = nextStart;
        nextStart = currentStart.plusDays(1);
    }
    
    return list;
}
 
Example 9
@Override
public int compare(IHoraireRows lhs, IHoraireRows rhs) {
    DateTimeFormatter formatter = null;
    DateTime eventDay1 = null;
    DateTime eventDay2 = null;

    if(lhs.getClass().equals(Event.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        eventDay1 = formatter.parseDateTime(lhs.getDateDebut());
    }
    if(rhs.getClass().equals(Event.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        eventDay2 = formatter.parseDateTime(rhs.getDateDebut());
    }

    if (lhs.getClass().equals(Seances.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
        eventDay1 = formatter.parseDateTime(lhs.getDateDebut());
    }
    if (rhs.getClass().equals(Seances.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
        eventDay2 = formatter.parseDateTime(rhs.getDateDebut());
    }

    if (eventDay1.isAfter(eventDay2)) {
        return 1;
    }
    else if(eventDay1.isBefore(eventDay2)){
        return -1;
    }
    else if(eventDay1.isEqual(eventDay2)){
        return 0;
    }
    return 0;
}
 
Example 10
@Override
public int compare(Trimestre lTrimestre, Trimestre rTrimestre) {
    DateTimeFormatter formatter = null;
    formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTime lDateTime = formatter.parseDateTime(lTrimestre.dateFin);
    DateTime rDateTime = formatter.parseDateTime(rTrimestre.dateFin);

    if (lDateTime.isEqual(rDateTime)) {
        return 0;
    } else if (lDateTime.isBefore(rDateTime)) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 11
Source Project: twiliochat-android   File: DateFormatter.java    License: MIT License 5 votes vote down vote up
public static String getDateTodayString(DateTime today) {
  DateTime todayMidnight = new DateTime().withTimeAtStartOfDay();
  String stringDate;
  if (todayMidnight.isEqual(today.withTimeAtStartOfDay())) {
    stringDate = "Today - ";
  } else {
    stringDate = today.toString("MMM. dd - ");
  }

  stringDate = stringDate.concat(today.toString("hh:mma"));

  return stringDate;
}
 
Example 12
Source Project: conference-app   File: Session.java    License: MIT License 5 votes vote down vote up
/**
 * Method defines if session is near to be started or finished +/- 1 hour
 * 
 * @param now
 * @return true if session will start in +/- 1 hour from now
 */
public boolean isInNearProgress(DateTime now) {
    DateTime startTime = DateTime.parse(this.date + " " + this.start, DateTimeFormat.forPattern("dd.MM.yyyy HH:mm"));
    DateTime beforeStart = now.minusHours(1);
    DateTime afterStart = now.plusHours(2);
    return ((startTime.isAfter(beforeStart) || startTime.isEqual(beforeStart)) && (startTime.isBefore(afterStart) || startTime.isEqual(afterStart)));
}
 
Example 13
Source Project: incubator-pinot   File: Grouping.java    License: Apache License 2.0 5 votes vote down vote up
private static long[] makeCutoffs(DateTime origin, DateTime max, Period bucketSize) {
  List<Long> offsets = new ArrayList<>();
  DateTime offset = origin;
  while (offset.isBefore(max) || offset.isEqual(max)) {
    offsets.add(offset.getMillis());
    offset = offset.plus(bucketSize);
  }
  return ArrayUtils.toPrimitive(offsets.toArray(new Long[offsets.size()]));
}
 
Example 14
public boolean getCanValidateContacts() {
    final DateTime now = new DateTime();
    final DateTime requestDate = getLastValidationRequestDate();
    if (requestDate == null || getNumberOfValidationRequests() == null) {
        return true;
    }
    final DateTime plus30 = requestDate.plusDays(30);
    if (now.isAfter(plus30) || now.isEqual(plus30)) {
        setNumberOfValidationRequests(0);
    }
    return getNumberOfValidationRequests() <= MAX_VALIDATION_REQUESTS;
}
 
Example 15
protected boolean isNow(Date date){
    DateTime now = DateTime.now();
    return (now.isAfter(date.getTime()) || now.isEqual(date.getTime()))
            && now.plusSeconds(-1).isBefore(date.getTime());
}
 
Example 16
private boolean hasExpired(DateTime partitionDateTime, DateTime expiryThreshold) {
    return partitionDateTime.isEqual(expiryThreshold) || partitionDateTime.isBefore(expiryThreshold);
}
 
Example 17
private static boolean isDateBeforeSecondEndWeek(DateTime endDate) {
    return endDate.isBefore(getEndDayOfSecondBiWeek(endDate)) || endDate.isEqual(getEndDayOfSecondBiWeek(endDate));
}
 
Example 18
private static boolean isDateBeforeFirstEndWeekly(DateTime endDate) {
    return endDate.isBefore(getEndDayOfFirstBiWeek(endDate)) || endDate.isEqual(getEndDayOfFirstBiWeek(endDate));
}
 
Example 19
Source Project: narrate-android   File: DateUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if a given date is anytime in the current
 * week Sun to Sat.
 *
 * @param   date Date to inspect
 * @return  True if the date is sometime this week, false if not
 */
public static boolean isCurrentWeek(DateTime date) {
    DateTime firstDayOfWeekMidnight = DateTime.now(DateTimeZone.getDefault()).withDayOfWeek(Calendar.getInstance(Locale.getDefault()).getMinimum(Calendar.DAY_OF_WEEK)).withTimeAtStartOfDay();
    DateTime firstDayOfNextWeek = firstDayOfWeekMidnight.plusDays(7);
    return ((firstDayOfWeekMidnight.isEqual(date.getMillis())) || firstDayOfWeekMidnight.isBefore(date.getMillis())) && firstDayOfNextWeek.isAfter(date.getMillis());
}
 
Example 20
Source Project: narrate-android   File: DateUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if a given date is anytime this month.
 *
 * @param   date Date to inspect
 * @return  True if the date is sometime this month, false if not
 */
public static boolean isCurrentMonth(DateTime date) {
    DateTime firstDayOfMonthMidnight = DateTime.now(DateTimeZone.getDefault()).withDayOfMonth(Calendar.getInstance(Locale.getDefault()).getMinimum(Calendar.DAY_OF_MONTH)).withTimeAtStartOfDay();
    DateTime firstDayOfNextMonth = firstDayOfMonthMidnight.plusMonths(1);
    return ((firstDayOfMonthMidnight.isEqual(date.getMillis())) || firstDayOfMonthMidnight.isBefore(date.getMillis())) && firstDayOfNextMonth.isAfter(date.getMillis());
}