07-01-2024 03:16 PM
Hi Everyone,
I need to consume data for december last week and january first week (split week) in a single execution as two different data sets as part of year end. Has anyone come across this scenario?
Kindly let me know for any further information needed.
Thanks in advance.
07-02-2024 06:31 AM - edited 07-02-2024 07:15 AM
If you want to do this using week numbering you need to be prepared for a rabbithole.
Otherwise, finding the dates of a split week in dec/january can be achieved with date calculations.
One sample is provided and attached which could give some inspiration.
As always there could probably be other ways to achieve the same goal.
Assuming weeks start on Mondays (ISO)
Sample output for year 2023 and 2024:
[
{
"year": "2023",
"split_week": true,
"previous_year_first_day_last_week": "2022-12-26T00:00:00.000 UTC",
"previous_year_last_date": "2022-12-31T00:00:00.000 UTC",
"current_year_first_date": "2023-01-01T00:00:00.000 UTC",
"current_year_last_day_first_week": "2023-01-01T00:00:00.000 UTC"
},
{
"year": "2024",
"split_week": false,
"previous_year_first_day_last_week": "2023-12-25T00:00:00.000 UTC",
"previous_year_last_date": "2023-12-31T00:00:00.000 UTC",
"current_year_first_date": "2024-01-01T00:00:00.000 UTC",
"current_year_last_day_first_week": "2024-01-07T00:00:00.000 UTC"
}
]
If the first week of the current year is split between two years (boolean)
The date of the last Monday in previous year
Date.parse($year, "yyyy").minusDays(1).getDay() == 0 ?
Date.parse($year, "yyyy").minusDays(7) :
Date.parse($year,"yyyy").minusDays(Date.parse($year,"yyyy").minusDays(1).getDay())
The date of the last day in last year. (Always 31st of December)
The date of the first day in this year. (Always 1st of January)
The date of the first Sunday of this year. (Last day of the first week)
Date.parse($year, "yyyy").getDay() == 0 ?
Date.parse($year, "yyyy") :
Date.parse($year, "yyyy").plusDays(7 - Date.parse($year, "yyyy").getDay())
07-04-2024 11:16 PM
Hi @endor_force
Thank you for the inputs. This is really helpful.
Sure, will work on the solution based on the inputs provided.