[英]Compare a date with null value
我正在使用自定义适配器在活动中显示一些帖子(由用户创建)。 在自定义适配器的构造函数中,我正在使用以下代码来获取查询结果。
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereGreaterThan("expire_date", new Date());
return query;
目标是 -用户可以为每个帖子设置过期日期,以使该帖子在过期后不再可见。 我正在尝试将expire_date列与当前时间进行比较,以检查帖子是否过期。
行query.whereGreaterThan("expire_date", new Date());
是后来添加的。 先前创建的所有行在expire_date列中都为空值。
因此,每次我运行查询时,都会根据条件检查在expire_date列中 具有date对象的所有行。 在expire_date列中 具有空值的行将永远不会返回 。
注意:expire_date列不是必填字段(用户可以选择在创建帖子时将其保留为空)。
是的,我可以为所有空/空字段设置默认日期以与到期日期进行比较。 但是我很好奇是否有办法让我要么返回所有具有空值的行,要么将当前时间与具有whereGreaterThan
条件的空对象进行whereGreaterThan
?
ParseQuery notExpiredPosts = new ParseQuery("Post");
query.whereGreaterThan("expire_date", new Date());
ParseQuery noExpiredDate = new ParseQuery("Post");
query.doesNotExist("expire_date");
ParseQuery expiredDateQuery = ParseQuery.or(notExpiredPosts, noExpiredDate);
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereMatchesKeyInQuery("objectId", "objectId", expiredDateQuery);
return query;
[((NotExpiredPost || NoExpiredDate)和(500英里内的location_point)]]
这就是您想要的,不是吗?
希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.