Calculations by end-of-week date in Javascript?

Is there a helper library for doing these types of date calculations like in Rails?

Date.today.end_of_week
+3
source share
3 answers

There is no built-in function, but you can define your own:

Date.prototype.endOfWeek = function(){
  return new Date( 
      this.getFullYear(), 
      this.getMonth(), 
      this.getDate() + 6 - this.getDay() 
  );
};

var now = new Date();

// returns next saturday; and returns saturday if it is saturday today.
console.log( now.endOfWeek() );
+10
source

Yes. Datejs

I’m not sure what you think is “the end of the week,” assuming that on Saturday, I think

Date.parse('saturday');

will give you the next Saturday (or today, if today is Saturday)

+3
source

, , time.js.

DateJS, , ;)

If I could reproduce the code necessary in order to remove any instance of Date before the end of the current week, but it is a bit involved. It should be simple enough to figure out the basics by looking at the code .

+1
source

Source: https://habr.com/ru/post/1776276/


All Articles