Overrride locale dateformat settings

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Overrride locale dateformat settings

Postby juan.cristobo » Tue Sep 23, 2014 11:19 am

Hi all, the locale.dateformat on server is set to 'dd-MM-yyyy', but I like to override this setting for a client. How can I do it? I only see a 'getDefaultDateFormat', method, but not a 'setDateFormat'.

Regards,
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am

Re: Overrride locale dateformat settings

Postby juan.cristobo » Thu Oct 16, 2014 9:31 am

Or is there an alternative? Our american users want to see date fields in us format, but spanish team want to see the fields in spanish format, and I don't know how to do it...
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am

Re: Overrride locale dateformat settings

Postby jcompagner » Thu Oct 23, 2014 9:55 am

problem with the system settings that they are global, they are not client specific (they are in the servoy.properties)

The best thing todo currently is for those fields that need those dateformats, don't depend on the default value but set your value on the field (or columns level) and then use an i1i8n text instead of a direct format string
Then you can add format strings per language/locale
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Overrride locale dateformat settings

Postby Bernd.N » Tue May 10, 2016 9:19 am

We created first a valuelist like this:

d.M.yy 1.1.15|d.M.yy
d.M.yyyy 1.1.2015|d.M.yyyy
dd.MM.yy 31.12.15|dd.MM.yy
dd.MM.yyyy 31.12.2015|dd.MM.yyyy
dd-MM-yyyy 31-12-2015|dd-MM-yyyy
dd/MM/yyyy 31/12/2015|dd/MM/yyyy
MM/dd/yyyy 12/31/2015|MM/dd/yyyy
yyyy-MM-dd 2015-12-31|yyyy-MM-dd

Then every user has a date format field in his settings and user record, where he can choose the format he likes.
On startup, a global variable scopes.person.currentDateFormat_dd_mm_yyyy is set to that field.

In the onShow() of a form where a date is involved, we set the format of each date field like this:

Code: Select all
elements.ps_birthday.format = scopes.person.currentDateFormat_dd_mm_yyyy;


I do not know if there is a more easy method, but for us that works fine.
The only disadvantage is that in table forms, you first see another format for some milliseconds.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: Overrride locale dateformat settings

Postby Harjo » Tue May 10, 2016 9:56 am

Even a better idea is to loop over all your forms with solution Model find your datefields, and change them accordingly.
That is very fast, and no worry of doing it in onShow on every form.
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Overrride locale dateformat settings

Postby Bernd.N » Tue May 10, 2016 11:03 am

As far as I remember, we need to call that line always in onShow(), so we can not put it in an
if (firstShow)
because the date format used to switch back when we did it only in firstShow.

But in case the looping with solutionModel works fine and that problem will not appear, it would be even better.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: Overrride locale dateformat settings

Postby paronne » Tue May 10, 2016 11:19 am

Harjo wrote:Even a better idea is to loop over all your forms with solution Model find your datefields, and change them accordingly.
That is very fast, and no worry of doing it in onShow on every form.


Harjo you mean to do that at the onSolutionOpen ? the solution suggested by Johan has less overhead since there is no need to iterate over all forms/elements at startup.
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: Overrride locale dateformat settings

Postby Harjo » Tue May 10, 2016 2:54 pm

jcompagner wrote:problem with the system settings that they are global, they are not client specific (they are in the servoy.properties)

The best thing todo currently is for those fields that need those dateformats, don't depend on the default value but set your value on the field (or columns level) and then use an i1i8n text instead of a direct format string
Then you can add format strings per language/locale


Hi Johan,

can you give an example? I'm not sure how you do that exactly
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Overrride locale dateformat settings

Postby paronne » Tue May 10, 2016 3:21 pm

You can add an i18n key called mykeys.settings.dateformat with value "dd-MM-yyyy". On the format property of the field (or of the database column) you can then use i18n:mykeys.settings.dateformat. The format expression will then be evaluated as an i18n. So depending on your locale the i18n key for the dateformat may have a different value, therefore a different format is applied to the field.
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: Overrride locale dateformat settings

Postby Harjo » Tue May 10, 2016 3:34 pm

ah oke... thanks.
never knew that! :)
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Overrride locale dateformat settings

Postby Bernd.N » Tue May 10, 2016 3:43 pm

May I add that language preference and date format preference of a single user is not necessary a one-to-one relation.
I have seen users who even prefer the ISO-8601-date format YYYY-MM-DD (like today 2016-05-10).

By decoupling the date format from the language, and by giving all users the ability to choose whatever they want in their UI, the users get maximum personal freedom for the date format.

Of course, the date format that will be printed on invoices etc. is another story, that is more specific to the company itself, but could be managed in a similar way.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: Overrride locale dateformat settings

Postby steve1376656734 » Wed May 11, 2016 11:17 am

One way of achieving the decoupling of the date format from the language and using the user preference suggested by Bernd but also keeping the efficiency of using an i18n string suggested by Johan would be to use the following in your solution startup (before any forms have loaded):

Code: Select all
   if(scopes.person.currentDateFormat_dd_mm_yyyy)
      i18n.setI18NMessage('mykeys.settings.dateformat',  scopes.person.currentDateFormat_dd_mm_yyyy);

In this manner if the user has selected a personalised format then that will be used otherwise the default for their locale will be used.

Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK


Return to Programming with Servoy

Who is online

Users browsing this forum: Manolo_Etec and 13 guests