-
Notifications
You must be signed in to change notification settings - Fork 97
world clock #73
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
base: main
Are you sure you want to change the base?
world clock #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [ZoneTransfer] | ||
| ZoneId=3 | ||
| ReferrerUrl=https://www.google.com/ | ||
| HostUrl=https://cdn4.vectorstock.com/i/1000x1000/63/73/world-clocks-vector-436373.jpg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| import React from "react"; | ||
| import logo from "./logo.png"; | ||
| import logo from "./clock.jpg"; | ||
| import "./App.css"; | ||
| import Clock from "./clock"; | ||
|
|
||
| class App extends React.Component { | ||
| // call clearInterval tear down the tier | ||
|
|
||
| render() { | ||
| return ( | ||
| <div className="App"> | ||
| <header className="App-header"> | ||
| <img src={logo} className="App-logo" alt="logo" /> | ||
| <p> | ||
| Edit <code>src/App.js</code> and save to reload. | ||
| </p> | ||
| <h1>Coordinated Universal Time</h1> | ||
| {/* Render date value that is stored in state */} | ||
| <Clock timeZone={"Asia/Singapore"} /> | ||
| <Clock timeZone={"UTC"} /> | ||
| {[1, 1, 1, 1, 1].map(() => ( | ||
| <Clock timeZone={"UTC"} /> | ||
| ))} | ||
| </header> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import React from "react"; | ||
|
|
||
| class Clock extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.timeZone = props.timeZone; | ||
|
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this here is unnecessary. You should just be able to use |
||
| // Initialise component state to contain "date" attribute with current date and time | ||
| this.state = { date: new Date() }; | ||
| console.log(props.timeZone); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's always remove console logs before pushing our code, as those are just for debugging |
||
| } | ||
|
|
||
| componentDidMount() { | ||
| // Set date value in state every second to current date and time | ||
| // Save setInterval timer ID in class variable for teardown in another class method | ||
| function updateDate() { | ||
| this.setState({date: new Date()}) | ||
| console.log("hi") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove |
||
| } | ||
| setInterval(updateDate, 10000); | ||
|
|
||
| this.timerId = setInterval(() => { | ||
| // callback function | ||
| this.setState({ | ||
| date: new Date(), | ||
| }); | ||
| }, 1000); | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| // Teardown setInterval timer with timer ID saved as class variable | ||
| clearInterval(this.timerId); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| // Render date value that is stored in state | ||
| <p> | ||
| {this.state.date.toLocaleString("en-GB", { timeZone: this.timeZone })} | ||
| </p> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default Clock; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // import Container from "react-bootstrap/Container"; | ||
| // import Row from "react-bootstrap/Row"; | ||
| // import Col from "react-bootstrap/Col"; | ||
|
|
||
|
|
||
| // function container() { | ||
| // return ( | ||
| // <Container> | ||
| // <Row> | ||
| // <Col>1 of 2</Col> | ||
| // <Col>2 of 2</Col> | ||
| // </Row> | ||
| // <Row> | ||
| // <Col>1 of 3</Col> | ||
| // <Col>2 of 3</Col> | ||
| // </Row> | ||
| // </Container> | ||
| // ); | ||
| // } | ||
|
|
||
| // export default container; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File should be capital
Clock.jsas this is a component. Components always capitalized