I pull data from an API for dynamic energy tarrifs. Every hour has a startsAt-property in this format: 2024-10-18T10:00:00.000+02:00
But I am missing the end time. I want to create calendar events from these objects to trigger a few energy related things. I have been breaking my mind about this and searching for a very long time now to get this done in a lambda when creating the event by filling in the end time as “start time + 1hr”. But I have not been able to find anything. At least nothing that was an option to include in one row of jsonata with lambda. Also, documentation on jsonata on time objects is very limited so I assume the options are too. Is there any way or are my assumptions correct?
Another option I could think off is to create a function that for every object creates a new property endsAt which value is “startsAt + 1hr”. Then I can fully use JavaScript to first parse the datetime string, then add 1 hour (add 3600s to epoch value) and then create a datetime string, again with offset (which also seems to be a bit of a challenge if one wants that time offset included). Then add the value to the new property.
Something else would be to just replace part of the string. Very ugly if you ask me and maybe prone to error. But every datetime entry has the exact same amount of characters and every element (hour, minute, second and so on) is in exactly the same index everytime. So I could just add 59 minutes and 59 seconds to replace the 00:00 in the string. Should work but doesn’t feel right.
I am wondering what your ideas and opinions would be for the mentioned options. Has anyone got any other idea? I am trying to find the cleanest, simplest and easiest to understand option. I have been thinking and searching a lot but delay in my project is starting to become too much for this seemingly simple problem…