Giter Club home page Giter Club logo

demo-app-weatheround's People

Contributors

getify avatar heapwolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

porushmarwaha

demo-app-weatheround's Issues

Remaining DST bugs

I did significant work to fix some DST bugs related to forecast data (daily -- sunrise/sunset, as well as hourly). The root of the problem is the weather API doesn't return forecast data with DST awareness. The API server itself switches to DST whenever according to its physical/logical location, but doesn't respect the DST status of any locations it's providing future forecast data for. This causes various off-by-one-hours.

Though most of the bugs were fixed, unfortunately, some DST bugs still remain. I think they're related to the specific DST-change day, not the subsequent days.

In particular, it seems like if you have selected the config to display/format times in your own timezone (instead of remote timezone), AND you look at a location in a different timezone from your own, AND it's the DST-change day... the logic currently used for fixing the hour timezone labels is bad. THAT logic is here:

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) ]
}
})
)
}
}

That logic makes the assumption for DST-change days that it needs to slide the hourly labels by 1 (upward or downward). But the amount it needs to slide (and pull from the previous or next days) is likely not 1 but needs to include the delta between your local timezone offset and the target timezone offset.

Likely to be very tricky logic here. Ugh.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.