This issue is regarding a DateTime issue where a Date, after it is calculated to only contains weekdays, is mismatched by 1 day when the Date is populated to a created record in Published Mode.
1. Store WeekdayDates and PublicHolidayDates between ToDate_Dp and FromDate_Dp
With(
{
// Generate a one-column table of all dates between start date & end date
varDateRange: ForAll(
Sequence(ToDate_Dp.Value - FromDate_Dp.Value + 1),
FromDate_Dp.Value + Value - 1
)
},
//Store Weekday Dates
ClearCollect(
WeekdayDates,
Filter(
varDateRange,
Weekday(Value) in [ 2, 3, 4, 5, 6 ]
)
);
//Store Public Holiday Dates
ClearCollect(
PublicHolidayDates,
Filter(
varDateRange,
Value in Filter( 'Public Holidays', 'Public Holidays (Views)'.'Active Public Holidays' ).Date
)
);
);
- Taking these dates as example:
- 01 Sep 2024 to 08 Sep 2024 (Sun to Sun)
- 04 Sep 2024 (Wed) as dummy Public Holiday.
*Following incorrect behaviours only occurs in Published Mode*
1. Patch() records where _Date Not In PublicHolidayDates (Correct results)
Patch(
'Reservation Details',
ForAll(
Sequence(
DateDiff( FromDate_Dp.Value, ToDate_Dp.Value, TimeUnit.Days ) + 1
),
With(
{
_Date: DateAdd( FromDate_Dp.Value, Value - 1, TimeUnit.Days )
},
If(
Not(_Date in PublicHolidayDates),
{
Date: _Date
}
);
)
)
);
1-Sep - Sun | 2-Sep -Mon | 3-Sep - Tue | 4-Sep - Wed | 5-Sep - Thu | 6-Sep - Fri | 7-Sep - Sat | 8-Sep - Sun | |
Expected ( Created? ) | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes |
Results ( Created? ) | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes |
2. Patch() records where _Date in WeekdaysDates (Incorrect results)
Patch(
'Reservation Details',
ForAll(
Sequence(
DateDiff( FromDate_Dp.Value, ToDate_Dp.Value, TimeUnit.Days ) + 1
),
With(
{
_Date: DateAdd( FromDate_Dp.Value, Value - 1, TimeUnit.Days )
},
If(
(_Date in WeekdayDates),
{
Date: _Date
}
);
)
)
);
1-Sep - Sun | 2-Sep -Mon | 3-Sep - Tue | 4-Sep - Wed | 5-Sep - Thu | 6-Sep - Fri | 7-Sep - Sat | 8-Sep - Sun | |
Expected ( Created? ) | No | Yes | Yes | Yes | Yes | Yes | No | No |
Results ( Created? ) | No | No | Yes | Yes | Yes | Yes | Yes | No |
3. Patch() records where _Date Not In PublicHolidayDates and _Date in WeekdaysDates (Incorrect results)
Patch(
'Reservation Details',
ForAll(
Sequence(
DateDiff( FromDate_Dp.Value, ToDate_Dp.Value, TimeUnit.Days ) + 1
),
With(
{
_Date: DateAdd( FromDate_Dp.Value, Value - 1, TimeUnit.Days )
},
If(
((_Date in WeekdayDates) && Not(_Date in PublicHolidayDates)),
{
Date: _Date
}
);
)
)
);
1-Sep - Sun | 2-Sep -Mon | 3-Sep - Tue | 4-Sep - Wed | 5-Sep - Thu | 6-Sep - Fri | 7-Sep - Sat | 8-Sep - Sun | |
Expected ( Created? ) | No | Yes | Yes | No | Yes | Yes | No | No |
Results ( Created? ) | No | No | Yes | No | Yes | Yes | Yes | No |
I have tested more scenarios, but to keep my question simple, the above 3 scenarios best describe the issue.
Current analysis and findings:
1. Dates populated by WeekdaysDates calculation is 1 day off during Patch()
2. Dates populated by PublicHolidayDates calculation is not affected
3. Issue only occur in Published Mode. In Editing Mode, the results are correct in all scenarios.
Date calculation issues beg the question - did you consider the timezone stored in you date field?
often a +/- 1 day difference tends to come from a date stored with UTC time and the calculation done with local time zone.
Are you storing your date fields as 'date only' with the time zone adjustment set to 'Date Only' or 'Time zone independent'? I'm guessing since you are doing holiday calculations, you don't need the time, so 'Date Only' makes sense to me. Take a look at how you've configured your date fields and you may have your answer there. Unfortunately you can't really change the Time Zone Adjustment once you've set it, so you may have to recreate the field.
WarrenBelz
770
Most Valuable Professional
stampcoin
494
MS.Ragavendar
399