Struggling with date format conversion

I have a little problem with timestamp conversion.
I’m trying to convert a timestamp that is stored in ISO8601/RFC3339 format as a string.

basically i want to do something like this:

from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "sessions")
  |> pivot(columnKey: ["_field"], rowKey: ["_time"], valueColumn: "_value")
  |> map(fn: (r) => ({
   r with 
    sessionEndTime: if r.sessionEndTime =~ /[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?([Zz]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?/ then <r.sessionEndTime AS EPOCH> else "now"

I’ve tried date.truncate(t: r.sessionEndTime, unit: 1s) but it does not accept strings
I’ve tried date.truncate(t: time(t: r.sessionEndTime), unit: 1s) but it sas time() looks for v as arg however Flux Library sas waits for a t arg
if i try date.truncate(t: time(v: r.sessionEndTime), unit: 1s) it says it accepts only time not string
Then how am i supposed to convert a string to time ?


Maybe I have misunderstood, but shouldn’t the time() function work?