trading-vue-js icon indicating copy to clipboard operation
trading-vue-js copied to clipboard

Botbar displaying hours instead of the day when timeframe is day, using timezone

Open adsonvinicius opened this issue 4 years ago • 9 comments

Botbar displays the candle's time as hours when the timezone is set and time frame is day:

image

I could see there's a condition on botbar.js at format_date function, enabling timezones only for tf less than a day

    format_date(p) {
        let t = p[1][0]
        t = this.grid_0.ti_map.i2t(t)
        let ti = this.$p.layout.grids[0].ti_map.tf
        // Enable timezones only for tf < 1D
        let k = ti < DAY ? 1 : 0
        let tZ = t + k * this.$p.timezone * HOUR
        //t += new Date(t).getTimezoneOffset() * MINUTE
        let d = new Date(tZ)
        if (p[2] === YEAR || Utils.year_start(t) === t) {
            return d.getUTCFullYear()
        }
        if (p[2] === MONTH || Utils.month_start(t) === t) {
            return MONTHMAP[d.getUTCMonth()]
        }
        // TODO(*) see grid_maker.js
        if (Utils.day_start(tZ) === tZ) return d.getUTCDate()
        let h = Utils.add_zero(d.getUTCHours())
        let m = Utils.add_zero(d.getUTCMinutes())
        return h + ":" + m
    }

But when a timeframe is set (in my case -3) the bot bar shows 03:00, which probably is not considered on this algorithm when Utils.day_start(tZ) is not equal to tZ, once the function to get the first day considering the tZ passed as UTC time, which is not the case.

So, Is this an easy fix to do just enabling timezones for tf also greater than 1D?

adsonvinicius avatar Nov 14 '20 03:11 adsonvinicius

Man, your template is not complete. Add the data.

C451 avatar Nov 14 '20 07:11 C451

I created a tvjs template to let more easy but then I figure out the problem is not related to the timezone itself, but another problem I'm struggling for a long time that I thought it would be solved with the timezone prop which is the real-time candles.

The timezone is not considered when chat.update (price, volume) is called so the new candle is always using UTC time. To workaround this I had to put all my candles timestamps 3 hours ahead and set timezone -3, which works but creates the issue mentioned above.

adsonvinicius avatar Nov 14 '20 16:11 adsonvinicius

Oh yeah, I was going to check that. You see, this lib was created with crypto markets in mind, so all the features for the traditional markets are delayed.

C451 avatar Nov 14 '20 17:11 C451

I was trying to reproduce the behavior on tvjs, but I think it doesn't need anymore. Some time ago I said about consider the utils.Now() as current browser time and it worked (but I wasn't sure about consequences), so I gave up about this idea because the new timezone prop solved this, but when I started to deal with daily candle's this came up.

adsonvinicius avatar Nov 14 '20 17:11 adsonvinicius

The main problem is that the samplers do not support non-UTC candle closes (including different exchange closing times, unequal month lengths etc), so as I mentioned I need to spend some time thinking about it.

C451 avatar Nov 14 '20 17:11 C451

Does format_date(p) just return a formatted text of timestamp to show on bottom bar? So we can easy patch it ? Even more we can output our locale language format?

obxyann avatar Mar 18 '21 08:03 obxyann

I think is no that easy because some operations use the display text to find prices for instance. So it would be different the candles timestamp from the botbar text.

On Thu, 18 Mar 2021 at 05:07 obxyann @.***> wrote:

Does format_date(p) just return a formatted text of timestamp to show on bottom bar? So we can easy patch it ? Even more we can output our locale language format?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tvjsx/trading-vue-js/issues/158#issuecomment-801718604, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRAKWZ4KF7EURHWI7HCGGLTEGYCTANCNFSM4TVJOKIQ .

-- Atenciosamente,

Adson Damasceno

adsonvinicius avatar Mar 18 '21 12:03 adsonvinicius

Hello adson , did you find any solution for this, the library is using UTC , but we need our local TZ

arul67800 avatar Jul 08 '21 20:07 arul67800

Hi Arul, I was using the code-change I mentioned above but as the author said it was a little bit more complicated so I was waiting for an improvement. However the library is not updated as before anymore, so I would recommend you to try what I did.

On Thu, Jul 8, 2021 at 5:33 PM Arul @.***> wrote:

Hello adson , did you find any solution for this, the library is using UTC , but we need our local TZ

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tvjsx/trading-vue-js/issues/158#issuecomment-876727987, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRAKW76TUHZ4RJWSP2EAADTWYDTBANCNFSM4TVJOKIQ .

-- Atenciosamente,

Adson Damasceno

adsonvinicius avatar Jul 08 '21 21:07 adsonvinicius