experimental

This commit is contained in:
David Ralph
2019-11-29 12:04:12 +00:00
committed by GitHub
parent 1a165f4f1d
commit cde3743ff8

View File

@@ -5,22 +5,27 @@ export default class Greeting extends React.Component {
constructor(...args) {
super(...args);
this.state = {
greeting: ``
greeting: ''
};
}
getGreeting() {
const h = new Date().getHours();
let t = 'Good evening'; // Set the default time string to "Good evening"
if (h < 12) t = 'Good morning'; // If it's before 12am, set the time string to "Good morning"
else if (h < 18) t = 'Good afternoon'; // If it's before 6pm, set the time string to "Good afternoon"
// Get current info
const t = new Date(); // Current date
const h = t.getHours(); // Current hour
// Normal
let g = 'Good evening'; // Set the default time string to "Good evening"
if (h < 12) g = 'Good morning'; // If it's before 12am, set the time string to "Good morning"
else if (h < 18) g = 'Good afternoon'; // If it's before 6pm, set the time string to "Good afternoon"
// Events
const today = new Date();
if (today.getMonth() === 0 && today.getDate() === 1) t = 'Happy new year';
else if (today.getMonth() === 11 && today.getDate() === 25) t = 'Merry Christmas';
else if (today.getMonth() === 9 && today.getDate() === 31) t = 'Happy Halloween';
this.setState({ greeting: t }); // Set the state to the time string
if (t.getMonth() === 0 && t.getDate() === 1) g = 'Happy new year'; // If the date is January 1st, set it to new year
else if (t.getMonth() === 11 && t.getDate() === 25) g = 'Merry Christmas'; // If it's December 25th, set it to xmas
else if (t.getMonth() === 9 && t.getDate() === 31) g = 'Happy Halloween'; // If it's October 31st, set it to halloween
this.setState({
greeting: g
}); // Set the state to the time string
}
componentDidMount() {
@@ -32,4 +37,4 @@ export default class Greeting extends React.Component {
{this.state.greeting}
</h1>;
}
}
}