A simple dataview query to induce urgency or a panic attack

let now = dv.date("now").toMillis();
const livedWeeks = 1249, totalWeeks = livedWeeks + 2760;
const periods = [
  ["==🍎you have🍎==", dv.date("today").minus({weeks: livedWeeks}), dv.date("today").plus({weeks: 2760 - livedWeeks})],
  ["Day", dv.date("today"), dv.date("tomorrow"), ['hours', 'minutes']],
  ["Week", dv.date("sow"), dv.date("eow"), ['days', 'hours']],
  ["Month", dv.date("som"), dv.date("eom"), ['weeks', 'days', 'hours']],
  ["Quarter", DateTime.fromFormat(dv.date("now").toFormat("yyyy-qq"), "yyyy-qq"), DateTime.fromFormat(dv.date("now").plus({quarter: 1}).toFormat("yyyy-qq"), "yyyy-qq"), ['months', 'weeks', 'days']],
  ["Year", dv.date("soy"), dv.date("eoy"), ['quarters', 'months', 'weeks', 'days']]
];

// Define a CSS style to set the progress bar width to 400px
const customProgressBarStyle = 'style="width: 700px;"';

dv.table(["Name", "Bar"], periods.map(([p, s, e, units]) => {
  let start = s.toMillis(), end = e.toMillis();
  let value = p === "==🍎you have🍎==" ? (livedWeeks * 100 / totalWeeks).toFixed(2) : ((now - start) * 100 / (end - start)).toFixed(2);
  let diffStr = p === "==🍎you have🍎==" ? `${totalWeeks - Math.round((now - start) / 604800000)} weeks left`
    : units.map(u => `${moment(end).diff(moment(now), u)} ${u}`).join(', ') + " left";
  return [p, `<progress value='${value}' max='100' ${customProgressBarStyle}></progress><span>${value}% | ${diffStr}</span>`];
}));

1 Like

Nice, I made some small changes so you can just set your birthday and end date without haveing to do the math

````dataviewjs 
const theEnd = 80
const birthDate = DateTime.fromFormat("19/08/2000", "dd/MM/yyyy");

let now = dv.date("now").toMillis();
const livedDuration = now - birthDate.toMillis(); 
const livedWeeks = Math.floor(livedDuration / (7 * 24 * 60 * 60 * 1000)); 
const totalWeeks = 52 * theEnd;

const periods = [
    ["==🍎you have🍎==", dv.date("today").minus({weeks: livedWeeks}), dv.date("today").plus({weeks: 2760 - livedWeeks})],
    ["Day", dv.date("today"), dv.date("tomorrow"), ['hours', 'minutes']],
    ["Week", dv.date("sow"), dv.date("eow"), ['days', 'hours']],
    ["Month", dv.date("som"), dv.date("eom"), ['weeks', 'days', 'hours']],
    ["Quarter", DateTime.fromFormat(dv.date("now").toFormat("yyyy-qq"), "yyyy-qq"), DateTime.fromFormat(dv.date("now").plus({quarter: 1}).toFormat("yyyy-qq"), "yyyy-qq"), ['months', 'weeks', 'days']],
    ["Year", dv.date("soy"), dv.date("eoy"), ['quarters', 'months', 'weeks', 'days']]
];

// Define a CSS style to set the progress bar width to 700px
const customProgressBarStyle = 'style="width: 700px;"';

dv.table(["Name", "Bar"], periods.map(([p, s, e, units]) => {
    let start = s.toMillis();
    let end = e.toMillis();

    let value = p === "==🍎you have🍎==" 
                ? (livedWeeks * 100 / totalWeeks).toFixed(2) 
                : ((now - start) * 100 / (end - start)).toFixed(2);

    let diffStr = p === "==🍎you have🍎==" 
                  ? `${totalWeeks - Math.round((now - start) / 604800000)} weeks left` 
                  : units.map(u => `${moment(end).diff(moment(now), u)} ${u}`).join(', ') + " left";

    return [p, `<progress value='${value}' max='100' ${customProgressBarStyle}></progress><span>${value}% | ${diffStr}</span>`];
}));