Richardsl / heatmap-calendar-obsidian

An Obsidian plugin for displaying data in a calendar similar to the github activity calendar
Apache License 2.0
623 stars 103 forks source link

Managing a more complicated date format #52

Closed shadowlift closed 1 year ago

shadowlift commented 1 year ago
  Hi there, I have a similar issue to @wesleyboers but am struggling to make it work. My daily notes are formatted in the form "dddd, MMMM Do YYYY" ("Wednesday, November 16th 2022").

Here is the code I'm trying to adapt:

dv.span("Physics")
const calendarData = {
    year: 2022,  // (optional) defaults to current year
    colors: {    // (optional) defaults to green
        blue:        ["#8cb9ff", "#69a3ff", "#428bff", "#1872ff", "#0058e2"], // first entry is considered default if supplied
        green:       ["#c6e48b", "#7bc96f", "#49af5d", "#2e8840", "#196127"],
        red:         ["#ff9e82", "#ff7b55", "#ff4d1a", "#e73400", "#bd2a00"],
        orange:      ["#ffa244", "#fd7f00", "#dd6f00", "#bf6000", "#9b4e00"],
        pink:        ["#ff96cb", "#ff70b8", "#ff3a9d", "#ee0077", "#c30062"],
        orangeToRed: ["#ffdf04", "#ffbe04", "#ff9a03", "#ff6d02", "#ff2c01"]
    },
    showCurrentDayBorder: true, // (optional) defaults to true
    defaultEntryIntensity: 4,   // (optional) defaults to 4
    intensityScaleStart: 10,    // (optional) defaults to lowest value passed to entries.intensity
    intensityScaleEnd: 100,     // (optional) defaults to highest value passed to entries.intensity
    entries: [],                // (required) populated in the DataviewJS loop below
}

//DataviewJS loop
for(let page of dv.pages('"1. Daily notes/2022/11-November/"').where(p=>p.physics).sort(p=>p.file.name)){
    //dv.span("<br>" + page.file.name) // uncomment for troubleshooting

    const date = new Date(page.file.name);
    const yyyy = date.getFullYear();
    let mm = date.getMonth() + 1; // Months start at 0!
    let dd = date.getDate();
    if (dd < 10) dd = '0' + dd;
    if (mm < 10) mm = '0' + mm;
    const formattedDate = yyyy + "-" + mm + '-' + dd;

    calendarData.entries.push({
        date: formattedDate,     // (required) Format YYYY-MM-DD
        intensity: page.physics, // (required) the data you want to track, will map color intensities automatically
        content: "🏋️",           // (optional) Add text to the date cell
        color: "orange",          // (optional) Reference from *calendarData.colors*. If no color is supplied; colors[0] is used
    })
}

renderHeatmapCalendar(this.container, calendarData)

Is the problem that getMonth(), getDate() etc. aren't working in this case of date format?

Reposted from https://github.com/Richardsl/heatmap-calendar-obsidian/discussions/2#discussioncomment-4158178 as a new issue

shadowlift commented 1 year ago

Fixed for now, by removing comma from title