Realm-java: Between, greaterThan, lessThan... ISO date support

Created on 3 Mar 2017  路  7Comments  路  Source: realm/realm-java

Hi guys
Is there a possibility to support iso date on :)

  • between()
  • greaterThan()
  • lessThan()
  • greaterThanOrEqualTo()
  • lessThanOrEqualTo()

Most helpful comment

This really is why I tend to say, it's best to keep API objects and RealmObjects separate.

All 7 comments

Why not store date as Date?

The api already returns ISO String saving it as Date needs to for loop each item and convert each ISO String field value to Date

Hi @atouchsimo . Doing that conversion for each query would be so much more expensive than you doing the conversion when inserting data into Realm. Also it would slow down any query as we would have to check if the input string was a ISO date.

So this is not something we would want to do. The Date data type was meant for this type of thing after all.

Note you can just do the conversion in your model classes

public Foo extends RealmObject {
  private Date date;
  SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); // Needs to be thread-local. It is not thread safe.

  public void setDate(String date) {
    date = inFormat.parse(date);
  } 
}

This really is why I tend to say, it's best to keep API objects and RealmObjects separate.

@cmelchior How about between/lessThan/greaterThan support for Strings?

So what exactly would it mean to be between two strings?

Well... greaterThan one and lessThan the other, I suppose 馃槒

I'd like to use it to grab a series of alphabetically-sorted chunks from a collection. If we can sort on a type (like String), then we should be able to comparison-query on it too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Merlin1993 picture Merlin1993  路  3Comments

bryanspano picture bryanspano  路  3Comments

David-Kuper picture David-Kuper  路  3Comments

harshvishu picture harshvishu  路  3Comments

wyvern610 picture wyvern610  路  3Comments