From be4790e1f3efd55fdc8b563f2a1e5b77bdf8dfba Mon Sep 17 00:00:00 2001 From: Alexis Sgarbossa Date: Fri, 27 Dec 2024 18:08:04 -0300 Subject: [PATCH] Refactor Timezone to fallback to local timezone. Closes #1268 --- README.md | 8 +- component/footer.tsx | 10 +- component/timezone.tsx | 36 ++- helpers/timezones.ts | 596 ----------------------------------------- pages/api/index.ts | 15 +- 5 files changed, 42 insertions(+), 623 deletions(-) delete mode 100644 helpers/timezones.ts diff --git a/README.md b/README.md index 33c683d1..0d94bf7f 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ There is an endpoint to use on your CI or just for fun at `https://shouldideploy You can also provide optional parameters to customize the API response: -- `tz`: The timezone to use when evaluating the date and time. The default value is UTC. Pass a valid timezone string, such as `America/New_York` or `Europe/London` default `UTC`. +- `tz`: The timezone to use when evaluating the date and time. By default, it uses your local timezone. You can override this by passing a valid timezone string, such as `America/New_York` or `Europe/London`. - `date`: The date to evaluate. The default value is the current date. Pass a valid date string in the format `YYYY-MM-DD`, such as `2023-03-31`. ### Examples -Get the default API response using the current date and time in the UTC timezone: +Get the API response using your local timezone: ``` @@ -38,7 +38,7 @@ Get the API response for a specific timezone (e.g., Europe/London): https://shouldideploy.today/api?tz=Europe/London ``` -Get the API response for a specific date (e.g., 2023-03-31) in the UTC timezone: +Get the API response for a specific date (e.g., 2023-03-31) in your local timezone: ``` https://shouldideploy.today/api?date=2023-03-31 @@ -63,7 +63,7 @@ Example response: ``` { - "timezone": "UTC", +"timezone": "America/New_York", "date": "2023-03-31T00:00:00.000Z", "shouldideploy": false, "message": "It's Friday, better not deploy today." diff --git a/component/footer.tsx b/component/footer.tsx index 5c92fb0c..22a88b10 100644 --- a/component/footer.tsx +++ b/component/footer.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import Timezone from './timezone' interface IFooter { @@ -7,6 +7,14 @@ interface IFooter { } const Footer = (props: IFooter) => { + useEffect(() => { + // Set initial timezone if not already set + if (!props.timezone) { + const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone + props.changeTimezone(localTimezone) + } + }, []) + return ( <>