Forum Discussion

sobha353's avatar
sobha353
New Contributor
2 years ago

Year end split week data consumption in two datasets for a single execution

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.

2 Replies

  • endor_force's avatar
    endor_force
    New Contributor III

    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())

     

  • sobha353's avatar
    sobha353
    New Contributor

    Hi endor_force 

    Thank you for the inputs. This is really helpful. 

    Sure, will work on the solution based on the inputs provided.