日記テンプレート
code:日記テンプレートS.js
(function() {
Date.prototype.format = function(format) {
// yyyy, MM, dd, ddd だけ
.replace('yyyy', this.getFullYear())
.replace('MM', ('0' + (this.getMonth() + 1)).slice(-2))
.replace('dd', ('0' + this.getDate()).slice(-2))
}
Date.prototype.dateToIso8601Week = function(date){
// 引数のDateと同じ週の木曜日を計算
// 259200000 = 3days * 24hour * 60min * 60s * 1000ms
// 205,200,000 = 259,200,000 - (15hour * 60min * 60s * 1000ms) -> 9hずれているので15引いて補正(205200000)
// 604800000 = 1week * 7days * 24hour * 60min * 60s * 1000ms
const thursday = new Date(Math.ceil((date.getTime() - 313200000) / 604800000) * 604800000)
// 木曜日と同じ年の1月1日を計算
const firstDayOfYear = new Date(thursday.getFullYear(), 0, 1)
// 木曜日がその年の第何週かを計算する
const weekOfYear = Math.floor((thursday.getTime() - firstDayOfYear.getTime()) / 604800000) + 1
// 日曜日の週が想定よりズレているので補正
//const weekOfYearSundaySuported = date.getDay() !== 0 ? weekOfYear : weekOfYear -1
return ${('0' + weekOfYear).slice(-2)}
}
// 処理ここから
const d = new Date()
const year = d.getFullYear()
const month = d.getMonth() + 1
const day = d.getDate()
const weekNum = new Date().dateToIso8601Week(new Date())
const yearWeekString = year + "'" + weekNum
const yearWeek = yearWeekString.split("'")
const dateFormat = "yyyy-MM-dd"
const dateFormat2 = "yyyy/MM/dd(ddd)"
const yyyyMMFormat = "yyyy/MM"
const dayFormat = "ddd"
// ここで返してるものがページのタイトルと本文
return `Date:${new Date().format(dateFormat2)}
朝
朝食
仕事
昼
昼食
仕事
夜
夕食
仕事
帰宅
家
--
日記をScrapBoxで書いているので、カレンダーと連携させたり色々した。