Minutes between dates, one local one UTC

I have started using a calendar plug in, it doesn’t give me the date of the events with any time zone information. So I want to assume that the time given (unless it starts to give time zone) is the current time zone.

How would I do this?

Here is the template I’m using right now, currently it works fine as I have the + 300 in there, but come March everything will be off by an hour, and I’d like to prevent that:

{{(((as_timestamp(states.calendar.ical_landstar_calendar.attributes.start_time) - as_timestamp(now())) / 60)+300 | default(99) | int) }}

I’m slightly confused because you say you are assuming it is local time and then add a conversion (the +300). So, I am assuming that it is not giving local time, as this wouldn’t be a problem if it was.

Since you are just calculating the difference in minutes, you don’t have to be using the correct timezones as long as they are the same timezone. The easiest way to do this would probably be to use utcnow() instead of now().

{{ as_local(as_datetime(state_attr("calendar.ical_landstar_calendar", "start_time"))) }}
{{states.calendar.ical_landstar_calendar.attributes.start_time}} < -- My Calendar time
{{now()}} <-- current time with timzone

outputs of the above:
2021-11-23 13:00:00 ← calendar, no timezone indication
2021-11-23 13:15:00.038451-05:00 ← Now, now has the -05:00 for timezone adjustment

Notice the NOW is 15mins after the calendar time. it is 1:15pm as I type this, and I am currently 15 mins into a meeting. I have this calculation:

{{(((as_timestamp(states.calendar.ical_landstar_calendar.attributes.start_time) - as_timestamp(now())) / 60)+300 | default(99) | int) }}

this gives me: -17.000047934055317 (little off as I was typing above)
without the +300 I get: 317

Thus the subtraction treats the calendar time as UTC, adjusts the now time to 18:… and comes up with a 5hour difference where their shouldn’t be one.

So I need to know how to tell the calculation that the current calendar time is in the current timezone so I don’t have to come back later and change the +300 to +240.

Hope that clears things up a bit more

I see what you mean now, and both replies should still apply.

You either need to provide now as a UTC timestamp, utcnow(), or convert the calendar timestamp to local, as_local(...) (credit to @koying).

@koying also made a slight change to your template, as it is better to use the state_attr() function than to reference the attribute directly.

Thank you both, I missed @koying modification. I also learned a new function, as_local, so over all a good day!