Nodejs Week Get getWeek()

Here you can find the source of getWeek()

Method Source Code

Date.prototype.getWeek = function () {
    var target  = new Date(this.valueOf());
    var dayNr   = (this.getDay() + 6) % 7;
    target.setDate(target.getDate() - dayNr + 3);
    var firstThursday = target.valueOf();
    target.setMonth(0, 1);/*from  w  w  w .  ja  va  2s.co  m*/
    if (target.getDay() != 4) {
        target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
    }
    return 1 + Math.ceil((firstThursday - target) / 604800000);
}

Related

  1. getWeek()
    Date.prototype.getWeek = function(){
        var day_miliseconds = 86400000,
            onejan = new Date(this.getFullYear(),0,1,0,0,0),
            onejan_day = (onejan.getDay()==0) ? 7 : onejan.getDay(),
            days_for_next_monday = (8-onejan_day),
            onejan_next_monday_time = onejan.getTime() + (days_for_next_monday * day_miliseconds),
            first_monday_year_time = (onejan_day>1) ? onejan_next_monday_time : onejan.getTime(),
            this_date = new Date(this.getFullYear(), this.getMonth(),this.getDate(),0,0,0),
            this_time = this_date.getTime(),
    ...
    
  2. getWeek()
    Date.prototype.getWeek = function() {
      var date = new Date(this.getTime());
      date.setHours(0, 0, 0, 0);
      date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
      var week1 = new Date(date.getFullYear(), 0, 4);
      return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
    function getDay(yyyyMMdd) {
      return new Date(yyyyMMdd).getDay();
    ...
    
  3. getWeek()
    Date.prototype.getWeek = function() {
      var date = new Date(this.getTime());
      date.setHours(0, 0, 0, 0);
      date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
      var week1 = new Date(date.getFullYear(), 0, 4);
      return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
    Date.prototype.getWeekYear = function() {
      var date = new Date(this.getTime());
    ...
    
  4. getWeek()
    'use strict';
    Date.prototype.getWeek = function() {
      var onejan = new Date(this.getFullYear(), 0, 1);
      return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    };
    
  5. getWeek()
    Date.prototype.getWeek = function() {
        var date = new Date(this.getTime());
        date.setHours(0, 0, 0, 0);
        date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
        var week1 = new Date(date.getFullYear(), 0, 4);
        return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000
            - 3 + (week1.getDay() + 6) % 7) / 7);
    Date.prototype.getWeekYear = function() {
    ...
    
  6. getWeek()
    Date.prototype.getWeek = function () {
        var determinedate = new Date();
        determinedate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate());
        var D = determinedate.getDay();
        if (D == 0) D = 7;
        determinedate.setDate(determinedate.getDate() + (4 - D));
        var YN = determinedate.getFullYear();
        var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
        var WN = 1 + Math.floor(ZBDoCY / 7);
    ...
    
  7. getWeek()
    Date.prototype.getWeek = function()
        var today = new Date(this.setHours(0, 0, 0, 0));
        var date = today.getDate() - today.getDay();
        var StartDate = new Date(today.setDate(date));
        var EndDate = new Date(today.setDate(date + 6));
        return [StartDate, EndDate];
    
  8. getWeek()
    Date.prototype.getWeek = function () {
      var onejan = new Date(this.getFullYear(), 0, 1);
      var time   = this.getMilliseconds() +
                   this.getSeconds() * 1000 +
                   this.getMinutes() * 60 * 1000 +
                   this.getHours() * 60 * 60 * 1000;
      return Math.ceil((((this - onejan - time) / 86400000) + onejan.getDay() + 1) / 7);
    };
    
  9. getWeek(dowOffset)
    Date.prototype.getWeek = function (dowOffset) {
        dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 1; 
        var newYear = new Date(this.getFullYear(),0,1);
        var day = newYear.getDay() - dowOffset; 
        day = (day >= 0 ? day : day + 7);
      var daynum = Math.floor((this.getTime() - newYear.getTime() - 
      (this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
      var weeknum;
      if(day < 4) {
    ...