rek Posted July 8, 2017 Share Posted July 8, 2017 Is there a way to access or use date/time information from within scripts? All I've found so far are the conditionals available from the Scheduler agent. Forgive the contrived examples but this is the sort of thing I'm thinking: Include current date/time pieces in a string, for any number of reasons. Store the current date/time away in a variable. Later on, extract date/time pieces to use. For example, a keypad button announces "The recirc pump power was last cycled on Saturday Feb. 12th". Do some simple date/time math. "The recirc pump power was last cycled 4 days ago". Then there's all the various postings here about calculating elapsed days, using repeating timers every x minutes to increment a variable to compute "how long", figuring out time until sunset, etc. As I type this, I realize this is a variation on a frequent topic and there probably isn't really a solution (correct me if I'm wrong). So, I'm turning this into a wish list for the Variable Manipulator driver from @alanchow. Support DAY{} TIME{} DATE{} for the current date/time in the Create String action, like in the Advanced Announcements driver. Add a new one, DATETIME{}. It replaces with current date and time info in whatever format is reasonably easy to work against later. Support some basic operations against a string PARAM (in the format returned above). Maybe just the same DAY{} TIME{} DATE{} are available when creating a string. Support some basic date/time math with two string PARAMs (or maybe one PARAM and the current date/time). Maybe just DAYSDIFF{} and HOURSDIFF{} are available when creating a string or number. I'm sure I've missed or oversimplified something but I think this would address my use cases. And then my solution to the time-until-sunset problem would be something like: Scheduler Event Every Day at Sunset Create SunsetString from current DATETIME{} When your_event_here Create AnnouncementString "The next sunset will be in HOURSDIFF{SunsetString} hours at TIME{SunsetString}" // should be off by less than a minute Quote Link to comment Share on other sites More sharing options...
rek Posted July 8, 2017 Author Share Posted July 8, 2017 In thinking about it @alanchow, I have a much better idea and a simpler request for the Variable Manipulator driver. Support DAY{}, TIME{}, DATE{} for the current date/time in the Create String action, like in the Advanced Announcements driver. Support something like EPOCHSECONDS{}. It would set your NUMBER variable to the number of seconds since some epoch of your choosing. I think that's it. A script could then stash away a pretty date/time string in any format they wanted for their own use later. A script could also capture EPOCHSECONDS whenever they wanted and do their own math to get elapsed days, hours, mins, secs. Quote Link to comment Share on other sites More sharing options...
alanchow Posted July 8, 2017 Share Posted July 8, 2017 With the variable manipulator you can do this using os.time() and os.date(). rek, dcovach and South Africa C4 user 3 Quote Link to comment Share on other sites More sharing options...
rek Posted July 8, 2017 Author Share Posted July 8, 2017 Nice - that does it all! Any other cool tricks with Variable Manipulator besides math. and os.? Quote Link to comment Share on other sites More sharing options...
JGLI Posted August 9, 2017 Share Posted August 9, 2017 rek, did you figure out how to do this and get it working? can you share the code? Quote Link to comment Share on other sites More sharing options...
rek Posted August 10, 2017 Author Share Posted August 10, 2017 I did enough playing to confirm the date and time functions should do what I wanted. But I haven't got around to incorporating them into my project, yet. Quote Link to comment Share on other sites More sharing options...
goldencat Posted March 31, 2022 Share Posted March 31, 2022 On 7/8/2017 at 2:42 AM, alanchow said: With the variable manipulator you can do this using os.time() and os.date(). Variable Manipulator with time I just started playing with Variable Manipulator, and the first thing I got stock is how to get Time parameters Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.