KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Wrong locale for DateRangePicker - offset #1913

Open MarkoS opened this topic on on Feb 19 - 5 comments

MarkoS commented on Feb 19

Hi there,

I am facing some strange date offset on DateRangePicker for my local time zone (Europe/Sarajevo). What does happen for me and with example below is that default date is changing in the middle of the morning. For example, at 08:00 AM shows date 2021-02-15 (date from yesterday) and at 09:00 AM switch to 2021-02-16 (actual date). I believe that there is default time zone set to different region. If I print date('now') with PHP, it shows correct time for Sarajevo.

I did check DateRangePicker.php library and on the line 144: "locale"=>$this->locale, defines locale. But I did not find where is default value. I am not sure if "locale"=>"bs", is correct way for setting it.

Sample code:

        <?php
                            DateRangePicker::create(array(
                                "name"=>"dateRange",
                                "language"=>"hr",
                                "locale"=>"bs",
                                "format"=>"YYYY-MM-DD",
                                "ranges"=>array(
                                    "Danas"=>DateRangePicker::today(),
                                    "Jučer"=>DateRangePicker::yesterday(),
                                    "Zadnjih 7 dana"=>DateRangePicker::last7days(),
                                    "Zadnjih 30 dana"=>DateRangePicker::last30days(),
                                    "Ovaj mjesec"=>DateRangePicker::thisMonth(),
                                    "Prošli mjesec"=>DateRangePicker::lastMonth(),
                                ),
                            ))
       ?>

Can someone help me with this?

Thx

KoolReport commented on Feb 21

So it happened on 02-15 or it still happens today

Eugene commented on Feb 21

Check your server timezone.

MarkoS commented on Feb 23

Hi thanks for reply, my server time zone is correct, shows correct time and date when printed using new Date('now)

I can't figure out why it's switching date at certain time and only on date picker.

Update:

           <div style="margin-left: 15px; font-size: 9px">
                <?php
                    date_default_timezone_set('Europe/Sarajevo');
                    if (date_default_timezone_get()) {
                        echo 'Show timezone: ' . date_default_timezone_get() . '<br />';
                    }
                    ?>
                </div>

It was set to America/Los Angeles. Which is totally strange.

MarkoS commented on Feb 24

I have found that echo date('Y-m-d'); will show correct date, and Koolreport Date Range picker will get wrong one from day before and switch to correct one at 8-9 AM. Please check attached image. On the left had side is report "K3" and on the right side is report "K1". There is no difference in PHP setup function or view itself.

On the right side you can see echo date which is 2021-2-24 and Date picker picks 23.02.2021 with "Yesterday" as default value.

My view code for date picker:

                       <?php
                            DateRangePicker::create(array(
                                "name"=>"dateRange",
                                "language"=>"hr",
                                "locale"=>"hr",
                                "format"=>"YYYY-MM-DD",
                                "ranges"=>array(
                                    "Danas"=>DateRangePicker::today(),
                                    "Jučer"=>DateRangePicker::yesterday(),
                                    "Zadnjih 7 dana"=>DateRangePicker::last7days(),
                                    "Zadnjih 30 dana"=>DateRangePicker::last30days(),
                                    "Ovaj mjesec"=>DateRangePicker::thisMonth(),
                                    "Prošli mjesec"=>DateRangePicker::lastMonth(),
                                ),
                            ))
                            ?>

Eugene commented on Feb 24

What do you see in the date section of phpinfo() ?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Inputs