week number in smart client

Questions, tips and tricks and techniques for scripting in Servoy

week number in smart client

Postby Hans Nieuwenhuis » Mon Dec 05, 2011 9:59 am

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,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: week number in smart client

Postby Bonkie » Mon Dec 05, 2011 10:28 am

You could set the locale using i18n.setLocale() function.
Rick Bonkestoter
Certified Servoy 7 Developer

Direct ICT / ServoyCamp
User avatar
Bonkie
 
Posts: 68
Joined: Wed Jun 27, 2007 11:05 am
Location: Den Ham, The Netherlands

Re: week number in smart client

Postby mboegem » Mon Dec 05, 2011 10:34 am

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
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1531
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: week number in smart client

Postby ROCLASI » Mon Dec 05, 2011 10:44 am

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Twitter: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5342
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: week number in smart client

Postby Hans Nieuwenhuis » Mon Dec 05, 2011 1:03 pm

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);
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 1 guest