Skip to content

Commit

Permalink
upd annual
Browse files Browse the repository at this point in the history
  • Loading branch information
kudrykv committed Aug 2, 2021
1 parent bb5c590 commit ec344a4
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions scripts/20_annual.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,33 @@ const rowOfMonths = (year, qrtr) =>
const tabularify = (columns, content) => interpolateTpl('calRow', {columns, content});

const monthTabular = (year, month) => {
let calendar = m.monthMonday(year, month)
.map(stringifyWeekNumbers)
.map(row => row.map(date => !date ? '' : ls.link(fmtDay(year, month, date), date)));

let daynum = 1;

let startingWeek = moment(new Date(year, month, daynum)).isoWeek();
calendar.forEach(row => {
month === 0 && startingWeek > 50
? row.unshift(ls.link('fwWeek ' + startingWeek, startingWeek))
: row.unshift(ls.link('Week ' + startingWeek, startingWeek));
daynum += 7;
startingWeek = moment(new Date(year, month, daynum)).isoWeek();
})
calendar = calendar.map(makeRow).join(' \\\\\n');
const monthStart = new Date(year, month, 1);
const week = moment(monthStart).subtract(1, 'week');
const date = moment(monthStart);

const columns = 8;
const date = moment(new Date(year, month, 1));
const calendar = m.monthMonday(year, month)
.map(row => [week.add(1, 'week').isoWeek(), ...row])
.map(row => [linkifyWeekNumbers(month, row[0]), ...row.slice(1)])
.map(row => [row[0], ...linkifyDays(year, month, row.slice(1))])
.map(makeRow)
.join(' \\\\\n');

return interpolateTpl('calendar', {
weekColumn: 'c |',
weekTag: 'W & ',
columns,
columns: 8,
monthName: ls.slink(date.format('MMMM')),
calendar: indent(calendar)
})
}

const stringifyWeekNumbers = row => row.map(item => item > 0 ? '' + item : '')
const linkifyWeekNumbers = (month, item) =>
month === 0 && item > 50
? ls.link('fwWeek ' + item, item)
: ls.link('Week ' + item, item);

const linkifyDays = (year, month, row) =>
row.map(date => !date ? '' : ls.link(fmtDay(year, month, date), date));

module.exports.annualTable = annualTable;
module.exports.monthTabular = monthTabular;

0 comments on commit ec344a4

Please sign in to comment.