Skip to content

Instantly share code, notes, and snippets.

@beeender
Created May 11, 2016 02:14
Show Gist options
  • Save beeender/13e149a073c19164415ea571c404cc80 to your computer and use it in GitHub Desktop.
Save beeender/13e149a073c19164415ea571c404cc80 to your computer and use it in GitHub Desktop.
@Test
public void dateSort() {
Date d20160127 = new GregorianCalendar(2016, Calendar.JANUARY, 27).getTime();
Date d20160227 = new GregorianCalendar(2016, Calendar.FEBRUARY, 27).getTime();
Date d20160510 = new GregorianCalendar(2016, Calendar.MAY, 10).getTime();
Date d20160527 = new GregorianCalendar(2016, Calendar.MAY, 27).getTime();
Date begin = new GregorianCalendar(2016, Calendar.JANUARY, 1).getTime();
Date end = new GregorianCalendar(2016, Calendar.FEBRUARY, 29).getTime();
realm.beginTransaction();
AllTypes allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnDate(d20160127);
allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnDate(d20160227);
allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnDate(d20160510);
allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnDate(d20160527);
realm.commitTransaction();
RealmResults<AllTypes> results = realm.where(AllTypes.class).between(AllTypes.FIELD_DATE, begin, end).findAll();
assertEquals(results.size(), 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment