primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Calendar: UTC/time zone support

Open inad9300 opened this issue 2 years ago • 13 comments

Describe the feature you would like to see added

Right now, dates typed in a calendar's input box seem to be interpreted as local times. However, this is not always what's desirable. In my case, I would like to be able to type a UTC date and have it be interpreted as a UTC date, rather than local time.

inad9300 avatar Mar 03 '23 16:03 inad9300

Similar to: https://github.com/primefaces/primereact/issues/4076

melloware avatar Mar 03 '23 16:03 melloware

Yeah, absolutely; sorry, I looked for "timezone" and didn't find anything related. In fact, your comment on the linked issue is quite on point... I'm rather certain now that this was a logical mistake on my side. Thanks for your help, and apologies for the noise!

inad9300 avatar Mar 03 '23 16:03 inad9300

OK I am going to close that other ticket too.

melloware avatar Mar 03 '23 16:03 melloware

Wait, my bad... Damn, dates are tricky. An easy way to see the problem is: the initial time used by the calendar corresponds to the local time of the machine that opens it. More generally, the representation of the value both in the selection elements and in the input box is as local time.

The representation in the input box is in fact configurable by the prop formatDateTime. However, the representation in the selection elements is not and shows only local time. That's what's missing.

inad9300 avatar Mar 03 '23 17:03 inad9300

Can you check this: https://github.com/primefaces/primereact/issues/3381

I thought it allowed you to set both...

melloware avatar Mar 03 '23 17:03 melloware

The time picker does not take this into account, see for instance https://github.com/primefaces/primereact/blob/master/components/lib/calendar/Calendar.js#L2926, where Date.prototype.getHours() is used, which (emphasis mine)

returns the hour for the specified date, according to local time

inad9300 avatar Mar 03 '23 17:03 inad9300

OK there are 11 spots in the code using new Date() that probably need to check the "locale" if set else you will just get the Browser date time.

melloware avatar Mar 03 '23 20:03 melloware

Note that there currently isn't a "time zone" setting in the "locale". Which I think makes sense, since there are many "locales" with more than one time zone. It probably should be a separate setting.

inad9300 avatar Mar 06 '23 07:03 inad9300

probably needs a timezone property itself that defaults to the browser timezone if not set?

melloware avatar Mar 06 '23 13:03 melloware

Any progress on this front? It's a rather fundamental feature for a date picker, I would say.

inad9300 avatar Oct 18 '23 07:10 inad9300

I was looking it has not been implemented in PrimeVue yet either. Maybe we have to be pioneers and be the first of the libs to implement this.

melloware avatar Oct 18 '23 12:10 melloware

Fullcalendar has it already implemented, I think that could be a good starter point to see how they are handling the TZ feature there.

softwarega avatar May 21 '25 13:05 softwarega

Any progress on this? It will be really helpful to be able to pass timezone to calendar.

ImmortalRabbit avatar Jun 17 '25 08:06 ImmortalRabbit

Is there any update for the setting the timezone for the selecting value or it should be same timezone as the browser's timezone!?

VR4CHeet avatar Oct 09 '25 12:10 VR4CHeet