Map if else, does it require all comparitors to be strings only?

I have this query:

from(bucket: "solartracking")
 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => r["_measurement"] == "solartracker")
 |> filter(fn: (r) => r["_field"] == "address" or r["_field"] == "moonrise" or r["_field"] == "moonset" or r["_field"] == "sunrise" or r["_field"] == "sunset" or r["_field"] == "day_length" or r["_field"] == "measurementDT")
 |> filter(fn: (r) => r["location"] == v.Location)
   |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
 |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
 |> map(fn: (r) => ({ r with moonrise: int(v: r.moonrise) }))
 |> map(fn: (r) => ({ r with MoonRise: (r.moonrise * 1000000000)}))
 |> map(fn: (r) => ({ r with MoonRise: if r.MoonRise == -1000000000 then "N/A" else string(v: time(v: r.MoonRise)) }))
 |> map(fn: (r) => ({ r with moonset: int(v:r.moonset) }))
 |> map(fn: (r) => ({ r with MoonSet: (r.moonset * 1000000000)}))
 |> map(fn: (r) => ({ r with MoonSet: if r.MoonSet == -1000000000 then "N/A" else string(v: time(v: r.MoonSet)) }))
 |> map(fn: (r) => ({ r with sunrise: int(v:r.sunrise) }))
 |> map(fn: (r) => ({ r with SunRise: (r.sunrise * 1000000000)}))
 |> map(fn: (r) => ({ r with SunRise: if r.sunrise == -1000000000 then "N/A" else string(v: time(v: r.SunRise)) }))
 |> map(fn: (r) => ({ r with sunset: int(v:r.sunset) }))
 |> map(fn: (r) => ({ r with SunSet: (r.sunset * 1000000000)}))
 |> map(fn: (r) => ({ r with SunSet: if r.sunset == -1000000000 then "N/A" else string(v: time(v: r.SunSet)) }))

 |> map(fn: (r) => ({ r with measurementDT: int(v:r.measurementDT) }))
 |> map(fn: (r) => ({ r with Checktime: (r.measurementDT * 1000000000)}))
 |> map(fn: (r) => ({ r with Checktime: time(v:r.Checktime)}))
 |> keep(columns: ["Checktime", "address", "MoonRise", "MoonSet", "SunRise", "SunSet", "day_length"])

Iam using an API to get some astronomy data which works great. The problem is that for moonrise, moonset, sunrise, and sunset I can get any of -:-, - , Always above the Horizon, Always below the horizon, or and actual epoch timestamp for the time of moon and sun rise and set.
before inserting data I leave the unix epoch time as is or I change everything else to -1. I really do not want to show the user 1 second before the epoch as the time so I tried using the Map function with and if else to either show the actual human readable time or “N/A”. When I do that I am limited(at least using my limited knowledge) to converting everything to a string. This displays actual times like this:
which is not the end of the world but not pretty. I tried to simply convert the sting back to a time with:

  |> map(fn: (r) => ({ r with MoonRise: time(v: r.MoonRise)}))

but that fails when the field is “N/A”, obviously.
I am stumped. Any help is appreciated.

Hello @johnm2161,
What do you mean by this?

What are you wanting to display instead of 2022-04-20T15:12:00.000000000Z? And what’s the value of r.MoonRise look like?

“-:-” and “-” are two of the possible responses from the API.
r.MoonRise can be either an actual Linux epoch timestamp or -1. I f I get text back from the API I am polling I insert -1 into InfluxDB to avoid errors with different data types. What I would like to see instead of 2022-04-20T15:12:00.000000000Z
2022-04-20 15:12:00
I.E. what would be the result of time( v: r.MoonRise) when MoonRise is a string which I seem to have to convert it to to use the if else logic.
Hope that makes sense.