How could we set globally in Sencha ExtJS version 6.0.2 the timezone that we want to use?

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

Our goal is to set the timezone on the frontend part to display the dates/times on the timezone that we desire and also get the dates generated from datefields, timefields etc. to be on the same timezone but at the end send the correct timestamp to the server.

Setting the timezone globally to a javascript application is not a trivial task according to this: How to initialize javascript date to a particular timezone

The solutions recommend libraries like momentjs, and please correct me if I am wrong, but this is out of the scope and incompatible with sencha extjs. In other words there are too many time conversions in Models and Components handled by sencha extjs that we cannot bypass.

In addition there is an effort to override the core functionality of Date object of javascript language itself found here: https://github.com/pligor/jstimezoner
While the above works for simple cases when integrated with a sencha extjs application the outcome is a disaster and not recommended.

Is there any configuration that we are missing that enables Sencha ExtJS to display and handle times and dates on a timezone of our choice?

Note that we always send/receive a timestamp to/from the server and therefore there is no issue of timezones there.

回答1:

Just like ExtJS doesn't really support internationalization, it doesn't support time zones.

We searched the internet and also stumbled upon MomentJS. But as you found out, you can then start to rewrite nearly everything in ExtJS that handles dates: You need a datetimewzonepicker, a model field of type:'datetimewzone', a datetimewzonecolumn and so on and so forth.

Back then, it seemed too much of an effort and we decided that it would be easier to send the desired client time zone to the server in every request, sending the corresponding datetime back and forth in Y-m-d H:i format, and doing everything else regarding time zones on the server. We regret this decision now, because that way, we have no possibility to calculate on the client side (e.g. cordova app in offline mode).

If you are proficient in ExtJS, writing all these momentdate-handling ExtJS extensions should be not only the clean and extensible, but also the easier way.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!