Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export default Something;

You can stop the countdown timer anytime by passing `true` (Boolean) with `stop` props.

You can change the language of the text to French by passing `FR` (String) with `format` props.

```
<Countdown
format="FR"
deadline="September 22, 2023"
/>
```

### Caution

Expand Down
16 changes: 14 additions & 2 deletions src/libs/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CountDown extends React.Component {
this.state = {
now: Math.trunc((new Date()).getTime() / 1000),
date: null,
diff: 0
diff: 0,
format: 'ENG'
}

this.seconds = this.seconds.bind(this);
Expand Down Expand Up @@ -59,6 +60,11 @@ class CountDown extends React.Component {
}

componentWillMount() {
if (this.props.format) {
this.setState({
format: this.props.format
})
}
this.setDateAndInterVal()
}

Expand Down Expand Up @@ -129,11 +135,17 @@ class CountDown extends React.Component {
}

setDayString() {
if (this.state.format === "FR") {
return this.days() > 1 ? 'jours' : 'jour';
}
return this.days() > 1 ? 'days' : 'day';
}

setHourString() {
return this.hours() > 1 ? 'hours' : 'hour';
if (this.state.format === "FR") {
return this.hours() > 1 ? 'heures' : 'heure';
}
return this.days() > 1 ? 'hours' : 'hour';
}

// update show days
Expand Down