fix(analytics): Support `Last Week` date range option
Problem
Closes https://github.com/PostHog/posthog/issues/39186
Changes
This is slightly different from Last month, which uses -1mStart and -1mEnd. As week is day sensitive, we need to adjust the parsed_dt ourselves first before applying relativedelta.
-1wStart: I want the first day of last week. It could be Sunday or Monday, dependent on the team's week start day. -1wEnd: I want the last day of last week. It could be Saturday or Sunday.
Tooltip issue
Previously, I couldn't get the date option to render correctly based on the week start of the day.
This is because the dateMapping is a constant in the util file:
https://github.com/PostHog/posthog/blob/be98be39fe854b5540ef477dd361ef1eb6fedc25/frontend/src/lib/utils.tsx#L1012-L1019
The tooltip now renders "Last Week" instead:
If this is important, I can open another issue to track this once we merge it in; I believe the tooltip is acceptable enough for this PR to go in :), let me know if yall think otherwise!
Order of date options
Updated the order of the date options based on https://github.com/PostHog/posthog/pull/39297#pullrequestreview-3403100172:
https://github.com/user-attachments/assets/bae2cf08-6b42-46d8-87ce-6c9fc6ec0338
How did you test this code?
Locally:
- Go to http://localhost:8010/project/1/settings/environment-product-analytics#date-and-time
- Set the week start to
Sunday - Go to a product analytics or a dashboard
- Click on the date range dropdown and select last week.
- You should see that the
resolved_date_rangeis last sunday to last saturday - Go back to http://localhost:8010/project/1/settings/environment-product-analytics#date-and-time and set the week start to
Monday - Repeat same process, should see that the
resolved_date_rangeis last monday to last sunday
Depends on https://github.com/PostHog/posthog/pull/43100