Skip to content

Commit

Permalink
now grabs location date
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Russell authored and Gabriel Russell committed Nov 28, 2020
1 parent 343c719 commit 8ac47a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintcache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"/Users/gabrielrussell/code/world-weather-app/src/reportWebVitals.js":"1","/Users/gabrielrussell/code/world-weather-app/src/App.js":"2","/Users/gabrielrussell/code/world-weather-app/src/index.js":"3"},{"size":362,"mtime":1606235130117,"results":"4","hashOfConfig":"5"},{"size":6456,"mtime":1606543422292,"results":"6","hashOfConfig":"5"},{"size":500,"mtime":1606235130116,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"139zll3",{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/gabrielrussell/code/world-weather-app/src/reportWebVitals.js",[],"/Users/gabrielrussell/code/world-weather-app/src/App.js",[],"/Users/gabrielrussell/code/world-weather-app/src/index.js",[]]
[{"/Users/gabrielrussell/code/world-weather-app/src/reportWebVitals.js":"1","/Users/gabrielrussell/code/world-weather-app/src/App.js":"2","/Users/gabrielrussell/code/world-weather-app/src/index.js":"3"},{"size":362,"mtime":1606235130117,"results":"4","hashOfConfig":"5"},{"size":6494,"mtime":1606545964947,"results":"6","hashOfConfig":"5"},{"size":500,"mtime":1606235130116,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"139zll3",{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/gabrielrussell/code/world-weather-app/src/reportWebVitals.js",[],"/Users/gabrielrussell/code/world-weather-app/src/App.js",[],"/Users/gabrielrussell/code/world-weather-app/src/index.js",[]]
25 changes: 15 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const timezones = {
'-3600': -1.0,
// '0': '0',
// '3600': 1.00,
// '7200': 0.00,
// '7200': 2.00,
// '10800': 3.00,
// '12600': 3.30,
// '14400': 4.00,
Expand Down Expand Up @@ -53,7 +53,7 @@ export default class App extends Component {
this.state = {
query: '',
weather: '',
date: new Date(),
date: '',
coords: {
lat: 0,
lon: 0,
Expand Down Expand Up @@ -87,10 +87,12 @@ export default class App extends Component {
)
.then((res) => res.json())
.then((result) => {
let d = String(new Date());
this.setState({
query: '',
weather: result,
climate: result.weather[0].main.toLowerCase(),
date: d,
});
});
});
Expand All @@ -106,10 +108,12 @@ export default class App extends Component {
.then((result) => {
console.log(result);
if (result.cod === 200) {
let d = this.locationDateCalc(result);
this.setState({
query: '',
weather: result,
climate: result.weather[0].main.toLowerCase(),
date: d,
});
} else {
this.setState({
Expand Down Expand Up @@ -161,10 +165,14 @@ export default class App extends Component {
}
};

locationTimeCalc = (offset) => {
let utc =
this.state.date.getTime() + this.state.date.getTimezoneOffset() * 60000;
return new Date(utc + 3600000 * timezones[this.state.weather.timezone]);
locationDateCalc = (loc) => {
let d = new Date();

let utc = d.getTime() + d.getTimezoneOffset() * 60000;

let locDate = new Date(utc + 3600000 * timezones[loc.timezone]);

return String(locDate);
};

render() {
Expand Down Expand Up @@ -223,10 +231,7 @@ export default class App extends Component {
<div className="location">
{this.state.weather.name}, {this.state.weather.sys.country}
</div>
<div className="date">
{String(this.state.date).slice(0, 15)}
{/* {this.locationTimeCalc('')} */}
</div>
<div className="date">{this.state.date.slice(0, 15)}</div>
</div>
<div className="weather-box">
<div className="temp">
Expand Down

0 comments on commit 8ac47a3

Please sign in to comment.