Time offset and number of days in a month. #436
-
I have a few graphs which are intended to show the current month's data, as well as that from the previous month. The problem I have is that with the time_offset switch, setting the value to 1M will show data from the last 30 days. If the month is 31 days long, it means the previous months data is displaced by a day. For example: I can correct this by changing the time_offset to 31 days, which puts the data in the correct place: This is all very well, but not all months are 31 days and so when the length of the month changes, the graph will be incorrect again. The question is, does there exist a method to make an entity always start at the beginning of the previous calendar month rather than by offsetting by a fixed number of days? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There's |
Beta Was this translation helpful? Give feedback.
-
Sorry I didn't post code - that's what I was using to select the date range. It works as expected to show this months data, but the issue is overlaying data from the previous month. The I think that the first script there is not necessary -
this should give the number of days in the preceding month as the output and append 'd' to it so it's the correct format for the It appears to work correctly, but I'll have to wait for a month with a different number of days to be sure. This is the output with the above script, which matches what I get when I set the number of days manually: The purpose of the graph is to show the difference in cost between the Octopus Agile tariff and the standard fixed rate tariff. The top part is the range and average of rates per day, and the weighted average over the whole month which accounts for the time energy was used. Thanks for the help. I'm not really that familiar with javascript so I muddle through with stuff like this. Here is the code for that graph:
|
Beta Was this translation helpful? Give feedback.
Sorry I didn't post code - that's what I was using to select the date range. It works as expected to show this months data, but the issue is overlaying data from the previous month. The
time_offset
function is fixed at 30 days, while the span ofcurrent_month
obviously varies with the number of days.I think that the first script there is not necessary -
current_month
does what it's supposed to. It'stime_offset
that's problematic. Thanks for the ChatGPT suggestion, I hadn't thought of using that. Here's what it gave me: