Nodejs Week Get getWeek()

Here you can find the source of getWeek()

Method Source Code

// Returns the ISO week of the date.
Date.prototype.getWeek = function() {
  var date = new Date(this.getTime());
  date.setHours(0, 0, 0, 0);//  www.  j a  v a 2  s. c  om
  // Thursday in current week decides the year.
  date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
  // January 4 is always in week 1.
  var week1 = new Date(date.getFullYear(), 0, 4);
  // Adjust to Thursday in week 1 and count number of weeks from date to week1.
  return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
}

function getDay(yyyyMMdd) {
   return new Date(yyyyMMdd).getDay();
}

function getWeek(yyyyMMdd) {
   return new Date(yyyyMMdd).getWeek();
}

function getMonthAsShortString(value) {
   months = [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
   return months[value-1];
}

function convertToDDMMYYYY(yyyyMMdd) {
   var pattern = /(\d{4})-(\d{2})-(\d{2})/;
   return yyyyMMdd.replace(pattern, '$3/$2/$1');
}

Related

  1. getWeek()
    Date.prototype.getWeek = function() {
      var onejan = new Date(this.getFullYear(), 0, 1);
      return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    var today = new Date();
    var daynum = today.getDOY();
    var weeknr = (new Date()).getWeek();
    var d = (new Date()).getDay();
    var day = (new Date()).getDate();
    ...
    
  2. getWeek()
    Date.prototype.getWeek = function() {
      var onejan = new Date(this.getFullYear(),0,1);
      var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
      var dayOfYear = ((today - onejan + 86400000)/86400000);
      return Math.ceil(dayOfYear/7)
    };
    var today = new Date();
    var currentWeekNumber = today.getWeek();
    console.log(currentWeekNumber);
    ...
    
  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);
    
  4. getWeek()
    Date.prototype.getWeek = function () {
        var onejan = new Date(this.getFullYear(), 0, 1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    function sumArr(arr) {
        return arr.reduce(function (a, b) { return a + b; }, 0);
    function formatTime(val) {
        var sec_num = parseInt(val, 10); 
    ...
    
  5. 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(),
    ...
    
  6. 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());
    ...
    
  7. 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);
    };
    
  8. 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() {
    ...
    
  9. getWeek()
    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);
        if (target.getDay() != 4) {
            target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
        return 1 + Math.ceil((firstThursday - target) / 604800000);