简体   繁体   English

使用 ObjectBox 进行 LocalTime 范围查询

[英]LocalTime range query with ObjectBox

Would this work with ObjectBox?这适用于 ObjectBox 吗?

class Hub {
    List<Schedule> schedules; 
}
class Schedule {
    String day;
    LocalTime opens;
    LocalTime closes;
}

And then query those Hubs which opens and closes during a specific day, say, query with this constraint:然后查询在特定日期打开和关闭的那些集线器,例如,使用此约束进行查询:

new Schedule().builder()
    .day("Monday")
    .opens(LocalTime.parse("08:00")
    .close(LocalTime.parse("17:00").build();

So in this case we want to query for Hubs that are open on Mondays at 8am to 5pm.因此,在这种情况下,我们想要查询周一上午 8 点到下午 5 点开放的集线器
How does this translate to Objectbox Query?这如何转化为对象框查询?

You can map LocalTime to a supported type like Integer , see https://docs.objectbox.io/advanced/custom-types .您可以将 map LocalTime为受支持的类型,例如Integer ,请参阅https://docs.objectbox.io/advanced/custom-types Then you can build a query with a less and greater condition on that Integer property.然后,您可以在该Integer属性上构建具有更少和更大条件的查询。

Quick example:快速示例:

box.query()
    .equal(Schedule_.day, "Monday")
    .greater(Schedule_.opens, 800 - 1)
    .less(Schedule_.closes, 1700 + 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM