Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing daylight saving #863

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions src/playground/App.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Datetime />
</div>
);
}
// 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 (
<div>
<Datetime
displayTimeZone={this.state.timeZone}
timeFormat={'h:mm a z'}
onChange={this.handleDateChange}
value={this.state.date}
/>
</div>
);
}
}

export default App;