|
if (forecastDatesDST.dstChange) { |
|
// processing hourly forecast data for a |
|
// future *starting-DST* day |
|
if ( |
|
forecastDatesDST.dstStart != null && |
|
forecastDatesDST.date === forecastDatesDST.dstStart |
|
) { |
|
json.hourly = Object.fromEntries( |
|
[ ...Object.entries(json.hourly) ] |
|
.map(([ key, data ]) => { |
|
if (key === 'time') { |
|
return [ |
|
key, |
|
data |
|
// to fix off-by-one error in hour labels, need |
|
// to skip the "2am" slot on a DST-start day; |
|
// slide all hour labels, from "3am" onward, |
|
// upward/earlier by one slot; the hours will |
|
// thus be: "00:00", "01:00", "03:00", ... |
|
// "23:00", "23:00" |
|
.map((v, idx) => ( |
|
(idx >= 2 && idx < (data.length - 1)) ? |
|
data[idx + 1] : |
|
v |
|
)) |
|
|
|
// drop the last hour label (duplicated "23:00") |
|
.slice(0, -1) |
|
] |
|
} |
|
else { |
|
// only need 23 data entries on a DST-start day, |
|
// since "2am" is skipped |
|
return [ key, data.slice(0, -1) ] |
|
} |
|
}) |
|
) |
|
} |
|
// processing hourly forecast data beyond a |
|
// future *starting-DST* day |
|
else if ( |
|
forecastDatesDST.dstStart != null && |
|
forecastDatesDST.date > forecastDatesDST.dstStart |
|
) { |
|
json.hourly = Object.fromEntries( |
|
[ ...Object.entries(json.hourly) ] |
|
.map(([ key, data ]) => { |
|
if (key === 'time') { |
|
return [ |
|
key, |
|
Array.from({ length: 24 }) |
|
// to fix off-by-one error in all data entries, |
|
// slide them all upward/earlier by one slot; the |
|
// hours will thus be: "23:00" (day before), "00:00" |
|
// (day of), "01:00", ... "22:00" |
|
.map((v, idx) => data[idx + 24]) |
|
] |
|
} |
|
else { |
|
// to fix off-by-one error, get 24 entries |
|
// from "23:00" the day before, to (and including) |
|
// "22:00" on the date in question |
|
return [ key, data.slice(-25, -1) ] |
|
} |
|
}) |
|
) |
|
} |
|
// processing hourly forecast data for a |
|
// future *ending-DST* day |
|
else if ( |
|
forecastDatesDST.dstEnd != null && |
|
forecastDatesDST.date === forecastDatesDST.dstEnd |
|
) { |
|
json.hourly = Object.fromEntries( |
|
[ ...Object.entries(json.hourly) ] |
|
.map(([ key, data ]) => { |
|
if (key === 'time') { |
|
return [ |
|
key, |
|
data |
|
// to fix off-by-one error in hour labels, need |
|
// to repeat the "1am" slot on a DST-end day; |
|
// slide all hour labels, from "1am" onward, |
|
// downward/later by one slot; the hours will |
|
// thus be: "00:00", "01:00", "01:00", "02:00", |
|
// ... "23:00" |
|
.slice(0, 25) |
|
.reverse() |
|
.map((v, idx) => ( |
|
(idx < 23) ? |
|
data[24 - (idx + 1)] : |
|
v |
|
)) |
|
.reverse() |
|
] |
|
} |
|
else { |
|
// actually need 25 data entries on a DST-end day, |
|
// since "1am" is repeated |
|
return [ key, data.slice(0, 25) ] |
|
} |
|
}) |
|
) |
|
} |
|
// processing hourly forecast data beyond a |
|
// future *ending-DST* day |
|
else if ( |
|
forecastDatesDST.dstEnd != null && |
|
forecastDatesDST.date > forecastDatesDST.dstEnd |
|
) { |
|
json.hourly = Object.fromEntries( |
|
[ ...Object.entries(json.hourly) ] |
|
.map(([ key, data ]) => { |
|
if (key === 'time') { |
|
return [ |
|
key, |
|
Array.from({ length: 24 }) |
|
// to fix off-by-one error in hour labels, |
|
// slide them downward/later by one slot; the |
|
// hours will thus be: "01:00", "02:00", ... |
|
// "23:00", "00:00" (day after) |
|
.map((v, idx) => data[24 - (idx + 1)]) |
|
.reverse() |
|
] |
|
} |
|
else { |
|
// to fix off-by-one error, get 24 entries |
|
// from "01:00" on the date in question, to (and |
|
// including) "00:00" on the next day |
|
return [ key, data.slice(1, 25) ] |
|
} |
|
}) |
|
) |
|
} |
|
} |