withTimeAtStartOfDay equivalent to thisYear?

pretty much topic.
I’ve been looking into the documentation but haven’t found something which would do withTimeAtStartOfDay but for current year.

in documentation there is

Returns a copy of this datetime with the time set to the start of the day.

and for year there is this method

withYear(int year)
Returns a copy of this datetime with the year field updated.

which sounds like current day with custom year

Basically I want to select data from influx which are in current year maximum, and in year -1
Can i use something like withTimeAtStartOfDay() or I need to compare dates manually?


Are you trying to return all persisted data within a time range using REST API calls?

basically yes I want to do this with persisted data

val max = (Weather_Temperature.maximumSince(now.withTimeAtStartOfDay).state as Number).floatValue

But to retreat this Year maximum not today’s maximum

Wouldn’t you use something like

dunno, does not look like working solution

val yRclean = (Service_Clean_Count.maximumSince(now.withMonthOfYear(1).withDayOfMonth(1).withYear(2019)).state as Number).intValue


val yRclean = (Service_Clean_Count.maximumSince(now.withMonthOfYear(1).withDayOfMonth(1).withYear(2020)).state as Number).intValue

produces same result (which I know is wrong, as it is total number in influx to date) so does not look like right
2019 should return 8 and 2020 should return 7, but both of them returns 15
I believe that 2019 version may have return 15 as it is maximum since, but 2020 should return only 7 to this date if I’m not wrong with understanding of this feature.

I couldn’t comment on your stored data, but it’s easy to verify the date targetting is working as expected.

logInfo("test", "now " + now.toString)
logInfo("test", "then " + now.withMonthOfYear(1).withDayOfMonth(1).withYear(2019).toString)

2020-04-27 00:37:42.533 [INFO ] [.eclipse.smarthome.model.script.test] - now 2020-04-27T00:37:42.530+01:00
2020-04-27 00:37:42.539 [INFO ] [.eclipse.smarthome.model.script.test] - then 2019-01-01T00:37:42.537Z

Confident your default persistence is the correct one?

yeah I’m confident on that one, as I do have only one persistence database and looking directly to that … :wink:

quite strange tho, maybe maximum since is working differently with past dates or something?

The system default does not I think get set to the only/last persistence you may have installed. I think you have to take positive action to set it. It would be surprise if it didn’t fail when unset though.
It’s really easy to remove all doubt and specify
… maximumSince(time, “influxdb”) …

What do you get for minimum, average ?

sometimes my brain would need to be spanked…
I know what is going on, maximumSince … damn I’m blind, maximumSince will be always the same in this case (as these are not temperatures, but counts).

I just reaplied this code for temperature on item numbers, and yes, logically 15 will be maximum since in any case.
Damn me.

hmm listing available commands there is nothing like countSince or something like that, is it?