See upcoming global rocket launches

What follows is an esoteric discussion on converting times in the most expedient way possible…added here mainly to document why I did what I did :).

Launch times in the JSON data stream are returned in Coordinated Universal Time (UTC) format, in an ISO8601-formatted string that looks like this: 2023-12-11T10:30:00Z. To convert that to local time, the macro has to split it into its individual parts for use in the TIME function. Up until now, this ugly looking regex did that:

The value from the TIME () function is then used with %ICUDateTimeFor% to get the user's local time, and put in a format that lets me split it into two parts for the final table format:

This struck me as probably the biggest slowdown spot in the macro–that's a lot of text processing it has to do for all five of the launches. So my friend and I spent some time today trying alternatives:

  • Using a one-liner bash script to calculate the unixtime value.
  • Using the Substring action to split the text, instead of a regular expression.
  • Using JavaScript for Automation to calculate the unixtime value.

Somewhat surprisingly, all three of these methods were slower than my original solution. Not dramatically, but multiplied five times, they'd amount to a noticeable change in speed. Then I found this post by @peternlewis in the Convert ICUDateTime to Unixtime discussion.

He showed another method of dealing with the calculations, so I tried a variation on that method.

It still uses regex, but not to split out separate variables. Instead, it just reformats the text into the format needed by the TIME() function, then (as shown in the linked thread) sets a variable to the text of the calculation I need to do, then uses the Filter action to actually do that calculation:

(The same final two steps are used, as shown above, to get it ready for use in the table.) As it turned out, this method saves about 0.05 seconds per loop, or roughly a quarter of a second overall.

image

It may not sound like much, but when the entire macro runs in just over a second, it's a pretty good improvement:

This version of the macro is now linked in the first article above.

-rob.

1 Like