diff --git a/.eslintrc.json b/.eslintrc.json index 23d7a4227ab861a9ef96cef7d8c613ba06caec2c..cfd661246ec2b478f133ab15ff037b6ecec5a18c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -27,9 +27,6 @@ "impliedStrict": true } }, - "plugins": [ - "jsdoc" - ], "rules": { "semi": ["warn", "always"], "semi-spacing": "warn", diff --git a/src/js/utilJS.js b/src/js/utilJS.js index 5f0ad823a11fddfcb591ab6fa4bb775ddc0ca51c..c80b279000fca03192567ab6d12c6ff91cf9f6d4 100644 --- a/src/js/utilJS.js +++ b/src/js/utilJS.js @@ -1108,35 +1108,45 @@ window.num = function(x) { * @returns {string} */ window.time = function(weeks) { - let r = ``; + let + r = ``, + years, + months; - if (weeks >= 52) { // at least one year - r += `${num(Math.trunc(weeks / 52))} year${Math.trunc(weeks / 52) != 1 ? `s` : ``}`; + if (weeks >= 52) { // at least one year + years = Math.trunc(weeks / 52); - if ((weeks - 52) % 4 !== 0) { // not exactly x years, y months + r += `${num(years)} year${years !== 1 ? `s` : ``}`; + + if ((weeks - 52) % 4.33 !== 0) { // not exactly x years, y months r += `, `; } else { - if (weeks % 52 !== 0) { // not exactly x years + if (weeks % 52 !== 0) { // not exactly x years r += ` and `; } } - weeks -= Math.trunc(weeks / 52) * 52; // rounds down to and drops number of years + weeks -= years * 52; // rounds down to and drops number of years } - if (weeks >= 4) { // at least one month - r += `${num(Math.trunc(weeks / 4))} month${Math.trunc(weeks / 4) != 1 ? `s` : ``}`; - weeks -= Math.trunc(weeks / 4) * 4; // rounds down to and drops number of months - if (weeks > 0) { + if (weeks >= 4.33) { // at least one month + months = Math.trunc(weeks / 4.33); + + r += `${num(months)} month${months !== 1 ? `s` : ``}`; + + weeks -= months * 4.33; // rounds down to and drops number of months + if (weeks >= 1) { r += ` and `; } } - if (weeks > 0) { - r += `${num(weeks)} week${weeks != 1 ? `s` : ``}`; + if (weeks >= 1) { + weeks = Math.trunc(weeks); + + r += `${num(weeks)} week${weeks !== 1 ? `s` : ``}`; } return r; -} +}; /** * @param {number} s