Skip to content

Instantly share code, notes, and snippets.

@Sebbenbear
Created April 14, 2018 06:54
Show Gist options
  • Save Sebbenbear/92759b38683d26c978e8a68e5b6c2ec8 to your computer and use it in GitHub Desktop.
Save Sebbenbear/92759b38683d26c978e8a68e5b6c2ec8 to your computer and use it in GitHub Desktop.
Google Timezone api usage
// Later on, use this to get the timezone based off the locations of the people
//const url = "https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=" + {REACT_APP_GOOGLE_TIMEZONE_API_KEY}
// componentDidMount() {
// const api = "https://maps.googleapis.com/maps/api/timezone/json?";
// const lat = 39.6034810;
// const lon = -119.6822510;
// const timestamp = 1331161200;
// const key = process.env.REACT_APP_GOOGLE_TIMEZONE_API_KEY;
// const url = api + "location=" + lat + "," + lon + "&timestamp=" + timestamp + "&key=" + key;
// this.setState({ isLoading: true });
// fetch(url)
// .then(response => {
// if (response.ok) {
// return response.json();
// } else {
// throw new Error('Something went wrong ...');
// }
// })
// .then(data => this.setState({
// timeZoneId: data.timeZoneId,
// timeZoneName: data.timeZoneName,
// dstOffset: data.dstOffset,
// rawOffset: data.rawOffset,
// isLoading: false
// }))
// .catch(error => this.setState({ error, isLoading: false }));
// }
//render() {
// const { hits, isLoading, error } = this.state;
// if (error) {
// return <p>{error.message}</p>;
// }
// if (isLoading) {
// return <p>Loading ...</p>;
// }
// return (
// <div>
// <img src="http://via.placeholder.com/300x300" />
// <p>{this.state.timeZoneId}</p>
// <p>{this.state.timeZoneName}</p>
// <p>{this.state.dstOffset}</p>
// <p>{this.state.rawOffset}</p>
// <p>Current time: {Date.now()} </p>
// <p>Current time: {new Date().getTime()} </p>
// <p>{this.calcTime(this.state.timeZoneId, this.state.dstOffset)}</p>
// <p>{this.calcTime("Australia, Sydney", 11)}</p>
// </div>
// );
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment