_includes/course.html in askclass-course-theme-0.7.2 vs _includes/course.html in askclass-course-theme-0.7.3
- old
+ new
@@ -61,20 +61,21 @@
</ul>
<script defer>
const due = document.querySelectorAll('.due');
const rocket = document.querySelectorAll('.rocket');
- due.forEach( el => {
- const d = new Date(el.dataset.date.split('-')).getTime();
- if (d < Date.now()) {
- el.classList.add('past');
- }
- });
- rocket.forEach( el => {
- if (el.dataset.date) {
- const d = new Date(el.dataset.date.split('-')).getTime();
- if (d < Date.now()) {
- el.innerText = 'rocket';
- }
- }
- });
+ const ymd2ms = d => {
+ const ymd = d.split('-');
+ ymd[1]--;
+ return new Date(...ymd).getTime();
+ };
+ due.forEach( el =>
+ ymd2ms(el.dataset.date) < Date.now() &&
+ el.classList.add('past')
+ );
+
+ rocket.forEach( el =>
+ el.dataset.date &&
+ ymd2ms(el.dataset.date) < Date.now() &&
+ (el.innerText = 'rocket')
+ );
</script>