光滑:筛选所有具有joda DateTime日期等于今天的记录

编程入门 行业动态 更新时间:2024-10-25 05:19:27
本文介绍了光滑:筛选所有具有joda DateTime日期等于今天的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一种实现方法是这样的:

One way to achieve it would be like this:

val now = DateTime.now val today = now.toLocalDate val tomorrow = today.plusDays(1) val startOfToday = today.toDateTimeAtStartOfDay(now.getZone) val startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone) val todayLogItems = logItems.filter(logItem => logItem.MyDateTime >= startOfToday && logItem.MyDateTime < startOfTomorrow ).list

有什么方法可以更简洁地编写查询?符合以下条件的东西:

Is there any way to write the query in a more concise way? Something on the lines of:

logItems.filter(_.MyDateTime.toDate == DateTime.now.toDate).list

我之所以这样问,是因为在LINQ to NHibernate中是可以实现的(使用nhibernate仅通过日期部分比较来按日期获取记录).

I'm asking this because in LINQ to NHibernate that is achievable (Fetching records by date with only day part comparison using nhibernate).

推荐答案

除非Slick joda映射器添加了对比较的支持,否则除非您自己添加比较,否则您将不走运.为了给它一个机会,这些可能是有用的指针: * slick.typesafe/doc/2.0.0/userdefined. html * slick.typesafe/doc /2.0.0/api/#scala.slick.lifted.ExtensionMethods * github/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala

Unless the Slick joda mapper adds support for comparisons you are out of luck unless you add it yourself. For giving it a shot these may be helpful pointers: * slick.typesafe/doc/2.0.0/userdefined.html * slick.typesafe/doc/2.0.0/api/#scala.slick.lifted.ExtensionMethods * github/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala

我创建了一个票证,以便在某些时候在Slick中对其进行研究: github. com/slick/slick/issues/627

I create a ticket to look into it in Slick at some point: github/slick/slick/issues/627

更多推荐

光滑:筛选所有具有joda DateTime日期等于今天的记录

本文发布于:2023-11-25 04:13:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:光滑   日期   joda   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!