Skip to content

Commit

Permalink
Merge pull request DannyFeliz#7 from vyzaldysanchez/feature/dates-cou…
Browse files Browse the repository at this point in the history
…ntdown

Verifies every second if the current date is in range
  • Loading branch information
DannyFeliz authored Apr 5, 2019
2 parents 51225a4 + ce1c28b commit 04ddf87
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/components/TimedContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,35 @@ export default {
},
data() {
return {
shouldShow: false
shouldShow: false,
countdown: null
};
},
created() {
const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
const from = moment.tz(this.from, dateTimeFormat, this.timezone);
const to = moment.tz(this.to, dateTimeFormat, this.timezone);
this.toggleContent();
this.shouldShow = moment.tz(this.timezone).isBetween(from, to);
this.countdown = setInterval(() => this.toggleContent(), 1000);
},
beforeDestroy() {
clearInterval(this.countdown);
},
methods: {
shouldShowContent() {
const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
const from = moment.tz(this.from, dateTimeFormat, this.timezone);
const to = moment.tz(this.to, dateTimeFormat, this.timezone);
return moment.tz(this.timezone).isBetween(from, to);
},
toggleContent() {
this.shouldShow = this.shouldShowContent();
if (this.shouldShow) {
this.$emit("show");
} else {
this.$emit("hide");
}
}
}
};
</script>

0 comments on commit 04ddf87

Please sign in to comment.