I’d do it in 3 steps:
- Use
fl()
to transform each element in the list into <absolute difference> <separator> <sign> <separator> <original time>
(where sign
is 0 if time is in the past and 1 if time is in the future)
- Use
tc(nsort)
to sort that list by the first number that appears in it (the absolute difference)
- Use
tc(reg)
to extract the first item with the appropriate sign
.
Assuming the string comes from a local variable called times
(set using lv(times, <string>)
, accessed using #times
), it would look something like this:
lv(now, df(S))
+ lv(transformed, tc(nsort, fl(0, tc(count, #times, ","), "i+1",
tc(reg, "
lv(n, tc(split, '"+#times+"', i)) +
mu(abs, "+#now+" - #n) + @ + ("+#now+" - #n < 0) + @ + #n
",
', tc(utf, 22)
),
","
), ",")
/* get the first time in the past */
+ tc(reg, #transformed, "(^|.*?,)[^,]+@0@([^,]+)(,.*|$)", "$1")
/* get the first time in the future */
+ tc(reg, #transformed, "(^|.*?,)[^,]+@1@([^,]+)(,.*|$)", "$1")
Though this is untested so treat it as a proof of concept more than a finished product.