From 4d77a11c7e4d8988d16cd4fe876f6c07803158ff Mon Sep 17 00:00:00 2001 From: Hamza Ait Aissa Date: Sat, 2 Sep 2023 15:31:42 +0100 Subject: [PATCH] Fixing daylight saving --- src/playground/App.js | 58 ++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/playground/App.js b/src/playground/App.js index 2673b5f9f..c622a668e 100644 --- a/src/playground/App.js +++ b/src/playground/App.js @@ -1,24 +1,48 @@ -// This file is the playground used for development purposes (npm run playground) -// not part of the library import React from 'react'; -import Datetime from '../DateTime'; +import Datetime from '../DateTime'; // Import your calendar library +import moment from 'moment-timezone'; -// import moment from 'moment'; -// import 'moment/locale/tzm-latn'; -// moment.locale('tzm-latn'); +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + date: new Date(), + timeZone: 'America/Los_Angeles', // Initial time zone + }; + } -class App extends React.Component { - state = { - date: new Date() - } + // Function to check if a date is in daylight saving time + checkDaylightSavingTime = (date) => { + // Use moment-timezone to determine if the date is in DST + const isDST = moment(date).tz('America/Los_Angeles').isDST(); + return isDST; + }; - render() { - return ( -
- -
- ); - } + // Function to update time zone and selected date + handleDateChange = (newDate) => { + const isDaylightSavingTime = this.checkDaylightSavingTime(newDate); + + // Update time zone based on daylight saving time + const newTimeZone = isDaylightSavingTime ? 'America/Los_Angeles' : 'America/Los_Angeles|PST PDT'; + + this.setState({ + date: newDate, + timeZone: newTimeZone, + }); + }; + + render() { + return ( +
+ +
+ ); + } } export default App;