WeatherKit API forecastStart value

Is there a way to take an API’s datasource result value that is a UTC based time and convert it to a local timezone? This isn’t stored in a database, it’s the Apple WeatherKit I am setting up as a datasource and even though it’s giving me today’s data, Apple doesnt adjust the forecastStart to be local to the timezone requested. It just provides me the data that is adjusted to my timezone.

Hopefull that makes sense.

This honestly cant be a new problem, can it?

welcome

Please provide some sample data, I am not sure I understand

So the weatherkit api call returns an hourly dataset that includes the time (forecastStart) but in UTC. Even though the data is from the time of which you want, apple returns the UTC time which doesnt work real well when I have no way to offset that output to my local timezone.

{
    "forecastHourly": {
        "name": "HourlyForecast",
        "metadata": {
            "attributionURL": "https://weatherkit.apple.com/legal-attribution.html",
            "expireTime": "2023-01-08T19:21:16Z",
            "latitude": 27.499,
            "longitude": -82.575,
            "readTime": "2023-01-08T18:21:16Z",
            "reportedTime": "2023-01-08T17:00:00Z",
            "units": "m",
            "version": 1
        },
        "hours": [
            {
                "forecastStart": "2023-01-08T18:00:00Z",
                "cloudCover": 0.10,
                "conditionCode": "Clear",
                "daylight": true,
                "humidity": 0.59,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1022.55,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 23.41,
                "temperatureApparent": 23.60,
                "temperatureDewPoint": 14.90,
                "uvIndex": 5,
                "visibility": 32781.00,
                "windDirection": 128,
                "windGust": 14.46,
                "windSpeed": 8.53
            },
            {
                "forecastStart": "2023-01-08T19:00:00Z",
                "cloudCover": 0.14,
                "conditionCode": "MostlyClear",
                "daylight": true,
                "humidity": 0.58,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.57,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 23.88,
                "temperatureApparent": 24.10,
                "temperatureDewPoint": 15.02,
                "uvIndex": 4,
                "visibility": 33233.87,
                "windDirection": 156,
                "windGust": 14.30,
                "windSpeed": 7.56
            },
            {
                "forecastStart": "2023-01-08T20:00:00Z",
                "cloudCover": 0.12,
                "conditionCode": "Clear",
                "daylight": true,
                "humidity": 0.58,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.91,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 23.65,
                "temperatureApparent": 23.86,
                "temperatureDewPoint": 14.96,
                "uvIndex": 3,
                "visibility": 31874.48,
                "windDirection": 210,
                "windGust": 15.15,
                "windSpeed": 8.40
            },
            {
                "forecastStart": "2023-01-08T21:00:00Z",
                "cloudCover": 0.11,
                "conditionCode": "Clear",
                "daylight": true,
                "humidity": 0.61,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.57,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 22.89,
                "temperatureApparent": 23.11,
                "temperatureDewPoint": 15.03,
                "uvIndex": 1,
                "visibility": 30864.05,
                "windDirection": 230,
                "windGust": 14.97,
                "windSpeed": 9.33
            },
            {
                "forecastStart": "2023-01-08T22:00:00Z",
                "cloudCover": 0.08,
                "conditionCode": "Clear",
                "daylight": true,
                "humidity": 0.66,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.59,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 21.77,
                "temperatureApparent": 22.01,
                "temperatureDewPoint": 15.21,
                "uvIndex": 0,
                "visibility": 30260.75,
                "windDirection": 236,
                "windGust": 13.98,
                "windSpeed": 9.71
            },
            {
                "forecastStart": "2023-01-08T23:00:00Z",
                "cloudCover": 0.10,
                "conditionCode": "Clear",
                "daylight": false,
                "humidity": 0.75,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.94,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 19.80,
                "temperatureApparent": 20.02,
                "temperatureDewPoint": 15.16,
                "uvIndex": 0,
                "visibility": 28831.43,
                "windDirection": 264,
                "windGust": 11.83,
                "windSpeed": 8.48
            },
            {
                "forecastStart": "2023-01-09T00:00:00Z",
                "cloudCover": 0.07,
                "conditionCode": "Clear",
                "daylight": false,
                "humidity": 0.80,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.51,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 18.54,
                "temperatureApparent": 18.71,
                "temperatureDewPoint": 14.98,
                "uvIndex": 0,
                "visibility": 26766.45,
                "windDirection": 293,
                "windGust": 15.74,
                "windSpeed": 9.17
            },
            {
                "forecastStart": "2023-01-09T01:00:00Z",
                "cloudCover": 0.22,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.83,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.88,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 17.96,
                "temperatureApparent": 18.13,
                "temperatureDewPoint": 14.99,
                "uvIndex": 0,
                "visibility": 26161.74,
                "windDirection": 305,
                "windGust": 15.92,
                "windSpeed": 9.25
            },
            {
                "forecastStart": "2023-01-09T02:00:00Z",
                "cloudCover": 0.21,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.84,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1022.19,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 17.67,
                "temperatureApparent": 17.84,
                "temperatureDewPoint": 14.97,
                "uvIndex": 0,
                "visibility": 25872.19,
                "windDirection": 318,
                "windGust": 18.25,
                "windSpeed": 10.18
            },
            {
                "forecastStart": "2023-01-09T03:00:00Z",
                "cloudCover": 0.15,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.86,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1022.18,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 17.12,
                "temperatureApparent": 17.26,
                "temperatureDewPoint": 14.82,
                "uvIndex": 0,
                "visibility": 25193.45,
                "windDirection": 327,
                "windGust": 15.57,
                "windSpeed": 8.93
            },
            {
                "forecastStart": "2023-01-09T04:00:00Z",
                "cloudCover": 0.28,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.88,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.78,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 16.46,
                "temperatureApparent": 16.53,
                "temperatureDewPoint": 14.45,
                "uvIndex": 0,
                "visibility": 23565.73,
                "windDirection": 350,
                "windGust": 10.32,
                "windSpeed": 7.62
            },
            {
                "forecastStart": "2023-01-09T05:00:00Z",
                "cloudCover": 0.42,
                "conditionCode": "PartlyCloudy",
                "daylight": false,
                "humidity": 0.90,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.02,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 15.89,
                "temperatureApparent": 15.93,
                "temperatureDewPoint": 14.27,
                "uvIndex": 0,
                "visibility": 23171.24,
                "windDirection": 15,
                "windGust": 11.80,
                "windSpeed": 7.39
            },
            {
                "forecastStart": "2023-01-09T06:00:00Z",
                "cloudCover": 0.53,
                "conditionCode": "PartlyCloudy",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.46,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 15.47,
                "temperatureApparent": 15.49,
                "temperatureDewPoint": 14.08,
                "uvIndex": 0,
                "visibility": 19733.18,
                "windDirection": 36,
                "windGust": 8.72,
                "windSpeed": 5.78
            },
            {
                "forecastStart": "2023-01-09T07:00:00Z",
                "cloudCover": 0.65,
                "conditionCode": "MostlyCloudy",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.20,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 15.26,
                "temperatureApparent": 15.24,
                "temperatureDewPoint": 13.87,
                "uvIndex": 0,
                "visibility": 14766.60,
                "windDirection": 41,
                "windGust": 6.07,
                "windSpeed": 4.63
            },
            {
                "forecastStart": "2023-01-09T08:00:00Z",
                "cloudCover": 0.37,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.13,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 14.80,
                "temperatureApparent": 14.70,
                "temperatureDewPoint": 13.33,
                "uvIndex": 0,
                "visibility": 14261.56,
                "windDirection": 21,
                "windGust": 6.19,
                "windSpeed": 3.91
            },
            {
                "forecastStart": "2023-01-09T09:00:00Z",
                "cloudCover": 0.22,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1019.95,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 14.32,
                "temperatureApparent": 14.17,
                "temperatureDewPoint": 12.95,
                "uvIndex": 0,
                "visibility": 13205.45,
                "windDirection": 53,
                "windGust": 5.22,
                "windSpeed": 3.16
            },
            {
                "forecastStart": "2023-01-09T10:00:00Z",
                "cloudCover": 0.25,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1019.70,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 14.15,
                "temperatureApparent": 13.98,
                "temperatureDewPoint": 12.74,
                "uvIndex": 0,
                "visibility": 11965.90,
                "windDirection": 77,
                "windGust": 5.53,
                "windSpeed": 3.17
            },
            {
                "forecastStart": "2023-01-09T11:00:00Z",
                "cloudCover": 0.29,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1019.98,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 13.73,
                "temperatureApparent": 13.51,
                "temperatureDewPoint": 12.36,
                "uvIndex": 0,
                "visibility": 10845.17,
                "windDirection": 76,
                "windGust": 5.91,
                "windSpeed": 3.86
            },
            {
                "forecastStart": "2023-01-09T12:00:00Z",
                "cloudCover": 0.36,
                "conditionCode": "MostlyClear",
                "daylight": false,
                "humidity": 0.91,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.36,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 13.57,
                "temperatureApparent": 13.32,
                "temperatureDewPoint": 12.14,
                "uvIndex": 0,
                "visibility": 10843.71,
                "windDirection": 86,
                "windGust": 5.45,
                "windSpeed": 3.63
            },
            {
                "forecastStart": "2023-01-09T13:00:00Z",
                "cloudCover": 0.40,
                "conditionCode": "PartlyCloudy",
                "daylight": true,
                "humidity": 0.90,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.01,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 14.18,
                "temperatureApparent": 13.99,
                "temperatureDewPoint": 12.61,
                "uvIndex": 0,
                "visibility": 11579.93,
                "windDirection": 88,
                "windGust": 5.66,
                "windSpeed": 3.24
            },
            {
                "forecastStart": "2023-01-09T14:00:00Z",
                "cloudCover": 0.44,
                "conditionCode": "PartlyCloudy",
                "daylight": true,
                "humidity": 0.88,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.61,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 15.50,
                "temperatureApparent": 15.43,
                "temperatureDewPoint": 13.52,
                "uvIndex": 1,
                "visibility": 12073.81,
                "windDirection": 70,
                "windGust": 6.53,
                "windSpeed": 2.70
            },
            {
                "forecastStart": "2023-01-09T15:00:00Z",
                "cloudCover": 0.32,
                "conditionCode": "MostlyClear",
                "daylight": true,
                "humidity": 0.81,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.98,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 17.92,
                "temperatureApparent": 18.02,
                "temperatureDewPoint": 14.58,
                "uvIndex": 2,
                "visibility": 19371.16,
                "windDirection": 54,
                "windGust": 7.96,
                "windSpeed": 3.17
            },
            {
                "forecastStart": "2023-01-09T16:00:00Z",
                "cloudCover": 0.29,
                "conditionCode": "MostlyClear",
                "daylight": true,
                "humidity": 0.74,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1021.80,
                "pressureTrend": "rising",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 19.84,
                "temperatureApparent": 20.03,
                "temperatureDewPoint": 15.04,
                "uvIndex": 4,
                "visibility": 16931.38,
                "windDirection": 335,
                "windGust": 10.33,
                "windSpeed": 4.30
            },
            {
                "forecastStart": "2023-01-09T17:00:00Z",
                "cloudCover": 0.23,
                "conditionCode": "MostlyClear",
                "daylight": true,
                "humidity": 0.70,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1020.98,
                "pressureTrend": "steady",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 21.18,
                "temperatureApparent": 21.50,
                "temperatureDewPoint": 15.55,
                "uvIndex": 5,
                "visibility": 20483.94,
                "windDirection": 320,
                "windGust": 13.64,
                "windSpeed": 7.63
            },
            {
                "forecastStart": "2023-01-09T18:00:00Z",
                "cloudCover": 0.19,
                "conditionCode": "MostlyClear",
                "daylight": true,
                "humidity": 0.68,
                "precipitationAmount": 0.0,
                "precipitationIntensity": 0.0,
                "precipitationChance": 0.00,
                "precipitationType": "clear",
                "pressure": 1019.97,
                "pressureTrend": "falling",
                "snowfallIntensity": 0.00,
                "snowfallAmount": 0.00,
                "temperature": 21.95,
                "temperatureApparent": 22.32,
                "temperatureDewPoint": 15.75,
                "uvIndex": 5,
                "visibility": 18323.52,
                "windDirection": 319,
                "windGust": 15.20,
                "windSpeed": 9.65
            }
        ]
    }
}
1 Like

I’m using the JSON API data source

1 Like

Welcome baxk as smith288 :wink:

Anyways, you want the utc time in from api to local time.

Which visualization will you be using?

Sorry about that. I logged in through GitHub on one and didn’t on my phone on the other. Haha

1 Like

Im using a time series graph.

1 Like

If you want to get the local time I would go with apache echart plugin

1 Like

Not sure if this is right, but do I make the appropriate offset in the map of the series like such?

data: sData.map((d, i) => [new Date(sTime[i]).setHours(new Date(sTime[i]).getHours() - 5), d.toFixed(2)]),

That could be problematic if dayvlight savings time is a thing in your area

Also check this out

So I think i figured it out. I actually just needed to update the datasource params to include a “hourlyStart” reference and use the ${__from:date}. The issue with Apple’s Weatherkit is regardless of the timezone I pass in, they will default to return data from 00:00:00Z instead of the time i requested based on the timezone (America/New_York). So I pass in hourlyStart param with grafana’s dashboard variable and it updates the api call to start at the time grafana has for the data request. Thanks so much for helping.

1 Like