Skip to content
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

How to work/add support with different time zones #781

Closed
kamilkazmierczak opened this issue Jul 4, 2021 · 6 comments · Fixed by #876
Closed

How to work/add support with different time zones #781

kamilkazmierczak opened this issue Jul 4, 2021 · 6 comments · Fixed by #876
Assignees
Labels
documentation Improvements or additions to the documentation
Milestone

Comments

@kamilkazmierczak
Copy link

Lightweight Charts Version: 3.3.0

Steps/code to reproduce:
Visit https://jsfiddle.net/b5v8L9et/

Actual behavior:
Day TickMark is displayed at 2:00 instead of 0:00

Expected behavior:
Allow to configure chart to display tickmark in position valid for specific locale - at 0:00 for day, month, year

Screenshots:
obraz

CodeSandbox/JSFiddle/etc link:
https://jsfiddle.net/b5v8L9et/

I provided custom tickMarkFormatter (and timeFormatter for easier readability) but there is no way to customize where specific tickMark should be displayed

@timocov timocov added the bug Unexpected problem or unintended behavior. label Jul 7, 2021
@timocov timocov added this to the 4.0 milestone Jul 7, 2021
@timocov
Copy link
Contributor

timocov commented Jul 7, 2021

As workaround you can try to "fix" the dates you provide in the data by adding timezone offset.

@maxbethke
Copy link

maxbethke commented Jul 15, 2021

I had the same problem. This is my workaround for it, incase anyone is feeling lazy:

chart.applyOptions({
    timeScale: {
        tickMarkFormatter: (time, tickMarkType) => {
            time = this.getTimezoneCorrectedTime(time)
            [...]
        }
    }
})
   

getTimezoneCorrectedTime(utcTime, returnAsUnixTimestamp = false) {
    if(utcTime instanceof Date) {
        utcTime = utcTime.getTime()/1000
    }

    const timezoneOffsetMinutes = new Date().getTimezoneOffset()
    const correctedTime = utcTime+(timezoneOffsetMinutes*60)

    if(returnAsUnixTimestamp) return correctedTime

    return new Date(correctedTime*1000)
}

@timocov timocov modified the milestones: 4.0, 3.7 Oct 5, 2021
@timocov timocov self-assigned this Oct 11, 2021
timocov added a commit that referenced this issue Oct 28, 2021
@timocov timocov added documentation Improvements or additions to the documentation and removed bug Unexpected problem or unintended behavior. labels Oct 28, 2021
@timocov timocov changed the title Invalid TickMark position due to TickMarkType designed for UTC How to work/add support with different time zones Nov 3, 2021
@timocov
Copy link
Contributor

timocov commented Nov 3, 2021

Please see https://github.com/tradingview/lightweight-charts/blob/7104e9a4fb399f18db7a2868a91b3246014c4324/docs/time-zones.md

@ChrisWphoto

This comment has been minimized.

@timocov

This comment has been minimized.

@ChrisWphoto

This comment has been minimized.

@tradingview tradingview locked as off-topic and limited conversation to collaborators Nov 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants