ミニコード:各週の日付テキストを作る
アウトライナーに項目を作るために作成
code:js
const getDaysAddedDate = (date, n) => {
const newDate = new Date(date);
newDate.setDate(date.getDate() + n);
return newDate;
};
const getDigit = (n) => ('00' + n).slice(-2);
const format = (date) => ${date.getFullYear()}/${getDigit(date.getMonth() + 1)}/${getDigit(date.getDate())};
const getText = (start, range) => format(start) + '-' + format(getDaysAddedDate(start, range));
const START = new Date('2023/12/31');
const arr = [];
for (let i = 0; i < 53; i++) {
const date = getDaysAddedDate(START, i * 7);
arr.push([${getDigit(i + 1)}]${getText(date, 6)});
}
console.log(arr.join("\n"));
/*
...
*/
code:ts
const getDaysAddedDate = (date: Date, n: number) => {
const newDate = new Date(date);
newDate.setDate(date.getDate() + n);
return newDate;
}
const getDigit = (n: number) => ('00' + n).slice(-2);
const format = (date: Date) => ${date.getFullYear()}/${getDigit(date.getMonth() + 1)}/${getDigit(date.getDate())};
const getText = (start: Date, range: number) => format(start) + '-' + format(getDaysAddedDate(start, range));
const START = new Date('2023/12/31');
const arr: string[] = [];
for (let i = 0; i < 53; i++) {
const date = getDaysAddedDate(START, i * 7);
arr.push([${getDigit(i + 1)}]${getText(date, 6)});
}
console.log(arr.join("\n"));
/*
...
*/