svyDateUtils week notations

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

svyDateUtils week notations

Postby jdbruijn » Fri Jul 09, 2021 2:41 pm

I am having an issue with the dateutils, with regards to the week calculations.
Which locale is this module using? Is this only dependent on the server locale or also on the client pc locale?
To me, it looks like it solely depents on the server locale.
I have a test server that is giving me unexpected results for the following code:
var dt = new scopes.svyDateUtils.DateTime();'Date: '+dt.toStartOfDay().toFirstDayOfWeek().addWeeks(-1).date.toISOString()+
' Week: '+scopes.svyDateUtils.getWeekOfYear(;
When I run this locally on my laptop in developer I get:
Date: 2021-06-27T22:00:00.000Z Week: 26

But on this test server I get:
Date: 2021-06-19T22:00:00.000Z Week: 25

The region settings of this server look the same as on my laptop:
Country or Region: Netherlands
Regional format: Dutch
Timezone: (UTC+01:00) Amsterdam

These time functions will also be used in API calls so what I would like to do, is to force them all to use the ISO standard which is included in ISO 8601. This system dictates that each week begins on a Monday and is associated with the year that contains that week's Thursday.
Hoewever I don’t think this is supported by svyDateUtils. So I am leaning to modify all java.util.Calendar.getInstance() to java.util.Calendar.getInstance(java.util.Locale.UK)
Or do you have a better suggestion for me?
Jos de Bruijn
Focus Feedback BV
Servoy Certified Developer
Posts: 490
Joined: Sun Apr 11, 2010 6:34 pm

Re: svyDateUtils week notations

Postby paronne » Fri Jul 09, 2021 3:44 pm

Hi Jos,

indeed the locale used for week calculations depends on the Server's locale (i assume you are running NGClient :wink: ).
There is very little support from the svyDateUtils in calculating week's number using different locales.

The only available signature is
Code: Select all
getDayOfWeek(date, useISO8601)

There is nothing for getWeekOfYear(date).
A possible idea can be to use the Time class instead of the Calendar class.
Maybe using the signatures below, since It may offer all the flexibility a solution may require ( e.g. use server defaults, force ISO, !ISO country, use logged user's locale )

getDayOfWeek(date, country, language)
getWeekOfYear(date, country, language)

Code: Select all
function getWeekOfYear(date, country, language) {
   var localDate = java.time.LocalDate.of(date.getFullYear(), date.getMonth() + 1, date.getDate());
   if (country && language) {
      return localDate.get(java.time.temporal.WeekFields.of(new java.util.Locale(country, language)).weekOfWeekBasedYear());
   } else {
      return localDate.get(java.time.temporal.WeekFields.of(java.util.Locale.getDefault()).weekOfWeekBasedYear());

Feel free to push a pull-request in our open source svyDateUtils. Happy to have a look at it.

Posts: 184
Joined: Fri Nov 02, 2012 3:21 pm

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests