Assuming this is how you get the current time in Joda time:
DateTime now = new DateTime();
How do you calculate values for the variables dateTimeAtStartOfToday
and dateTimeAtEndOfToday
?
What I'm trying to do is generate some SQL to do a lookup of all transactions that have occurred between the startOfToday
and endOfToday
.
I would use:
Then check if
startOfToday <= time < startOfTomorrow
for any particular time.Of course, it partly depends on exactly what's stored in the database - and what time zone you're interested in.
works for me.
This works...
...but as far as the SQL, I tend to use BETWEEN as the where clause rather than do the > and <= stuff
This works better, it turns out DateTime has a method called toInterval which does this exact thing (figures out midnight to midnight). In my tests, it appears to have no problem with DST transitions.
JODA looks to be very well thought out.
As a Kotlin extension function it looks like this:
This does not contain times equaling the end of the day (start is included) so maybe add an "or"-case with
interval.getEnd().isEqual(this))
.