days and week of year

node v10.24.1
version: 3.0.0
endpointsharetweet
const dayjs = require('dayjs'); const pluralStr = function (num, nom, gen, plur) { const nn = num % 100; if (nn >= 11 && nn <= 19) { return plur; } const rem = nn % 10; switch (rem) { case 1: return nom; case 2: case 3: case 4: return gen; default: return plur; } }; const yearProgress = function () { const now = dayjs(); const endOfYear = now.endOf('year'); const days = endOfYear.diff(now, 'days'); const weeks = endOfYear.diff(now, 'weeks'); console.log(days, weeks); const msg = `До конца года ${days} ${pluralStr(days, 'день', 'дня', 'дней')}, ${weeks} ${pluralStr(weeks, 'неделя', 'недели', 'недель')}`; console.log(msg); return msg; } exports.endpoint = function (request, response) { response.end(yearProgress()); };
Loading…

no comments

    sign in to comment