Unexpected results when using first day of the week based on locale
Hi, I've created a sample project configured with First day of week set to Default based on locale in project settings. Then I have this demo_user account setup with Language is Dutch, Netherlands. I have the following function created in a microflow: parseInteger(formatDateTime($Test/EndDate,'w')). When $Test/EndDate is filled with 09-07-2017 00:00, I get the week nr 28. I would expect this to be 27, because of the locale language settings. When changing the First day of week to Monday, I get the expected result 27. What did I miss? Edit: The microflow above is called on click of a button. The microflow is executed in the context of a user with a language setting and timezone. This means all timezone operations performed for this user on the server are defined by the users timezone setting, for example when a Microflow formats a DateTime value as a String to get the current hour of the day, see section What is the purpose of setting a time zone for a user? https://docs.mendix.com/refguide6/datetime-handling-faq#what-is-datetime-in-terms-of-computer-programs-must-read. If the microflow is executed in the system context, then you would require something like the ParseDateTimeWithTimezone from the Community Commons module. In this scenario you do not know the timezone setting, and for timezone operations you would need to add the timezone as a parameter. However in the scenario described above you would need a different java action (i.e. FormatDateTimeWithTimezone) to convert the datetime to string, instead of the ParseDateTimeWithTimezone which does the other way around. The documentation about the First day of the week option in project settings says that this setting determines the first day of the week in the date picker widget. It does not only affect the date picker widget, as it also changes the output of the formatDateTime function in a microflow. See section First day of the week: https://docs.mendix.com/refguide6/project-settings#first-day-of-the-week Edit2: One more thing:) In the sample project I have my demo_user account configured with Language is English, United States. The First day of week is set to Monday in project settings. Then when I create a microflow with an StartDate having filled with [%BeginOfCurrentWeek%], the output is 7/3/2017, 12:00 AM. Which is expected if Monday is First day of the week. However if you display the StartDate in the datetime picker widget, you see a calendar showing Sunday as first day of the week. I expect to see Monday as first day of the week. Then if you change the language to English, United Kingdom, then you will find that datetime picker shows Monday as first day of the week. And this is expected. I do not understand why changing the language to English, United States has impact on the datetime picker widget, while I expect this to be configured by First day of the week option.
I run into issues with TImeZone formatting constantly. One of the things to keep in mind is that Mendix uses java Instant to represent time - https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html. This has the implication that any attribute/variables of type DateTime have no TimeZone information attached to it.
Whenever you show the DateTime it will be rendered in the timezone of the current context.
If this context is a page that is shown to a user then he will see the time Instant formatted based on his local timezone/UTC /depending on the attribute properties).
If the context is a microflow then the Instant will be handled based on the default Server timezone (not the user timezone).
In order to solve this you can either -
1. use UTC (non localized time) for EndDate
2. Correct the timezone based on the current user default timezone
You will need to use some java magic for this. ParseDateTimeWithTimezone from the CommunityCommons might be a good place to start.
On the basis of this information I have created a microflow that created a full year with weeknumbers, day of the week etc. based on the ISO standard. I use the result to determine what week 20 is etc. Mail me if you want the microflows to create year, months and days.