下面列出了怎么用org.joda.time.DateTimeComparator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Order RepairRun instances by time. Primarily endTime, secondarily startTime. Descending, i.e. latest first.
*
* @param other the RepairRun compared to
* @return negative if this RepairRun is later than the specified RepairRun. Positive if earlier. 0 if equal.
*/
@Override
public int compareTo(RepairRun other) {
DateTimeComparator comparator = DateTimeComparator.getInstance();
int endTimeComparison = comparator.compare(endTime, other.endTime);
if (endTimeComparison != 0) {
return -endTimeComparison;
} else {
return -comparator.compare(startTime, other.startTime);
}
}
public void fillListView(){
try {
List<Seances> seances = databaseHelper.getDao(Seances.class).queryForAll();
List<Event> events = databaseHelper.getDao(Event.class).queryForAll();
allseanceAdapter.setItemList(seances, events);
List<Seances> upcomingSeances = new ArrayList<>();
List<Event> upcomingEvents = new ArrayList<>();
DateTime now = new DateTime();
for(Seances sc : seances){
DateTime scDate = DateTime.parse(sc.getDateDebut());
if( DateTimeComparator.getDateOnlyInstance().compare(now, scDate) <= 0 ){
upcomingSeances.add(sc);
}
}
for(Event ev : events){
DateTime evDate = DateTime.parse(ev.getDateDebut());
if( DateTimeComparator.getDateOnlyInstance().compare(now, evDate) <= 0 ){
upcomingEvents.add(ev);
}
}
upcomingseanceAdapter.setItemList(upcomingSeances,upcomingEvents);
} catch (SQLException e) {
e.printStackTrace();
}
allseanceAdapter.notifyDataSetChanged();
upcomingseanceAdapter.notifyDataSetChanged();
}
private boolean isToday(long dateMs) {
TimeZone timeZone = getCurrentUserTimezone();
DateTime thisDate = new DateTime(dateMs).withZone(DateTimeZone.forTimeZone(timeZone));
//Start of day at this local
DateTime today = new DateTime().withTime(0, 0, 0, 0).withZone(DateTimeZone.forTimeZone(timeZone));
DateTimeComparator dtComp = DateTimeComparator.getDateOnlyInstance();
return (dtComp.compare(thisDate, today) == 0);
}
private boolean isToday(long dateMs) {
TimeZone timeZone = getCurrentUserTimezone();
DateTime thisDate = new DateTime(dateMs).withZone(DateTimeZone.forTimeZone(timeZone));
//Start of day at this local
DateTime today = new DateTime().withTime(0, 0, 0, 0).withZone(DateTimeZone.forTimeZone(timeZone));
DateTimeComparator dtComp = DateTimeComparator.getDateOnlyInstance();
return (dtComp.compare(thisDate, today) == 0);
}