Date Countdown


#5

Turn logging to full. Execute the piston and then copy paste the logs into here


#6

OK! So I kinda figured it out. I am able to get the dates to send but I have another question (and i can post this to the forum if you think it’d be better). Right now the below works by sending me the days until christmas. Is there a way to word the notificatino so it picks the earliest variable date & then holiday. So it would say “only 73 days until Christmas” or on Dec 26. It would say (with this current set up) only 300 days until Halloween? Again, I’d be happy to create a topic on this if you think it be better for the world now that it somewhat works :slight_smile:


#7

I think I can come up with a hack to make it work.

"There are " min(daysUntilchristmasday, daysUntilhalloween, daysUntilthanksgiving) " days until the next holiday”

Plug that into the expression box. See if that works


made this topic public #8

#9

@bangali do you know of a way to store these values in a list so it’s easy to reference the next holiday?


#10

unmodified webcore code or modified? :slight_smile:

unmodified do this:

define
   string dates = "01/01/2017,07/04/2017,12/25/2017"
   date[] dateA
  int i
end define

if $currentEventAttribute = 'test'
   for i = 0 to 20 step 1
      set dateA[i] = date(arraryItem(i, dates))
      if isEmpty(dateA[i]) is 'true'
         break
      end if
   end for
end if

‘modified’ do this:

define
   string dates = "0:01/01/2017,1:07/04/2017,2:12/25/2017"
   date[] dateA
end define

if $currentEventAttribute = 'test'
   set dateA[*ALL] = dates
end if

https://community.webcore.co/t/stuffing-a-list-all/1368


#11

LOL WOW @bangali! I think I’m in a little over my head.

  1. Being a newb i would assume I’m under the Unmodified WC, but looking at the above, i would think i could only write the modified part.

  2. I have zero experience with this. I was just able to write the below (literally copying the modified above) but not sure what it means at all. What will this do what do i add to the “then” to send out a notification.


#12

the modified version was for @c1arkbar :slight_smile:

give me a few minutes …


#13

Sorry @Jrrobertson3. I was trying to think more manageable long term aside from adding 2 new variables each time. Basically what I was thinking was having a couple lists. First list has the dates of the holidays and the second has the name of the holiday. Then we can figure out which date is closest and find the corresponding title of the holiday. @bangali is the go to list guy so I made the post public and brought him in.


#14

@c1arkbar - Not a problem! Probably better anyway so others can search and review!

I was also thinking of adding several 'If" statements depending on the $now months and then act on the next upcoming. I saved what i have above to play and learn with that later. I’m interested to see @bangali’s suggestion to use, review and learn. That is a completely different level than my thinking and knowledge!


#15

He is great at this. He takes things to a whole new level!!


#16

could you please try this … date is behaving a little funky i am still looking at it. but your feedback would be great.


#17

Below are the logs. it looks like its getting stuck on the 999 set date to?

image

If was to add the send SMS notification, would i add that after the “log” info?


#18

sorry, click the test button before the piston fires on the timer … then wait for it to run on the timer.


#19

OK here is the new logs.

10/4/2017, 10:18:59 PM +118ms
+1ms ╔Received event [Home].time = 1507180740000 with a delay of -883ms
+128ms ║RunTime Analysis CS > 18ms > PS > 58ms > PE > 53ms > CE
+140ms ║Runtime (42183 bytes) successfully initialized in 58ms (v0.2.0ec.20170927) (138ms)
+142ms ║╔Execution stage started
+161ms ║║Cancelling statement #8’s schedules…
+169ms ║║Executed virtual command setVariable (3ms)
+201ms ║║Comparison (date) 1514707200000 is_greater_than (date) 1507100400000 = true (3ms)
+203ms ║║Cancelling condition #19’s schedules…
+204ms ║║Condition #19 evaluated true (21ms)
+206ms ║║Cancelling condition #11’s schedules…
+207ms ║║Condition group #11 evaluated true (state changed) (25ms)
+210ms ║║Cancelling statement #12’s schedules…
+228ms ║║Calculating (date) 1514707200000 - (date) 1507100400000 >> (date) 7606800000
+236ms ║║Calculating (integer) -1044334592 % (integer) 86400000 >> (integer) -7534592
+242ms ║║Executed virtual command setVariable (4ms)
+252ms ║║Comparison (integer) 9999 is_greater_than (integer) -7534592 = true (2ms)
+254ms ║║Condition #18 evaluated true (7ms)
+255ms ║║Condition group #14 evaluated true (state did not change) (9ms)
+258ms ║║Cancelling statement #15’s schedules…
+265ms ║║Executed virtual command setVariable (3ms)
+272ms ║║Executed virtual command setVariable (3ms)
+299ms ║║Comparison (date) 1530687600000 is_greater_than (date) 1507100400000 = true (3ms)
+301ms ║║Condition #19 evaluated true (14ms)
+302ms ║║Condition group #11 evaluated true (state did not change) (15ms)
+306ms ║║Cancelling statement #12’s schedules…
+323ms ║║Calculating (date) 1530687600000 - (date) 1507100400000 >> (date) 23587200000
+331ms ║║Calculating (integer) 2051163520 % (integer) 86400000 >> (integer) 63963520
+338ms ║║Executed virtual command setVariable (4ms)
+348ms ║║Comparison (integer) -7534592 is_greater_than (integer) 63963520 = false (2ms)
+350ms ║║Cancelling condition #18’s schedules…
+351ms ║║Condition #18 evaluated false (9ms)
+352ms ║║Cancelling condition #14’s schedules…
+354ms ║║Condition group #14 evaluated false (state changed) (11ms)
+380ms ║║Comparison (date) 1514102400000 is_greater_than (date) 1507100400000 = true (3ms)
+382ms ║║Condition #19 evaluated true (13ms)
+383ms ║║Condition group #11 evaluated true (state did not change) (15ms)
+387ms ║║Cancelling statement #12’s schedules…
+404ms ║║Calculating (date) 1514102400000 - (date) 1507100400000 >> (date) 7002000000
+412ms ║║Calculating (integer) -1649134592 % (integer) 86400000 >> (integer) -7534592
+418ms ║║Executed virtual command setVariable (3ms)
+428ms ║║Comparison (integer) -7534592 is_greater_than (integer) -7534592 = false (3ms)
+430ms ║║Condition #18 evaluated false (8ms)
+432ms ║║Condition group #14 evaluated false (state did not change) (9ms)
+441ms ║║Cancelling statement #4’s schedules…
+458ms ║║Calculating (string) Guess What!?! There are + (string) -7534592 >> (string) Guess What!?! There are -7534592
+463ms ║║Calculating (string) Guess What!?! There are -7534592 + (string) days until >> (string) Guess What!?! There are -7534592 days until
+468ms ║║Calculating (string) Guess What!?! There are -7534592 days until + (string) New Years >> (string) Guess What!?! There are -7534592 days until New Years
+472ms ║║Calculating (string) Guess What!?! There are -7534592 days until New Years + (string) !!! >> (string) Guess What!?! There are -7534592 days until New Years!!!
+477ms ║║Guess What!?! There are -7534592 days until New Years!!!
+479ms ║║Executed virtual command log (1ms)
+484ms ║╚Execution stage complete. (343ms)
+486ms ║Setting up scheduled job for Thu, Oct 5 2017 @ 10:19:00 PM PDT (in 86400.397s)
+505ms ╚Event processed successfully (505ms)


#20

yeah, same results … the days are -ve. let me look at this tomorrow and fix it up.

sorry, its taking so long.


#21

Sounds great sir! Greatly appreciated!

Sorry, i did forget i changed the previous past dates to 2018. I moved them back and go the same results, except christmas is listed. here is the update below from the way you had it exactly.

10/4/2017, 10:23:59 PM +139ms
+1ms ╔Received event [Home].time = 1507181040000 with a delay of -862ms
+207ms ║RunTime Analysis CS > 23ms > PS > 75ms > PE > 109ms > CE
+331ms ║Runtime (42208 bytes) successfully initialized in 75ms (v0.2.0ec.20170927) (329ms)
+333ms ║╔Execution stage started
+358ms ║║Cancelling statement #8’s schedules…
+368ms ║║Executed virtual command setVariable (5ms)
+407ms ║║Comparison (date) 1483171200000 is_greater_than (date) 1507100400000 = false (4ms)
+410ms ║║Condition #19 evaluated false (24ms)
+413ms ║║Condition group #11 evaluated false (state did not change) (26ms)
+444ms ║║Comparison (date) 1499151600000 is_greater_than (date) 1507100400000 = false (4ms)
+448ms ║║Condition #19 evaluated false (16ms)
+450ms ║║Condition group #11 evaluated false (state did not change) (19ms)
+481ms ║║Comparison (date) 1514102400000 is_greater_than (date) 1507100400000 = true (4ms)
+484ms ║║Cancelling condition #19’s schedules…
+486ms ║║Condition #19 evaluated true (18ms)
+488ms ║║Cancelling condition #11’s schedules…
+490ms ║║Condition group #11 evaluated true (state changed) (24ms)
+495ms ║║Cancelling statement #12’s schedules…
+517ms ║║Calculating (date) 1514102400000 - (date) 1507100400000 >> (date) 7002000000
+526ms ║║Calculating (integer) -1649134592 % (integer) 86400000 >> (integer) -7534592
+534ms ║║Executed virtual command setVariable (3ms)
+546ms ║║Comparison (integer) 9999 is_greater_than (integer) -7534592 = true (2ms)
+549ms ║║Cancelling condition #18’s schedules…
+551ms ║║Condition #18 evaluated true (11ms)
+553ms ║║Cancelling condition #14’s schedules…
+555ms ║║Condition group #14 evaluated true (state changed) (16ms)
+560ms ║║Cancelling statement #15’s schedules…
+569ms ║║Executed virtual command setVariable (3ms)
+578ms ║║Executed virtual command setVariable (4ms)
+591ms ║║Cancelling statement #4’s schedules…
+609ms ║║Calculating (string) Guess What!?! There are + (string) -7534592 >> (string) Guess What!?! There are -7534592
+615ms ║║Calculating (string) Guess What!?! There are -7534592 + (string) days until >> (string) Guess What!?! There are -7534592 days until
+621ms ║║Calculating (string) Guess What!?! There are -7534592 days until + (string) Christmas >> (string) Guess What!?! There are -7534592 days until Christmas
+626ms ║║Calculating (string) Guess What!?! There are -7534592 days until Christmas + (string) !!! >> (string) Guess What!?! There are -7534592 days until Christmas!!!
+633ms ║║Guess What!?! There are -7534592 days until Christmas!!!
+635ms ║║Executed virtual command log (2ms)
+642ms ║╚Execution stage complete. (308ms)
+645ms ║Setting up scheduled job for Thu, Oct 5 2017 @ 10:24:00 PM PDT (in 86400.217s)
+666ms ╚Event processed successfully (665ms)


#22

try this. remember to hit the test button before the timer kicks in. (you need to do this once when you change dates, dateNames or numberOfHolidays. if you change the first two, remember to set numberOfHolidays to the right count of holidays.)


#23

Try this.


#24

Thanks @bangali! That worked and lead me in the right direction. I think I got it and starting to understand it now! I have updated it slightly to add the SMS notification as well. The SMS notification also gives an update how long until Christmas (since thats always a big countdown :slight_smile: It will be a little wierd after thanksgiving but i can always update the SMS output then and put it back on afterwards. Greatly appreciate your help!

Below is an example piston in case anyone else would like to use it.