[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/calendar-locales/date/jalali/ -> date-helper.js (source)

   1  !(function(Date){
   2      'use strict';
   3  
   4      var localNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
   5  
   6  /** BEGIN: DATE OBJECT PATCHES **/
   7  /** Adds the number of days array to the Date object. */
   8  Date.gregorian_MD = [31,28,31,30,31,30,31,31,30,31,30,31];
   9  Date.local_MD     = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
  10  
  11  /** Constants used for time computations */
  12  Date.SECOND = 1000 /* milliseconds */;
  13  Date.MINUTE = 60 * Date.SECOND;
  14  Date.HOUR   = 60 * Date.MINUTE;
  15  Date.DAY    = 24 * Date.HOUR;
  16  Date.WEEK   =  7 * Date.DAY;
  17  
  18  /** MODIFY ONLY THE MARKED PARTS OF THE METHODS **/
  19  /************ START *************/
  20  /** INTERFACE METHODS FOR THE CALENDAR PICKER **/
  21  
  22  /********************** *************************/
  23  /**************** SETTERS ***********************/
  24  /********************** *************************/
  25  
  26  /** Sets the date for the current date without h/m/s. */
  27  Date.prototype.setLocalDateOnly = function (dateType, date) {
  28      if (dateType != 'gregorian') {
  29          /** Modify to match the current calendar when overriding **/
  30          return '';
  31      } else {
  32          var tmp = new Date(date);
  33          this.setDate(1);
  34          this.setFullYear(tmp.getFullYear());
  35          this.setMonth(tmp.getMonth());
  36          this.setDate(tmp.getDate());
  37      }
  38  };
  39  
  40  /** Sets the full date for the current date. */
  41  Date.prototype.setLocalDate = function (dateType, d) {
  42      if (dateType != 'gregorian') {
  43          /** Modify to match the current calendar when overriding **/
  44          return this.setJalaliDate(d);
  45      } else {
  46          return this.setDate(d);
  47      }
  48  };
  49  
  50  /** Sets the month for the current date. */
  51  Date.prototype.setLocalMonth = function (dateType, m, d) {
  52      if (dateType != 'gregorian') {
  53          /** Modify to match the current calendar when overriding **/
  54          return this.setJalaliMonth(m, d);
  55      } else {
  56          if (d == undefined) this.getDate();
  57          return this.setMonth(m);
  58      }
  59  };
  60  
  61  /** Sets the year for the current date. */
  62  Date.prototype.setOtherFullYear = function(dateType, y) {
  63      if (dateType != 'gregorian') {
  64          /** Modify to match the current calendar when overriding **/
  65          var date = new Date(this);
  66          date.setLocalFullYear(y);
  67          if (date.getLocalMonth('jalali') != this.getLocalMonth('jalali')) this.setLocalDate('jalali', 29);
  68          return this.setLocalFullYear('jalali', y);
  69      } else {
  70          var date = new Date(this);
  71          date.setFullYear(y);
  72          if (date.getMonth() != this.getMonth()) this.setDate(28);
  73          return this.setUTCFullYear(y);
  74      }
  75  };
  76  
  77  /** Sets the year for the current date. */
  78  Date.prototype.setLocalFullYear = function (dateType, y) {
  79      if (dateType != 'gregorian') {
  80          /** Modify to match the current calendar when overriding **/
  81          return this.setJalaliFullYear(y);
  82      } else {
  83          var date = new Date(this);
  84          date.setFullYear(y);
  85          if (date.getMonth() != this.getMonth()) this.setDate(28);
  86          return this.setFullYear(y);
  87      }
  88  };
  89  
  90  /********************** *************************/
  91  /**************** GETTERS ***********************/
  92  /********************** *************************/
  93  
  94  /** The number of days per week **/
  95  Date.prototype.getLocalWeekDays = function (dateType, y) {
  96      if (dateType != 'gregorian') {
  97          /** Modify to match the current calendar when overriding **/
  98          return 6;
  99      } else {
 100          return 6; // 7 days per week
 101      }
 102  };
 103  
 104  /** Returns the year for the current date. */
 105  Date.prototype.getOtherFullYear = function (dateType) {
 106      if (dateType != 'gregorian') {
 107          /** Modify to match the current calendar when overriding **/
 108          return this.getJalaliFullYear();
 109      } else {
 110          return this.getFullYear();
 111      }
 112  };
 113  
 114  /** Returns the year for the current date. */
 115  Date.prototype.getLocalFullYear = function (dateType) {
 116      if (dateType != 'gregorian') {
 117          /** Modify to match the current calendar when overriding **/
 118          return this.getJalaliFullYear();
 119      } else {
 120          return this.getFullYear();
 121      }
 122  };
 123  
 124  /** Returns the month the date. */
 125  Date.prototype.getLocalMonth = function (dateType) {
 126      if (dateType != 'gregorian') {
 127          /** Modify to match the current calendar when overriding **/
 128          return this.getJalaliMonth();
 129      } else {
 130          return this.getMonth();
 131      }
 132  };
 133  
 134  /** Returns the date. */
 135  Date.prototype.getLocalDate = function (dateType) {
 136      if (dateType != 'gregorian') {
 137          /** Modify to match the current calendar when overriding **/
 138          return this.getJalaliDate();
 139      } else {
 140          return this.getDate();
 141      }
 142  };
 143  
 144  /** Returns the number of day in the year. */
 145  Date.prototype.getLocalDay = function(dateType) {
 146      if (dateType  != 'gregorian') {
 147          return this.getJalaliDay();
 148      } else {
 149          return this.getDay();
 150      }
 151  };
 152  
 153  /** Returns the number of days in the current month */
 154  Date.prototype.getLocalMonthDays = function(dateType, month) {
 155      if (dateType != 'gregorian') {
 156          /** Modify to match the current calendar when overriding **/
 157          var year = this.getLocalFullYear('jalali');
 158          if (typeof month == "undefined") {
 159              month = this.getLocalMonth('jalali');
 160          }
 161          if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
 162              return 29;
 163          } else {
 164              return Date.local_MD[month];
 165          }
 166      } else {
 167          var year = this.getFullYear();
 168          if (typeof month == "undefined") {
 169              month = this.getMonth();
 170          }
 171          if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
 172              return 29;
 173          } else {
 174              return Date.gregorian_MD[month];
 175          }
 176      }
 177  };
 178  
 179  /** Returns the week number for the current date. */
 180  Date.prototype.getLocalWeekNumber = function(dateType) {
 181      if (dateType != 'gregorian') {
 182          var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
 183          var DoW = d.getDay();
 184          d.setDate(d.getDate() - (DoW + 6) % 7 + 3);                                     // Nearest Thu
 185          var ms = d.valueOf();                                                           // GMT
 186          d.setMonth(0);
 187          d.setDate(4);                                                                   // Thu in Week 1
 188          return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
 189      } else {
 190          var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
 191          var DoW = d.getDay();
 192          d.setDate(d.getDate() - (DoW + 6) % 7 + 3);                                     // Nearest Thu
 193          var ms = d.valueOf();                                                           // GMT
 194          d.setMonth(0);
 195          d.setDate(4);                                                                   // Thu in Week 1
 196          return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
 197      }
 198  };
 199  
 200  /** Returns the number of day in the year. */
 201  Date.prototype.getLocalDayOfYear = function(dateType) {
 202      if (dateType  != 'gregorian') {
 203          var now = new Date(this.getOtherFullYear(dateType), this.getLocalMonth(dateType), this.getLocalDate(dateType), 0, 0, 0);
 204          var then = new Date(this.getOtherFullYear(dateType), 0, 0, 0, 0, 0);
 205          var time = now - then;
 206          return Math.floor(time / Date.DAY);
 207      } else {
 208          var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
 209          var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
 210          var time = now - then;
 211          return Math.floor(time / Date.DAY);
 212      }
 213  };
 214  
 215  /** Returns the number of days in the current month */
 216  Date.prototype.getMonthDays = function(month) {
 217      var year = this.getFullYear();
 218      if (typeof month == "undefined") {
 219          month = this.getMonth();
 220      }
 221      if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
 222          return 29;
 223      } else {
 224          if (Date.dateType != 'gregorian') {
 225              return Date.local_MD[month];
 226          } else {
 227              return Date.gregorian_MD[month];
 228          }
 229      }
 230  };
 231  
 232  /** Checks date and time equality */
 233  Date.prototype.equalsTo = function(date) {
 234      return ((this.getFullYear() == date.getFullYear()) &&
 235      (this.getMonth() == date.getMonth()) &&
 236      (this.getDate() == date.getDate()) &&
 237      (this.getHours() == date.getHours()) &&
 238      (this.getMinutes() == date.getMinutes()));
 239  };
 240  
 241  /** Converts foreign date to gregorian date. */
 242  Date.localCalToGregorian = function(y, m, d) {
 243      /** Modify to match the current calendar when overriding **/
 244      return JalaliDate.jalaliToGregorian(y, m, d);
 245  };
 246  
 247  /** Converts gregorian date to foreign date. */
 248  Date.gregorianToLocalCal = function(y, m, d) {
 249      /** Modify to match the current calendar when overriding **/
 250      return JalaliDate.gregorianToJalali(y, m, d);
 251  };
 252  
 253  /** Method to convert numbers from local symbols to English numbers. */
 254  Date.numbersToIso = function(str) {
 255      var i, nums = [0,1,2,3,4,5,6,7,8,9];
 256      str = str.toString();
 257  
 258  
 259      for (i = 0; i < nums.length; i++) {
 260          str = str.replace(new RegExp(localNumbers[i], 'g'), nums[i]);
 261      }
 262  
 263      return str;
 264  };
 265  
 266  /** Method to convert numbers to local symbols. */
 267  Date.convertNumbers = function(str) {
 268      str = str.toString();
 269  
 270      for (var i = 0, l = localNumbers.length; i < l; i++) {
 271          str = str.replace(new RegExp(i, 'g'), localNumbers[i]);
 272      }
 273  
 274      return str;
 275  };
 276  
 277  /** Translates to english numbers a string. */
 278  Date.toEnglish = function(str) {
 279      str = this.toString();
 280      var nums = [0,1,2,3,4,5,6,7,8,9];
 281      for (var i = 0; i < 10; i++) {
 282          str = str.replace(new RegExp(nums[i], 'g'), i);
 283      }
 284      return str;
 285  };
 286  
 287      /** Order the days from Gergorian to calendar order */
 288      Date.monthsToLocalOrder = function(months, dateType) {
 289          if (dateType === 'jalali'){
 290              months.push(months.shift()); // January to the end
 291              months.push(months.shift()); // February to the end
 292  
 293              return months;
 294          } else {
 295              return months;
 296          }
 297      };
 298  
 299  /** INTERFACE METHODS FOR THE CALENDAR PICKER **/
 300  /************* END **************/
 301  
 302  /** Prints the date in a string according to the given format. */
 303  Date.prototype.print = function (str, dateType, translate, localStrings) {
 304      /** Handle calendar type **/
 305      if (typeof dateType !== 'string') str = '';
 306      if (!dateType) dateType = 'gregorian';
 307  
 308      /** Handle wrong format **/
 309      if (typeof str !== 'string') str = '';
 310      if (!str) return '';
 311  
 312  
 313      if (this.getLocalDate(dateType) == 'NaN' || !this.getLocalDate(dateType)) return '';
 314      var m = this.getLocalMonth(dateType);
 315      var d = this.getLocalDate(dateType);
 316      var y = this.getLocalFullYear(dateType);
 317      var wn = this.getLocalWeekNumber(dateType);
 318      var w = this.getLocalDay(dateType);
 319      var s = {};
 320      var hr = this.getHours();
 321      var pm = (hr >= 12);
 322      var ir = (pm) ? (hr - 12) : hr;
 323      var dy = this.getLocalDayOfYear(dateType);
 324      if (ir == 0)
 325          ir = 12;
 326      var min = this.getMinutes();
 327      var sec = this.getSeconds();
 328      s["%a"] = localStrings.shortDays[w];                                                        // abbreviated weekday name
 329      s["%A"] = localStrings.days[w];                                                             // full weekday name
 330      s["%b"] = localStrings.shortMonths[m];                                                      // abbreviated month name
 331      s["%B"] = localStrings.months[m];                                                           // full month name
 332      // FIXME: %c : preferred date and time representation for the current locale
 333      s["%C"] = 1 + Math.floor(y / 100);                                                          // the century number
 334      s["%d"] = (d < 10) ? ("0" + d) : d;                                                         // the day of the month (range 01 to 31)
 335      s["%e"] = d;                                                                                // the day of the month (range 1 to 31)
 336      // FIXME: %D : american date style: %m/%d/%y
 337      // FIXME: %E, %F, %G, %g, %h (man strftime)
 338      s["%H"] = (hr < 10) ? ("0" + hr) : hr;                                                      // hour, range 00 to 23 (24h format)
 339      s["%I"] = (ir < 10) ? ("0" + ir) : ir;                                                      // hour, range 01 to 12 (12h format)
 340      s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy;                         // day of the year (range 001 to 366)
 341      s["%k"] = hr;                                                                               // hour, range 0 to 23 (24h format)
 342      s["%l"] = ir;                                                                               // hour, range 1 to 12 (12h format)
 343      s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m);                                                  // month, range 01 to 12
 344      s["%M"] = (min < 10) ? ("0" + min) : min;                                                   // minute, range 00 to 59
 345      s["%n"] = "\n";                                                                             // a newline character
 346      s["%p"] = pm ? localStrings.pm.toUpperCase() : localStrings.am.toUpperCase();
 347      s["%P"] = pm ? localStrings.pm : localStrings.am;
 348      // FIXME: %r : the time in am/pm notation %I:%M:%S %p
 349      // FIXME: %R : the time in 24-hour notation %H:%M
 350      s["%s"] = Math.floor(this.getTime() / 1000);
 351      s["%S"] = (sec < 10) ? ("0" + sec) : sec;                                                   // seconds, range 00 to 59
 352      s["%t"] = "\t";                                                                             // a tab character
 353      // FIXME: %T : the time in 24-hour notation (%H:%M:%S)
 354      s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
 355      s["%u"] = w + 1;                                                                            // the day of the week (range 1 to 7, 1 = MON)
 356      s["%w"] = w;                                                                                // the day of the week (range 0 to 6, 0 = SUN)
 357      // FIXME: %x : preferred date representation for the current locale without the time
 358      // FIXME: %X : preferred time representation for the current locale without the date
 359      s["%y"] = ('' + y).substr(2, 2);                                                            // year without the century (range 00 to 99)
 360      s["%Y"] = y;                                                                                // year with the century
 361      s["%%"] = "%";                                                                              // a literal '%' character
 362  
 363      var re = /%./g;
 364  
 365      var tmpDate = str.replace(re, function (par) { return s[par] || par; });
 366      if (translate) {
 367          tmpDate = Date.convertNumbers(tmpDate);
 368      }
 369  
 370      return tmpDate;
 371  };
 372  
 373  Date.parseFieldDate = function(str, fmt, dateType, localStrings) {
 374      str = Date.numbersToIso(str);
 375  
 376      var today = new Date();
 377      var y = 0;
 378      var m = -1;
 379      var d = 0;
 380      var a = str.split(/\W+/);
 381      var b = fmt.match(/%./g);
 382      var i = 0, j = 0;
 383      var hr = 0;
 384      var min = 0;
 385      var sec = 0;
 386      for (i = 0; i < a.length; ++i) {
 387          if (!a[i])
 388              continue;
 389          switch (b[i]) {
 390              case "%d":
 391              case "%e":
 392                  d = parseInt(a[i], 10);
 393                  break;
 394  
 395              case "%m":
 396                  m = parseInt(a[i], 10) - 1;
 397                  break;
 398  
 399              case "%Y":
 400              case "%y":
 401                  y = parseInt(a[i], 10);
 402                  (y < 100) && (y += (y > 29) ? 1900 : 2000);
 403                  break;
 404  
 405              case "%b":
 406              case "%B":
 407                  for (j = 0; j < 12; ++j) {
 408                      if (localStrings.months[j].substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { m = j; break; }
 409                  }
 410                  break;
 411  
 412              case "%H":
 413              case "%I":
 414              case "%k":
 415              case "%l":
 416                  hr = parseInt(a[i], 10);
 417                  break;
 418  
 419              case "%P":
 420              case "%p":
 421                  if (/pm/i.test(a[i]) && hr < 12)
 422                      hr += 12;
 423                  else if (/am/i.test(a[i]) && hr >= 12)
 424                      hr -= 12;
 425                  break;
 426  
 427              case "%M":
 428                  min = parseInt(a[i], 10);
 429                  break;
 430              case "%S":
 431                  sec = parseInt(a[i], 10);
 432                  break;
 433          }
 434      }
 435      if (isNaN(y)) y = today.getFullYear();
 436      if (isNaN(m)) m = today.getMonth();
 437      if (isNaN(d)) d = today.getDate();
 438      if (isNaN(hr)) hr = today.getHours();
 439      if (isNaN(min)) min = today.getMinutes();
 440      if (y != 0 && m != -1 && d != 0)
 441          return new Date(y, m, d, hr, min, 0);
 442      y = 0; m = -1; d = 0;
 443      for (i = 0; i < a.length; ++i) {
 444          if (a[i].search(/[a-zA-Z]+/) != -1) {
 445              var t = -1;
 446              for (j = 0; j < 12; ++j) {
 447                  if (localStrings.months[j].substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { t = j; break; }
 448              }
 449              if (t != -1) {
 450                  if (m != -1) {
 451                      d = m+1;
 452                  }
 453                  m = t;
 454              }
 455          } else if (parseInt(a[i], 10) <= 12 && m == -1) {
 456              m = a[i]-1;
 457          } else if (parseInt(a[i], 10) > 31 && y == 0) {
 458              y = parseInt(a[i], 10);
 459              (y < 100) && (y += (y > 29) ? 1900 : 2000);
 460          } else if (d == 0) {
 461              d = a[i];
 462          }
 463      }
 464      if (y == 0)
 465          y = today.getFullYear();
 466      if (m != -1 && d != 0)
 467          return new Date(y, m, d, hr, min, 0);
 468      return today;
 469  };
 470  
 471  /*
 472   * JalaliJSCalendar - Jalali Extension for Date Object
 473   * Copyright (c) 2008 Ali Farhadi (http://farhadi.ir/)
 474   * Released under the terms of the GNU General Public License.
 475   * See the GPL for details (http://www.gnu.org/licenses/gpl.html).
 476   *
 477   * Based on code from http://farsiweb.info
 478   */
 479  
 480  var JalaliDate = {
 481      g_days_in_month: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
 482      j_days_in_month: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
 483  };
 484  
 485  JalaliDate.jalaliToGregorian = function(j_y, j_m, j_d)
 486  {
 487      j_y = parseInt(j_y);
 488      j_m = parseInt(j_m);
 489      j_d = parseInt(j_d);
 490      var jy = j_y-979;
 491      var jm = j_m-1;
 492      var jd = j_d-1;
 493  
 494      var j_day_no = 365*jy + parseInt(jy / 33)*8 + parseInt((jy%33+3) / 4);
 495      for (var i=0; i < jm; ++i) j_day_no += JalaliDate.j_days_in_month[i];
 496  
 497      j_day_no += jd;
 498  
 499      var g_day_no = j_day_no+79;
 500  
 501      var gy = 1600 + 400 * parseInt(g_day_no / 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
 502      g_day_no = g_day_no % 146097;
 503  
 504      var leap = true;
 505      if (g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */
 506      {
 507          g_day_no--;
 508          gy += 100*parseInt(g_day_no/  36524); /* 36524 = 365*100 + 100/4 - 100/100 */
 509          g_day_no = g_day_no % 36524;
 510  
 511          if (g_day_no >= 365)
 512              g_day_no++;
 513          else
 514              leap = false;
 515      }
 516  
 517      gy += 4*parseInt(g_day_no/ 1461); /* 1461 = 365*4 + 4/4 */
 518      g_day_no %= 1461;
 519  
 520      if (g_day_no >= 366) {
 521          leap = false;
 522  
 523          g_day_no--;
 524          gy += parseInt(g_day_no/ 365);
 525          g_day_no = g_day_no % 365;
 526      }
 527  
 528      for (var i = 0; g_day_no >= JalaliDate.g_days_in_month[i] + (i == 1 && leap); i++)
 529          g_day_no -= JalaliDate.g_days_in_month[i] + (i == 1 && leap);
 530      var gm = i+1;
 531      var gd = g_day_no+1;
 532  
 533      return [gy, gm, gd];
 534  };
 535  
 536  JalaliDate.checkDate = function(j_y, j_m, j_d)
 537  {
 538      return !(j_y < 0 || j_y > 32767 || j_m < 1 || j_m > 12 || j_d < 1 || j_d >
 539      (JalaliDate.j_days_in_month[j_m-1] + (j_m == 12 && !((j_y-979)%33%4))));
 540  };
 541  
 542  JalaliDate.gregorianToJalali = function(g_y, g_m, g_d)
 543  {
 544      g_y = parseInt(g_y);
 545      g_m = parseInt(g_m);
 546      g_d = parseInt(g_d);
 547      var gy = g_y-1600;
 548      var gm = g_m-1;
 549      var gd = g_d-1;
 550  
 551      var g_day_no = 365*gy+parseInt((gy+3) / 4)-parseInt((gy+99)/100)+parseInt((gy+399)/400);
 552  
 553      for (var i=0; i < gm; ++i)
 554          g_day_no += JalaliDate.g_days_in_month[i];
 555      if (gm>1 && ((gy%4==0 && gy%100!=0) || (gy%400==0)))
 556      /* leap and after Feb */
 557          ++g_day_no;
 558      g_day_no += gd;
 559  
 560      var j_day_no = g_day_no-79;
 561  
 562      var j_np = parseInt(j_day_no/ 12053);
 563      j_day_no %= 12053;
 564  
 565      var jy = 979+33*j_np+4*parseInt(j_day_no/1461);
 566  
 567      j_day_no %= 1461;
 568  
 569      if (j_day_no >= 366) {
 570          jy += parseInt((j_day_no-1)/ 365);
 571          j_day_no = (j_day_no-1)%365;
 572      }
 573  
 574      for (var i = 0; i < 11 && j_day_no >= JalaliDate.j_days_in_month[i]; ++i) {
 575          j_day_no -= JalaliDate.j_days_in_month[i];
 576      }
 577      var jm = i+1;
 578      var jd = j_day_no+1;
 579  
 580  
 581      return [jy, jm, jd];
 582  };
 583  
 584  Date.prototype.setJalaliFullYear = function(y, m, d) {
 585      var gd = this.getDate();
 586      var gm = this.getMonth();
 587      var gy = this.getFullYear();
 588      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 589      if (y < 100) y += 1300;
 590      j[0] = y;
 591      if (m != undefined) {
 592          if (m > 11) {
 593              j[0] += Math.floor(m / 12);
 594              m = m % 12;
 595          }
 596          j[1] = m + 1;
 597      }
 598      if (d != undefined) j[2] = d;
 599      var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
 600      return this.setFullYear(g[0], g[1]-1, g[2]);
 601  };
 602  
 603  Date.prototype.setJalaliMonth = function(m, d) {
 604      var gd = this.getDate();
 605      var gm = this.getMonth();
 606      var gy = this.getFullYear();
 607      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 608      if (m > 11) {
 609          j[0] += Math.floor(m / 12);
 610          m = m % 12;
 611      }
 612      j[1] = m+1;
 613      if (d != undefined) j[2] = d;
 614      var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
 615      return this.setFullYear(g[0], g[1]-1, g[2]);
 616  };
 617  
 618  Date.prototype.setJalaliDate = function(d) {
 619      var gd = this.getDate();
 620      var gm = this.getMonth();
 621      var gy = this.getFullYear();
 622      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 623      j[2] = d;
 624      var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
 625      return this.setFullYear(g[0], g[1]-1, g[2]);
 626  };
 627  
 628  Date.prototype.getJalaliFullYear = function() {
 629      var gd = this.getDate();
 630      var gm = this.getMonth();
 631      var gy = this.getFullYear();
 632      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 633      return j[0];
 634  };
 635  
 636  Date.prototype.getJalaliMonth = function() {
 637      var gd = this.getDate();
 638      var gm = this.getMonth();
 639      var gy = this.getFullYear();
 640      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 641      return j[1]-1;
 642  };
 643  
 644  Date.prototype.getJalaliDate = function() {
 645      var gd = this.getDate();
 646      var gm = this.getMonth();
 647      var gy = this.getFullYear();
 648      var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
 649      return j[2];
 650  };
 651  
 652  Date.prototype.getJalaliDay = function() {
 653      var day = this.getDay();
 654      day = (day) % 7;
 655      return day;
 656  };
 657  
 658  })(Date);


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer