LocalTime range query with ObjectBox

馋奶兔 提交于 2021-01-28 02:07:13

问题


Would this work with 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.
How does this translate to Objectbox Query?


回答1:


You can map LocalTime to a supported type like Integer, see https://docs.objectbox.io/advanced/custom-types. Then you can build a query with a less and greater condition on that Integer property.

Quick example:

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


来源:https://stackoverflow.com/questions/65439440/localtime-range-query-with-objectbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!