Custom timezone

Hello, platform, long time no see.

Is there a simple way to change timezone shift values for the system? My customer wants to see Moscow time as +0, but not as +3 GMT. Corresponding timezone shifts should be recounted respectively, so we should see [+/-]<...> Moscow Time. There is no strict demands about whether it should be only displayed timeshift, or persistent. I thought about using a custom datatype, but stuck on inventing an algorithm of recounting timezone, so I’m asking you here for some help or giving me a direction - where to search for a solution. Thanks in advance.

P.S. Not to say it’s extremely exotic request, because as we install any Debian-like OS, it always shows current user timezone as +0 (swtchable to GMT, UTC, CET and others)

Hi,
As I see, logic of timezone name formatting is concentrated in the com.haulmont.cuba.core.global.TimeZones global Spring bean.

You need to override this bean in your project and implement your own formatting logic as you like.

Can you, please, provide some more information about the way of doing this? where to create my new implementation (my guess is package com.company.app.core) and how to register it, will this (spring.xml <bean name="cuba_TimeZones" class="com.company.app.core.CustomTimeZones" />) be enough? do i need to implement all methods of the overridden bean, or can i simply extend it?

Hi,
Bean extension described in the manual: Extending Business Logic - CUBA Platform. Developer’s Manual

You need to register extending bean in the web module’s spring.xml.

You need to extend the bean class because TimeZones doesn’t have API interface, it is used directly in other beans.

1 Like

Thanks for your answer, but not in web module. In core module. It took some time and a ClassNotFoundException to figure it out. Anyway, i’m doing something wrong: i extend the TimeZones, add any string to returned String of getDisplayOffset(TimeZone);, like return super.getDizplayOffset(timeZone) + "test"; and see nothing happen in my application, it shows my timezone as MSK (GMT+03:00)

Well,

TimeZones bean is defined in cuba-global module. This means that it is instantiated twice: one instance in core module, another - in web module.
But all usages of TimeZones in CUBA code are located in gui and web modules, so it is OK to forget about core module.

So you need to create extended bean in web module, and register it in the web module’s spring.xml.

1 Like

Thank you so much