This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: akaknksha <[email protected]>
- Loading branch information
1 parent
dd08a50
commit d92dbcf
Showing
2 changed files
with
52 additions
and
23 deletions.
There are no files selected for viewing
71 changes: 50 additions & 21 deletions
71
src/components/UsernameForm/TimeMessage/getTimeMessage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
const getTimeMessage = () => { | ||
const today = new Date(); | ||
const currentMonth = today.getMonth(); | ||
const daysLeft = 31 - today.getDate(); | ||
|
||
if (currentMonth !== 9) { | ||
return "It isn't even October yet!"; | ||
} | ||
|
||
if (daysLeft === 0) { | ||
return "It's the very last day! Get your last PRs in!"; | ||
import React from 'react'; | ||
import * as moment from 'moment'; | ||
class RemainTime extends React.Component { | ||
state = { days: null, hours: null, minutes: null, seconds: null }; | ||
componentDidMount() { | ||
setInterval(() => { | ||
const currYear = new Date().getFullYear(); | ||
const now = moment(); | ||
const festEnd = moment( | ||
`11-01-${currYear} 00:00 AM`, | ||
'MM-DD-YYYY hh:mm A' | ||
); | ||
const diff = festEnd.diff(now); | ||
const diffDuration = moment.duration(diff); | ||
this.setState({ | ||
days: String(diffDuration.days()).padStart(2, '0'), | ||
hours: String(diffDuration.hours()).padStart(2, '0'), | ||
minutes: String(diffDuration.minutes()).padStart(2, '0'), | ||
seconds: String(diffDuration.seconds()).padStart(2, '0'), | ||
}); | ||
}, 1000); | ||
} | ||
|
||
if (daysLeft === 1) { | ||
return 'One more day, keep it going!'; | ||
render() { | ||
var timeMessage = ''; | ||
var remainTime = ''; | ||
const today = new Date(); | ||
const currentMonth = today.getMonth(); | ||
const daysLeft = 31 - today.getDate(); | ||
if (currentMonth !== 9) { | ||
timeMessage = "It isn't even October yet!"; | ||
} else if (daysLeft === 0) { | ||
timeMessage = "It's the very last day! Get your last PRs in!"; | ||
} else if (daysLeft === 1) { | ||
timeMessage = 'One more day, keep it going!'; | ||
} else if (daysLeft < 10) { | ||
timeMessage = `There are only ${daysLeft} days left! You can do it!`; | ||
} else { | ||
timeMessage = `There are ${daysLeft} days remaining!`; | ||
} | ||
if (currentMonth == 9) { | ||
remainTime = `Remaining time: ${this.state.days}:${this.state.hours}:${this.state.minutes}:${this.state.seconds}`; | ||
} | ||
return ( | ||
<div className="time"> | ||
{timeMessage} | ||
<br /> | ||
{this.state.days != null ? remainTime : ''} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
if (daysLeft < 10) { | ||
return `There are only ${daysLeft} days left! You can do it!`; | ||
} | ||
|
||
return `There are ${daysLeft} days remaining!`; | ||
}; | ||
|
||
export default getTimeMessage; | ||
export default RemainTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters