/* use function style */ /** * create a calendar view as ASCII-String, suitable for console program * or for debug. * * @param {object} calendar an object with structure like * ```{ * (TODO: Doc) * }``` * @param {object} locationCode * * @return {string} ASCII-String represents a month in a calendar. * */ export function asciiCalendar(calendar, locationCode) { let dayNames = locationCode["weekDays"]; const month = locationCode["months"][calendar["month"]], year = calendar["year"]; let view = "\n\n"; for (let day of calendar["weekDays"]) { view += dayNames[day] + ' '; } view += "\n"; let title = `${month} ${year}`; let width = view.length - 4; let padWidth = (width - title.length)/2|0; // only integer part title = ' '.repeat(padWidth)+title; view = `${title}${view}` let week = ""; let dayWidth = `${dayNames[0]}`.length; for(let w of calendar["weeks"]) { for(let d of w) { let day = `${d}`; if (day.length === 0) { day = ' '.repeat(dayWidth); } else if (day.length === 1) { day = `0${day}`; } day = ' '.repeat(dayWidth - day.length) + day; week += (day + ' '); } week += "\n"; } return view + week; } export function domCalendar(calendar, location) { const month = location.months[calendar.month], year = calendar.year; let htmlSegment = ``; const dayNames = location["weekDays"]; for(let d of calendar.weekDays) { htmlSegment += `` } htmlSegment += "\n\n"; for(let w of calendar.weeks) { htmlSegment += ""; for(let d of w) { htmlSegment += ``; } htmlSegment += "\n"; } htmlSegment += "
${month} ${year}
${dayNames[d]}
${d}
"; return htmlSegment; }