Giter VIP home page Giter VIP logo

Comments (2)

ospfranco avatar ospfranco commented on May 10, 2024

months have different colors until I have more time to make this graph look nicer, please ignore all the time tracking for now

from sol.

Angelk90 avatar Angelk90 commented on May 10, 2024

@ospfranco : For the calculation of the lastDays what do you think of a solution of these two, the times seem to be reduced.

  const lNow = DateTime.now();
  const lThreeMonthsAgo = lNow.minus({month: 3}).startOf("week");
  let num = Math.ceil(lNow.diff(lThreeMonthsAgo, "days").days);
  let lastDays = [...Array(num).keys()].reduce(
      (acc, val) => [...acc, lThreeMonthsAgo.plus({day: val})],
      [] as Array<DateTime>
  );

o

let now = new Date();
let start = new Date(now.getFullYear(), now.getMonth() - 3, now.getDate());
// If date "overflowed" into next month, then bring it back:
if ((start.getMonth() + 3) % 12 != now.getMonth()) {
     start.setDate(0); // Go to last day of previous month
}
// Go to previous Monday if not yet a Monday
start.setDate(start.getDate() - (start.getDay() + 6) % 7); 
let lastDays = [];
while (start < now) {
    lastDays.push(start.toLocaleDateString("en-SE")); // Format YYYY-MM-DD
    start.setDate(start.getDate() + 1); // Next day
}

o

let now = new Date();
let start = new Date(now.getFullYear(), now.getMonth() - 3, now.getDate());
if ((start.getMonth() + 3) % 12 != now.getMonth()) start.setDate(0);
start.setDate(start.getDate() - (start.getDay() + 6) % 7); 
const diffTime = Math.abs(now - start);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); 

let lastDays = [...Array(diffDays).keys()].reduce(
  (acc, val) => {
    let d = start.toLocaleDateString("en-SE")
    start.setDate(start.getDate() + 1);
    return [...acc, d]
  },
  []
);

from sol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.