Page 1 of 1

week number in smart client

PostPosted: Mon Dec 05, 2011 9:59 am
by Hans Nieuwenhuis
Hi,

The weeknumber returned by
Code: Select all
parseInt(utils.dateFormat(new Date(), 'w'))
returns 49 when the locale is Dutch and 50 when the locale is English(Us).
I wunder if it is possible ( in a method ) to get the dutch week number, even if the locale settings of the (smart) client is set to the wrong value (english for instance).

Regards,

Re: week number in smart client

PostPosted: Mon Dec 05, 2011 10:28 am
by Bonkie
You could set the locale using i18n.setLocale() function.

Re: week number in smart client

PostPosted: Mon Dec 05, 2011 10:34 am
by mboegem
Hi Hans,

this difference is caused by 'firstDayOfWeek'.
Dutch is using monday where US is using sunday...

As Rick mentioned, you could set the local just temporary to the one you want.
Another option is using the dateutils plugin of servoy-plugins.de (free plugin)
There you can set what the first day of week is and use the 'dateFormat' function of the plugin.

Hope this helps

Re: week number in smart client

PostPosted: Mon Dec 05, 2011 10:44 am
by ROCLASI
And if you don't want to (or can't) install a plugin you can always take a look at the excellent mod_datejs module (based on Date.js) from Greg Pierce.

Hope this helps.

Re: week number in smart client

PostPosted: Mon Dec 05, 2011 1:03 pm
by Hans Nieuwenhuis
Thanks guys,

This seems to work without any plugin or module

Code: Select all
//get current locale settings   
var coun = i18n.getCurrentCountry();
var lang = i18n.getCurrentLanguage();
//set locale to nl
i18n.setLocale('nl','NL');
//get weekno
weekno = parseInt(utils.dateFormat(new Date(), 'w'));
//set locale back to previous value
i18n.setLocale(lang,coun);