agrim khanna
agrim khanna

Reputation: 105

How to filter on basis of JodaTime in objectify

I am new to Google Appengine. In my application, the datastore entities store a org.joda.time.DateTime object. I want to query the datastore to return all the entities in between a range of 2 particular DateTime. My code for this is :

@Entity
@Cache
@Index
public class Sample {

    @Id
    Long id; // autogen

    private DateTime dateTime;
    private int activeCount;
    private int inactiveCount;
}

I want a query similar to -

 Iterable<Sample> sampleIterable = ofy().load().type(Sample.class)
                    .filter("dateTime <", DateTime.now())
                    .filter("dateTime >", DateTime.now().minusDays(1))
                    .iterable();

Is it possible to query the DateTime like this ? What would be the correct way to query DateTime in objectify ? I am sorry for the lack of clearity.

Upvotes: 1

Views: 463

Answers (1)

stickfigure
stickfigure

Reputation: 13556

If you register the Joda translators with Objectify, you can use DateTime as both a field and a filter clause. You can use DateTime to filter against regular Date properties too.

JodaTimeTranslators.add(ObjectifyService.factory());

This is not enabled by default because everyone would then need to include joda time as a dependency.

Upvotes: 3

Related Questions