From 61cab320d0d63cc8a7029c9a506b5b1f8c45b53f Mon Sep 17 00:00:00 2001 From: Avris Date: Fri, 15 Oct 2021 21:49:49 +0200 Subject: [PATCH] [terminology][calendar] sort events --- src/calendar/helpers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calendar/helpers.js b/src/calendar/helpers.js index e996b485..47f360c3 100644 --- a/src/calendar/helpers.js +++ b/src/calendar/helpers.js @@ -23,6 +23,11 @@ class Day { toString() { return `${this.year}-${this.month.toString().padStart(2, '0')}-${this.day.toString().padStart(2, '0')}`; } + + // for comparisons + toInt() { + return parseInt(`${this.year}${this.month.toString().padStart(2, '0')}${this.day.toString().padStart(2, '0')}`); + } } module.exports.Day = Day; @@ -153,6 +158,10 @@ class Year { this.eventsByTerm[term].push(event); } } + for (let term in this.eventsByTerm) { + if (!this.eventsByTerm.hasOwnProperty(term)) { continue; } + this.eventsByTerm[term].sort((a, b) => a.getDays(this.year)[0].toInt() - b.getDays(this.year)[0].toInt()) + } } isCurrent() {