Context: OH 4.1.2 running on Debian 12. In a bash shell the output of date
shows the correct local time. I’ve tried setting the timezone in OH settings to GMT and also leaving it blank in the hope that OH would pick up the OS setting. After setting the timezone to blank I see this in the log:
2024-04-01 11:50:20.916 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone is not set, falling back to the default time zone.
I have a rule that reads electricity unit prices from here. The data is in JSON format and looks like this:
{
"count": 6284,
"next": "https://api.octopus.energy/v1/products/AGILE-23-12-06/electricity-tariffs/E-1R-AGILE-23-12-06-G/standard-unit-rates/?page=2",
"previous": null,
"results": [
{
"value_exc_vat": 14.03,
"value_inc_vat": 14.7315,
"valid_from": "2024-04-01T21:30:00Z",
"valid_to": "2024-04-01T22:00:00Z",
"payment_method": null
},
etc
etc
etc
The times in the JSOC are UTC, at least that’s my understanding of timestamps that end in the Z character.
The rule was working fine until yesterday when the UK moved from GMT to BST. Now, all the unit prices are skew-whiff, shifted by one hour. I use the time.toLocalDateTime method to convert the time in the valid_from element to the local time. Before Sunday the time in the valid_from element was unchanged when converted with toLocalDateTime. After Sunday the in the valid_from element is… still unchanged. Here’s a test rule:
rules.JSRule({
name: 'Test UTC vs local time',
description: 'Test UTC vs local time',
triggers: [triggers.ItemStateChangeTrigger('DEVTEST_SWITCH')],
execute: data => {
var logger = log('DEVTEST')
logger.info('Test UTC from Octopus agile JSON vs localdatetime rule...')
var agileprices = String(items.getItem('OctopusAgilePrices_AgilePricesJSON').state)
var obj = JSON.parse(agileprices)
for (var i = obj.results.length - 1; i >= 0; i--) {
var valid_from = obj.results[i].valid_from;
var valid_from_zdt = time.toZDT(valid_from);
var valid_from_ldt = valid_from_zdt.toLocalDateTime(); //get valid_from as LocalDateTime
logger.info("Index ({}), valid_From time ({}) converted to local date time ({}).", String(i), String(obj.results[i].valid_from), String(valid_from_ldt));
}
}
})
And an excerpt from the output in the log:
11:43:53 Index (5), valid_From time (2024-04-01T19:00:00Z) converted to local date time (2024-04-01T19:00).
11:43:53 Index (4), valid_From time (2024-04-01T19:30:00Z) converted to local date time (2024-04-01T19:30).
11:43:53 Index (3), valid_From time (2024-04-01T20:00:00Z) converted to local date time (2024-04-01T20:00).
11:43:53 Index (2), valid_From time (2024-04-01T20:30:00Z) converted to local date time (2024-04-01T20:30).
11:43:53 Index (1), valid_From time (2024-04-01T21:00:00Z) converted to local date time (2024-04-01T21:00).
11:43:53 Index (0), valid_From time (2024-04-01T21:30:00Z) converted to local date time (2024-04-01T21:30).
What do I need to do to convert the UTC timestamp in the JSON to a localdate time?