[RELEASE] Date Time Parser driver (aka schedule_ur_garbage_cans)

Thank you for your quick and attentive response (and for your extra states)! I use your driver often.

It may be a "weekend" issue, but both calendar-365.com and my Amazon Alexa are stating today, August 13 in the United States, the week of the year is 32, whereas your program is indicating week 33. Again, this may be an international "first day of the week" issue. I just wanted to point it out because I know you are committed to making your program the best it can be!

Thanks again!

Strangely, I was aware of this, and figured no one would care or be affected! If you're a date/time person we can share horror stories - DIffering versions of Java, PHP and even SQL all are inconsistent in odd ways. I'm using the legacy SimpleDateFormat - a now defunct class extender of java.time from the way back machine.
There are a couple problems to overcome to resolve this little issue - Timezone and region. and besides the region of the local device doing the viewing, the region of the HUB.
To my knowledge, the hub doesn't check a region. It only stores a timezone. This presents a hurdle of fairly large portion - I'd need to store nearly 800 regional values to an array to get the week to correctly display! My take is the hub is US born, and I'm just gonna have to leave this alone for now, either until I get better understanding of how the region values of a hub are handled so I can pull Locale (not to be confused with TZ) - or I rewrite the app completely with DateTimeFormatter and get off the defunct SimpleDateTime.

If you're following and interested -

jshell> Locale.getDefault(); $2 ==> en_GB

It was en_GB, which means English and the United Kingdom.

Our live application is deployed inside a Docker container. I checked the default locale there. It was en_US: English and the United States.

I began to wonder if the UK and the US have different conventions for week years. So I looked online and found the excellent timeanddate.com.

The timeanddate.com 2021 UK calendar says: “Week numbers: ISO 8601 (week starts Monday) — week 1 is the first week with Thursday.”

The timeanddate.com 2021 US calendar says: “Week numbers: Week starts Sunday – week 1 is the one with January 1.”

Accordingly, Since Jan 1st was on a Saturday, in the US that was week one. Most of the world uses a 'first week to contain Thursday' but in some countries it is even different than that!

Savvytime.com give a nice display of the calendar and makes it easy to count the weeks - per them, we're in week 34...
There's also a really neat discussion of the twitter problem that crashed them a few years back - specifically because of this!

So, while I have no doubt there are conflicts with this tool, my fallback is it was written for me and my use and in the end I determine what value I'd get by working further on this - I can live with the oddity, and I hope you can too! And by that I mean if it is critical to your Rule - you'll need to apply math to it - and 'minus 1' it if you're not using US based regions. **caveat - and of course this will be wrong next year! **

Released updated 0.3.1 - found typo which caused WeekOfMonNumOdd and WeekOfMonNumEven reporting Null.
Should roll through HPM automagically.

Thank you once again for responding so quickly, and I totally understand the issue you face with the way in which the week of the year is handled. As a programmer myself (as a hobby), I appreciate that you took the time to explain everything, and it was actually quite interesting.

I want to express my gratitude to you for providing this helpful driver for our community. As I've stated before, I use it often.

1 Like

This is a cool idea - plan to use it. I’d like to also have the full date string and full time string as an attribute that I can use in a dashboard and in TTS events. Seems like it would be an easy update.

1 Like

Any chance you could add date variables for DSTbegins and DSTends?

hi there. hm. in an abstract way I have. since the definition of dst begin and end is:
DST in the United States begins each year on the second Sunday in March, when clocks are set forward by one hour. They are turned back again to standard time on the first Sunday in November as DST ends.

So based on the given variables it is simply a if(dstB=DayOfWeek=="Sun" && MonthOfYear=="March"),dstB=True' or something like that (forgive me - 3 margaritas...)

Were you hoping for a hard code Boolean (t/f?) or the actual date each year stored?
I pulled all the values created by the java library and DST Begin and End aren't actually one of them. Not to say it isn't useful, just pointing that out.

or some such

Either would work, but your example should work as well. I'm not sure why it didn't occur to me to test it like that.

Update: I think this will work, though it'll be a while til I know for sure, lol. This is the finished rule, designed to halve the annual change in sunset time (here it is nearly 4 hours including DST and this drops it to nearly two hours) for the lighting in my parrot room. (Though I didn't wind up needing it here I did load your driver for future use)

Don't know how I missed this previously, but just stumbled onto it and integrated it into my weekly trash reminder (recycle odd weeks, greens even weeks) so I can get specific reminders each week. Thanks for this!

1 Like

Advice please? I’ve been trying to offset a date-only (no time) variable by a certain number of days and struggling to figure out how to do it.

My use-case is to set a due date to replace my HVAC filters (as well as other similar home maintenance items) every 6-12 months. The due dates for each item are on a dashboard and, upon button-press, is deemed complete, whereupon the due date is to be cycled forward another 6 months or whatever the appropriate maintenance period is

What I can’t figure out is how to offset a date-only datetime variable by a certain amount of time. If I use the RM offset, it always adds a time to the variable, which mucks with the dashboard UI.

I then came here looking for an answer but it’s not clear to me that I’ve found it here either.

Any ideas? TIA….

The Date Time Parser was designed to help cut date and time strings into simple to use pieces. You may be over thinking this!
Built into Rule Machine is 'Periodic Schedule'. That might simplify what you're trying to do. I'm out the door so can't write a quickie for you - but does that spur an idea? That btw is without using DateTimeParser. DTP is real good for 'every odd week' or every odd month' type stuff. while you can write your need with it, HE gives some pretty sharp tools out of the box too!

I think @jshimota is mostly right. I thought of this utility myself when someone posted a similar question, I may have even commented about it, but soon remembered the focus on pulling apart the date value, with a few other conveniences.

The bit I'm suspecting a regular RM periodic schedule may not satisfy your needs @mluck, is if your response to the reminder is to do the job either early or later, so the triggering 6 months after the reminder will not be accurate. Would that be right?

Probably worth posting a topic of your own to canvas any ideas people may have.

Yep @sburke781 nailed the reason why I want to offset a date-only variable, despite @jshimota’s fair points.

@jshimota an idea: If this parser driver could be altered to take any Unix timestamp as a parameter (as opposed to current time, as I believe it does now) and produce the same attributes it already does, it would address an array of interesting use cases I suspect — including mine.

In the meantime, I band-aided my needs by doing all the calcs using Unix time and then used this rule logic, courtesy of @Automatican to translate to human-readable, Gregorian, date-only form for dashboards. Not exactly elegant, but it works.

1 Like

Yeah, adding minutes offset to a date-only value doesn't actually make sense -- the implication being that RM would have to convert minutes to months, or otherwise invent a time value. So, getting an error makes sense in this case. This action could perhaps be a bit more polite in delivering the error, but either way it won't work.

Not sure what you mean about this. Variable quantity of what?