Date Countdown


#1

Hello Sir!

I cant seem to find this in the Wiki so I thought I’d go straight to the source. I’m still pretty new to all this but I had the idea to create a countdown notification for the wife. She likes to countdown the days till Bdays/Holidays/etc. I’d like to list a group of dates in the variables and then every day (or maybe once a week) send a text message with how many days until the next event. I’ve tried creating this off of just 1 date but keep getting a random date/time. Any chance you could help me with the formula? I dont quite get the logic yet of Date - Date = Days or how to write that. I didnt see a Now or todays date as a variable option so i used date & time with the $now. Any general direction would be greatly appreciated.


#2

What was the result of your piston?


#3

“Hey! Guess What? There are only Mon, Mar 23 1970 @ 2:48:00 am PST days left until Christmas”


#4

I updated it to the below, but am getting the same answer, minus the time.


#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.