[%BeginOfCurrentWeek%] on a Sunday behavior

0
It’s my understanding that [%BeginOfCurrentWeek%] returns the Monday of the current week, which is fine. If I need to report thinigs Sunday to Sunday, I can just use some date functions.   My problem is that on a Sunday, you would expect [%BeginOfCurrentWeek%] to return the Monday from 6 days previous. it doesn’t it returns the next monday (tommorrow). I assume this is because mendix recognized that technically weeks start on a Sunday and that if [%BeginOfCurrentWeek%] is to return the first Monday of a week, then running [%BeginOfCurrentWeek%] on a Sunday which technically return one day in the future. However this is truly madening. If I want to have some kind of validation for a report that someone is filling out and I want to make sure they can only fill out a date for the current week I should just have to write a check such as:   $Form/FormDate >= [%BeginOfCurrentWeek%]   However if I fill out a form on a sunday, let’s say 9/12, because this Begin system variable is 9/13 the expression checks if the current sunday date 9/12 is greater than or equal to 9/13. So no one can fill out a form on a SUNDAY! I have to do some crazy check to see if the current date is a Sunday, and if so, subtract one week from [%BeginOfCurrentWeek%].   Are there are plans on fixing this? It seems absurd to me that it’s possible for [%BeginOfCurrentWeek%] to return a future 
asked
2 answers
1

DateTime, always a pain in the @$$

When testing on my machine,  [%BeginOfCurrentWeek%] returns Sunday, 12:00 AM

if…. 

  1. DateTime Attribute = not localized
  2. Use [%BeginOfCurrentWeekUTC%] 

    OR

 

  1. DateTime Attribute = localized
  2. Use [%BeginOfCurrentWeek%] 

 

But returns Saturday 10PM if

  1. DateTime attribute is = not localized
  2. Use [%BeginOfCurrentWeek%]

 

Returns Sunday 2:00 AM if

  1. DateTimeAttribute is localized
  2. Use [%BeginOfCurrentWeekUTC%]

 

Long story short; [%BeginOfCurrentWeek%] is returning sunday. BUT you have to be aware of localization. My test was executed time zone CEST, which is UTC +2. As you are located in the US, it will be UTC-A lot of hours.

Advise; if time difference over locations where the app is used isn’t important (which is in most cases the case) then don’t localize your DateTime attributes (unfortunately localizing is the default) and use ….UTC variables and functions

If you still end up with Mondays, then I’m quite curious to get more details of how you implemented this, to help you out

answered
0

There must be something why you get the next Monday instead of previous one. 

Instead of using the system variable [%BeginOfCurrentWeek%], you could use this function instead, which bring you more control

Create a integer variable $Day, with value: parseInteger(formatDateTimeUTC([%CurrentDateTime%], 'u'))

Create a DateTime variable $Date, with value: addDaysUTC([%BeginOfCurrentDayUTC%],-$Day)

If this also returns a Monday, then its a combination of Server, app and User DateTime settings

answered