-
Notifications
You must be signed in to change notification settings - Fork 861
Expand file tree
/
Copy pathApp.js
More file actions
48 lines (41 loc) · 1.22 KB
/
App.js
File metadata and controls
48 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import Datetime from '../DateTime'; // Import your calendar library
import moment from 'moment-timezone';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date(),
timeZone: 'America/Los_Angeles', // Initial time zone
};
}
// 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;
};
// 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;