New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getTimeZoneOffset callback passes inconsistent value type #13042
Comments
On this occasion, maybe also the return type of the function should be documented correctly: It should be |
Thanks for reporting @mediafreakch FYI @TorsteinHonsi, @bre1470 |
Looks like the documentation is incorrect and we will investigate, why it sometimes provide timestamp instead of Date instance. As timezone information is only available on the Date instance and timestamp is always GMT, it makes more sense to have always a Date instance for this callback. |
@bre1470 We use this callback to get around the limitation that timezones are only supported with Moment.js. We use We use the following callback to transform to a highcharts compatible format: export function getTimezoneOffset(timestamp: number | Date): number {
let serverUTCTime: number
if (typeof timestamp === 'object') {
serverUTCTime = timestamp.getTime()
} else {
serverUTCTime = timestamp
}
const stationUnixTime = utcToZonedTime(serverUTCTime, this.timeZone).getTime()
const utcUnixTime = utcToZonedTime(serverUTCTime, 'UTC').getTime()
// for highcharts, we need the reverse-offset: how much does UTC offset from stationTime?
// For Date.UTC(2020, 0, 1) Europe/Zurich it is -01:00
const offsetInMinutes = Math.floor((utcUnixTime - stationUnixTime) / 1000 / 60)
return offsetInMinutes
} An example: https://codesandbox.io/s/morning-thunder-9yw3n |
@mediafreakch |
Expected behaviour
time.getTimezoneOffset
should take a parametertimestamp
that is milliseconds since January 1 1970 according to docsActual behaviour
Effectively
timestamp
is sometimes the number of milliseconds, but also aDate()
object. I think it depends on what kind of "thing" is being transformed (label, axis, value, ...).Live demo with steps to reproduce
https://jsfiddle.net/tw6gujfv/ (observe in console)
Product version
Highcharts JS v8.0.0 (2019-12-10)
Affected browser(s)
all
The text was updated successfully, but these errors were encountered: