Calculating next event

Has anyone worked with trying to calculate the next event time at all? I can get the number of hours since the lstart time, but I need to do a mode division on that number of hours send then figure out the next event based on how many hours it’s been.

Basically, I have a starting time (20180201T000000 UTC) and I have an ever to that occurs every 15 hours. I only care about knowing the time of the NEXT event.

So, I get current date, calculate number of hours from start date to current date, and then I ewant to do modules division by 15. There’s nothing in calculate, but there is “mode” in Calcualte statistics, but no fields to fill in, and I can’t find documentation.

I also tried to figure out how to feed the hours into pClac, but I can’t get the mod operation to “donate” to Shortcuts., despite doing it a whole bunch of times.

I mean, I could do a repeat loop, but that is really ugly just to manually do a mod operation.

NB: I do not need all events, I do not need a calendar entry, I just need to know what time (local time, where ever local is) until the next event. Als, I may want to change the number of hours, so nothing that relies on a specific trick related to 15 hours. It should work with 7, 13, or 19. Or even 31.)

Searching the engines for help with shortcuts is nigh-impossible, btw. #ThanksApple for not picking an actual name.

Progress, of a sort. I got “Modulo clipboard and clipboard” into Shortcuts form PCalc, but how do I set two clipboards?

Modulus is in calculate.

1 Like

I don’t know if I’ve misunderstood your requirement, but there is a Modulus operation in the shortcuts ‘Calculate’ step. You need to choose Scientific Operation (the … button) and then choose ‘Modulus’ from the list

1 Like

OK, never do shortcuts on your iPhone. I could not see the three dots clearly and thought it was a minus. Yes, I know there was already a minus.

I did get a reply from @pcal and I suspect I am going to have the same problem, since I’ve seen it referenced other places as an issue.

Once I have a NUMBER of hours. I cannot then put the number into “Adjust Date” because I get a “Shortcuts couldn’t convert from Number to Date”

(checks, yep, same issue).

Are you trying to do something like this?

1 Like

No, I am trying to end up with “The next ever is in 5 hours and 14 minutes” or “the next event is in 4 days, 6 hours, and 19 minutes” or similar, based on the calculations, but adjust date will evidently not take any sort of variable/magic variable other than a date that Shortcuts has generated.

What you have works. but only returns a numeric result of approximately how many hours and I do want a date/time result. (partly because I’m not sure right now how that result might end up being used).

(approximate because it will say 17 hours when there is 17:00 hours and 17:59:59 hours)

That was just an example, not a full solution. The calculation does show the time to the next event based on the 15 day period you noted originally, so it sounds to me like it is just a case of granularity and formatting.

If you want more granularity change to minutes (note you’ll need to change to 21,600 minutes per 15 days rather than in hours) and you’ll get the time to occur back in minutes.

Once you have the time in minutes it should just be a case of some maths to build the time result in the format you want.

  • Divide the minutes by 1,440 (mins per day) and take the integer part to get the number of days.
  • Take the remainder and multiply it back up to get the number of minutes remaining after you have taken off the number of days. Or take a shortcut and just do it as a single calculation :wink:
  • Repeat the approach for hours (rather than days).
  • Anything you’re left with after the hours would be your minutes.

Put them together and you have the granularity you want in your result.

Hopefully that all makes sense.

1 Like

The math is not the issue, the issue is having an actual date/time instead of a series of numbers posing as a date time.

Basically, the Adjust Date action will take a number if you type it in manually in the shortcut, but otherwise it will not take any variable.

Time is actually a numerical measure of an elapsed standard period from a fixed point. Date/times are really just numbers, we’re just presenting them in a more readable form or in a form that makes them easier to work with for certain types of date time calculations. If you have a number representing a date/time the fundamentally, you do have a date time … it just may not be in your preferred format.

In Shortcuts you can commute between date/time and strings as long as it is into standardised formats that the app understands.

The example shortcut I posted actually includes an example of taking your original text based time representation and converting that into a date format that Shortcuts can use.

If necessary, you can coerce your numeric values to text and then operate on them just like I did above, but there’s a plethora of ways to attack conversions.

1 Like

Try it with Adjust Date. that’s where the problem is. (same result with a text field)

You’re trying to date adjust a number by itself…

Don’t you want to do something more akin to this?

1 Like

That exact shortcut does not work.

Off to find an iPad without 12.2 beta on it…

Ugh. Rebooted iPad and all is as it should be. Egads, that was a few hours wasted.

This is what I ended up with. Not sure it would be useful for anyone else, but I did make it generic for any purpose.if the event is happening now, it speaks how much time is remaining in the event, otherwise it speaks the time u til the next event start. It also pops up Notifications.

I cleaned up a lttle and improved this.
Next Event