How to get UTC time with local time and location information?

#1

My main entity type has the following definition:

type Car {
    id: string
    location: Facility
    time: datetime <-----local time
    ......
}

type Facility {
    placedAt: Location <--- this links to lat and lon through address.geometry
    ......
}

I want to fetch instances of Car and get UTC time based on the local time and location information. How to do this?

0 Likes

#2

why do you want to use location information if local time (should already have zone information) is already specified?

You can do something like:

type Car {
    id: string
    location: Facility
    time: datetime <-----local time
    utcTime: datetime calc 'convertToTimeZone("UTC", time)'
    ......
}
0 Likes

#3

How does the platform know what time zone “time” is. Assume we are loading time without the time zone information so the only clue is based on the location.

0 Likes

#4

If the “time” field doesn’t have any time zone information then the convertToTimeZone function will not be able to perform its duty. Currently we do NOT have a way to convert a datetime in a particular zone from lat / long by default in the expression engine.

You can alternatively add a javascript function to find out the time zone based on the lat long (via the WeatherStation) and then use the convert function on TimeZone type to get the date in the right timezone.

0 Likes