Nodejs Week Get getWeek(dowOffset)

Here you can find the source of getWeek(dowOffset)

Method Source Code

/**/*ww w  .jav  a2  s  .  co  m*/
 * Returns the week number for this date.  dowOffset is the day of week the week
 * "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
 * the week returned is the ISO 8601 week number.
 * @param int dowOffset
 * @return int
 */
Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.epoch-calendar.com */

    dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 1; //default dowOffset to zero -> 1 means Monday = first day
    var newYear = new Date(this.getFullYear(),0,1);
    var day = newYear.getDay() - dowOffset; //the day of week the year begins on
    day = (day >= 0 ? day : day + 7);
   var daynum = Math.floor((this.getTime() - newYear.getTime() - 
   (this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
   var weeknum;
   //if the year starts before the middle of a week
   if(day < 4) {
      weeknum = Math.floor((daynum+day-1)/7) + 1;
      if(weeknum > 52) {
         var nYear = new Date(this.getFullYear() + 1,0,1);
         var nday = nYear.getDay() - dowOffset;
         nday = nday >= 0 ? nday : nday + 7;
         /* if the next year starts before the middle of the week, it is week #1 of that year */
         weeknum = nday < 4 ? 1 : 53;
      }
   }
   else {
      weeknum = Math.floor((daynum+day-1)/7);
   }
   return weeknum;
};

Related

  1. 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() {
    ...
    
  2. 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);
    
  3. 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);
    ...
    
  4. 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];
    
  5. 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);
    };
    
  6. getWeek(dowOffset)
    Date.prototype.getWeek = function (dowOffset) {
      dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; 
      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) {
    ...
    
  7. getWeekDayName()
    Date.prototype.getWeekDayName = function(){
      return this.weekDayName()[this.getDay()];
    };
    Date.prototype.weekDayName = function(){
      return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    };
    sec = 1000;
    min = 60*sec;
    hour = 60*min;
    ...
    
  8. getWeekDayName(lang)
    Date.prototype.getWeekDayName = function(lang) {
        lang = lang && (lang in Date.locale) ? lang : 'de';
        return Date.locale[lang].day_names[this.getDay()];
    };
    Date.locale = {
        de: {
            month_names: ['Januar', 'Februar', 'M?', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
            month_names_short: ['Jan', 'Feb', 'M?, 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
            day_names: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    ...
    
  9. getWeekDayNameShort(lang)
    Date.prototype.getWeekDayNameShort = function(lang) {
        lang = lang && (lang in Date.locale) ? lang : 'de';
        return Date.locale[lang].day_names_short[this.getDay()];
    };
    Date.locale = {
        de: {
            month_names: ['Januar', 'Februar', 'M?', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
            month_names_short: ['Jan', 'Feb', 'M?, 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
            day_names: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    ...