stephanecollot / DatetimepickerBundle

MIT License
57 stars 58 forks source link

issue with timezones #16

Open evgeny-s opened 9 years ago

evgeny-s commented 9 years ago

So, I pick date for example 15.05.2015, but in controller I got 14.05.2015.

some code:

->add('date', 'collot_datetime', array( 'pickerOptions' =>
                array('format' => 'dd.mm.yyyy',
                    'startDate' => '+0d',
                    'endDate' => '+100d',
                    'autoclose' => true,
                    'language' => 'ru',
                    'minView' => 'month',
                    'maxView' => 'month',
                    'weekStart' => 1,
                ),
                    'attr' => array('class' => 'form-control', 'autocomplete' => "off", 'readonly' => 'readonly'),
                'data' => new \DateTime()
                )
            );

My timezone is 'Europe/Moscow'.

Any ideas?

Thank you.

asimonyan commented 9 years ago

I have some problem , too !! How to fix this problem ??

evgeny-s commented 9 years ago

I think, that it's not a problem with this bundle, but with configuration with your server. Check if server configuration is correct.

artemalexpetrov commented 8 years ago

Hi! I had the same problem. It was in ICU(International Components for Unicode) that used by php5-intl extension. You need to update ICU to fix it. http://site.icu-project.org/

kcaporaso commented 8 years ago

Updating, ICU, doesn't seem to fix this issue. I've updated my OSes ICU library and php5-intl as well. On the client if I log the "changeDate" event for the datetimepicker, I'm getting a date -1 day to what I pick in the picker. The picker displays the correct chosen date, the event.date attribute is returning a different date. This varies depending on which "time" of the day I choose. Almost like it's trying to think for me which is not a desired behavior.
Example: I choose Mar 28 2016 12:09 (PM), I get client event.date = Wed Apr 27 2016 21:09:00 GMT-0400 (EDT).

Here's my datepicker init and event capture code, please let me know if there's a work around or if I have configured something incorrectly.

$('#id_for_date_picker').datetimepicker(
                {
                    format: 'yyyy-mm-dd hh:ii',
                    autoclose: true,
                    todayBtn: true,
                    viewSelect: 'day',
                    minView: 'day'
                }
            ).on('changeDate', function(event) {
                    console.log(event.date);
            })

Thanks for any insight.

erne-mt commented 8 years ago

Any news or advice on this?

I think I have a similar issue with this:

In the picker I choose 09:00 the object is set to 07:00:00, so GMT+2 is ignored, although php is correctly configured (date() shows the actual date).

Further: despite the format, it seems to be the case, that the meridian is set? because i always get an invalid formField, if I pick a time after 12:00.

kcaporaso commented 8 years ago

@erne-mt , this remained an issue for me so I had to come up with a work around. I was able to just grab the value of the datetimepicker document element and that had the correct date, time and meridian, in my case something like: 2016-09-22 2:00 PM

So, this works for me:

$('#id_for_date_picker').datetimepicker({
            format: 'yyyy-mm-dd HH:ii P',
            showMeridian: true,
            autoclose: true,
            todayBtn: true,
            minView: 'hour',
            minuteStep: 10
  }).on('changeDate', function(ev) {
         // this date looks wrong on return.
         //console.log('changeDate', ev.date);
});
....
// however, this date is correct:
$('#id_for_date_picker').val();

See if that works for you on the client-side.

If you're using this in a Form and need to get the correct timezone in say your Controller, I had to actually force the timezone. I'm not sure what the bigger issue is, but this corrected it, and I haven't had time to dive deep.

// create TZ from php.ini setting - which should already happen, but something's amiss.
$tz = new \DateTimeZone(ini_get('date.timezone'));
// datetime picker in the form
$object->getDatePickerField()->setTimezone($tz);

Maybe this will help you.

erne-mt commented 7 years ago

@kcaporaso thank you for your reply.

This somewhat helped. At least I am getting the correct timezone now, client-side and in object.

But I still have the problem that the datefield will not accept a 24h format, e.g. 1400h is an invalid field.

Any thoughts on that?