- Timestamp:
- 09/03/12 18:05:54 (12 years ago)
- Location:
- branches/2.4/prototype
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4/prototype/modules/calendar/templates/preferences_calendar.ejs
r6933 r7151 23 23 <label for="hourFormat">Formato de hora:</label> 24 24 <select name="hourFormat" > 25 <option value="HH:mm" <%= data.preferences.hourFormat =='HH:mm' ? 'selected="selected"':'' %>> 13:00</option>26 <option value="hh:mm tt" <%= data.preferences.hourFormat =='hh:mm tt' ? 'selected="selected"':'' %>>01:00pm</option> 25 <option value="HH:mm" <%= data.preferences.hourFormat =='HH:mm' ? 'selected="selected"':'' %>>24 horas</option> 26 <option value="hh:mm tt" <%= data.preferences.hourFormat =='hh:mm tt' ? 'selected="selected"':'' %>>12 horas (am/pm)</option> 27 27 </select> 28 28 </p> -
branches/2.4/prototype/plugins/datejs/core-debug.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 12-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-04-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 9 /** 10 * Gets the month number (0-11) if given a Culture Info specific string which is a valid monthName or abbreviatedMonthName. 11 * @param {String} The name of the month (eg. "February, "Feb", "october", "oct"). 12 * @return {Number} The day number 13 */ 14 Date.getMonthNumberFromName = function (name) { 15 var n = Date.CultureInfo.monthNames, m = Date.CultureInfo.abbreviatedMonthNames, s = name.toLowerCase(); 16 for (var i = 0; i < n.length; i++) { 17 if (n[i].toLowerCase() == s || m[i].toLowerCase() == s) { 18 return i; 19 } 9 10 (function () { 11 var $D = Date, 12 $P = $D.prototype, 13 $C = $D.CultureInfo, 14 p = function (s, l) { 15 if (!l) { 16 l = 2; 17 } 18 return ("000" + s).slice(l * -1); 19 }; 20 21 /** 22 * Resets the time of this Date object to 12:00 AM (00:00), which is the start of the day. 23 * @param {Boolean} .clone() this date instance before clearing Time 24 * @return {Date} this 25 */ 26 $P.clearTime = function () { 27 this.setHours(0); 28 this.setMinutes(0); 29 this.setSeconds(0); 30 this.setMilliseconds(0); 31 return this; 32 }; 33 34 /** 35 * Resets the time of this Date object to the current time ('now'). 36 * @return {Date} this 37 */ 38 $P.setTimeToNow = function () { 39 var n = new Date(); 40 this.setHours(n.getHours()); 41 this.setMinutes(n.getMinutes()); 42 this.setSeconds(n.getSeconds()); 43 this.setMilliseconds(n.getMilliseconds()); 44 return this; 45 }; 46 47 /** 48 * Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM). 49 * @return {Date} The current date. 50 */ 51 $D.today = function () { 52 return new Date().clearTime(); 53 }; 54 55 /** 56 * Compares the first date to the second date and returns an number indication of their relative values. 57 * @param {Date} First Date object to compare [Required]. 58 * @param {Date} Second Date object to compare to [Required]. 59 * @return {Number} -1 = date1 is lessthan date2. 0 = values are equal. 1 = date1 is greaterthan date2. 60 */ 61 $D.compare = function (date1, date2) { 62 if (isNaN(date1) || isNaN(date2)) { 63 throw new Error(date1 + " - " + date2); 64 } else if (date1 instanceof Date && date2 instanceof Date) { 65 return (date1 < date2) ? -1 : (date1 > date2) ? 1 : 0; 66 } else { 67 throw new TypeError(date1 + " - " + date2); 68 } 69 }; 70 71 /** 72 * Compares the first Date object to the second Date object and returns true if they are equal. 73 * @param {Date} First Date object to compare [Required] 74 * @param {Date} Second Date object to compare to [Required] 75 * @return {Boolean} true if dates are equal. false if they are not equal. 76 */ 77 $D.equals = function (date1, date2) { 78 return (date1.compareTo(date2) === 0); 79 }; 80 81 /** 82 * Gets the day number (0-6) if given a CultureInfo specific string which is a valid dayName, abbreviatedDayName or shortestDayName (two char). 83 * @param {String} The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we"). 84 * @return {Number} The day number 85 */ 86 $D.getDayNumberFromName = function (name) { 87 var n = $C.dayNames, m = $C.abbreviatedDayNames, o = $C.shortestDayNames, s = name.toLowerCase(); 88 for (var i = 0; i < n.length; i++) { 89 if (n[i].toLowerCase() == s || m[i].toLowerCase() == s || o[i].toLowerCase() == s) { 90 return i; 91 } 92 } 93 return -1; 94 }; 95 96 /** 97 * Gets the month number (0-11) if given a Culture Info specific string which is a valid monthName or abbreviatedMonthName. 98 * @param {String} The name of the month (eg. "February, "Feb", "october", "oct"). 99 * @return {Number} The day number 100 */ 101 $D.getMonthNumberFromName = function (name) { 102 var n = $C.monthNames, m = $C.abbreviatedMonthNames, s = name.toLowerCase(); 103 for (var i = 0; i < n.length; i++) { 104 if (n[i].toLowerCase() == s || m[i].toLowerCase() == s) { 105 return i; 106 } 107 } 108 return -1; 109 }; 110 111 /** 112 * Determines if the current date instance is within a LeapYear. 113 * @param {Number} The year. 114 * @return {Boolean} true if date is within a LeapYear, otherwise false. 115 */ 116 $D.isLeapYear = function (year) { 117 return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0); 118 }; 119 120 /** 121 * Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear. 122 * @param {Number} The year. 123 * @param {Number} The month (0-11). 124 * @return {Number} The number of days in the month. 125 */ 126 $D.getDaysInMonth = function (year, month) { 127 return [31, ($D.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; 128 }; 129 130 $D.getTimezoneAbbreviation = function (offset) { 131 var z = $C.timezones, p; 132 for (var i = 0; i < z.length; i++) { 133 if (z[i].offset === offset) { 134 return z[i].name; 135 } 136 } 137 return null; 138 }; 139 140 $D.getTimezoneOffset = function (name) { 141 var z = $C.timezones, p; 142 for (var i = 0; i < z.length; i++) { 143 if (z[i].name === name.toUpperCase()) { 144 return z[i].offset; 145 } 146 } 147 return null; 148 }; 149 150 /** 151 * Returns a new Date object that is an exact date and time copy of the original instance. 152 * @return {Date} A new Date instance 153 */ 154 $P.clone = function () { 155 return new Date(this.getTime()); 156 }; 157 158 /** 159 * Compares this instance to a Date object and returns an number indication of their relative values. 160 * @param {Date} Date object to compare [Required] 161 * @return {Number} -1 = this is lessthan date. 0 = values are equal. 1 = this is greaterthan date. 162 */ 163 $P.compareTo = function (date) { 164 return Date.compare(this, date); 165 }; 166 167 /** 168 * Compares this instance to another Date object and returns true if they are equal. 169 * @param {Date} Date object to compare. If no date to compare, new Date() [now] is used. 170 * @return {Boolean} true if dates are equal. false if they are not equal. 171 */ 172 $P.equals = function (date) { 173 return Date.equals(this, date || new Date()); 174 }; 175 176 /** 177 * Determines if this instance is between a range of two dates or equal to either the start or end dates. 178 * @param {Date} Start of range [Required] 179 * @param {Date} End of range [Required] 180 * @return {Boolean} true is this is between or equal to the start and end dates, else false 181 */ 182 $P.between = function (start, end) { 183 return this.getTime() >= start.getTime() && this.getTime() <= end.getTime(); 184 }; 185 186 /** 187 * Determines if this date occurs after the date to compare to. 188 * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used. 189 * @return {Boolean} true if this date instance is greater than the date to compare to (or "now"), otherwise false. 190 */ 191 $P.isAfter = function (date) { 192 return this.compareTo(date || new Date()) === 1; 193 }; 194 195 /** 196 * Determines if this date occurs before the date to compare to. 197 * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used. 198 * @return {Boolean} true if this date instance is less than the date to compare to (or "now"). 199 */ 200 $P.isBefore = function (date) { 201 return (this.compareTo(date || new Date()) === -1); 202 }; 203 204 /** 205 * Determines if the current Date instance occurs today. 206 * @return {Boolean} true if this date instance is 'today', otherwise false. 207 */ 208 209 /** 210 * Determines if the current Date instance occurs on the same Date as the supplied 'date'. 211 * If no 'date' to compare to is provided, the current Date instance is compared to 'today'. 212 * @param {date} Date object to compare. If no date to compare, the current Date ("now") is used. 213 * @return {Boolean} true if this Date instance occurs on the same Day as the supplied 'date'. 214 */ 215 $P.isToday = $P.isSameDay = function (date) { 216 return this.clone().clearTime().equals((date || new Date()).clone().clearTime()); 217 }; 218 219 /** 220 * Adds the specified number of milliseconds to this instance. 221 * @param {Number} The number of milliseconds to add. The number can be positive or negative [Required] 222 * @return {Date} this 223 */ 224 $P.addMilliseconds = function (value) { 225 this.setMilliseconds(this.getMilliseconds() + value * 1); 226 return this; 227 }; 228 229 /** 230 * Adds the specified number of seconds to this instance. 231 * @param {Number} The number of seconds to add. The number can be positive or negative [Required] 232 * @return {Date} this 233 */ 234 $P.addSeconds = function (value) { 235 return this.addMilliseconds(value * 1000); 236 }; 237 238 /** 239 * Adds the specified number of seconds to this instance. 240 * @param {Number} The number of seconds to add. The number can be positive or negative [Required] 241 * @return {Date} this 242 */ 243 $P.addMinutes = function (value) { 244 return this.addMilliseconds(value * 60000); /* 60*1000 */ 245 }; 246 247 /** 248 * Adds the specified number of hours to this instance. 249 * @param {Number} The number of hours to add. The number can be positive or negative [Required] 250 * @return {Date} this 251 */ 252 $P.addHours = function (value) { 253 return this.addMilliseconds(value * 3600000); /* 60*60*1000 */ 254 }; 255 256 /** 257 * Adds the specified number of days to this instance. 258 * @param {Number} The number of days to add. The number can be positive or negative [Required] 259 * @return {Date} this 260 */ 261 $P.addDays = function (value) { 262 this.setDate(this.getDate() + value * 1); 263 return this; 264 }; 265 266 /** 267 * Adds the specified number of weeks to this instance. 268 * @param {Number} The number of weeks to add. The number can be positive or negative [Required] 269 * @return {Date} this 270 */ 271 $P.addWeeks = function (value) { 272 return this.addDays(value * 7); 273 }; 274 275 /** 276 * Adds the specified number of months to this instance. 277 * @param {Number} The number of months to add. The number can be positive or negative [Required] 278 * @return {Date} this 279 */ 280 $P.addMonths = function (value) { 281 var n = this.getDate(); 282 this.setDate(1); 283 this.setMonth(this.getMonth() + value * 1); 284 this.setDate(Math.min(n, $D.getDaysInMonth(this.getFullYear(), this.getMonth()))); 285 return this; 286 }; 287 288 /** 289 * Adds the specified number of years to this instance. 290 * @param {Number} The number of years to add. The number can be positive or negative [Required] 291 * @return {Date} this 292 */ 293 $P.addYears = function (value) { 294 return this.addMonths(value * 12); 295 }; 296 297 /** 298 * Adds (or subtracts) to the value of the years, months, weeks, days, hours, minutes, seconds, milliseconds of the date instance using given configuration object. Positive and Negative values allowed. 299 * Example 300 <pre><code> 301 Date.today().add( { days: 1, months: 1 } ) 302 303 new Date().add( { years: -1 } ) 304 </code></pre> 305 * @param {Object} Configuration object containing attributes (months, days, etc.) 306 * @return {Date} this 307 */ 308 $P.add = function (config) { 309 if (typeof config == "number") { 310 this._orient = config; 311 return this; 312 } 313 314 var x = config; 315 316 if (x.milliseconds) { 317 this.addMilliseconds(x.milliseconds); 318 } 319 if (x.seconds) { 320 this.addSeconds(x.seconds); 321 } 322 if (x.minutes) { 323 this.addMinutes(x.minutes); 324 } 325 if (x.hours) { 326 this.addHours(x.hours); 327 } 328 if (x.weeks) { 329 this.addWeeks(x.weeks); 330 } 331 if (x.months) { 332 this.addMonths(x.months); 333 } 334 if (x.years) { 335 this.addYears(x.years); 336 } 337 if (x.days) { 338 this.addDays(x.days); 339 } 340 return this; 341 }; 342 343 var $y, $m, $d; 344 345 /** 346 * Get the week number. Week one (1) is the week which contains the first Thursday of the year. Monday is considered the first day of the week. 347 * This algorithm is a JavaScript port of the work presented by Claus Tøndering at http://www.tondering.dk/claus/cal/node8.html#SECTION00880000000000000000 348 * .getWeek() Algorithm Copyright (c) 2008 Claus Tondering. 349 * The .getWeek() function does NOT convert the date to UTC. The local datetime is used. Please use .getISOWeek() to get the week of the UTC converted date. 350 * @return {Number} 1 to 53 351 */ 352 $P.getWeek = function () { 353 var a, b, c, d, e, f, g, n, s, w; 354 355 $y = (!$y) ? this.getFullYear() : $y; 356 $m = (!$m) ? this.getMonth() + 1 : $m; 357 $d = (!$d) ? this.getDate() : $d; 358 359 if ($m <= 2) { 360 a = $y - 1; 361 b = (a / 4 | 0) - (a / 100 | 0) + (a / 400 | 0); 362 c = ((a - 1) / 4 | 0) - ((a - 1) / 100 | 0) + ((a - 1) / 400 | 0); 363 s = b - c; 364 e = 0; 365 f = $d - 1 + (31 * ($m - 1)); 366 } else { 367 a = $y; 368 b = (a / 4 | 0) - (a / 100 | 0) + (a / 400 | 0); 369 c = ((a - 1) / 4 | 0) - ((a - 1) / 100 | 0) + ((a - 1) / 400 | 0); 370 s = b - c; 371 e = s + 1; 372 f = $d + ((153 * ($m - 3) + 2) / 5) + 58 + s; 373 } 374 375 g = (a + b) % 7; 376 d = (f + g - e) % 7; 377 n = (f + 3 - d) | 0; 378 379 if (n < 0) { 380 w = 53 - ((g - s) / 5 | 0); 381 } else if (n > 364 + s) { 382 w = 1; 383 } else { 384 w = (n / 7 | 0) + 1; 385 } 386 387 $y = $m = $d = null; 388 389 return w; 390 }; 391 392 /** 393 * Get the ISO 8601 week number. Week one ("01") is the week which contains the first Thursday of the year. Monday is considered the first day of the week. 394 * The .getISOWeek() function does convert the date to it's UTC value. Please use .getWeek() to get the week of the local date. 395 * @return {String} "01" to "53" 396 */ 397 $P.getISOWeek = function () { 398 $y = this.getUTCFullYear(); 399 $m = this.getUTCMonth() + 1; 400 $d = this.getUTCDate(); 401 return p(this.getWeek()); 402 }; 403 404 /** 405 * Moves the date to Monday of the week set. Week one (1) is the week which contains the first Thursday of the year. 406 * @param {Number} A Number (1 to 53) that represents the week of the year. 407 * @return {Date} this 408 */ 409 $P.setWeek = function (n) { 410 return this.moveToDayOfWeek(1).addWeeks(n - this.getWeek()); 411 }; 412 413 // private 414 var validate = function (n, min, max, name) { 415 if (typeof n == "undefined") { 416 return false; 417 } else if (typeof n != "number") { 418 throw new TypeError(n + " is not a Number."); 419 } else if (n < min || n > max) { 420 throw new RangeError(n + " is not a valid value for " + name + "."); 421 } 422 return true; 423 }; 424 425 /** 426 * Validates the number is within an acceptable range for milliseconds [0-999]. 427 * @param {Number} The number to check if within range. 428 * @return {Boolean} true if within range, otherwise false. 429 */ 430 $D.validateMillisecond = function (value) { 431 return validate(value, 0, 999, "millisecond"); 432 }; 433 434 /** 435 * Validates the number is within an acceptable range for seconds [0-59]. 436 * @param {Number} The number to check if within range. 437 * @return {Boolean} true if within range, otherwise false. 438 */ 439 $D.validateSecond = function (value) { 440 return validate(value, 0, 59, "second"); 441 }; 442 443 /** 444 * Validates the number is within an acceptable range for minutes [0-59]. 445 * @param {Number} The number to check if within range. 446 * @return {Boolean} true if within range, otherwise false. 447 */ 448 $D.validateMinute = function (value) { 449 return validate(value, 0, 59, "minute"); 450 }; 451 452 /** 453 * Validates the number is within an acceptable range for hours [0-23]. 454 * @param {Number} The number to check if within range. 455 * @return {Boolean} true if within range, otherwise false. 456 */ 457 $D.validateHour = function (value) { 458 return validate(value, 0, 23, "hour"); 459 }; 460 461 /** 462 * Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth]. 463 * @param {Number} The number to check if within range. 464 * @return {Boolean} true if within range, otherwise false. 465 */ 466 $D.validateDay = function (value, year, month) { 467 return validate(value, 1, $D.getDaysInMonth(year, month), "day"); 468 }; 469 470 /** 471 * Validates the number is within an acceptable range for months [0-11]. 472 * @param {Number} The number to check if within range. 473 * @return {Boolean} true if within range, otherwise false. 474 */ 475 $D.validateMonth = function (value) { 476 return validate(value, 0, 11, "month"); 477 }; 478 479 /** 480 * Validates the number is within an acceptable range for years. 481 * @param {Number} The number to check if within range. 482 * @return {Boolean} true if within range, otherwise false. 483 */ 484 $D.validateYear = function (value) { 485 return validate(value, 0, 9999, "year"); 486 }; 487 488 /** 489 * Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object. 490 * Example 491 <pre><code> 492 Date.today().set( { day: 20, month: 1 } ) 493 494 new Date().set( { millisecond: 0 } ) 495 </code></pre> 496 * 497 * @param {Object} Configuration object containing attributes (month, day, etc.) 498 * @return {Date} this 499 */ 500 $P.set = function (config) { 501 if ($D.validateMillisecond(config.millisecond)) { 502 this.addMilliseconds(config.millisecond - this.getMilliseconds()); 503 } 504 505 if ($D.validateSecond(config.second)) { 506 this.addSeconds(config.second - this.getSeconds()); 507 } 508 509 if ($D.validateMinute(config.minute)) { 510 this.addMinutes(config.minute - this.getMinutes()); 511 } 512 513 if ($D.validateHour(config.hour)) { 514 this.addHours(config.hour - this.getHours()); 515 } 516 517 if ($D.validateMonth(config.month)) { 518 this.addMonths(config.month - this.getMonth()); 519 } 520 521 if ($D.validateYear(config.year)) { 522 this.addYears(config.year - this.getFullYear()); 523 } 524 525 /* day has to go last because you can't validate the day without first knowing the month */ 526 if ($D.validateDay(config.day, this.getFullYear(), this.getMonth())) { 527 this.addDays(config.day - this.getDate()); 528 } 529 530 if (config.timezone) { 531 this.setTimezone(config.timezone); 532 } 533 534 if (config.timezoneOffset) { 535 this.setTimezoneOffset(config.timezoneOffset); 536 } 537 538 if (config.week && validate(config.week, 0, 53, "week")) { 539 this.setWeek(config.week); 540 } 541 542 return this; 543 }; 544 545 /** 546 * Moves the date to the first day of the month. 547 * @return {Date} this 548 */ 549 $P.moveToFirstDayOfMonth = function () { 550 return this.set({ day: 1 }); 551 }; 552 553 /** 554 * Moves the date to the last day of the month. 555 * @return {Date} this 556 */ 557 $P.moveToLastDayOfMonth = function () { 558 return this.set({ day: $D.getDaysInMonth(this.getFullYear(), this.getMonth())}); 559 }; 560 561 /** 562 * Moves the date to the next n'th occurrence of the dayOfWeek starting from the beginning of the month. The number (-1) is a magic number and will return the last occurrence of the dayOfWeek in the month. 563 * @param {Number} The dayOfWeek to move to 564 * @param {Number} The n'th occurrence to move to. Use (-1) to return the last occurrence in the month 565 * @return {Date} this 566 */ 567 $P.moveToNthOccurrence = function (dayOfWeek, occurrence) { 568 var shift = 0; 569 if (occurrence > 0) { 570 shift = occurrence - 1; 571 } 572 else if (occurrence === -1) { 573 this.moveToLastDayOfMonth(); 574 if (this.getDay() !== dayOfWeek) { 575 this.moveToDayOfWeek(dayOfWeek, -1); 576 } 577 return this; 578 } 579 return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek, +1).addWeeks(shift); 580 }; 581 582 /** 583 * Move to the next or last dayOfWeek based on the orient value. 584 * @param {Number} The dayOfWeek to move to 585 * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional] 586 * @return {Date} this 587 */ 588 $P.moveToDayOfWeek = function (dayOfWeek, orient) { 589 var diff = (dayOfWeek - this.getDay() + 7 * (orient || +1)) % 7; 590 return this.addDays((diff === 0) ? diff += 7 * (orient || +1) : diff); 591 }; 592 593 /** 594 * Move to the next or last month based on the orient value. 595 * @param {Number} The month to move to. 0 = January, 11 = December 596 * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional] 597 * @return {Date} this 598 */ 599 $P.moveToMonth = function (month, orient) { 600 var diff = (month - this.getMonth() + 12 * (orient || +1)) % 12; 601 return this.addMonths((diff === 0) ? diff += 12 * (orient || +1) : diff); 602 }; 603 604 /** 605 * Get the Ordinal day (numeric day number) of the year, adjusted for leap year. 606 * @return {Number} 1 through 365 (366 in leap years) 607 */ 608 $P.getOrdinalNumber = function () { 609 return Math.ceil((this.clone().clearTime() - new Date(this.getFullYear(), 0, 1)) / 86400000) + 1; 610 }; 611 612 /** 613 * Get the time zone abbreviation of the current date. 614 * @return {String} The abbreviated time zone name (e.g. "EST") 615 */ 616 $P.getTimezone = function () { 617 return $D.getTimezoneAbbreviation(this.getUTCOffset()); 618 }; 619 620 $P.setTimezoneOffset = function (offset) { 621 var here = this.getTimezoneOffset(), there = Number(offset) * -6 / 10; 622 return this.addMinutes(there - here); 623 }; 624 625 $P.setTimezone = function (offset) { 626 return this.setTimezoneOffset($D.getTimezoneOffset(offset)); 627 }; 628 629 /** 630 * Indicates whether Daylight Saving Time is observed in the current time zone. 631 * @return {Boolean} true|false 632 */ 633 $P.hasDaylightSavingTime = function () { 634 return (Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== Date.today().set({month: 6, day: 1}).getTimezoneOffset()); 635 }; 636 637 /** 638 * Indicates whether this Date instance is within the Daylight Saving Time range for the current time zone. 639 * @return {Boolean} true|false 640 */ 641 $P.isDaylightSavingTime = function () { 642 return Date.today().set({month: 0, day: 1}).getTimezoneOffset() != this.getTimezoneOffset(); 643 }; 644 645 /** 646 * Get the offset from UTC of the current date. 647 * @return {String} The 4-character offset string prefixed with + or - (e.g. "-0500") 648 */ 649 $P.getUTCOffset = function () { 650 var n = this.getTimezoneOffset() * -10 / 6, r; 651 if (n < 0) { 652 r = (n - 10000).toString(); 653 return r.charAt(0) + r.substr(2); 654 } else { 655 r = (n + 10000).toString(); 656 return "+" + r.substr(1); 657 } 658 }; 659 660 /** 661 * Returns the number of milliseconds between this date and date. 662 * @param {Date} Defaults to now 663 * @return {Number} The diff in milliseconds 664 */ 665 $P.getElapsed = function (date) { 666 return (date || new Date()) - this; 667 }; 668 669 if (!$P.toISOString) { 670 /** 671 * Converts the current date instance into a string with an ISO 8601 format. The date is converted to it's UTC value. 672 * @return {String} ISO 8601 string of date 673 */ 674 $P.toISOString = function () { 675 // From http://www.json.org/json.js. Public Domain. 676 function f(n) { 677 return n < 10 ? '0' + n : n; 678 } 679 680 return '"' + this.getUTCFullYear() + '-' + 681 f(this.getUTCMonth() + 1) + '-' + 682 f(this.getUTCDate()) + 'T' + 683 f(this.getUTCHours()) + ':' + 684 f(this.getUTCMinutes()) + ':' + 685 f(this.getUTCSeconds()) + 'Z"'; 686 }; 20 687 } 21 return -1; 22 }; 23 24 /** 25 * Gets the day number (0-6) if given a CultureInfo specific string which is a valid dayName, abbreviatedDayName or shortestDayName (two char). 26 * @param {String} The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we"). 27 * @return {Number} The day number 28 */ 29 Date.getDayNumberFromName = function (name) { 30 var n = Date.CultureInfo.dayNames, m = Date.CultureInfo.abbreviatedDayNames, o = Date.CultureInfo.shortestDayNames, s = name.toLowerCase(); 31 for (var i = 0; i < n.length; i++) { 32 if (n[i].toLowerCase() == s || m[i].toLowerCase() == s) { 33 return i; 34 } 35 } 36 return -1; 37 }; 38 39 /** 40 * Determines if the current date instance is within a LeapYear. 41 * @param {Number} The year (0-9999). 42 * @return {Boolean} true if date is within a LeapYear, otherwise false. 43 */ 44 Date.isLeapYear = function (year) { 45 return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)); 46 }; 47 48 /** 49 * Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear. 50 * @param {Number} The year (0-9999). 51 * @param {Number} The month (0-11). 52 * @return {Number} The number of days in the month. 53 */ 54 Date.getDaysInMonth = function (year, month) { 55 return [31, (Date.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; 56 }; 57 58 Date.getTimezoneOffset = function (s, dst) { 59 return (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST[s.toUpperCase()] : 60 Date.CultureInfo.abbreviatedTimeZoneStandard[s.toUpperCase()]; 61 }; 62 63 Date.getTimezoneAbbreviation = function (offset, dst) { 64 var n = (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST : Date.CultureInfo.abbreviatedTimeZoneStandard, p; 65 for (p in n) { 66 if (n[p] === offset) { 67 return p; 68 } 69 } 70 return null; 71 }; 72 73 /** 74 * Returns a new Date object that is an exact date and time copy of the original instance. 75 * @return {Date} A new Date instance 76 */ 77 Date.prototype.clone = function () { 78 return new Date(this.getTime()); 79 }; 80 81 /** 82 * Compares this instance to a Date object and return an number indication of their relative values. 83 * @param {Date} Date object to compare [Required] 84 * @return {Number} 1 = this is greaterthan date. -1 = this is lessthan date. 0 = values are equal 85 */ 86 Date.prototype.compareTo = function (date) { 87 if (isNaN(this)) { 88 throw new Error(this); 89 } 90 if (date instanceof Date && !isNaN(date)) { 91 return (this > date) ? 1 : (this < date) ? -1 : 0; 92 } else { 93 throw new TypeError(date); 94 } 95 }; 96 97 /** 98 * Compares this instance to another Date object and returns true if they are equal. 99 * @param {Date} Date object to compare [Required] 100 * @return {Boolean} true if dates are equal. false if they are not equal. 101 */ 102 Date.prototype.equals = function (date) { 103 return (this.compareTo(date) === 0); 104 }; 105 106 /** 107 * Determines is this instance is between a range of two dates or equal to either the start or end dates. 108 * @param {Date} Start of range [Required] 109 * @param {Date} End of range [Required] 110 * @return {Boolean} true is this is between or equal to the start and end dates, else false 111 */ 112 Date.prototype.between = function (start, end) { 113 var t = this.getTime(); 114 return t >= start.getTime() && t <= end.getTime(); 115 }; 116 117 /** 118 * Adds the specified number of milliseconds to this instance. 119 * @param {Number} The number of milliseconds to add. The number can be positive or negative [Required] 120 * @return {Date} this 121 */ 122 Date.prototype.addMilliseconds = function (value) { 123 this.setMilliseconds(this.getMilliseconds() + value); 124 return this; 125 }; 126 127 /** 128 * Adds the specified number of seconds to this instance. 129 * @param {Number} The number of seconds to add. The number can be positive or negative [Required] 130 * @return {Date} this 131 */ 132 Date.prototype.addSeconds = function (value) { 133 return this.addMilliseconds(value * 1000); 134 }; 135 136 /** 137 * Adds the specified number of seconds to this instance. 138 * @param {Number} The number of seconds to add. The number can be positive or negative [Required] 139 * @return {Date} this 140 */ 141 Date.prototype.addMinutes = function (value) { 142 return this.addMilliseconds(value * 60000); /* 60*1000 */ 143 }; 144 145 /** 146 * Adds the specified number of hours to this instance. 147 * @param {Number} The number of hours to add. The number can be positive or negative [Required] 148 * @return {Date} this 149 */ 150 Date.prototype.addHours = function (value) { 151 return this.addMilliseconds(value * 3600000); /* 60*60*1000 */ 152 }; 153 154 /** 155 * Adds the specified number of days to this instance. 156 * @param {Number} The number of days to add. The number can be positive or negative [Required] 157 * @return {Date} this 158 */ 159 Date.prototype.addDays = function (value) { 160 return this.addMilliseconds(value * 86400000); /* 60*60*24*1000 */ 161 }; 162 163 /** 164 * Adds the specified number of weeks to this instance. 165 * @param {Number} The number of weeks to add. The number can be positive or negative [Required] 166 * @return {Date} this 167 */ 168 Date.prototype.addWeeks = function (value) { 169 return this.addMilliseconds(value * 604800000); /* 60*60*24*7*1000 */ 170 }; 171 172 /** 173 * Adds the specified number of months to this instance. 174 * @param {Number} The number of months to add. The number can be positive or negative [Required] 175 * @return {Date} this 176 */ 177 Date.prototype.addMonths = function (value) { 178 var n = this.getDate(); 179 this.setDate(1); 180 this.setMonth(this.getMonth() + value); 181 this.setDate(Math.min(n, this.getDaysInMonth())); 182 return this; 183 }; 184 185 /** 186 * Adds the specified number of years to this instance. 187 * @param {Number} The number of years to add. The number can be positive or negative [Required] 188 * @return {Date} this 189 */ 190 Date.prototype.addYears = function (value) { 191 return this.addMonths(value * 12); 192 }; 193 194 /** 195 * Adds (or subtracts) to the value of the year, month, day, hour, minute, second, millisecond of the date instance using given configuration object. Positive and Negative values allowed. 196 * Example 197 <pre><code> 198 Date.today().add( { day: 1, month: 1 } ) 199 200 new Date().add( { year: -1 } ) 201 </code></pre> 202 * @param {Object} Configuration object containing attributes (month, day, etc.) 203 * @return {Date} this 204 */ 205 Date.prototype.add = function (config) { 206 if (typeof config == "number") { 207 this._orient = config; 208 return this; 209 } 210 var x = config; 211 if (x.millisecond || x.milliseconds) { 212 this.addMilliseconds(x.millisecond || x.milliseconds); 213 } 214 if (x.second || x.seconds) { 215 this.addSeconds(x.second || x.seconds); 216 } 217 if (x.minute || x.minutes) { 218 this.addMinutes(x.minute || x.minutes); 219 } 220 if (x.hour || x.hours) { 221 this.addHours(x.hour || x.hours); 222 } 223 if (x.month || x.months) { 224 this.addMonths(x.month || x.months); 225 } 226 if (x.year || x.years) { 227 this.addYears(x.year || x.years); 228 } 229 if (x.day || x.days) { 230 this.addDays(x.day || x.days); 231 } 232 return this; 233 }; 234 235 // private 236 Date._validate = function (value, min, max, name) { 237 if (typeof value != "number") { 238 throw new TypeError(value + " is not a Number."); 239 } else if (value < min || value > max) { 240 throw new RangeError(value + " is not a valid value for " + name + "."); 241 } 242 return true; 243 }; 244 245 /** 246 * Validates the number is within an acceptable range for milliseconds [0-999]. 247 * @param {Number} The number to check if within range. 248 * @return {Boolean} true if within range, otherwise false. 249 */ 250 Date.validateMillisecond = function (n) { 251 return Date._validate(n, 0, 999, "milliseconds"); 252 }; 253 254 /** 255 * Validates the number is within an acceptable range for seconds [0-59]. 256 * @param {Number} The number to check if within range. 257 * @return {Boolean} true if within range, otherwise false. 258 */ 259 Date.validateSecond = function (n) { 260 return Date._validate(n, 0, 59, "seconds"); 261 }; 262 263 /** 264 * Validates the number is within an acceptable range for minutes [0-59]. 265 * @param {Number} The number to check if within range. 266 * @return {Boolean} true if within range, otherwise false. 267 */ 268 Date.validateMinute = function (n) { 269 return Date._validate(n, 0, 59, "minutes"); 270 }; 271 272 /** 273 * Validates the number is within an acceptable range for hours [0-23]. 274 * @param {Number} The number to check if within range. 275 * @return {Boolean} true if within range, otherwise false. 276 */ 277 Date.validateHour = function (n) { 278 return Date._validate(n, 0, 23, "hours"); 279 }; 280 281 /** 282 * Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth]. 283 * @param {Number} The number to check if within range. 284 * @return {Boolean} true if within range, otherwise false. 285 */ 286 Date.validateDay = function (n, year, month) { 287 return Date._validate(n, 1, Date.getDaysInMonth(year, month), "days"); 288 }; 289 290 /** 291 * Validates the number is within an acceptable range for months [0-11]. 292 * @param {Number} The number to check if within range. 293 * @return {Boolean} true if within range, otherwise false. 294 */ 295 Date.validateMonth = function (n) { 296 return Date._validate(n, 0, 11, "months"); 297 }; 298 299 /** 300 * Validates the number is within an acceptable range for years [0-9999]. 301 * @param {Number} The number to check if within range. 302 * @return {Boolean} true if within range, otherwise false. 303 */ 304 Date.validateYear = function (n) { 305 return Date._validate(n, 1, 9999, "seconds"); 306 }; 307 308 /** 309 * Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object. 310 * Example 311 <pre><code> 312 Date.today().set( { day: 20, month: 1 } ) 313 314 new Date().set( { millisecond: 0 } ) 315 </code></pre> 316 * 317 * @param {Object} Configuration object containing attributes (month, day, etc.) 318 * @return {Date} this 319 */ 320 Date.prototype.set = function (config) { 321 var x = config; 322 323 if (!x.millisecond && x.millisecond !== 0) { 324 x.millisecond = -1; 325 } 326 if (!x.second && x.second !== 0) { 327 x.second = -1; 328 } 329 if (!x.minute && x.minute !== 0) { 330 x.minute = -1; 331 } 332 if (!x.hour && x.hour !== 0) { 333 x.hour = -1; 334 } 335 if (!x.day && x.day !== 0) { 336 x.day = -1; 337 } 338 if (!x.month && x.month !== 0) { 339 x.month = -1; 340 } 341 if (!x.year && x.year !== 0) { 342 x.year = -1; 343 } 344 345 if (x.millisecond != -1 && Date.validateMillisecond(x.millisecond)) { 346 this.addMilliseconds(x.millisecond - this.getMilliseconds()); 347 } 348 if (x.second != -1 && Date.validateSecond(x.second)) { 349 this.addSeconds(x.second - this.getSeconds()); 350 } 351 if (x.minute != -1 && Date.validateMinute(x.minute)) { 352 this.addMinutes(x.minute - this.getMinutes()); 353 } 354 if (x.hour != -1 && Date.validateHour(x.hour)) { 355 this.addHours(x.hour - this.getHours()); 356 } 357 if (x.month !== -1 && Date.validateMonth(x.month)) { 358 this.addMonths(x.month - this.getMonth()); 359 } 360 if (x.year != -1 && Date.validateYear(x.year)) { 361 this.addYears(x.year - this.getFullYear()); 362 } 363 364 /* day has to go last because you can't validate the day without first knowing the month */ 365 if (x.day != -1 && Date.validateDay(x.day, this.getFullYear(), this.getMonth())) { 366 this.addDays(x.day - this.getDate()); 367 } 368 if (x.timezone) { 369 this.setTimezone(x.timezone); 370 } 371 if (x.timezoneOffset) { 372 this.setTimezoneOffset(x.timezoneOffset); 373 } 374 375 return this; 376 }; 377 378 /** 379 * Resets the time of this Date object to 12:00 AM (00:00), which is the start of the day. 380 * @return {Date} this 381 */ 382 Date.prototype.clearTime = function () { 383 this.setHours(0); 384 this.setMinutes(0); 385 this.setSeconds(0); 386 this.setMilliseconds(0); 387 return this; 388 }; 389 390 /** 391 * Determines whether or not this instance is in a leap year. 392 * @return {Boolean} true if this instance is in a leap year, else false 393 */ 394 Date.prototype.isLeapYear = function () { 395 var y = this.getFullYear(); 396 return (((y % 4 === 0) && (y % 100 !== 0)) || (y % 400 === 0)); 397 }; 398 399 /** 400 * Determines whether or not this instance is a weekday. 401 * @return {Boolean} true if this instance is a weekday 402 */ 403 Date.prototype.isWeekday = function () { 404 return !(this.is().sat() || this.is().sun()); 405 }; 406 407 /** 408 * Get the number of days in the current month, adjusted for leap year. 409 * @return {Number} The number of days in the month 410 */ 411 Date.prototype.getDaysInMonth = function () { 412 return Date.getDaysInMonth(this.getFullYear(), this.getMonth()); 413 }; 414 415 /** 416 * Moves the date to the first day of the month. 417 * @return {Date} this 418 */ 419 Date.prototype.moveToFirstDayOfMonth = function () { 420 return this.set({ day: 1 }); 421 }; 422 423 /** 424 * Moves the date to the last day of the month. 425 * @return {Date} this 426 */ 427 Date.prototype.moveToLastDayOfMonth = function () { 428 return this.set({ day: this.getDaysInMonth()}); 429 }; 430 431 /** 432 * Move to the next or last dayOfWeek based on the orient value. 433 * @param {Number} The dayOfWeek to move to. 434 * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional] 435 * @return {Date} this 436 */ 437 Date.prototype.moveToDayOfWeek = function (day, orient) { 438 var diff = (day - this.getDay() + 7 * (orient || +1)) % 7; 439 return this.addDays((diff === 0) ? diff += 7 * (orient || +1) : diff); 440 }; 441 442 /** 443 * Move to the next or last month based on the orient value. 444 * @param {Number} The month to move to. 0 = January, 11 = December. 445 * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional] 446 * @return {Date} this 447 */ 448 Date.prototype.moveToMonth = function (month, orient) { 449 var diff = (month - this.getMonth() + 12 * (orient || +1)) % 12; 450 return this.addMonths((diff === 0) ? diff += 12 * (orient || +1) : diff); 451 }; 452 453 /** 454 * Get the numeric day number of the year, adjusted for leap year. 455 * @return {Number} 0 through 364 (365 in leap years) 456 */ 457 Date.prototype.getDayOfYear = function () { 458 return Math.floor((this - new Date(this.getFullYear(), 0, 1)) / 86400000); 459 }; 460 461 /** 462 * Get the week of the year for the current date instance. 463 * @param {Number} A Number that represents the first day of the week (0-6) [Optional] 464 * @return {Number} 0 through 53 465 */ 466 Date.prototype.getWeekOfYear = function (firstDayOfWeek) { 467 var y = this.getFullYear(), m = this.getMonth(), d = this.getDate(); 468 469 var dow = firstDayOfWeek || Date.CultureInfo.firstDayOfWeek; 470 471 var offset = 7 + 1 - new Date(y, 0, 1).getDay(); 472 if (offset == 8) { 473 offset = 1; 474 } 475 var daynum = ((Date.UTC(y, m, d, 0, 0, 0) - Date.UTC(y, 0, 1, 0, 0, 0)) / 86400000) + 1; 476 var w = Math.floor((daynum - offset + 7) / 7); 477 if (w === dow) { 478 y--; 479 var prevOffset = 7 + 1 - new Date(y, 0, 1).getDay(); 480 if (prevOffset == 2 || prevOffset == 8) { 481 w = 53; 482 } else { 483 w = 52; 484 } 485 } 486 return w; 487 }; 488 489 /** 490 * Determine whether Daylight Saving Time (DST) is in effect 491 * @return {Boolean} True if DST is in effect. 492 */ 493 Date.prototype.isDST = function () { 494 console.log('isDST'); 495 /* TODO: not sure if this is portable ... get from Date.CultureInfo? */ 496 return this.toString().match(/(E|C|M|P)(S|D)T/)[2] == "D"; 497 }; 498 499 /** 500 * Get the timezone abbreviation of the current date. 501 * @return {String} The abbreviated timezone name (e.g. "EST") 502 */ 503 Date.prototype.getTimezone = function () { 504 return Date.getTimezoneAbbreviation(this.getUTCOffset, this.isDST()); 505 }; 506 507 Date.prototype.setTimezoneOffset = function (s) { 508 var here = this.getTimezoneOffset(), there = Number(s) * -6 / 10; 509 this.addMinutes(there - here); 510 return this; 511 }; 512 513 Date.prototype.setTimezone = function (s) { 514 return this.setTimezoneOffset(Date.getTimezoneOffset(s)); 515 }; 516 517 /** 518 * Get the offset from UTC of the current date. 519 * @return {String} The 4-character offset string prefixed with + or - (e.g. "-0500") 520 */ 521 Date.prototype.getUTCOffset = function () { 522 var n = this.getTimezoneOffset() * -10 / 6, r; 523 if (n < 0) { 524 r = (n - 10000).toString(); 525 return r[0] + r.substr(2); 526 } else { 527 r = (n + 10000).toString(); 528 return "+" + r.substr(1); 529 } 530 }; 531 532 /** 533 * Gets the name of the day of the week. 534 * @param {Boolean} true to return the abbreviated name of the day of the week 535 * @return {String} The name of the day 536 */ 537 Date.prototype.getDayName = function (abbrev) { 538 return abbrev ? Date.CultureInfo.abbreviatedDayNames[this.getDay()] : 539 Date.CultureInfo.dayNames[this.getDay()]; 540 }; 541 542 /** 543 * Gets the month name. 544 * @param {Boolean} true to return the abbreviated name of the month 545 * @return {String} The name of the month 546 */ 547 Date.prototype.getMonthName = function (abbrev) { 548 return abbrev ? Date.CultureInfo.abbreviatedMonthNames[this.getMonth()] : 549 Date.CultureInfo.monthNames[this.getMonth()]; 550 }; 551 552 // private 553 Date.prototype._toString = Date.prototype.toString; 554 555 /** 556 * Converts the value of the current Date object to its equivalent string representation. 557 * Format Specifiers 558 <pre> 559 Format Description Example 560 ------ --------------------------------------------------------------------------- ----------------------- 561 s The seconds of the minute between 1-59. "1" to "59" 562 ss The seconds of the minute with leading zero if required. "01" to "59" 563 564 m The minute of the hour between 0-59. "1" or "59" 565 mm The minute of the hour with leading zero if required. "01" or "59" 566 567 h The hour of the day between 1-12. "1" to "12" 568 hh The hour of the day with leading zero if required. "01" to "12" 569 570 H The hour of the day between 1-23. "1" to "23" 571 HH The hour of the day with leading zero if required. "01" to "23" 572 573 d The day of the month between 1 and 31. "1" to "31" 574 dd The day of the month with leading zero if required. "01" to "31" 575 ddd Abbreviated day name. Date.CultureInfo.abbreviatedDayNames. "Mon" to "Sun" 576 dddd The full day name. Date.CultureInfo.dayNames. "Monday" to "Sunday" 577 578 M The month of the year between 1-12. "1" to "12" 579 MM The month of the year with leading zero if required. "01" to "12" 580 MMM Abbreviated month name. Date.CultureInfo.abbreviatedMonthNames. "Jan" to "Dec" 581 MMMM The full month name. Date.CultureInfo.monthNames. "January" to "December" 582 583 yy Displays the year as a maximum two-digit number. "99" or "07" 584 yyyy Displays the full four digit year. "1999" or "2007" 585 586 t Displays the first character of the A.M./P.M. designator. "A" or "P" 587 Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator 588 tt Displays the A.M./P.M. designator. "AM" or "PM" 589 Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator 590 </pre> 591 * @param {String} A format string consisting of one or more format spcifiers [Optional]. 592 * @return {String} A string representation of the current Date object. 593 */ 594 Date.prototype.toString = function (format) { 595 var self = this; 596 597 var p = function p(s) { 598 return (s.toString().length == 1) ? "0" + s : s; 599 }; 600 601 return format ? format.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g, 602 function (format) { 603 switch (format) { 604 case "hh": 605 return p(self.getHours() < 13 ? self.getHours() : (self.getHours() - 12)); 606 case "h": 607 return self.getHours() < 13 ? self.getHours() : (self.getHours() - 12); 608 case "HH": 609 return p(self.getHours()); 610 case "H": 611 return self.getHours(); 612 case "mm": 613 return p(self.getMinutes()); 614 case "m": 615 return self.getMinutes(); 616 case "ss": 617 return p(self.getSeconds()); 618 case "s": 619 return self.getSeconds(); 620 case "yyyy": 621 return self.getFullYear(); 622 case "yy": 623 return self.getFullYear().toString().substring(2, 4); 624 case "dddd": 625 return self.getDayName(); 626 case "ddd": 627 return self.getDayName(true); 628 case "dd": 629 return p(self.getDate()); 630 case "d": 631 return self.getDate().toString(); 632 case "MMMM": 633 return self.getMonthName(); 634 case "MMM": 635 return self.getMonthName(true); 636 case "MM": 637 return p((self.getMonth() + 1)); 638 case "M": 639 return self.getMonth() + 1; 640 case "t": 641 return self.getHours() < 12 ? Date.CultureInfo.amDesignator.substring(0, 1) : Date.CultureInfo.pmDesignator.substring(0, 1); 642 case "tt": 643 return self.getHours() < 12 ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator; 644 case "zzz": 645 case "zz": 646 case "z": 647 return ""; 648 } 649 } 650 ) : this._toString(); 651 }; 688 689 // private 690 $P._toString = $P.toString; 691 692 /** 693 * Converts the value of the current Date object to its equivalent string representation. 694 * Format Specifiers 695 <pre> 696 CUSTOM DATE AND TIME FORMAT STRINGS 697 Format Description Example 698 ------ --------------------------------------------------------------------------- ----------------------- 699 s The seconds of the minute between 0-59. "0" to "59" 700 ss The seconds of the minute with leading zero if required. "00" to "59" 701 702 m The minute of the hour between 0-59. "0" or "59" 703 mm The minute of the hour with leading zero if required. "00" or "59" 704 705 h The hour of the day between 1-12. "1" to "12" 706 hh The hour of the day with leading zero if required. "01" to "12" 707 708 H The hour of the day between 0-23. "0" to "23" 709 HH The hour of the day with leading zero if required. "00" to "23" 710 711 d The day of the month between 1 and 31. "1" to "31" 712 dd The day of the month with leading zero if required. "01" to "31" 713 ddd Abbreviated day name. $C.abbreviatedDayNames. "Mon" to "Sun" 714 dddd The full day name. $C.dayNames. "Monday" to "Sunday" 715 716 M The month of the year between 1-12. "1" to "12" 717 MM The month of the year with leading zero if required. "01" to "12" 718 MMM Abbreviated month name. $C.abbreviatedMonthNames. "Jan" to "Dec" 719 MMMM The full month name. $C.monthNames. "January" to "December" 720 721 yy The year as a two-digit number. "99" or "08" 722 yyyy The full four digit year. "1999" or "2008" 723 724 t Displays the first character of the A.M./P.M. designator. "A" or "P" 725 $C.amDesignator or $C.pmDesignator 726 tt Displays the A.M./P.M. designator. "AM" or "PM" 727 $C.amDesignator or $C.pmDesignator 728 729 S The ordinal suffix ("st, "nd", "rd" or "th") of the current day. "st, "nd", "rd" or "th" 730 731 || *Format* || *Description* || *Example* || 732 || d || The CultureInfo shortDate Format Pattern || "M/d/yyyy" || 733 || D || The CultureInfo longDate Format Pattern || "dddd, MMMM dd, yyyy" || 734 || F || The CultureInfo fullDateTime Format Pattern || "dddd, MMMM dd, yyyy h:mm:ss tt" || 735 || m || The CultureInfo monthDay Format Pattern || "MMMM dd" || 736 || r || The CultureInfo rfc1123 Format Pattern || "ddd, dd MMM yyyy HH:mm:ss GMT" || 737 || s || The CultureInfo sortableDateTime Format Pattern || "yyyy-MM-ddTHH:mm:ss" || 738 || t || The CultureInfo shortTime Format Pattern || "h:mm tt" || 739 || T || The CultureInfo longTime Format Pattern || "h:mm:ss tt" || 740 || u || The CultureInfo universalSortableDateTime Format Pattern || "yyyy-MM-dd HH:mm:ssZ" || 741 || y || The CultureInfo yearMonth Format Pattern || "MMMM, yyyy" || 742 743 744 STANDARD DATE AND TIME FORMAT STRINGS 745 Format Description Example ("en-US") 746 ------ --------------------------------------------------------------------------- ----------------------- 747 d The CultureInfo shortDate Format Pattern "M/d/yyyy" 748 D The CultureInfo longDate Format Pattern "dddd, MMMM dd, yyyy" 749 F The CultureInfo fullDateTime Format Pattern "dddd, MMMM dd, yyyy h:mm:ss tt" 750 m The CultureInfo monthDay Format Pattern "MMMM dd" 751 r The CultureInfo rfc1123 Format Pattern "ddd, dd MMM yyyy HH:mm:ss GMT" 752 s The CultureInfo sortableDateTime Format Pattern "yyyy-MM-ddTHH:mm:ss" 753 t The CultureInfo shortTime Format Pattern "h:mm tt" 754 T The CultureInfo longTime Format Pattern "h:mm:ss tt" 755 u The CultureInfo universalSortableDateTime Format Pattern "yyyy-MM-dd HH:mm:ssZ" 756 y The CultureInfo yearMonth Format Pattern "MMMM, yyyy" 757 </pre> 758 * @param {String} A format string consisting of one or more format spcifiers [Optional]. 759 * @return {String} A string representation of the current Date object. 760 */ 761 $P.toString = function (format) { 762 var x = this; 763 764 // Standard Date and Time Format Strings. Formats pulled from CultureInfo file and 765 // may vary by culture. 766 if (format && format.length == 1) { 767 var c = $C.formatPatterns; 768 x.t = x.toString; 769 switch (format) { 770 case "d": 771 return x.t(c.shortDate); 772 case "D": 773 return x.t(c.longDate); 774 case "F": 775 return x.t(c.fullDateTime); 776 case "m": 777 return x.t(c.monthDay); 778 case "r": 779 return x.t(c.rfc1123); 780 case "s": 781 return x.t(c.sortableDateTime); 782 case "t": 783 return x.t(c.shortTime); 784 case "T": 785 return x.t(c.longTime); 786 case "u": 787 return x.t(c.universalSortableDateTime); 788 case "y": 789 return x.t(c.yearMonth); 790 } 791 } 792 793 var ord = function (n) { 794 switch (n * 1) { 795 case 1: 796 case 21: 797 case 31: 798 return "st"; 799 case 2: 800 case 22: 801 return "nd"; 802 case 3: 803 case 23: 804 return "rd"; 805 default: 806 return "th"; 807 } 808 }; 809 810 return format ? format.replace(/(\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S)/g, 811 function (m) { 812 if (m.charAt(0) === "\\") { 813 return m.replace("\\", ""); 814 } 815 x.h = x.getHours; 816 switch (m) { 817 case "hh": 818 return p(x.h() < 13 ? (x.h() === 0 ? 12 : x.h()) : (x.h() - 12)); 819 case "h": 820 return x.h() < 13 ? (x.h() === 0 ? 12 : x.h()) : (x.h() - 12); 821 case "HH": 822 return p(x.h()); 823 case "H": 824 return x.h(); 825 case "mm": 826 return p(x.getMinutes()); 827 case "m": 828 return x.getMinutes(); 829 case "ss": 830 return p(x.getSeconds()); 831 case "s": 832 return x.getSeconds(); 833 case "yyyy": 834 return p(x.getFullYear(), 4); 835 case "yy": 836 return p(x.getFullYear()); 837 case "dddd": 838 return $C.dayNames[x.getDay()]; 839 case "ddd": 840 return $C.abbreviatedDayNames[x.getDay()]; 841 case "dd": 842 return p(x.getDate()); 843 case "d": 844 return x.getDate(); 845 case "MMMM": 846 return $C.monthNames[x.getMonth()]; 847 case "MMM": 848 return $C.abbreviatedMonthNames[x.getMonth()]; 849 case "MM": 850 return p((x.getMonth() + 1)); 851 case "M": 852 return x.getMonth() + 1; 853 case "t": 854 return x.h() < 12 ? $C.amDesignator.substring(0, 1) : $C.pmDesignator.substring(0, 1); 855 case "tt": 856 return x.h() < 12 ? $C.amDesignator : $C.pmDesignator; 857 case "S": 858 return ord(x.getDate()); 859 default: 860 return m; 861 } 862 } 863 ) : this._toString(); 864 }; 865 }()); -
branches/2.4/prototype/plugins/datejs/core.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 13-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 Date.getMonthNumberFromName=function(name){var n=Date.CultureInfo.monthNames,m=Date.CultureInfo.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 9 return-1;};Date.getDayNumberFromName=function(name){var n=Date.CultureInfo.dayNames,m=Date.CultureInfo.abbreviatedDayNames,o=Date.CultureInfo.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 10 return-1;};Date.isLeapYear=function(year){return(((year%4===0)&&(year%100!==0))||(year%400===0));};Date.getDaysInMonth=function(year,month){return[31,(Date.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};Date.getTimezoneOffset=function(s,dst){return(dst||false)?Date.CultureInfo.abbreviatedTimeZoneDST[s.toUpperCase()]:Date.CultureInfo.abbreviatedTimeZoneStandard[s.toUpperCase()];};Date.getTimezoneAbbreviation=function(offset,dst){var n=(dst||false)?Date.CultureInfo.abbreviatedTimeZoneDST:Date.CultureInfo.abbreviatedTimeZoneStandard,p;for(p in n){if(n[p]===offset){return p;}} 11 return null;};Date.prototype.clone=function(){return new Date(this.getTime());};Date.prototype.compareTo=function(date){if(isNaN(this)){throw new Error(this);} 12 if(date instanceof Date&&!isNaN(date)){return(this>date)?1:(this<date)?-1:0;}else{throw new TypeError(date);}};Date.prototype.equals=function(date){return(this.compareTo(date)===0);};Date.prototype.between=function(start,end){var t=this.getTime();return t>=start.getTime()&&t<=end.getTime();};Date.prototype.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};Date.prototype.addSeconds=function(value){return this.addMilliseconds(value*1000);};Date.prototype.addMinutes=function(value){return this.addMilliseconds(value*60000);};Date.prototype.addHours=function(value){return this.addMilliseconds(value*3600000);};Date.prototype.addDays=function(value){return this.addMilliseconds(value*86400000);};Date.prototype.addWeeks=function(value){return this.addMilliseconds(value*604800000);};Date.prototype.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,this.getDaysInMonth()));return this;};Date.prototype.addYears=function(value){return this.addMonths(value*12);};Date.prototype.add=function(config){if(typeof config=="number"){this._orient=config;return this;} 13 var x=config;if(x.millisecond||x.milliseconds){this.addMilliseconds(x.millisecond||x.milliseconds);} 14 if(x.second||x.seconds){this.addSeconds(x.second||x.seconds);} 15 if(x.minute||x.minutes){this.addMinutes(x.minute||x.minutes);} 16 if(x.hour||x.hours){this.addHours(x.hour||x.hours);} 17 if(x.month||x.months){this.addMonths(x.month||x.months);} 18 if(x.year||x.years){this.addYears(x.year||x.years);} 19 if(x.day||x.days){this.addDays(x.day||x.days);} 20 return this;};Date._validate=function(value,min,max,name){if(typeof value!="number"){throw new TypeError(value+" is not a Number.");}else if(value<min||value>max){throw new RangeError(value+" is not a valid value for "+name+".");} 21 return true;};Date.validateMillisecond=function(n){return Date._validate(n,0,999,"milliseconds");};Date.validateSecond=function(n){return Date._validate(n,0,59,"seconds");};Date.validateMinute=function(n){return Date._validate(n,0,59,"minutes");};Date.validateHour=function(n){return Date._validate(n,0,23,"hours");};Date.validateDay=function(n,year,month){return Date._validate(n,1,Date.getDaysInMonth(year,month),"days");};Date.validateMonth=function(n){return Date._validate(n,0,11,"months");};Date.validateYear=function(n){return Date._validate(n,1,9999,"seconds");};Date.prototype.set=function(config){var x=config;if(!x.millisecond&&x.millisecond!==0){x.millisecond=-1;} 22 if(!x.second&&x.second!==0){x.second=-1;} 23 if(!x.minute&&x.minute!==0){x.minute=-1;} 24 if(!x.hour&&x.hour!==0){x.hour=-1;} 25 if(!x.day&&x.day!==0){x.day=-1;} 26 if(!x.month&&x.month!==0){x.month=-1;} 27 if(!x.year&&x.year!==0){x.year=-1;} 28 if(x.millisecond!=-1&&Date.validateMillisecond(x.millisecond)){this.addMilliseconds(x.millisecond-this.getMilliseconds());} 29 if(x.second!=-1&&Date.validateSecond(x.second)){this.addSeconds(x.second-this.getSeconds());} 30 if(x.minute!=-1&&Date.validateMinute(x.minute)){this.addMinutes(x.minute-this.getMinutes());} 31 if(x.hour!=-1&&Date.validateHour(x.hour)){this.addHours(x.hour-this.getHours());} 32 if(x.month!==-1&&Date.validateMonth(x.month)){this.addMonths(x.month-this.getMonth());} 33 if(x.year!=-1&&Date.validateYear(x.year)){this.addYears(x.year-this.getFullYear());} 34 if(x.day!=-1&&Date.validateDay(x.day,this.getFullYear(),this.getMonth())){this.addDays(x.day-this.getDate());} 35 if(x.timezone){this.setTimezone(x.timezone);} 36 if(x.timezoneOffset){this.setTimezoneOffset(x.timezoneOffset);} 37 return this;};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};Date.prototype.isLeapYear=function(){var y=this.getFullYear();return(((y%4===0)&&(y%100!==0))||(y%400===0));};Date.prototype.isWeekday=function(){return!(this.is().sat()||this.is().sun());};Date.prototype.getDaysInMonth=function(){return Date.getDaysInMonth(this.getFullYear(),this.getMonth());};Date.prototype.moveToFirstDayOfMonth=function(){return this.set({day:1});};Date.prototype.moveToLastDayOfMonth=function(){return this.set({day:this.getDaysInMonth()});};Date.prototype.moveToDayOfWeek=function(day,orient){var diff=(day-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};Date.prototype.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};Date.prototype.getDayOfYear=function(){return Math.floor((this-new Date(this.getFullYear(),0,1))/86400000);};Date.prototype.getWeekOfYear=function(firstDayOfWeek){var y=this.getFullYear(),m=this.getMonth(),d=this.getDate();var dow=firstDayOfWeek||Date.CultureInfo.firstDayOfWeek;var offset=7+1-new Date(y,0,1).getDay();if(offset==8){offset=1;} 38 var daynum=((Date.UTC(y,m,d,0,0,0)-Date.UTC(y,0,1,0,0,0))/86400000)+1;var w=Math.floor((daynum-offset+7)/7);if(w===dow){y--;var prevOffset=7+1-new Date(y,0,1).getDay();if(prevOffset==2||prevOffset==8){w=53;}else{w=52;}} 39 return w;};Date.prototype.isDST=function(){console.log('isDST');return this.toString().match(/(E|C|M|P)(S|D)T/)[2]=="D";};Date.prototype.getTimezone=function(){return Date.getTimezoneAbbreviation(this.getUTCOffset,this.isDST());};Date.prototype.setTimezoneOffset=function(s){var here=this.getTimezoneOffset(),there=Number(s)*-6/10;this.addMinutes(there-here);return this;};Date.prototype.setTimezone=function(s){return this.setTimezoneOffset(Date.getTimezoneOffset(s));};Date.prototype.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r[0]+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};Date.prototype.getDayName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedDayNames[this.getDay()]:Date.CultureInfo.dayNames[this.getDay()];};Date.prototype.getMonthName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedMonthNames[this.getMonth()]:Date.CultureInfo.monthNames[this.getMonth()];};Date.prototype._toString=Date.prototype.toString;Date.prototype.toString=function(format){var self=this;var p=function p(s){return(s.toString().length==1)?"0"+s:s;};return format?format.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g,function(format){switch(format){case"hh":return p(self.getHours()<13?self.getHours():(self.getHours()-12));case"h":return self.getHours()<13?self.getHours():(self.getHours()-12);case"HH":return p(self.getHours());case"H":return self.getHours();case"mm":return p(self.getMinutes());case"m":return self.getMinutes();case"ss":return p(self.getSeconds());case"s":return self.getSeconds();case"yyyy":return self.getFullYear();case"yy":return self.getFullYear().toString().substring(2,4);case"dddd":return self.getDayName();case"ddd":return self.getDayName(true);case"dd":return p(self.getDate());case"d":return self.getDate().toString();case"MMMM":return self.getMonthName();case"MMM":return self.getMonthName(true);case"MM":return p((self.getMonth()+1));case"M":return self.getMonth()+1;case"t":return self.getHours()<12?Date.CultureInfo.amDesignator.substring(0,1):Date.CultureInfo.pmDesignator.substring(0,1);case"tt":return self.getHours()<12?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;case"zzz":case"zz":case"z":return"";}}):this._toString();}; 9 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,p=function(s,l){if(!l){l=2;} 10 return("000"+s).slice(l*-1);};$P.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};$P.setTimeToNow=function(){var n=new Date();this.setHours(n.getHours());this.setMinutes(n.getMinutes());this.setSeconds(n.getSeconds());this.setMilliseconds(n.getMilliseconds());return this;};$D.today=function(){return new Date().clearTime();};$D.compare=function(date1,date2){if(isNaN(date1)||isNaN(date2)){throw new Error(date1+" - "+date2);}else if(date1 instanceof Date&&date2 instanceof Date){return(date1<date2)?-1:(date1>date2)?1:0;}else{throw new TypeError(date1+" - "+date2);}};$D.equals=function(date1,date2){return(date1.compareTo(date2)===0);};$D.getDayNumberFromName=function(name){var n=$C.dayNames,m=$C.abbreviatedDayNames,o=$C.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s||o[i].toLowerCase()==s){return i;}} 11 return-1;};$D.getMonthNumberFromName=function(name){var n=$C.monthNames,m=$C.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 12 return-1;};$D.isLeapYear=function(year){return((year%4===0&&year%100!==0)||year%400===0);};$D.getDaysInMonth=function(year,month){return[31,($D.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};$D.getTimezoneAbbreviation=function(offset){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].offset===offset){return z[i].name;}} 13 return null;};$D.getTimezoneOffset=function(name){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].name===name.toUpperCase()){return z[i].offset;}} 14 return null;};$P.clone=function(){return new Date(this.getTime());};$P.compareTo=function(date){return Date.compare(this,date);};$P.equals=function(date){return Date.equals(this,date||new Date());};$P.between=function(start,end){return this.getTime()>=start.getTime()&&this.getTime()<=end.getTime();};$P.isAfter=function(date){return this.compareTo(date||new Date())===1;};$P.isBefore=function(date){return(this.compareTo(date||new Date())===-1);};$P.isToday=function(){return this.isSameDay(new Date());};$P.isSameDay=function(date){return this.clone().clearTime().equals(date.clone().clearTime());};$P.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};$P.addSeconds=function(value){return this.addMilliseconds(value*1000);};$P.addMinutes=function(value){return this.addMilliseconds(value*60000);};$P.addHours=function(value){return this.addMilliseconds(value*3600000);};$P.addDays=function(value){this.setDate(this.getDate()+value);return this;};$P.addWeeks=function(value){return this.addDays(value*7);};$P.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,$D.getDaysInMonth(this.getFullYear(),this.getMonth())));return this;};$P.addYears=function(value){return this.addMonths(value*12);};$P.add=function(config){if(typeof config=="number"){this._orient=config;return this;} 15 var x=config;if(x.milliseconds){this.addMilliseconds(x.milliseconds);} 16 if(x.seconds){this.addSeconds(x.seconds);} 17 if(x.minutes){this.addMinutes(x.minutes);} 18 if(x.hours){this.addHours(x.hours);} 19 if(x.weeks){this.addWeeks(x.weeks);} 20 if(x.months){this.addMonths(x.months);} 21 if(x.years){this.addYears(x.years);} 22 if(x.days){this.addDays(x.days);} 23 return this;};var $y,$m,$d;$P.getWeek=function(){var a,b,c,d,e,f,g,n,s,w;$y=(!$y)?this.getFullYear():$y;$m=(!$m)?this.getMonth()+1:$m;$d=(!$d)?this.getDate():$d;if($m<=2){a=$y-1;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=0;f=$d-1+(31*($m-1));}else{a=$y;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=s+1;f=$d+((153*($m-3)+2)/5)+58+s;} 24 g=(a+b)%7;d=(f+g-e)%7;n=(f+3-d)|0;if(n<0){w=53-((g-s)/5|0);}else if(n>364+s){w=1;}else{w=(n/7|0)+1;} 25 $y=$m=$d=null;return w;};$P.getISOWeek=function(){$y=this.getUTCFullYear();$m=this.getUTCMonth()+1;$d=this.getUTCDate();return p(this.getWeek());};$P.setWeek=function(n){return this.moveToDayOfWeek(1).addWeeks(n-this.getWeek());};$D._validate=function(n,min,max,name){if(typeof n=="undefined"){return false;}else if(typeof n!="number"){throw new TypeError(n+" is not a Number.");}else if(n<min||n>max){throw new RangeError(n+" is not a valid value for "+name+".");} 26 return true;};$D.validateMillisecond=function(value){return $D._validate(value,0,999,"millisecond");};$D.validateSecond=function(value){return $D._validate(value,0,59,"second");};$D.validateMinute=function(value){return $D._validate(value,0,59,"minute");};$D.validateHour=function(value){return $D._validate(value,0,23,"hour");};$D.validateDay=function(value,year,month){return $D._validate(value,1,$D.getDaysInMonth(year,month),"day");};$D.validateMonth=function(value){return $D._validate(value,0,11,"month");};$D.validateYear=function(value){return $D._validate(value,0,9999,"year");};$P.set=function(config){if($D.validateMillisecond(config.millisecond)){this.addMilliseconds(config.millisecond-this.getMilliseconds());} 27 if($D.validateSecond(config.second)){this.addSeconds(config.second-this.getSeconds());} 28 if($D.validateMinute(config.minute)){this.addMinutes(config.minute-this.getMinutes());} 29 if($D.validateHour(config.hour)){this.addHours(config.hour-this.getHours());} 30 if($D.validateMonth(config.month)){this.addMonths(config.month-this.getMonth());} 31 if($D.validateYear(config.year)){this.addYears(config.year-this.getFullYear());} 32 if($D.validateDay(config.day,this.getFullYear(),this.getMonth())){this.addDays(config.day-this.getDate());} 33 if(config.timezone){this.setTimezone(config.timezone);} 34 if(config.timezoneOffset){this.setTimezoneOffset(config.timezoneOffset);} 35 if(config.week&&$D._validate(config.week,0,53,"week")){this.setWeek(config.week);} 36 return this;};$P.moveToFirstDayOfMonth=function(){return this.set({day:1});};$P.moveToLastDayOfMonth=function(){return this.set({day:$D.getDaysInMonth(this.getFullYear(),this.getMonth())});};$P.moveToNthOccurrence=function(dayOfWeek,occurrence){var shift=0;if(occurrence>0){shift=occurrence-1;} 37 else if(occurrence===-1){this.moveToLastDayOfMonth();if(this.getDay()!==dayOfWeek){this.moveToDayOfWeek(dayOfWeek,-1);} 38 return this;} 39 return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek,+1).addWeeks(shift);};$P.moveToDayOfWeek=function(dayOfWeek,orient){var diff=(dayOfWeek-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};$P.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};$P.getOrdinalNumber=function(){return Math.ceil((this.clone().clearTime()-new Date(this.getFullYear(),0,1))/86400000)+1;};$P.getTimezone=function(){return $D.getTimezoneAbbreviation(this.getUTCOffset());};$P.setTimezoneOffset=function(offset){var here=this.getTimezoneOffset(),there=Number(offset)*-6/10;return this.addMinutes(there-here);};$P.setTimezone=function(offset){return this.setTimezoneOffset($D.getTimezoneOffset(offset));};$P.hasDaylightSavingTime=function(){return(Date.today().set({month:0,day:1}).getTimezoneOffset()!==Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.isDaylightSavingTime=function(){return(this.hasDaylightSavingTime()&&new Date().getTimezoneOffset()===Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r.charAt(0)+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};$P.getElapsed=function(date){return(date||new Date())-this;};if(!$P.toISOString){$P.toISOString=function(){function f(n){return n<10?'0'+n:n;} 40 return'"'+this.getUTCFullYear()+'-'+ 41 f(this.getUTCMonth()+1)+'-'+ 42 f(this.getUTCDate())+'T'+ 43 f(this.getUTCHours())+':'+ 44 f(this.getUTCMinutes())+':'+ 45 f(this.getUTCSeconds())+'Z"';};} 46 $P._toString=$P.toString;$P.toString=function(format){var x=this;if(format&&format.length==1){var c=$C.formatPatterns;x.t=x.toString;switch(format){case"d":return x.t(c.shortDate);case"D":return x.t(c.longDate);case"F":return x.t(c.fullDateTime);case"m":return x.t(c.monthDay);case"r":return x.t(c.rfc1123);case"s":return x.t(c.sortableDateTime);case"t":return x.t(c.shortTime);case"T":return x.t(c.longTime);case"u":return x.t(c.universalSortableDateTime);case"y":return x.t(c.yearMonth);}} 47 var ord=function(n){switch(n*1){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}};return format?format.replace(/(\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S)/g,function(m){if(m.charAt(0)==="\\"){return m.replace("\\","");} 48 x.h=x.getHours;switch(m){case"hh":return p(x.h()<13?(x.h()===0?12:x.h()):(x.h()-12));case"h":return x.h()<13?(x.h()===0?12:x.h()):(x.h()-12);case"HH":return p(x.h());case"H":return x.h();case"mm":return p(x.getMinutes());case"m":return x.getMinutes();case"ss":return p(x.getSeconds());case"s":return x.getSeconds();case"yyyy":return p(x.getFullYear(),4);case"yy":return p(x.getFullYear());case"dddd":return $C.dayNames[x.getDay()];case"ddd":return $C.abbreviatedDayNames[x.getDay()];case"dd":return p(x.getDate());case"d":return x.getDate();case"MMMM":return $C.monthNames[x.getMonth()];case"MMM":return $C.abbreviatedMonthNames[x.getMonth()];case"MM":return p((x.getMonth()+1));case"M":return x.getMonth()+1;case"t":return x.h()<12?$C.amDesignator.substring(0,1):$C.pmDesignator.substring(0,1);case"tt":return x.h()<12?$C.amDesignator:$C.pmDesignator;case"S":return ord(x.getDate());default:return m;}}):this._toString();};}()); -
branches/2.4/prototype/plugins/datejs/date-pt-BR.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 13-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 Date.CultureInfo={name:"pt-BR",englishName:"Portuguese (Brazil)",nativeName:"Português (Brasil)",dayNames:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"],abbreviatedDayNames:["dom","seg","ter","qua","qui","sex","sáb"],shortestDayNames:["dom","seg","ter","qua","qui","sex","sáb"],firstLetterDayNames:["d","s","t","q","q","s","s"],monthNames:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"],abbreviatedMonthNames:["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"],amDesignator:"",pmDesignator:"",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"dmy",formatPatterns:{shortDate:"d/M/yyyy",longDate:"dddd, d' de 'MMMM' de 'yyyy",shortTime:"H:mm",longTime:"H:mm:ss",fullDateTime:"dddd, d' de 'MMMM' de 'yyyy H:mm:ss",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"dd' de 'MMMM",yearMonth:"MMMM' de 'yyyy"},regexPatterns:{jan:/^jan(eiro)?/i,feb:/^fev(ereiro)?/i,mar:/^mar(ço)?/i,apr:/^abr(il)?/i,may:/^mai(o)?/i,jun:/^jun(ho)?/i,jul:/^jul(ho)?/i,aug:/^ago(sto)?/i,sep:/^set(embro)?/i,oct:/^out(ubro)?/i,nov:/^nov(embro)?/i,dec:/^dez(embro)?/i,sun:/^domingo/i,mon:/^segunda-feira/i,tue:/^terça-feira/i,wed:/^quarta-feira/i,thu:/^quinta-feira/i,fri:/^sexta-feira/i,sat:/^sábado/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|after|from)/i,subtract:/^(\-|before|ago)/i,yesterday:/^yesterday/i,today:/^t(oday)?/i,tomorrow:/^tomorrow/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^min(ute)?s?/i,hour:/^h(ou)?rs?/i,week:/^w(ee)?k/i,month:/^m(o(nth)?s?)?/i,day:/^d(ays?)?/i,year:/^y((ea)?rs?)?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a|p)/i},abbreviatedTimeZoneStandard:{GMT:"-000",EST:"-0400",CST:"-0500",MST:"-0600",PST:"-0700"},abbreviatedTimeZoneDST:{GMT:"-000",EDT:"-0500",CDT:"-0600",MDT:"-0700",PDT:"-0800"}}; 9 Date.getMonthNumberFromName=function(name){var n=Date.CultureInfo.monthNames,m=Date.CultureInfo.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 10 return-1;};Date.getDayNumberFromName=function(name){var n=Date.CultureInfo.dayNames,m=Date.CultureInfo.abbreviatedDayNames,o=Date.CultureInfo.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 11 return-1;};Date.isLeapYear=function(year){return(((year%4===0)&&(year%100!==0))||(year%400===0));};Date.getDaysInMonth=function(year,month){return[31,(Date.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};Date.getTimezoneOffset=function(s,dst){return(dst||false)?Date.CultureInfo.abbreviatedTimeZoneDST[s.toUpperCase()]:Date.CultureInfo.abbreviatedTimeZoneStandard[s.toUpperCase()];};Date.getTimezoneAbbreviation=function(offset,dst){var n=(dst||false)?Date.CultureInfo.abbreviatedTimeZoneDST:Date.CultureInfo.abbreviatedTimeZoneStandard,p;for(p in n){if(n[p]===offset){return p;}} 12 return null;};Date.prototype.clone=function(){return new Date(this.getTime());};Date.prototype.compareTo=function(date){if(isNaN(this)){throw new Error(this);} 13 if(date instanceof Date&&!isNaN(date)){return(this>date)?1:(this<date)?-1:0;}else{throw new TypeError(date);}};Date.prototype.equals=function(date){return(this.compareTo(date)===0);};Date.prototype.between=function(start,end){var t=this.getTime();return t>=start.getTime()&&t<=end.getTime();};Date.prototype.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};Date.prototype.addSeconds=function(value){return this.addMilliseconds(value*1000);};Date.prototype.addMinutes=function(value){return this.addMilliseconds(value*60000);};Date.prototype.addHours=function(value){return this.addMilliseconds(value*3600000);};Date.prototype.addDays=function(value){return this.addMilliseconds(value*86400000);};Date.prototype.addWeeks=function(value){return this.addMilliseconds(value*604800000);};Date.prototype.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,this.getDaysInMonth()));return this;};Date.prototype.addYears=function(value){return this.addMonths(value*12);};Date.prototype.add=function(config){if(typeof config=="number"){this._orient=config;return this;} 14 var x=config;if(x.millisecond||x.milliseconds){this.addMilliseconds(x.millisecond||x.milliseconds);} 15 if(x.second||x.seconds){this.addSeconds(x.second||x.seconds);} 16 if(x.minute||x.minutes){this.addMinutes(x.minute||x.minutes);} 17 if(x.hour||x.hours){this.addHours(x.hour||x.hours);} 18 if(x.month||x.months){this.addMonths(x.month||x.months);} 19 if(x.year||x.years){this.addYears(x.year||x.years);} 20 if(x.day||x.days){this.addDays(x.day||x.days);} 21 return this;};Date._validate=function(value,min,max,name){if(typeof value!="number"){throw new TypeError(value+" is not a Number.");}else if(value<min||value>max){throw new RangeError(value+" is not a valid value for "+name+".");} 22 return true;};Date.validateMillisecond=function(n){return Date._validate(n,0,999,"milliseconds");};Date.validateSecond=function(n){return Date._validate(n,0,59,"seconds");};Date.validateMinute=function(n){return Date._validate(n,0,59,"minutes");};Date.validateHour=function(n){return Date._validate(n,0,23,"hours");};Date.validateDay=function(n,year,month){return Date._validate(n,1,Date.getDaysInMonth(year,month),"days");};Date.validateMonth=function(n){return Date._validate(n,0,11,"months");};Date.validateYear=function(n){return Date._validate(n,1,9999,"seconds");};Date.prototype.set=function(config){var x=config;if(!x.millisecond&&x.millisecond!==0){x.millisecond=-1;} 23 if(!x.second&&x.second!==0){x.second=-1;} 24 if(!x.minute&&x.minute!==0){x.minute=-1;} 25 if(!x.hour&&x.hour!==0){x.hour=-1;} 26 if(!x.day&&x.day!==0){x.day=-1;} 27 if(!x.month&&x.month!==0){x.month=-1;} 28 if(!x.year&&x.year!==0){x.year=-1;} 29 if(x.millisecond!=-1&&Date.validateMillisecond(x.millisecond)){this.addMilliseconds(x.millisecond-this.getMilliseconds());} 30 if(x.second!=-1&&Date.validateSecond(x.second)){this.addSeconds(x.second-this.getSeconds());} 31 if(x.minute!=-1&&Date.validateMinute(x.minute)){this.addMinutes(x.minute-this.getMinutes());} 32 if(x.hour!=-1&&Date.validateHour(x.hour)){this.addHours(x.hour-this.getHours());} 33 if(x.month!==-1&&Date.validateMonth(x.month)){this.addMonths(x.month-this.getMonth());} 34 if(x.year!=-1&&Date.validateYear(x.year)){this.addYears(x.year-this.getFullYear());} 35 if(x.day!=-1&&Date.validateDay(x.day,this.getFullYear(),this.getMonth())){this.addDays(x.day-this.getDate());} 36 if(x.timezone){this.setTimezone(x.timezone);} 37 if(x.timezoneOffset){this.setTimezoneOffset(x.timezoneOffset);} 38 return this;};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};Date.prototype.isLeapYear=function(){var y=this.getFullYear();return(((y%4===0)&&(y%100!==0))||(y%400===0));};Date.prototype.isWeekday=function(){return!(this.is().sat()||this.is().sun());};Date.prototype.getDaysInMonth=function(){return Date.getDaysInMonth(this.getFullYear(),this.getMonth());};Date.prototype.moveToFirstDayOfMonth=function(){return this.set({day:1});};Date.prototype.moveToLastDayOfMonth=function(){return this.set({day:this.getDaysInMonth()});};Date.prototype.moveToDayOfWeek=function(day,orient){var diff=(day-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};Date.prototype.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};Date.prototype.getDayOfYear=function(){return Math.floor((this-new Date(this.getFullYear(),0,1))/86400000);};Date.prototype.getWeekOfYear=function(firstDayOfWeek){var y=this.getFullYear(),m=this.getMonth(),d=this.getDate();var dow=firstDayOfWeek||Date.CultureInfo.firstDayOfWeek;var offset=7+1-new Date(y,0,1).getDay();if(offset==8){offset=1;} 39 var daynum=((Date.UTC(y,m,d,0,0,0)-Date.UTC(y,0,1,0,0,0))/86400000)+1;var w=Math.floor((daynum-offset+7)/7);if(w===dow){y--;var prevOffset=7+1-new Date(y,0,1).getDay();if(prevOffset==2||prevOffset==8){w=53;}else{w=52;}} 40 return w;};Date.prototype.isDST=function(){console.log('isDST');return this.toString().match(/(E|C|M|P)(S|D)T/)[2]=="D";};Date.prototype.getTimezone=function(){return Date.getTimezoneAbbreviation(this.getUTCOffset,this.isDST());};Date.prototype.setTimezoneOffset=function(s){var here=this.getTimezoneOffset(),there=Number(s)*-6/10;this.addMinutes(there-here);return this;};Date.prototype.setTimezone=function(s){return this.setTimezoneOffset(Date.getTimezoneOffset(s));};Date.prototype.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r[0]+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};Date.prototype.getDayName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedDayNames[this.getDay()]:Date.CultureInfo.dayNames[this.getDay()];};Date.prototype.getMonthName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedMonthNames[this.getMonth()]:Date.CultureInfo.monthNames[this.getMonth()];};Date.prototype._toString=Date.prototype.toString;Date.prototype.toString=function(format){var self=this;var p=function p(s){return(s.toString().length==1)?"0"+s:s;};return format?format.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g,function(format){switch(format){case"hh":return p(self.getHours()<13?self.getHours():(self.getHours()-12));case"h":return self.getHours()<13?self.getHours():(self.getHours()-12);case"HH":return p(self.getHours());case"H":return self.getHours();case"mm":return p(self.getMinutes());case"m":return self.getMinutes();case"ss":return p(self.getSeconds());case"s":return self.getSeconds();case"yyyy":return self.getFullYear();case"yy":return self.getFullYear().toString().substring(2,4);case"dddd":return self.getDayName();case"ddd":return self.getDayName(true);case"dd":return p(self.getDate());case"d":return self.getDate().toString();case"MMMM":return self.getMonthName();case"MMM":return self.getMonthName(true);case"MM":return p((self.getMonth()+1));case"M":return self.getMonth()+1;case"t":return self.getHours()<12?Date.CultureInfo.amDesignator.substring(0,1):Date.CultureInfo.pmDesignator.substring(0,1);case"tt":return self.getHours()<12?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;case"zzz":case"zz":case"z":return"";}}):this._toString();}; 41 Date.now=function(){return new Date();};Date.today=function(){return Date.now().clearTime();};Date.prototype._orient=+1;Date.prototype.next=function(){this._orient=+1;return this;};Date.prototype.last=Date.prototype.prev=Date.prototype.previous=function(){this._orient=-1;return this;};Date.prototype._is=false;Date.prototype.is=function(){this._is=true;return this;};Number.prototype._dateElement="day";Number.prototype.fromNow=function(){var c={};c[this._dateElement]=this;return Date.now().add(c);};Number.prototype.ago=function(){var c={};c[this._dateElement]=this*-1;return Date.now().add(c);};(function(){var $D=Date.prototype,$N=Number.prototype;var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),de;var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} 42 return this.moveToDayOfWeek(n,this._orient);};};for(var i=0;i<dx.length;i++){$D[dx[i]]=$D[dx[i].substring(0,3)]=df(i);} 9 Date.CultureInfo={name:"pt-BR",englishName:"Portuguese (Brazil)",nativeName:"Português (Brasil)",dayNames:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"],abbreviatedDayNames:["dom","seg","ter","qua","qui","sex","sáb"],shortestDayNames:["dom","seg","ter","qua","qui","sex","sáb"],firstLetterDayNames:["d","s","t","q","q","s","s"],monthNames:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"],abbreviatedMonthNames:["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"],amDesignator:"",pmDesignator:"",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"dmy",formatPatterns:{shortDate:"d/M/yyyy",longDate:"dddd, d' de 'MMMM' de 'yyyy",shortTime:"H:mm",longTime:"H:mm:ss",fullDateTime:"dddd, d' de 'MMMM' de 'yyyy H:mm:ss",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"dd' de 'MMMM",yearMonth:"MMMM' de 'yyyy"},regexPatterns:{jan:/^jan(eiro)?/i,feb:/^fev(ereiro)?/i,mar:/^mar(ço)?/i,apr:/^abr(il)?/i,may:/^mai(o)?/i,jun:/^jun(ho)?/i,jul:/^jul(ho)?/i,aug:/^ago(sto)?/i,sep:/^set(embro)?/i,oct:/^out(ubro)?/i,nov:/^nov(embro)?/i,dec:/^dez(embro)?/i,sun:/^domingo/i,mon:/^segunda-feira/i,tue:/^terça-feira/i,wed:/^quarta-feira/i,thu:/^quinta-feira/i,fri:/^sexta-feira/i,sat:/^sábado/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|aft(er)?|from|hence)/i,subtract:/^(\-|bef(ore)?|ago)/i,yesterday:/^yes(terday)?/i,today:/^t(od(ay)?)?/i,tomorrow:/^tom(orrow)?/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^mn|min(ute)?s?/i,hour:/^h(our)?s?/i,week:/^w(eek)?s?/i,month:/^m(onth)?s?/i,day:/^d(ay)?s?/i,year:/^y(ear)?s?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt|utc)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a(?!u|p)|p)/i},timezones:[{name:"UTC",offset:"-000"},{name:"GMT",offset:"-000"},{name:"EST",offset:"-0500"},{name:"EDT",offset:"-0400"},{name:"CST",offset:"-0600"},{name:"CDT",offset:"-0500"},{name:"MST",offset:"-0700"},{name:"MDT",offset:"-0600"},{name:"PST",offset:"-0800"},{name:"PDT",offset:"-0700"}]}; 10 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,p=function(s,l){if(!l){l=2;} 11 return("000"+s).slice(l*-1);};$P.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};$P.setTimeToNow=function(){var n=new Date();this.setHours(n.getHours());this.setMinutes(n.getMinutes());this.setSeconds(n.getSeconds());this.setMilliseconds(n.getMilliseconds());return this;};$D.today=function(){return new Date().clearTime();};$D.compare=function(date1,date2){if(isNaN(date1)||isNaN(date2)){throw new Error(date1+" - "+date2);}else if(date1 instanceof Date&&date2 instanceof Date){return(date1<date2)?-1:(date1>date2)?1:0;}else{throw new TypeError(date1+" - "+date2);}};$D.equals=function(date1,date2){return(date1.compareTo(date2)===0);};$D.getDayNumberFromName=function(name){var n=$C.dayNames,m=$C.abbreviatedDayNames,o=$C.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s||o[i].toLowerCase()==s){return i;}} 12 return-1;};$D.getMonthNumberFromName=function(name){var n=$C.monthNames,m=$C.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 13 return-1;};$D.isLeapYear=function(year){return((year%4===0&&year%100!==0)||year%400===0);};$D.getDaysInMonth=function(year,month){return[31,($D.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};$D.getTimezoneAbbreviation=function(offset){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].offset===offset){return z[i].name;}} 14 return null;};$D.getTimezoneOffset=function(name){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].name===name.toUpperCase()){return z[i].offset;}} 15 return null;};$P.clone=function(){return new Date(this.getTime());};$P.compareTo=function(date){return Date.compare(this,date);};$P.equals=function(date){return Date.equals(this,date||new Date());};$P.between=function(start,end){return this.getTime()>=start.getTime()&&this.getTime()<=end.getTime();};$P.isAfter=function(date){return this.compareTo(date||new Date())===1;};$P.isBefore=function(date){return(this.compareTo(date||new Date())===-1);};$P.isToday=function(){return this.isSameDay(new Date());};$P.isSameDay=function(date){return this.clone().clearTime().equals(date.clone().clearTime());};$P.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};$P.addSeconds=function(value){return this.addMilliseconds(value*1000);};$P.addMinutes=function(value){return this.addMilliseconds(value*60000);};$P.addHours=function(value){return this.addMilliseconds(value*3600000);};$P.addDays=function(value){this.setDate(this.getDate()+value);return this;};$P.addWeeks=function(value){return this.addDays(value*7);};$P.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,$D.getDaysInMonth(this.getFullYear(),this.getMonth())));return this;};$P.addYears=function(value){return this.addMonths(value*12);};$P.add=function(config){if(typeof config=="number"){this._orient=config;return this;} 16 var x=config;if(x.milliseconds){this.addMilliseconds(x.milliseconds);} 17 if(x.seconds){this.addSeconds(x.seconds);} 18 if(x.minutes){this.addMinutes(x.minutes);} 19 if(x.hours){this.addHours(x.hours);} 20 if(x.weeks){this.addWeeks(x.weeks);} 21 if(x.months){this.addMonths(x.months);} 22 if(x.years){this.addYears(x.years);} 23 if(x.days){this.addDays(x.days);} 24 return this;};var $y,$m,$d;$P.getWeek=function(){var a,b,c,d,e,f,g,n,s,w;$y=(!$y)?this.getFullYear():$y;$m=(!$m)?this.getMonth()+1:$m;$d=(!$d)?this.getDate():$d;if($m<=2){a=$y-1;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=0;f=$d-1+(31*($m-1));}else{a=$y;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=s+1;f=$d+((153*($m-3)+2)/5)+58+s;} 25 g=(a+b)%7;d=(f+g-e)%7;n=(f+3-d)|0;if(n<0){w=53-((g-s)/5|0);}else if(n>364+s){w=1;}else{w=(n/7|0)+1;} 26 $y=$m=$d=null;return w;};$P.getISOWeek=function(){$y=this.getUTCFullYear();$m=this.getUTCMonth()+1;$d=this.getUTCDate();return p(this.getWeek());};$P.setWeek=function(n){return this.moveToDayOfWeek(1).addWeeks(n-this.getWeek());};$D._validate=function(n,min,max,name){if(typeof n=="undefined"){return false;}else if(typeof n!="number"){throw new TypeError(n+" is not a Number.");}else if(n<min||n>max){throw new RangeError(n+" is not a valid value for "+name+".");} 27 return true;};$D.validateMillisecond=function(value){return $D._validate(value,0,999,"millisecond");};$D.validateSecond=function(value){return $D._validate(value,0,59,"second");};$D.validateMinute=function(value){return $D._validate(value,0,59,"minute");};$D.validateHour=function(value){return $D._validate(value,0,23,"hour");};$D.validateDay=function(value,year,month){return $D._validate(value,1,$D.getDaysInMonth(year,month),"day");};$D.validateMonth=function(value){return $D._validate(value,0,11,"month");};$D.validateYear=function(value){return $D._validate(value,0,9999,"year");};$P.set=function(config){if($D.validateMillisecond(config.millisecond)){this.addMilliseconds(config.millisecond-this.getMilliseconds());} 28 if($D.validateSecond(config.second)){this.addSeconds(config.second-this.getSeconds());} 29 if($D.validateMinute(config.minute)){this.addMinutes(config.minute-this.getMinutes());} 30 if($D.validateHour(config.hour)){this.addHours(config.hour-this.getHours());} 31 if($D.validateMonth(config.month)){this.addMonths(config.month-this.getMonth());} 32 if($D.validateYear(config.year)){this.addYears(config.year-this.getFullYear());} 33 if($D.validateDay(config.day,this.getFullYear(),this.getMonth())){this.addDays(config.day-this.getDate());} 34 if(config.timezone){this.setTimezone(config.timezone);} 35 if(config.timezoneOffset){this.setTimezoneOffset(config.timezoneOffset);} 36 if(config.week&&$D._validate(config.week,0,53,"week")){this.setWeek(config.week);} 37 return this;};$P.moveToFirstDayOfMonth=function(){return this.set({day:1});};$P.moveToLastDayOfMonth=function(){return this.set({day:$D.getDaysInMonth(this.getFullYear(),this.getMonth())});};$P.moveToNthOccurrence=function(dayOfWeek,occurrence){var shift=0;if(occurrence>0){shift=occurrence-1;} 38 else if(occurrence===-1){this.moveToLastDayOfMonth();if(this.getDay()!==dayOfWeek){this.moveToDayOfWeek(dayOfWeek,-1);} 39 return this;} 40 return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek,+1).addWeeks(shift);};$P.moveToDayOfWeek=function(dayOfWeek,orient){var diff=(dayOfWeek-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};$P.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};$P.getOrdinalNumber=function(){return Math.ceil((this.clone().clearTime()-new Date(this.getFullYear(),0,1))/86400000)+1;};$P.getTimezone=function(){return $D.getTimezoneAbbreviation(this.getUTCOffset());};$P.setTimezoneOffset=function(offset){var here=this.getTimezoneOffset(),there=Number(offset)*-6/10;return this.addMinutes(there-here);};$P.setTimezone=function(offset){return this.setTimezoneOffset($D.getTimezoneOffset(offset));};$P.hasDaylightSavingTime=function(){return(Date.today().set({month:0,day:1}).getTimezoneOffset()!==Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.isDaylightSavingTime=function(){return(this.hasDaylightSavingTime()&&new Date().getTimezoneOffset()===Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r.charAt(0)+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};$P.getElapsed=function(date){return(date||new Date())-this;};if(!$P.toISOString){$P.toISOString=function(){function f(n){return n<10?'0'+n:n;} 41 return'"'+this.getUTCFullYear()+'-'+ 42 f(this.getUTCMonth()+1)+'-'+ 43 f(this.getUTCDate())+'T'+ 44 f(this.getUTCHours())+':'+ 45 f(this.getUTCMinutes())+':'+ 46 f(this.getUTCSeconds())+'Z"';};} 47 $P._toString=$P.toString;$P.toString=function(format){var x=this;if(format&&format.length==1){var c=$C.formatPatterns;x.t=x.toString;switch(format){case"d":return x.t(c.shortDate);case"D":return x.t(c.longDate);case"F":return x.t(c.fullDateTime);case"m":return x.t(c.monthDay);case"r":return x.t(c.rfc1123);case"s":return x.t(c.sortableDateTime);case"t":return x.t(c.shortTime);case"T":return x.t(c.longTime);case"u":return x.t(c.universalSortableDateTime);case"y":return x.t(c.yearMonth);}} 48 var ord=function(n){switch(n*1){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}};return format?format.replace(/(\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S)/g,function(m){if(m.charAt(0)==="\\"){return m.replace("\\","");} 49 x.h=x.getHours;switch(m){case"hh":return p(x.h()<13?(x.h()===0?12:x.h()):(x.h()-12));case"h":return x.h()<13?(x.h()===0?12:x.h()):(x.h()-12);case"HH":return p(x.h());case"H":return x.h();case"mm":return p(x.getMinutes());case"m":return x.getMinutes();case"ss":return p(x.getSeconds());case"s":return x.getSeconds();case"yyyy":return p(x.getFullYear(),4);case"yy":return p(x.getFullYear());case"dddd":return $C.dayNames[x.getDay()];case"ddd":return $C.abbreviatedDayNames[x.getDay()];case"dd":return p(x.getDate());case"d":return x.getDate();case"MMMM":return $C.monthNames[x.getMonth()];case"MMM":return $C.abbreviatedMonthNames[x.getMonth()];case"MM":return p((x.getMonth()+1));case"M":return x.getMonth()+1;case"t":return x.h()<12?$C.amDesignator.substring(0,1):$C.pmDesignator.substring(0,1);case"tt":return x.h()<12?$C.amDesignator:$C.pmDesignator;case"S":return ord(x.getDate());default:return m;}}):this._toString();};}()); 50 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,$N=Number.prototype;$P._orient=+1;$P._nth=null;$P._is=false;$P._same=false;$P._isSecond=false;$N._dateElement="day";$P.next=function(){this._orient=+1;return this;};$D.next=function(){return $D.today().next();};$P.last=$P.prev=$P.previous=function(){this._orient=-1;return this;};$D.last=$D.prev=$D.previous=function(){return $D.today().last();};$P.is=function(){this._is=true;return this;};$P.same=function(){this._same=true;this._isSecond=false;return this;};$P.today=function(){return this.same().day();};$P.weekday=function(){if(this._is){this._is=false;return(!this.is().sat()&&!this.is().sun());} 51 return false;};$P.at=function(time){return(typeof time==="string")?$D.parse(this.toString("d")+" "+time):this.set(time);};$N.fromNow=$N.after=function(date){var c={};c[this._dateElement]=this;return((!date)?new Date():date.clone()).add(c);};$N.ago=$N.before=function(date){var c={};c[this._dateElement]=this*-1;return((!date)?new Date():date.clone()).add(c);};var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),pxf=("Milliseconds Seconds Minutes Hours Date Week Month FullYear").split(/\s/),nth=("final first second third fourth fifth").split(/\s/),de;$P.toObject=function(){var o={};for(var i=0;i<px.length;i++){o[px[i].toLowerCase()]=this["get"+pxf[i]]();} 52 return o;};$D.fromObject=function(config){config.week=null;return Date.today().set(config);};var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} 53 if(this._nth!==null){if(this._isSecond){this.addSeconds(this._orient*-1);} 54 this._isSecond=false;var ntemp=this._nth;this._nth=null;var temp=this.clone().moveToLastDayOfMonth();this.moveToNthOccurrence(n,ntemp);if(this>temp){throw new RangeError($D.getDayName(n)+" does not occur "+ntemp+" times in the month of "+$D.getMonthName(temp.getMonth())+" "+temp.getFullYear()+".");} 55 return this;} 56 return this.moveToDayOfWeek(n,this._orient);};};var sdf=function(n){return function(){var t=$D.today(),shift=n-t.getDay();if(n===0&&$C.firstDayOfWeek===1&&t.getDay()!==0){shift=shift+7;} 57 return t.addDays(shift);};};for(var i=0;i<dx.length;i++){$D[dx[i].toUpperCase()]=$D[dx[i].toUpperCase().substring(0,3)]=i;$D[dx[i]]=$D[dx[i].substring(0,3)]=sdf(i);$P[dx[i]]=$P[dx[i].substring(0,3)]=df(i);} 43 58 var mf=function(n){return function(){if(this._is){this._is=false;return this.getMonth()===n;} 44 return this.moveToMonth(n,this._orient);};};for(var j=0;j<mx.length;j++){$D[mx[j]]=$D[mx[j].substring(0,3)]=mf(j);} 45 var ef=function(j){return function(){if(j.substring(j.length-1)!="s"){j+="s";} 46 return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$D[de]=$D[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);}}());Date.prototype.toJSONString=function(){return this.toString("yyyy-MM-ddThh:mm:ssZ");};Date.prototype.toShortDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern);};Date.prototype.toLongDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.longDatePattern);};Date.prototype.toShortTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortTimePattern);};Date.prototype.toLongTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.longTimePattern);};Date.prototype.getOrdinal=function(){switch(this.getDate()){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}}; 59 return this.moveToMonth(n,this._orient);};};var smf=function(n){return function(){return $D.today().set({month:n,day:1});};};for(var j=0;j<mx.length;j++){$D[mx[j].toUpperCase()]=$D[mx[j].toUpperCase().substring(0,3)]=j;$D[mx[j]]=$D[mx[j].substring(0,3)]=smf(j);$P[mx[j]]=$P[mx[j].substring(0,3)]=mf(j);} 60 var ef=function(j){return function(){if(this._isSecond){this._isSecond=false;return this;} 61 if(this._same){this._same=this._is=false;var o1=this.toObject(),o2=(arguments[0]||new Date()).toObject(),v="",k=j.toLowerCase();for(var m=(px.length-1);m>-1;m--){v=px[m].toLowerCase();if(o1[v]!=o2[v]){return false;} 62 if(k==v){break;}} 63 return true;} 64 if(j.substring(j.length-1)!="s"){j+="s";} 65 return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$P[de]=$P[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);} 66 $P._ss=ef("Second");var nthfn=function(n){return function(dayOfWeek){if(this._same){return this._ss(arguments[0]);} 67 if(dayOfWeek||dayOfWeek===0){return this.moveToNthOccurrence(dayOfWeek,n);} 68 this._nth=n;if(n===2&&(dayOfWeek===undefined||dayOfWeek===null)){this._isSecond=true;return this.addSeconds(this._orient);} 69 return this;};};for(var l=0;l<nth.length;l++){$P[nth[l]]=(l===0)?nthfn(-1):nthfn(l);}}()); 47 70 (function(){Date.Parsing={Exception:function(s){this.message="Parse error at '"+s.substring(0,10)+" ...'";}};var $P=Date.Parsing;var _=$P.Operators={rtoken:function(r){return function(s){var mx=s.match(r);if(mx){return([mx[0],s.substring(mx[0].length)]);}else{throw new $P.Exception(s);}};},token:function(s){return function(s){return _.rtoken(new RegExp("^\s*"+s+"\s*"))(s);};},stoken:function(s){return _.rtoken(new RegExp("^"+s));},until:function(p){return function(s){var qx=[],rx=null;while(s.length){try{rx=p.call(this,s);}catch(e){qx.push(rx[0]);s=rx[1];continue;} 48 71 break;} … … 79 102 return rx;};}};var _generator=function(op){return function(){var args=null,rx=[];if(arguments.length>1){args=Array.prototype.slice.call(arguments);}else if(arguments[0]instanceof Array){args=arguments[0];} 80 103 if(args){for(var i=0,px=args.shift();i<px.length;i++){args.unshift(px[i]);rx.push(op.apply(null,args));args.shift();return rx;}}else{return op.apply(null,arguments);}};};var gx="optional not ignore cache".split(/\s/);for(var i=0;i<gx.length;i++){_[gx[i]]=_generator(_[gx[i]]);} 81 var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} 82 return rx;};Date.Grammar={};Date.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=((s.length==3)?Date.getMonthNumberFromName(s):(Number(s)-1));};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<Date.CultureInfo.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];var now=new Date();this.year=now.getFullYear();this.month=now.getMonth();this.day=1;this.hour=0;this.minute=0;this.second=0;for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} 83 this.hour=(this.meridian=="p"&&this.hour<13)?this.hour+12:this.hour;if(this.day>Date.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} 104 var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo;var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} 105 return rx;};$D.Grammar={};$D.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=(s.length==3)?"jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4:Number(s)-1;};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<$C.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} 106 var now=new Date();if((this.hour||this.minute)&&(!this.month&&!this.year&&!this.day)){this.day=now.getDate();} 107 if(!this.year){this.year=now.getFullYear();} 108 if(!this.month&&this.month!==0){this.month=now.getMonth();} 109 if(!this.day){this.day=1;} 110 if(!this.hour){this.hour=0;} 111 if(!this.minute){this.minute=0;} 112 if(!this.second){this.second=0;} 113 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 114 if(this.day>$D.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} 84 115 var r=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){r.set({timezone:this.timezone});}else if(this.timezoneOffset){r.set({timezoneOffset:this.timezoneOffset});} 85 116 return r;},finish:function(x){x=(x instanceof Array)?flattenAndCompact(x):[x];if(x.length===0){return null;} 86 117 for(var i=0;i<x.length;i++){if(typeof x[i]=="function"){x[i].call(this);}} 87 if(this.now){return new Date();} 88 var today=Date.today();var method=null;var expression=!!(this.days!=null||this.orient||this.operator);if(expression){var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(this.weekday){this.unit="day";gap=(Date.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} 89 if(this.month){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} 118 var today=$D.today();if(this.now&&!this.unit&&!this.operator){return new Date();}else if(this.now){today=new Date();} 119 var expression=!!(this.days&&this.days!==null||this.orient||this.operator);var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(!this.now&&"hour minute second".indexOf(this.unit)!=-1){today.setTimeToNow();} 120 if(this.month||this.month===0){if("year day hour minute second".indexOf(this.unit)!=-1){this.value=this.month+1;this.month=null;expression=true;}} 121 if(!expression&&this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(!this.month){this.month=temp.getMonth();} 122 this.year=temp.getFullYear();} 123 if(expression&&this.weekday&&this.unit!="month"){this.unit="day";gap=($D.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} 124 if(this.month&&this.unit=="day"&&this.operator){this.value=(this.month+1);this.month=null;} 125 if(this.value!=null&&this.month!=null&&this.year!=null){this.day=this.value*1;} 126 if(this.month&&!this.day&&this.value){today.set({day:this.value*1});if(!expression){this.day=this.value*1;}} 127 if(!this.month&&this.value&&this.unit=="month"&&!this.now){this.month=this.value;expression=true;} 128 if(expression&&(this.month||this.month===0)&&this.unit!="year"){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} 90 129 if(!this.unit){this.unit="day";} 91 if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} 92 if(this.unit=="week"){this.unit="day";this.value=this.value*7;} 130 if(!this.value&&this.operator&&this.operator!==null&&this[this.unit+"s"]&&this[this.unit+"s"]!==null){this[this.unit+"s"]=this[this.unit+"s"]+((this.operator=="add")?1:-1)+(this.value||0)*orient;}else if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} 93 131 this[this.unit+"s"]=this.value*orient;} 94 return today.add(this);}else{if(this.meridian&&this.hour){this.hour=(this.hour<13&&this.meridian=="p")?this.hour+12:this.hour;} 95 if(this.weekday&&!this.day){this.day=(today.addDays((Date.getDayNumberFromName(this.weekday)-today.getDay()))).getDate();} 96 if(this.month&&!this.day){this.day=1;} 97 return today.set(this);}}};var _=Date.Parsing.Operators,g=Date.Grammar,t=Date.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=Date.CultureInfo.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} 132 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 133 if(this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(temp.getMonth()!==today.getMonth()){this.month=temp.getMonth();}} 134 if((this.month||this.month===0)&&!this.day){this.day=1;} 135 if(!this.orient&&!this.operator&&this.unit=="week"&&this.value&&!this.day&&!this.month){return Date.today().setWeek(this.value);} 136 if(expression&&this.timezone&&this.day&&this.days){this.day=this.days;} 137 return(expression)?today.add(this):today.set(this);}};var _=$D.Parsing.Operators,g=$D.Grammar,t=$D.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|@|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=$C.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} 98 138 fn=_C[keys]=_.any.apply(null,px);} 99 return fn;};g.ctoken2=function(key){return _.rtoken(Date.CultureInfo.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.mm,g.ss],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^(\+|\-)?\s*\d\d\d\d?/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^(\+|\-)\s*\d\d\d\d/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[Date.CultureInfo.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw Date.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} 100 return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["yyyy-MM-ddTHH:mm:ss","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} 101 return g._start.call({},s);};}());Date._parse=Date.parse;Date.parse=function(s){var r=null;if(!s){return null;} 102 try{r=Date.Grammar.start.call({},s);}catch(e){return null;} 103 return((r[1].length===0)?r[0]:null);};Date.getParseFunction=function(fx){var fn=Date.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} 104 return((r[1].length===0)?r[0]:null);};};Date.parseExact=function(s,fx){return Date.getParseFunction(fx)(s);}; 139 return fn;};g.ctoken2=function(key){return _.rtoken($C.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.m,g.s],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("second minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[$C.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw $D.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} 140 return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["\"yyyy-MM-ddTHH:mm:ssZ\"","yyyy-MM-ddTHH:mm:ssZ","yyyy-MM-ddTHH:mm:ssz","yyyy-MM-ddTHH:mm:ss","yyyy-MM-ddTHH:mmZ","yyyy-MM-ddTHH:mmz","yyyy-MM-ddTHH:mm","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","MMddyyyy","ddMMyyyy","Mddyyyy","ddMyyyy","Mdyyyy","dMyyyy","yyyy","Mdyy","dMyy","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} 141 return g._start.call({},s);};$D._parse=$D.parse;$D.parse=function(s){var r=null;if(!s){return null;} 142 if(s instanceof Date){return s;} 143 try{r=$D.Grammar.start.call({},s.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));}catch(e){return null;} 144 return((r[1].length===0)?r[0]:null);};$D.getParseFunction=function(fx){var fn=$D.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} 145 return((r[1].length===0)?r[0]:null);};};$D.parseExact=function(s,fx){return $D.getParseFunction(fx)(s);};}()); -
branches/2.4/prototype/plugins/datejs/date.js
r5341 r7151 1 1 /** 2 * Please include a date.js file from the /build/ folder. 3 * 4 * Individual date.js files have been compiled for each of the 150+ supported Cultures. 5 * 6 * Example: 7 * date.js // English (United States) 8 * date-en-US.js // English (United States) 9 * date-de-DE.js // Deutsch (Deutschland) 10 * date-es-MX.js // français (France) 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 11 8 */ 12 13 alert( 14 "Please include a date.js file from the /build/ folder.\n\n" + 15 "Individual date.js files have been compiled for each supported Culture.\n\n" + 16 "Example:\n" + 17 " date.js // English (United States)\n" + 18 " date-en-US.js // English (United States)\n" + 19 " date-de-DE.js // Deutsch (Deutschland)\n" + 20 " date-es-MX.js // français (France)\n" 21 ); 9 Date.CultureInfo={name:"en-US",englishName:"English (United States)",nativeName:"English (United States)",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbreviatedDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortestDayNames:["Su","Mo","Tu","We","Th","Fr","Sa"],firstLetterDayNames:["S","M","T","W","T","F","S"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbreviatedMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],amDesignator:"AM",pmDesignator:"PM",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"mdy",formatPatterns:{shortDate:"M/d/yyyy",longDate:"dddd, MMMM dd, yyyy",shortTime:"h:mm tt",longTime:"h:mm:ss tt",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"MMMM dd",yearMonth:"MMMM, yyyy"},regexPatterns:{jan:/^jan(uary)?/i,feb:/^feb(ruary)?/i,mar:/^mar(ch)?/i,apr:/^apr(il)?/i,may:/^may/i,jun:/^jun(e)?/i,jul:/^jul(y)?/i,aug:/^aug(ust)?/i,sep:/^sep(t(ember)?)?/i,oct:/^oct(ober)?/i,nov:/^nov(ember)?/i,dec:/^dec(ember)?/i,sun:/^su(n(day)?)?/i,mon:/^mo(n(day)?)?/i,tue:/^tu(e(s(day)?)?)?/i,wed:/^we(d(nesday)?)?/i,thu:/^th(u(r(s(day)?)?)?)?/i,fri:/^fr(i(day)?)?/i,sat:/^sa(t(urday)?)?/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|aft(er)?|from|hence)/i,subtract:/^(\-|bef(ore)?|ago)/i,yesterday:/^yes(terday)?/i,today:/^t(od(ay)?)?/i,tomorrow:/^tom(orrow)?/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^mn|min(ute)?s?/i,hour:/^h(our)?s?/i,week:/^w(eek)?s?/i,month:/^m(onth)?s?/i,day:/^d(ay)?s?/i,year:/^y(ear)?s?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt|utc)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a(?!u|p)|p)/i},timezones:[{name:"UTC",offset:"-000"},{name:"GMT",offset:"-000"},{name:"EST",offset:"-0500"},{name:"EDT",offset:"-0400"},{name:"CST",offset:"-0600"},{name:"CDT",offset:"-0500"},{name:"MST",offset:"-0700"},{name:"MDT",offset:"-0600"},{name:"PST",offset:"-0800"},{name:"PDT",offset:"-0700"}]}; 10 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,p=function(s,l){if(!l){l=2;} 11 return("000"+s).slice(l*-1);};$P.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};$P.setTimeToNow=function(){var n=new Date();this.setHours(n.getHours());this.setMinutes(n.getMinutes());this.setSeconds(n.getSeconds());this.setMilliseconds(n.getMilliseconds());return this;};$D.today=function(){return new Date().clearTime();};$D.compare=function(date1,date2){if(isNaN(date1)||isNaN(date2)){throw new Error(date1+" - "+date2);}else if(date1 instanceof Date&&date2 instanceof Date){return(date1<date2)?-1:(date1>date2)?1:0;}else{throw new TypeError(date1+" - "+date2);}};$D.equals=function(date1,date2){return(date1.compareTo(date2)===0);};$D.getDayNumberFromName=function(name){var n=$C.dayNames,m=$C.abbreviatedDayNames,o=$C.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s||o[i].toLowerCase()==s){return i;}} 12 return-1;};$D.getMonthNumberFromName=function(name){var n=$C.monthNames,m=$C.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} 13 return-1;};$D.isLeapYear=function(year){return((year%4===0&&year%100!==0)||year%400===0);};$D.getDaysInMonth=function(year,month){return[31,($D.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};$D.getTimezoneAbbreviation=function(offset){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].offset===offset){return z[i].name;}} 14 return null;};$D.getTimezoneOffset=function(name){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].name===name.toUpperCase()){return z[i].offset;}} 15 return null;};$P.clone=function(){return new Date(this.getTime());};$P.compareTo=function(date){return Date.compare(this,date);};$P.equals=function(date){return Date.equals(this,date||new Date());};$P.between=function(start,end){return this.getTime()>=start.getTime()&&this.getTime()<=end.getTime();};$P.isAfter=function(date){return this.compareTo(date||new Date())===1;};$P.isBefore=function(date){return(this.compareTo(date||new Date())===-1);};$P.isToday=function(){return this.isSameDay(new Date());};$P.isSameDay=function(date){return this.clone().clearTime().equals(date.clone().clearTime());};$P.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};$P.addSeconds=function(value){return this.addMilliseconds(value*1000);};$P.addMinutes=function(value){return this.addMilliseconds(value*60000);};$P.addHours=function(value){return this.addMilliseconds(value*3600000);};$P.addDays=function(value){this.setDate(this.getDate()+value);return this;};$P.addWeeks=function(value){return this.addDays(value*7);};$P.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,$D.getDaysInMonth(this.getFullYear(),this.getMonth())));return this;};$P.addYears=function(value){return this.addMonths(value*12);};$P.add=function(config){if(typeof config=="number"){this._orient=config;return this;} 16 var x=config;if(x.milliseconds){this.addMilliseconds(x.milliseconds);} 17 if(x.seconds){this.addSeconds(x.seconds);} 18 if(x.minutes){this.addMinutes(x.minutes);} 19 if(x.hours){this.addHours(x.hours);} 20 if(x.weeks){this.addWeeks(x.weeks);} 21 if(x.months){this.addMonths(x.months);} 22 if(x.years){this.addYears(x.years);} 23 if(x.days){this.addDays(x.days);} 24 return this;};var $y,$m,$d;$P.getWeek=function(){var a,b,c,d,e,f,g,n,s,w;$y=(!$y)?this.getFullYear():$y;$m=(!$m)?this.getMonth()+1:$m;$d=(!$d)?this.getDate():$d;if($m<=2){a=$y-1;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=0;f=$d-1+(31*($m-1));}else{a=$y;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=s+1;f=$d+((153*($m-3)+2)/5)+58+s;} 25 g=(a+b)%7;d=(f+g-e)%7;n=(f+3-d)|0;if(n<0){w=53-((g-s)/5|0);}else if(n>364+s){w=1;}else{w=(n/7|0)+1;} 26 $y=$m=$d=null;return w;};$P.getISOWeek=function(){$y=this.getUTCFullYear();$m=this.getUTCMonth()+1;$d=this.getUTCDate();return p(this.getWeek());};$P.setWeek=function(n){return this.moveToDayOfWeek(1).addWeeks(n-this.getWeek());};$D._validate=function(n,min,max,name){if(typeof n=="undefined"){return false;}else if(typeof n!="number"){throw new TypeError(n+" is not a Number.");}else if(n<min||n>max){throw new RangeError(n+" is not a valid value for "+name+".");} 27 return true;};$D.validateMillisecond=function(value){return $D._validate(value,0,999,"millisecond");};$D.validateSecond=function(value){return $D._validate(value,0,59,"second");};$D.validateMinute=function(value){return $D._validate(value,0,59,"minute");};$D.validateHour=function(value){return $D._validate(value,0,23,"hour");};$D.validateDay=function(value,year,month){return $D._validate(value,1,$D.getDaysInMonth(year,month),"day");};$D.validateMonth=function(value){return $D._validate(value,0,11,"month");};$D.validateYear=function(value){return $D._validate(value,0,9999,"year");};$P.set=function(config){if($D.validateMillisecond(config.millisecond)){this.addMilliseconds(config.millisecond-this.getMilliseconds());} 28 if($D.validateSecond(config.second)){this.addSeconds(config.second-this.getSeconds());} 29 if($D.validateMinute(config.minute)){this.addMinutes(config.minute-this.getMinutes());} 30 if($D.validateHour(config.hour)){this.addHours(config.hour-this.getHours());} 31 if($D.validateMonth(config.month)){this.addMonths(config.month-this.getMonth());} 32 if($D.validateYear(config.year)){this.addYears(config.year-this.getFullYear());} 33 if($D.validateDay(config.day,this.getFullYear(),this.getMonth())){this.addDays(config.day-this.getDate());} 34 if(config.timezone){this.setTimezone(config.timezone);} 35 if(config.timezoneOffset){this.setTimezoneOffset(config.timezoneOffset);} 36 if(config.week&&$D._validate(config.week,0,53,"week")){this.setWeek(config.week);} 37 return this;};$P.moveToFirstDayOfMonth=function(){return this.set({day:1});};$P.moveToLastDayOfMonth=function(){return this.set({day:$D.getDaysInMonth(this.getFullYear(),this.getMonth())});};$P.moveToNthOccurrence=function(dayOfWeek,occurrence){var shift=0;if(occurrence>0){shift=occurrence-1;} 38 else if(occurrence===-1){this.moveToLastDayOfMonth();if(this.getDay()!==dayOfWeek){this.moveToDayOfWeek(dayOfWeek,-1);} 39 return this;} 40 return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek,+1).addWeeks(shift);};$P.moveToDayOfWeek=function(dayOfWeek,orient){var diff=(dayOfWeek-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};$P.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};$P.getOrdinalNumber=function(){return Math.ceil((this.clone().clearTime()-new Date(this.getFullYear(),0,1))/86400000)+1;};$P.getTimezone=function(){return $D.getTimezoneAbbreviation(this.getUTCOffset());};$P.setTimezoneOffset=function(offset){var here=this.getTimezoneOffset(),there=Number(offset)*-6/10;return this.addMinutes(there-here);};$P.setTimezone=function(offset){return this.setTimezoneOffset($D.getTimezoneOffset(offset));};$P.hasDaylightSavingTime=function(){return(Date.today().set({month:0,day:1}).getTimezoneOffset()!==Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.isDaylightSavingTime=function(){return(this.hasDaylightSavingTime()&&new Date().getTimezoneOffset()===Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r.charAt(0)+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};$P.getElapsed=function(date){return(date||new Date())-this;};if(!$P.toISOString){$P.toISOString=function(){function f(n){return n<10?'0'+n:n;} 41 return'"'+this.getUTCFullYear()+'-'+ 42 f(this.getUTCMonth()+1)+'-'+ 43 f(this.getUTCDate())+'T'+ 44 f(this.getUTCHours())+':'+ 45 f(this.getUTCMinutes())+':'+ 46 f(this.getUTCSeconds())+'Z"';};} 47 $P._toString=$P.toString;$P.toString=function(format){var x=this;if(format&&format.length==1){var c=$C.formatPatterns;x.t=x.toString;switch(format){case"d":return x.t(c.shortDate);case"D":return x.t(c.longDate);case"F":return x.t(c.fullDateTime);case"m":return x.t(c.monthDay);case"r":return x.t(c.rfc1123);case"s":return x.t(c.sortableDateTime);case"t":return x.t(c.shortTime);case"T":return x.t(c.longTime);case"u":return x.t(c.universalSortableDateTime);case"y":return x.t(c.yearMonth);}} 48 var ord=function(n){switch(n*1){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}};return format?format.replace(/(\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S)/g,function(m){if(m.charAt(0)==="\\"){return m.replace("\\","");} 49 x.h=x.getHours;switch(m){case"hh":return p(x.h()<13?(x.h()===0?12:x.h()):(x.h()-12));case"h":return x.h()<13?(x.h()===0?12:x.h()):(x.h()-12);case"HH":return p(x.h());case"H":return x.h();case"mm":return p(x.getMinutes());case"m":return x.getMinutes();case"ss":return p(x.getSeconds());case"s":return x.getSeconds();case"yyyy":return p(x.getFullYear(),4);case"yy":return p(x.getFullYear());case"dddd":return $C.dayNames[x.getDay()];case"ddd":return $C.abbreviatedDayNames[x.getDay()];case"dd":return p(x.getDate());case"d":return x.getDate();case"MMMM":return $C.monthNames[x.getMonth()];case"MMM":return $C.abbreviatedMonthNames[x.getMonth()];case"MM":return p((x.getMonth()+1));case"M":return x.getMonth()+1;case"t":return x.h()<12?$C.amDesignator.substring(0,1):$C.pmDesignator.substring(0,1);case"tt":return x.h()<12?$C.amDesignator:$C.pmDesignator;case"S":return ord(x.getDate());default:return m;}}):this._toString();};}()); 50 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,$N=Number.prototype;$P._orient=+1;$P._nth=null;$P._is=false;$P._same=false;$P._isSecond=false;$N._dateElement="day";$P.next=function(){this._orient=+1;return this;};$D.next=function(){return $D.today().next();};$P.last=$P.prev=$P.previous=function(){this._orient=-1;return this;};$D.last=$D.prev=$D.previous=function(){return $D.today().last();};$P.is=function(){this._is=true;return this;};$P.same=function(){this._same=true;this._isSecond=false;return this;};$P.today=function(){return this.same().day();};$P.weekday=function(){if(this._is){this._is=false;return(!this.is().sat()&&!this.is().sun());} 51 return false;};$P.at=function(time){return(typeof time==="string")?$D.parse(this.toString("d")+" "+time):this.set(time);};$N.fromNow=$N.after=function(date){var c={};c[this._dateElement]=this;return((!date)?new Date():date.clone()).add(c);};$N.ago=$N.before=function(date){var c={};c[this._dateElement]=this*-1;return((!date)?new Date():date.clone()).add(c);};var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),pxf=("Milliseconds Seconds Minutes Hours Date Week Month FullYear").split(/\s/),nth=("final first second third fourth fifth").split(/\s/),de;$P.toObject=function(){var o={};for(var i=0;i<px.length;i++){o[px[i].toLowerCase()]=this["get"+pxf[i]]();} 52 return o;};$D.fromObject=function(config){config.week=null;return Date.today().set(config);};var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} 53 if(this._nth!==null){if(this._isSecond){this.addSeconds(this._orient*-1);} 54 this._isSecond=false;var ntemp=this._nth;this._nth=null;var temp=this.clone().moveToLastDayOfMonth();this.moveToNthOccurrence(n,ntemp);if(this>temp){throw new RangeError($D.getDayName(n)+" does not occur "+ntemp+" times in the month of "+$D.getMonthName(temp.getMonth())+" "+temp.getFullYear()+".");} 55 return this;} 56 return this.moveToDayOfWeek(n,this._orient);};};var sdf=function(n){return function(){var t=$D.today(),shift=n-t.getDay();if(n===0&&$C.firstDayOfWeek===1&&t.getDay()!==0){shift=shift+7;} 57 return t.addDays(shift);};};for(var i=0;i<dx.length;i++){$D[dx[i].toUpperCase()]=$D[dx[i].toUpperCase().substring(0,3)]=i;$D[dx[i]]=$D[dx[i].substring(0,3)]=sdf(i);$P[dx[i]]=$P[dx[i].substring(0,3)]=df(i);} 58 var mf=function(n){return function(){if(this._is){this._is=false;return this.getMonth()===n;} 59 return this.moveToMonth(n,this._orient);};};var smf=function(n){return function(){return $D.today().set({month:n,day:1});};};for(var j=0;j<mx.length;j++){$D[mx[j].toUpperCase()]=$D[mx[j].toUpperCase().substring(0,3)]=j;$D[mx[j]]=$D[mx[j].substring(0,3)]=smf(j);$P[mx[j]]=$P[mx[j].substring(0,3)]=mf(j);} 60 var ef=function(j){return function(){if(this._isSecond){this._isSecond=false;return this;} 61 if(this._same){this._same=this._is=false;var o1=this.toObject(),o2=(arguments[0]||new Date()).toObject(),v="",k=j.toLowerCase();for(var m=(px.length-1);m>-1;m--){v=px[m].toLowerCase();if(o1[v]!=o2[v]){return false;} 62 if(k==v){break;}} 63 return true;} 64 if(j.substring(j.length-1)!="s"){j+="s";} 65 return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$P[de]=$P[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);} 66 $P._ss=ef("Second");var nthfn=function(n){return function(dayOfWeek){if(this._same){return this._ss(arguments[0]);} 67 if(dayOfWeek||dayOfWeek===0){return this.moveToNthOccurrence(dayOfWeek,n);} 68 this._nth=n;if(n===2&&(dayOfWeek===undefined||dayOfWeek===null)){this._isSecond=true;return this.addSeconds(this._orient);} 69 return this;};};for(var l=0;l<nth.length;l++){$P[nth[l]]=(l===0)?nthfn(-1):nthfn(l);}}()); 70 (function(){Date.Parsing={Exception:function(s){this.message="Parse error at '"+s.substring(0,10)+" ...'";}};var $P=Date.Parsing;var _=$P.Operators={rtoken:function(r){return function(s){var mx=s.match(r);if(mx){return([mx[0],s.substring(mx[0].length)]);}else{throw new $P.Exception(s);}};},token:function(s){return function(s){return _.rtoken(new RegExp("^\s*"+s+"\s*"))(s);};},stoken:function(s){return _.rtoken(new RegExp("^"+s));},until:function(p){return function(s){var qx=[],rx=null;while(s.length){try{rx=p.call(this,s);}catch(e){qx.push(rx[0]);s=rx[1];continue;} 71 break;} 72 return[qx,s];};},many:function(p){return function(s){var rx=[],r=null;while(s.length){try{r=p.call(this,s);}catch(e){return[rx,s];} 73 rx.push(r[0]);s=r[1];} 74 return[rx,s];};},optional:function(p){return function(s){var r=null;try{r=p.call(this,s);}catch(e){return[null,s];} 75 return[r[0],r[1]];};},not:function(p){return function(s){try{p.call(this,s);}catch(e){return[null,s];} 76 throw new $P.Exception(s);};},ignore:function(p){return p?function(s){var r=null;r=p.call(this,s);return[null,r[1]];}:null;},product:function(){var px=arguments[0],qx=Array.prototype.slice.call(arguments,1),rx=[];for(var i=0;i<px.length;i++){rx.push(_.each(px[i],qx));} 77 return rx;},cache:function(rule){var cache={},r=null;return function(s){try{r=cache[s]=(cache[s]||rule.call(this,s));}catch(e){r=cache[s]=e;} 78 if(r instanceof $P.Exception){throw r;}else{return r;}};},any:function(){var px=arguments;return function(s){var r=null;for(var i=0;i<px.length;i++){if(px[i]==null){continue;} 79 try{r=(px[i].call(this,s));}catch(e){r=null;} 80 if(r){return r;}} 81 throw new $P.Exception(s);};},each:function(){var px=arguments;return function(s){var rx=[],r=null;for(var i=0;i<px.length;i++){if(px[i]==null){continue;} 82 try{r=(px[i].call(this,s));}catch(e){throw new $P.Exception(s);} 83 rx.push(r[0]);s=r[1];} 84 return[rx,s];};},all:function(){var px=arguments,_=_;return _.each(_.optional(px));},sequence:function(px,d,c){d=d||_.rtoken(/^\s*/);c=c||null;if(px.length==1){return px[0];} 85 return function(s){var r=null,q=null;var rx=[];for(var i=0;i<px.length;i++){try{r=px[i].call(this,s);}catch(e){break;} 86 rx.push(r[0]);try{q=d.call(this,r[1]);}catch(ex){q=null;break;} 87 s=q[1];} 88 if(!r){throw new $P.Exception(s);} 89 if(q){throw new $P.Exception(q[1]);} 90 if(c){try{r=c.call(this,r[1]);}catch(ey){throw new $P.Exception(r[1]);}} 91 return[rx,(r?r[1]:s)];};},between:function(d1,p,d2){d2=d2||d1;var _fn=_.each(_.ignore(d1),p,_.ignore(d2));return function(s){var rx=_fn.call(this,s);return[[rx[0][0],r[0][2]],rx[1]];};},list:function(p,d,c){d=d||_.rtoken(/^\s*/);c=c||null;return(p instanceof Array?_.each(_.product(p.slice(0,-1),_.ignore(d)),p.slice(-1),_.ignore(c)):_.each(_.many(_.each(p,_.ignore(d))),px,_.ignore(c)));},set:function(px,d,c){d=d||_.rtoken(/^\s*/);c=c||null;return function(s){var r=null,p=null,q=null,rx=null,best=[[],s],last=false;for(var i=0;i<px.length;i++){q=null;p=null;r=null;last=(px.length==1);try{r=px[i].call(this,s);}catch(e){continue;} 92 rx=[[r[0]],r[1]];if(r[1].length>0&&!last){try{q=d.call(this,r[1]);}catch(ex){last=true;}}else{last=true;} 93 if(!last&&q[1].length===0){last=true;} 94 if(!last){var qx=[];for(var j=0;j<px.length;j++){if(i!=j){qx.push(px[j]);}} 95 p=_.set(qx,d).call(this,q[1]);if(p[0].length>0){rx[0]=rx[0].concat(p[0]);rx[1]=p[1];}} 96 if(rx[1].length<best[1].length){best=rx;} 97 if(best[1].length===0){break;}} 98 if(best[0].length===0){return best;} 99 if(c){try{q=c.call(this,best[1]);}catch(ey){throw new $P.Exception(best[1]);} 100 best[1]=q[1];} 101 return best;};},forward:function(gr,fname){return function(s){return gr[fname].call(this,s);};},replace:function(rule,repl){return function(s){var r=rule.call(this,s);return[repl,r[1]];};},process:function(rule,fn){return function(s){var r=rule.call(this,s);return[fn.call(this,r[0]),r[1]];};},min:function(min,rule){return function(s){var rx=rule.call(this,s);if(rx[0].length<min){throw new $P.Exception(s);} 102 return rx;};}};var _generator=function(op){return function(){var args=null,rx=[];if(arguments.length>1){args=Array.prototype.slice.call(arguments);}else if(arguments[0]instanceof Array){args=arguments[0];} 103 if(args){for(var i=0,px=args.shift();i<px.length;i++){args.unshift(px[i]);rx.push(op.apply(null,args));args.shift();return rx;}}else{return op.apply(null,arguments);}};};var gx="optional not ignore cache".split(/\s/);for(var i=0;i<gx.length;i++){_[gx[i]]=_generator(_[gx[i]]);} 104 var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo;var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} 105 return rx;};$D.Grammar={};$D.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=(s.length==3)?"jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4:Number(s)-1;};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<$C.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} 106 var now=new Date();if((this.hour||this.minute)&&(!this.month&&!this.year&&!this.day)){this.day=now.getDate();} 107 if(!this.year){this.year=now.getFullYear();} 108 if(!this.month&&this.month!==0){this.month=now.getMonth();} 109 if(!this.day){this.day=1;} 110 if(!this.hour){this.hour=0;} 111 if(!this.minute){this.minute=0;} 112 if(!this.second){this.second=0;} 113 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 114 if(this.day>$D.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} 115 var r=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){r.set({timezone:this.timezone});}else if(this.timezoneOffset){r.set({timezoneOffset:this.timezoneOffset});} 116 return r;},finish:function(x){x=(x instanceof Array)?flattenAndCompact(x):[x];if(x.length===0){return null;} 117 for(var i=0;i<x.length;i++){if(typeof x[i]=="function"){x[i].call(this);}} 118 var today=$D.today();if(this.now&&!this.unit&&!this.operator){return new Date();}else if(this.now){today=new Date();} 119 var expression=!!(this.days&&this.days!==null||this.orient||this.operator);var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(!this.now&&"hour minute second".indexOf(this.unit)!=-1){today.setTimeToNow();} 120 if(this.month||this.month===0){if("year day hour minute second".indexOf(this.unit)!=-1){this.value=this.month+1;this.month=null;expression=true;}} 121 if(!expression&&this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(!this.month){this.month=temp.getMonth();} 122 this.year=temp.getFullYear();} 123 if(expression&&this.weekday&&this.unit!="month"){this.unit="day";gap=($D.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} 124 if(this.month&&this.unit=="day"&&this.operator){this.value=(this.month+1);this.month=null;} 125 if(this.value!=null&&this.month!=null&&this.year!=null){this.day=this.value*1;} 126 if(this.month&&!this.day&&this.value){today.set({day:this.value*1});if(!expression){this.day=this.value*1;}} 127 if(!this.month&&this.value&&this.unit=="month"&&!this.now){this.month=this.value;expression=true;} 128 if(expression&&(this.month||this.month===0)&&this.unit!="year"){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} 129 if(!this.unit){this.unit="day";} 130 if(!this.value&&this.operator&&this.operator!==null&&this[this.unit+"s"]&&this[this.unit+"s"]!==null){this[this.unit+"s"]=this[this.unit+"s"]+((this.operator=="add")?1:-1)+(this.value||0)*orient;}else if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} 131 this[this.unit+"s"]=this.value*orient;} 132 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 133 if(this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(temp.getMonth()!==today.getMonth()){this.month=temp.getMonth();}} 134 if((this.month||this.month===0)&&!this.day){this.day=1;} 135 if(!this.orient&&!this.operator&&this.unit=="week"&&this.value&&!this.day&&!this.month){return Date.today().setWeek(this.value);} 136 if(expression&&this.timezone&&this.day&&this.days){this.day=this.days;} 137 return(expression)?today.add(this):today.set(this);}};var _=$D.Parsing.Operators,g=$D.Grammar,t=$D.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|@|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=$C.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} 138 fn=_C[keys]=_.any.apply(null,px);} 139 return fn;};g.ctoken2=function(key){return _.rtoken($C.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.m,g.s],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("second minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[$C.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw $D.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} 140 return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["\"yyyy-MM-ddTHH:mm:ssZ\"","yyyy-MM-ddTHH:mm:ssZ","yyyy-MM-ddTHH:mm:ssz","yyyy-MM-ddTHH:mm:ss","yyyy-MM-ddTHH:mmZ","yyyy-MM-ddTHH:mmz","yyyy-MM-ddTHH:mm","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","MMddyyyy","ddMMyyyy","Mddyyyy","ddMyyyy","Mdyyyy","dMyyyy","yyyy","Mdyy","dMyy","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} 141 return g._start.call({},s);};$D._parse=$D.parse;$D.parse=function(s){var r=null;if(!s){return null;} 142 if(s instanceof Date){return s;} 143 try{r=$D.Grammar.start.call({},s.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));}catch(e){return null;} 144 return((r[1].length===0)?r[0]:null);};$D.getParseFunction=function(fx){var fn=$D.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} 145 return((r[1].length===0)?r[0]:null);};};$D.parseExact=function(s,fx){return $D.getParseFunction(fx)(s);};}()); -
branches/2.4/prototype/plugins/datejs/parser-debug.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 12-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-04-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 9 9 10 (function () { 10 11 Date.Parsing = { 11 Exception: function (s) { 12 Exception: function (s) { 12 13 this.message = "Parse error at '" + s.substring(0, 10) + " ...'"; 13 14 } … … 465 466 466 467 (function () { 468 var $D = Date, $P = $D.prototype, $C = $D.CultureInfo; 469 467 470 var flattenAndCompact = function (ax) { 468 471 var rx = []; … … 479 482 }; 480 483 481 Date.Grammar = {};484 $D.Grammar = {}; 482 485 483 Date.Translator = {486 $D.Translator = { 484 487 hour: function (s) { 485 488 return function () { … … 520 523 month: function (s) { 521 524 return function () { 522 this.month = ( (s.length == 3) ? Date.getMonthNumberFromName(s) : (Number(s) - 1));525 this.month = (s.length == 3) ? "jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4 : Number(s) - 1; 523 526 }; 524 527 }, … … 527 530 var n = Number(s); 528 531 this.year = ((s.length > 2) ? n : 529 (n + (((n + 2000) < Date.CultureInfo.twoDigitYearMax) ? 2000 : 1900)));532 (n + (((n + 2000) < $C.twoDigitYearMax) ? 2000 : 1900))); 530 533 }; 531 534 }, … … 551 554 finishExact: function (x) { 552 555 x = (x instanceof Array) ? x : [ x ]; 553 554 var now = new Date();555 556 this.year = now.getFullYear();557 this.month = now.getMonth();558 this.day = 1;559 560 this.hour = 0;561 this.minute = 0;562 this.second = 0;563 556 564 557 for (var i = 0 ; i < x.length ; i++) { … … 566 559 x[i].call(this); 567 560 } 568 } 569 570 this.hour = (this.meridian == "p" && this.hour < 13) ? this.hour + 12 : this.hour; 571 572 if (this.day > Date.getDaysInMonth(this.year, this.month)) { 561 } 562 563 var now = new Date(); 564 565 if ((this.hour || this.minute) && (!this.month && !this.year && !this.day)) { 566 this.day = now.getDate(); 567 } 568 569 if (!this.year) { 570 this.year = now.getFullYear(); 571 } 572 573 if (!this.month && this.month !== 0) { 574 this.month = now.getMonth(); 575 } 576 577 if (!this.day) { 578 this.day = 1; 579 } 580 581 if (!this.hour) { 582 this.hour = 0; 583 } 584 585 if (!this.minute) { 586 this.minute = 0; 587 } 588 589 if (!this.second) { 590 this.second = 0; 591 } 592 593 if (this.meridian && this.hour) { 594 if (this.meridian == "p" && this.hour < 12) { 595 this.hour = this.hour + 12; 596 } else if (this.meridian == "a" && this.hour == 12) { 597 this.hour = 0; 598 } 599 } 600 601 if (this.day > $D.getDaysInMonth(this.year, this.month)) { 573 602 throw new RangeError(this.day + " is not a valid value for days."); 574 603 } … … 581 610 r.set({ timezoneOffset: this.timezoneOffset }); 582 611 } 612 583 613 return r; 584 614 }, … … 595 625 } 596 626 } 597 598 if (this.now) { 627 628 var today = $D.today(); 629 630 if (this.now && !this.unit && !this.operator) { 599 631 return new Date(); 600 } 601 602 var today = Date.today(); 603 var method = null; 604 605 var expression = !!(this.days != null || this.orient || this.operator); 606 if (expression) { 607 var gap, mod, orient; 608 orient = ((this.orient == "past" || this.operator == "subtract") ? -1 : 1); 609 610 if (this.weekday) { 611 this.unit = "day"; 612 gap = (Date.getDayNumberFromName(this.weekday) - today.getDay()); 613 mod = 7; 614 this.days = gap ? ((gap + (orient * mod)) % mod) : (orient * mod); 615 } 616 if (this.month) { 617 this.unit = "month"; 618 gap = (this.month - today.getMonth()); 619 mod = 12; 620 this.months = gap ? ((gap + (orient * mod)) % mod) : (orient * mod); 632 } else if (this.now) { 633 today = new Date(); 634 } 635 636 var expression = !!(this.days && this.days !== null || this.orient || this.operator); 637 638 var gap, mod, orient; 639 orient = ((this.orient == "past" || this.operator == "subtract") ? -1 : 1); 640 641 if(!this.now && "hour minute second".indexOf(this.unit) != -1) { 642 today.setTimeToNow(); 643 } 644 645 if (this.month || this.month === 0) { 646 if ("year day hour minute second".indexOf(this.unit) != -1) { 647 this.value = this.month + 1; 621 648 this.month = null; 622 } 623 if (!this.unit) { 624 this.unit = "day"; 625 } 626 if (this[this.unit + "s"] == null || this.operator != null) { 627 if (!this.value) { 628 this.value = 1; 629 } 630 631 if (this.unit == "week") { 632 this.unit = "day"; 633 this.value = this.value * 7; 634 } 635 636 this[this.unit + "s"] = this.value * orient; 637 } 638 return today.add(this); 639 } else { 640 if (this.meridian && this.hour) { 641 this.hour = (this.hour < 13 && this.meridian == "p") ? this.hour + 12 : this.hour; 642 } 643 if (this.weekday && !this.day) { 644 this.day = (today.addDays((Date.getDayNumberFromName(this.weekday) - today.getDay()))).getDate(); 645 } 646 if (this.month && !this.day) { 647 this.day = 1; 648 } 649 return today.set(this); 650 } 651 } 652 }; 653 654 var _ = Date.Parsing.Operators, g = Date.Grammar, t = Date.Translator, _fn; 649 expression = true; 650 } 651 } 652 653 if (!expression && this.weekday && !this.day && !this.days) { 654 var temp = Date[this.weekday](); 655 this.day = temp.getDate(); 656 if (!this.month) { 657 this.month = temp.getMonth(); 658 } 659 this.year = temp.getFullYear(); 660 } 661 662 if (expression && this.weekday && this.unit != "month") { 663 this.unit = "day"; 664 gap = ($D.getDayNumberFromName(this.weekday) - today.getDay()); 665 mod = 7; 666 this.days = gap ? ((gap + (orient * mod)) % mod) : (orient * mod); 667 } 668 669 if (this.month && this.unit == "day" && this.operator) { 670 this.value = (this.month + 1); 671 this.month = null; 672 } 673 674 if (this.value != null && this.month != null && this.year != null) { 675 this.day = this.value * 1; 676 } 677 678 if (this.month && !this.day && this.value) { 679 today.set({ day: this.value * 1 }); 680 if (!expression) { 681 this.day = this.value * 1; 682 } 683 } 684 685 if (!this.month && this.value && this.unit == "month" && !this.now) { 686 this.month = this.value; 687 expression = true; 688 } 689 690 if (expression && (this.month || this.month === 0) && this.unit != "year") { 691 this.unit = "month"; 692 gap = (this.month - today.getMonth()); 693 mod = 12; 694 this.months = gap ? ((gap + (orient * mod)) % mod) : (orient * mod); 695 this.month = null; 696 } 697 698 if (!this.unit) { 699 this.unit = "day"; 700 } 701 702 if (!this.value && this.operator && this.operator !== null && this[this.unit + "s"] && this[this.unit + "s"] !== null) { 703 this[this.unit + "s"] = this[this.unit + "s"] + ((this.operator == "add") ? 1 : -1) + (this.value||0) * orient; 704 } else if (this[this.unit + "s"] == null || this.operator != null) { 705 if (!this.value) { 706 this.value = 1; 707 } 708 this[this.unit + "s"] = this.value * orient; 709 } 710 711 if (this.meridian && this.hour) { 712 if (this.meridian == "p" && this.hour < 12) { 713 this.hour = this.hour + 12; 714 } else if (this.meridian == "a" && this.hour == 12) { 715 this.hour = 0; 716 } 717 } 718 719 if (this.weekday && !this.day && !this.days) { 720 var temp = Date[this.weekday](); 721 this.day = temp.getDate(); 722 if (temp.getMonth() !== today.getMonth()) { 723 this.month = temp.getMonth(); 724 } 725 } 726 727 if ((this.month || this.month === 0) && !this.day) { 728 this.day = 1; 729 } 730 731 if (!this.orient && !this.operator && this.unit == "week" && this.value && !this.day && !this.month) { 732 return Date.today().setWeek(this.value); 733 } 734 735 if (expression && this.timezone && this.day && this.days) { 736 this.day = this.days; 737 } 738 739 return (expression) ? today.add(this) : today.set(this); 740 } 741 }; 742 743 var _ = $D.Parsing.Operators, g = $D.Grammar, t = $D.Translator, _fn; 655 744 656 745 g.datePartDelimiter = _.rtoken(/^([\s\-\.\,\/\x27]+)/); 657 746 g.timePartDelimiter = _.stoken(":"); 658 747 g.whiteSpace = _.rtoken(/^\s*/); 659 g.generalDelimiter = _.rtoken(/^(([\s\,]|at| on)+)/);748 g.generalDelimiter = _.rtoken(/^(([\s\,]|at|@|on)+)/); 660 749 661 750 var _C = {}; … … 663 752 var fn = _C[keys]; 664 753 if (! fn) { 665 var c = Date.CultureInfo.regexPatterns;754 var c = $C.regexPatterns; 666 755 var kx = keys.split(/\s+/), px = []; 667 756 for (var i = 0; i < kx.length ; i++) { … … 673 762 }; 674 763 g.ctoken2 = function (key) { 675 return _.rtoken( Date.CultureInfo.regexPatterns[key]);764 return _.rtoken($C.regexPatterns[key]); 676 765 }; 677 766 … … 685 774 g.s = _.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/), t.second)); 686 775 g.ss = _.cache(_.process(_.rtoken(/^[0-5][0-9]/), t.second)); 687 g.hms = _.cache(_.sequence([g.H, g.m m, g.ss], g.timePartDelimiter));776 g.hms = _.cache(_.sequence([g.H, g.m, g.s], g.timePartDelimiter)); 688 777 689 778 // _.min(1, _.set([ g.H, g.m, g.s ], g._t)); 690 779 g.t = _.cache(_.process(g.ctoken2("shortMeridian"), t.meridian)); 691 780 g.tt = _.cache(_.process(g.ctoken2("longMeridian"), t.meridian)); 692 g.z = _.cache(_.process(_.rtoken(/^(\+|\-)?\s*\d\d\d\d?/), t.timezone)); 693 g.zz = _.cache(_.process(_.rtoken(/^(\+|\-)\s*\d\d\d\d/), t.timezone)); 781 g.z = _.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/), t.timezone)); 782 g.zz = _.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/), t.timezone)); 783 694 784 g.zzz = _.cache(_.process(g.ctoken2("timezone"), t.timezone)); 695 785 g.timeSuffix = _.each(_.ignore(g.whiteSpace), _.set([ g.tt, g.zzz ])); 696 786 g.time = _.each(_.optional(_.ignore(_.stoken("T"))), g.hms, g.timeSuffix); 697 787 698 788 // days, months, years 699 789 g.d = _.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/), … … 742 832 ); 743 833 g.rday = _.process(g.ctoken("yesterday tomorrow today now"), t.rday); 744 g.unit = _.process(g.ctoken(" minute hour day week month year"),834 g.unit = _.process(g.ctoken("second minute hour day week month year"), 745 835 function (s) { 746 836 return function () { … … 766 856 g.dmy = _fn(g.ddd, g.day, g.month, g.year); 767 857 g.date = function (s) { 768 return ((g[ Date.CultureInfo.dateElementOrder] || g.mdy).call(this, s));858 return ((g[$C.dateElementOrder] || g.mdy).call(this, s)); 769 859 }; 770 860 … … 781 871 return g[fmt]; 782 872 } else { 783 throw Date.Parsing.Exception(fmt);873 throw $D.Parsing.Exception(fmt); 784 874 } 785 875 } … … 830 920 // check for these formats first 831 921 g._formats = g.formats([ 922 "\"yyyy-MM-ddTHH:mm:ssZ\"", 923 "yyyy-MM-ddTHH:mm:ssZ", 924 "yyyy-MM-ddTHH:mm:ssz", 832 925 "yyyy-MM-ddTHH:mm:ss", 926 "yyyy-MM-ddTHH:mmZ", 927 "yyyy-MM-ddTHH:mmz", 928 "yyyy-MM-ddTHH:mm", 833 929 "ddd, MMM dd, yyyy H:mm:ss tt", 834 930 "ddd MMM d yyyy HH:mm:ss zzz", 931 "MMddyyyy", 932 "ddMMyyyy", 933 "Mddyyyy", 934 "ddMyyyy", 935 "Mdyyyy", 936 "dMyyyy", 937 "yyyy", 938 "Mdyy", 939 "dMyy", 835 940 "d" 836 941 ]); … … 851 956 return g._start.call({}, s); 852 957 }; 853 854 }()); 855 856 857 Date._parse = Date.parse; 858 859 /** 860 * Converts the specified string value into its JavaScript Date equivalent using CultureInfo specific format information. 861 * 862 * Example 863 <pre><code> 864 /////////// 865 // Dates // 866 /////////// 867 868 // 15-Oct-2004 869 var d1 = Date.parse("10/15/2004"); 870 871 // 15-Oct-2004 872 var d1 = Date.parse("15-Oct-2004"); 873 874 // 15-Oct-2004 875 var d1 = Date.parse("2004.10.15"); 876 877 //Fri Oct 15, 2004 878 var d1 = Date.parse("Fri Oct 15, 2004"); 879 880 /////////// 881 // Times // 882 /////////// 883 884 // Today at 10 PM. 885 var d1 = Date.parse("10 PM"); 886 887 // Today at 10:30 PM. 888 var d1 = Date.parse("10:30 P.M."); 889 890 // Today at 6 AM. 891 var d1 = Date.parse("06am"); 892 893 ///////////////////// 894 // Dates and Times // 895 ///////////////////// 896 897 // 8-July-2004 @ 10:30 PM 898 var d1 = Date.parse("July 8th, 2004, 10:30 PM"); 899 900 // 1-July-2004 @ 10:30 PM 901 var d1 = Date.parse("2004-07-01T22:30:00"); 902 903 //////////////////// 904 // Relative Dates // 905 //////////////////// 906 907 // Returns today's date. The string "today" is culture specific. 908 var d1 = Date.parse("today"); 909 910 // Returns yesterday's date. The string "yesterday" is culture specific. 911 var d1 = Date.parse("yesterday"); 912 913 // Returns the date of the next thursday. 914 var d1 = Date.parse("Next thursday"); 915 916 // Returns the date of the most previous monday. 917 var d1 = Date.parse("last monday"); 918 919 // Returns today's day + one year. 920 var d1 = Date.parse("next year"); 921 922 /////////////// 923 // Date Math // 924 /////////////// 925 926 // Today + 2 days 927 var d1 = Date.parse("t+2"); 928 929 // Today + 2 days 930 var d1 = Date.parse("today + 2 days"); 931 932 // Today + 3 months 933 var d1 = Date.parse("t+3m"); 934 935 // Today - 1 year 936 var d1 = Date.parse("today - 1 year"); 937 938 // Today - 1 year 939 var d1 = Date.parse("t-1y"); 940 941 942 ///////////////////////////// 943 // Partial Dates and Times // 944 ///////////////////////////// 945 946 // July 15th of this year. 947 var d1 = Date.parse("July 15"); 948 949 // 15th day of current day and year. 950 var d1 = Date.parse("15"); 951 952 // July 1st of current year at 10pm. 953 var d1 = Date.parse("7/1 10pm"); 954 </code></pre> 955 * 956 * @param {String} The string value to convert into a Date object [Required] 957 * @return {Date} A Date object or null if the string cannot be converted into a Date. 958 */ 959 Date.parse = function (s) { 960 var r = null; 961 if (!s) { 962 return null; 963 } 964 try { 965 r = Date.Grammar.start.call({}, s); 966 } catch (e) { 967 return null; 968 } 969 return ((r[1].length === 0) ? r[0] : null); 970 }; 971 972 Date.getParseFunction = function (fx) { 973 var fn = Date.Grammar.formats(fx); 974 return function (s) { 975 var r = null; 958 959 $D._parse = $D.parse; 960 961 /** 962 * Converts the specified string value into its JavaScript Date equivalent using CultureInfo specific format information. 963 * 964 * Example 965 <pre><code> 966 /////////// 967 // Dates // 968 /////////// 969 970 // 15-Oct-2004 971 var d1 = Date.parse("10/15/2004"); 972 973 // 15-Oct-2004 974 var d1 = Date.parse("15-Oct-2004"); 975 976 // 15-Oct-2004 977 var d1 = Date.parse("2004.10.15"); 978 979 //Fri Oct 15, 2004 980 var d1 = Date.parse("Fri Oct 15, 2004"); 981 982 /////////// 983 // Times // 984 /////////// 985 986 // Today at 10 PM. 987 var d1 = Date.parse("10 PM"); 988 989 // Today at 10:30 PM. 990 var d1 = Date.parse("10:30 P.M."); 991 992 // Today at 6 AM. 993 var d1 = Date.parse("06am"); 994 995 ///////////////////// 996 // Dates and Times // 997 ///////////////////// 998 999 // 8-July-2004 @ 10:30 PM 1000 var d1 = Date.parse("July 8th, 2004, 10:30 PM"); 1001 1002 // 1-July-2004 @ 10:30 PM 1003 var d1 = Date.parse("2004-07-01T22:30:00"); 1004 1005 //////////////////// 1006 // Relative Dates // 1007 //////////////////// 1008 1009 // Returns today's date. The string "today" is culture specific. 1010 var d1 = Date.parse("today"); 1011 1012 // Returns yesterday's date. The string "yesterday" is culture specific. 1013 var d1 = Date.parse("yesterday"); 1014 1015 // Returns the date of the next thursday. 1016 var d1 = Date.parse("Next thursday"); 1017 1018 // Returns the date of the most previous monday. 1019 var d1 = Date.parse("last monday"); 1020 1021 // Returns today's day + one year. 1022 var d1 = Date.parse("next year"); 1023 1024 /////////////// 1025 // Date Math // 1026 /////////////// 1027 1028 // Today + 2 days 1029 var d1 = Date.parse("t+2"); 1030 1031 // Today + 2 days 1032 var d1 = Date.parse("today + 2 days"); 1033 1034 // Today + 3 months 1035 var d1 = Date.parse("t+3m"); 1036 1037 // Today - 1 year 1038 var d1 = Date.parse("today - 1 year"); 1039 1040 // Today - 1 year 1041 var d1 = Date.parse("t-1y"); 1042 1043 1044 ///////////////////////////// 1045 // Partial Dates and Times // 1046 ///////////////////////////// 1047 1048 // July 15th of this year. 1049 var d1 = Date.parse("July 15"); 1050 1051 // 15th day of current day and year. 1052 var d1 = Date.parse("15"); 1053 1054 // July 1st of current year at 10pm. 1055 var d1 = Date.parse("7/1 10pm"); 1056 </code></pre> 1057 * 1058 * @param {String} The string value to convert into a Date object [Required] 1059 * @return {Date} A Date object or null if the string cannot be converted into a Date. 1060 */ 1061 $D.parse = function (s) { 1062 var r = null; 1063 if (!s) { 1064 return null; 1065 } 1066 if (s instanceof Date) { 1067 return s; 1068 } 976 1069 try { 977 r = fn.call({}, s);1070 r = $D.Grammar.start.call({}, s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1")); 978 1071 } catch (e) { 979 1072 return null; … … 981 1074 return ((r[1].length === 0) ? r[0] : null); 982 1075 }; 983 }; 984 /** 985 * Converts the specified string value into its JavaScript Date equivalent using the specified format {String} or formats {Array} and the CultureInfo specific format information. 986 * The format of the string value must match one of the supplied formats exactly. 987 * 988 * Example 989 <pre><code> 990 // 15-Oct-2004 991 var d1 = Date.parseExact("10/15/2004", "M/d/yyyy"); 992 993 // 15-Oct-2004 994 var d1 = Date.parse("15-Oct-2004", "M-ddd-yyyy"); 995 996 // 15-Oct-2004 997 var d1 = Date.parse("2004.10.15", "yyyy.MM.dd"); 998 999 // Multiple formats 1000 var d1 = Date.parseExact("10/15/2004", [ "M/d/yyyy" , "MMMM d, yyyy" ]); 1001 </code></pre> 1002 * 1003 * @param {String} The string value to convert into a Date object [Required]. 1004 * @param {Object} The expected format {String} or an array of expected formats {Array} of the date string [Required]. 1005 * @return {Date} A Date object or null if the string cannot be converted into a Date. 1006 */ 1007 Date.parseExact = function (s, fx) { 1008 return Date.getParseFunction(fx)(s); 1009 }; 1076 1077 $D.getParseFunction = function (fx) { 1078 var fn = $D.Grammar.formats(fx); 1079 return function (s) { 1080 var r = null; 1081 try { 1082 r = fn.call({}, s); 1083 } catch (e) { 1084 return null; 1085 } 1086 return ((r[1].length === 0) ? r[0] : null); 1087 }; 1088 }; 1089 1090 /** 1091 * Converts the specified string value into its JavaScript Date equivalent using the specified format {String} or formats {Array} and the CultureInfo specific format information. 1092 * The format of the string value must match one of the supplied formats exactly. 1093 * 1094 * Example 1095 <pre><code> 1096 // 15-Oct-2004 1097 var d1 = Date.parseExact("10/15/2004", "M/d/yyyy"); 1098 1099 // 15-Oct-2004 1100 var d1 = Date.parse("15-Oct-2004", "M-ddd-yyyy"); 1101 1102 // 15-Oct-2004 1103 var d1 = Date.parse("2004.10.15", "yyyy.MM.dd"); 1104 1105 // Multiple formats 1106 var d1 = Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]); 1107 </code></pre> 1108 * 1109 * @param {String} The string value to convert into a Date object [Required]. 1110 * @param {Object} The expected format {String} or an array of expected formats {Array} of the date string [Required]. 1111 * @return {Date} A Date object or null if the string cannot be converted into a Date. 1112 */ 1113 $D.parseExact = function (s, fx) { 1114 return $D.getParseFunction(fx)(s); 1115 }; 1116 }()); -
branches/2.4/prototype/plugins/datejs/parser.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 13-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 9 (function(){Date.Parsing={Exception:function(s){this.message="Parse error at '"+s.substring(0,10)+" ...'";}};var $P=Date.Parsing;var _=$P.Operators={rtoken:function(r){return function(s){var mx=s.match(r);if(mx){return([mx[0],s.substring(mx[0].length)]);}else{throw new $P.Exception(s);}};},token:function(s){return function(s){return _.rtoken(new RegExp("^\s*"+s+"\s*"))(s);};},stoken:function(s){return _.rtoken(new RegExp("^"+s));},until:function(p){return function(s){var qx=[],rx=null;while(s.length){try{rx=p.call(this,s);}catch(e){qx.push(rx[0]);s=rx[1];continue;} … … 40 41 return rx;};}};var _generator=function(op){return function(){var args=null,rx=[];if(arguments.length>1){args=Array.prototype.slice.call(arguments);}else if(arguments[0]instanceof Array){args=arguments[0];} 41 42 if(args){for(var i=0,px=args.shift();i<px.length;i++){args.unshift(px[i]);rx.push(op.apply(null,args));args.shift();return rx;}}else{return op.apply(null,arguments);}};};var gx="optional not ignore cache".split(/\s/);for(var i=0;i<gx.length;i++){_[gx[i]]=_generator(_[gx[i]]);} 42 var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} 43 return rx;};Date.Grammar={};Date.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=((s.length==3)?Date.getMonthNumberFromName(s):(Number(s)-1));};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<Date.CultureInfo.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];var now=new Date();this.year=now.getFullYear();this.month=now.getMonth();this.day=1;this.hour=0;this.minute=0;this.second=0;for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} 44 this.hour=(this.meridian=="p"&&this.hour<13)?this.hour+12:this.hour;if(this.day>Date.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} 43 var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo;var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} 44 return rx;};$D.Grammar={};$D.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=(s.length==3)?"jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4:Number(s)-1;};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<$C.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} 45 var now=new Date();if((this.hour||this.minute)&&(!this.month&&!this.year&&!this.day)){this.day=now.getDate();} 46 if(!this.year){this.year=now.getFullYear();} 47 if(!this.month&&this.month!==0){this.month=now.getMonth();} 48 if(!this.day){this.day=1;} 49 if(!this.hour){this.hour=0;} 50 if(!this.minute){this.minute=0;} 51 if(!this.second){this.second=0;} 52 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 53 if(this.day>$D.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} 45 54 var r=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){r.set({timezone:this.timezone});}else if(this.timezoneOffset){r.set({timezoneOffset:this.timezoneOffset});} 46 55 return r;},finish:function(x){x=(x instanceof Array)?flattenAndCompact(x):[x];if(x.length===0){return null;} 47 56 for(var i=0;i<x.length;i++){if(typeof x[i]=="function"){x[i].call(this);}} 48 if(this.now){return new Date();} 49 var today=Date.today();var method=null;var expression=!!(this.days!=null||this.orient||this.operator);if(expression){var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(this.weekday){this.unit="day";gap=(Date.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} 50 if(this.month){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} 57 var today=$D.today();if(this.now&&!this.unit&&!this.operator){return new Date();}else if(this.now){today=new Date();} 58 var expression=!!(this.days&&this.days!==null||this.orient||this.operator);var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(!this.now&&"hour minute second".indexOf(this.unit)!=-1){today.setTimeToNow();} 59 if(this.month||this.month===0){if("year day hour minute second".indexOf(this.unit)!=-1){this.value=this.month+1;this.month=null;expression=true;}} 60 if(!expression&&this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(!this.month){this.month=temp.getMonth();} 61 this.year=temp.getFullYear();} 62 if(expression&&this.weekday&&this.unit!="month"){this.unit="day";gap=($D.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} 63 if(this.month&&this.unit=="day"&&this.operator){this.value=(this.month+1);this.month=null;} 64 if(this.value!=null&&this.month!=null&&this.year!=null){this.day=this.value*1;} 65 if(this.month&&!this.day&&this.value){today.set({day:this.value*1});if(!expression){this.day=this.value*1;}} 66 if(!this.month&&this.value&&this.unit=="month"&&!this.now){this.month=this.value;expression=true;} 67 if(expression&&(this.month||this.month===0)&&this.unit!="year"){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} 51 68 if(!this.unit){this.unit="day";} 52 if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} 53 if(this.unit=="week"){this.unit="day";this.value=this.value*7;} 69 if(!this.value&&this.operator&&this.operator!==null&&this[this.unit+"s"]&&this[this.unit+"s"]!==null){this[this.unit+"s"]=this[this.unit+"s"]+((this.operator=="add")?1:-1)+(this.value||0)*orient;}else if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} 54 70 this[this.unit+"s"]=this.value*orient;} 55 return today.add(this);}else{if(this.meridian&&this.hour){this.hour=(this.hour<13&&this.meridian=="p")?this.hour+12:this.hour;} 56 if(this.weekday&&!this.day){this.day=(today.addDays((Date.getDayNumberFromName(this.weekday)-today.getDay()))).getDate();} 57 if(this.month&&!this.day){this.day=1;} 58 return today.set(this);}}};var _=Date.Parsing.Operators,g=Date.Grammar,t=Date.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=Date.CultureInfo.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} 71 if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} 72 if(this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(temp.getMonth()!==today.getMonth()){this.month=temp.getMonth();}} 73 if((this.month||this.month===0)&&!this.day){this.day=1;} 74 if(!this.orient&&!this.operator&&this.unit=="week"&&this.value&&!this.day&&!this.month){return Date.today().setWeek(this.value);} 75 if(expression&&this.timezone&&this.day&&this.days){this.day=this.days;} 76 return(expression)?today.add(this):today.set(this);}};var _=$D.Parsing.Operators,g=$D.Grammar,t=$D.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|@|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=$C.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} 59 77 fn=_C[keys]=_.any.apply(null,px);} 60 return fn;};g.ctoken2=function(key){return _.rtoken(Date.CultureInfo.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.mm,g.ss],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^(\+|\-)?\s*\d\d\d\d?/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^(\+|\-)\s*\d\d\d\d/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[Date.CultureInfo.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw Date.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} 61 return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["yyyy-MM-ddTHH:mm:ss","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} 62 return g._start.call({},s);};}());Date._parse=Date.parse;Date.parse=function(s){var r=null;if(!s){return null;} 63 try{r=Date.Grammar.start.call({},s);}catch(e){return null;} 64 return((r[1].length===0)?r[0]:null);};Date.getParseFunction=function(fx){var fn=Date.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} 65 return((r[1].length===0)?r[0]:null);};};Date.parseExact=function(s,fx){return Date.getParseFunction(fx)(s);}; 78 return fn;};g.ctoken2=function(key){return _.rtoken($C.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.m,g.s],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("second minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[$C.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw $D.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} 79 return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["\"yyyy-MM-ddTHH:mm:ssZ\"","yyyy-MM-ddTHH:mm:ssZ","yyyy-MM-ddTHH:mm:ssz","yyyy-MM-ddTHH:mm:ss","yyyy-MM-ddTHH:mmZ","yyyy-MM-ddTHH:mmz","yyyy-MM-ddTHH:mm","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","MMddyyyy","ddMMyyyy","Mddyyyy","ddMyyyy","Mdyyyy","dMyyyy","yyyy","Mdyy","dMyy","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} 80 return g._start.call({},s);};$D._parse=$D.parse;$D.parse=function(s){var r=null;if(!s){return null;} 81 if(s instanceof Date){return s;} 82 try{r=$D.Grammar.start.call({},s.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));}catch(e){return null;} 83 return((r[1].length===0)?r[0]:null);};$D.getParseFunction=function(fx){var fn=$D.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} 84 return((r[1].length===0)?r[0]:null);};};$D.parseExact=function(s,fx){return $D.getParseFunction(fx)(s);};}()); -
branches/2.4/prototype/plugins/datejs/sugarpak-debug.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 12-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-04-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 9 … … 13 14 */ 14 15 15 /**16 * Gets a date that is set to the current date and time.17 * @return {Date} The current date and time.18 */19 Date.now = function () {20 return new Date();21 };22 23 /**24 * Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM).25 * @return {Date} The current date.26 */27 Date.today = function () {28 return Date.now().clearTime();29 };30 31 // private32 Date.prototype._orient = +1;33 34 /**35 * Moves the date to the next instance of a date as specified by a trailing date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).36 * Example37 <pre><code>38 Date.today().next().friday();39 Date.today().next().fri();40 Date.today().next().march();41 Date.today().next().mar();42 Date.today().next().week();43 </code></pre>44 *45 * @return {Date} this46 */47 Date.prototype.next = function () {48 this._orient = +1;49 return this;50 };51 52 /**53 * Moves the date to the previous instance of a date as specified by a trailing date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).54 * Example55 <pre><code>56 Date.today().last().friday();57 Date.today().last().fri();58 Date.today().last().march();59 Date.today().last().mar();60 Date.today().last().week();61 </code></pre>62 *63 * @return {Date} this64 */65 Date.prototype.last = Date.prototype.prev = Date.prototype.previous = function () {66 this._orient = -1;67 return this;68 };69 70 // private71 Date.prototype._is = false;72 73 /**74 * Performs a equality check when followed by either a month name or day name function.75 * Example76 <pre><code>77 Date.today().is().friday(); // true|false78 Date.today().is().fri();79 Date.today().is().march();80 Date.today().is().mar();81 </code></pre>82 *83 * @return {bool} true|false84 */85 Date.prototype.is = function () {86 this._is = true;87 return this;88 };89 90 // private91 Number.prototype._dateElement = "day";92 93 /**94 * Creates a new Date (Date.now()) and adds this (Number) to the date based on the preceding date element function (eg. second|minute|hour|day|month|year).95 * Example96 <pre><code>97 // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.98 (3).days().fromNow();99 (6).months().fromNow();100 101 // Declared Number variables do not require parentheses.102 var n = 6;103 n.months().fromNow();104 </code></pre>105 *106 * @return {Date} A new Date instance107 */108 Number.prototype.fromNow = function () {109 var c = {};110 c[this._dateElement] = this;111 return Date.now().add(c);112 };113 114 /**115 * Creates a new Date (Date.now()) and subtract this (Number) from the date based on the preceding date element function (eg. second|minute|hour|day|month|year).116 * Example117 <pre><code>118 // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.119 (3).days().ago();120 (6).months().ago();121 122 // Declared Number variables do not require parentheses.123 var n = 6;124 n.months().ago();125 </code></pre>126 *127 * @return {Date} A new Date instance128 */129 Number.prototype.ago = function () {130 var c = {};131 c[this._dateElement] = this * -1;132 return Date.now().add(c);133 };134 135 // Build dynamic date element, month name and day name functions.136 16 (function () { 137 var $D = Date.prototype, $N = Number.prototype; 138 139 /* Do NOT modify the following string tokens. These tokens are used to build dynamic functions. */ 17 var $D = Date, $P = $D.prototype, $C = $D.CultureInfo, $N = Number.prototype; 18 19 // private 20 $P._orient = +1; 21 22 // private 23 $P._nth = null; 24 25 // private 26 $P._is = false; 27 28 // private 29 $P._same = false; 30 31 // private 32 $P._isSecond = false; 33 34 // private 35 $N._dateElement = "day"; 36 37 /** 38 * Moves the date to the next instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()). 39 * Example 40 <pre><code> 41 Date.today().next().friday(); 42 Date.today().next().fri(); 43 Date.today().next().march(); 44 Date.today().next().mar(); 45 Date.today().next().week(); 46 </code></pre> 47 * 48 * @return {Date} date 49 */ 50 $P.next = function () { 51 this._orient = +1; 52 return this; 53 }; 54 55 /** 56 * Creates a new Date (Date.today()) and moves the date to the next instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()). 57 * Example 58 <pre><code> 59 Date.next().friday(); 60 Date.next().fri(); 61 Date.next().march(); 62 Date.next().mar(); 63 Date.next().week(); 64 </code></pre> 65 * 66 * @return {Date} date 67 */ 68 $D.next = function () { 69 return $D.today().next(); 70 }; 71 72 /** 73 * Moves the date to the previous instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()). 74 * Example 75 <pre><code> 76 Date.today().last().friday(); 77 Date.today().last().fri(); 78 Date.today().last().march(); 79 Date.today().last().mar(); 80 Date.today().last().week(); 81 </code></pre> 82 * 83 * @return {Date} date 84 */ 85 $P.last = $P.prev = $P.previous = function () { 86 this._orient = -1; 87 return this; 88 }; 89 90 /** 91 * Creates a new Date (Date.today()) and moves the date to the previous instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()). 92 * Example 93 <pre><code> 94 Date.last().friday(); 95 Date.last().fri(); 96 Date.previous().march(); 97 Date.prev().mar(); 98 Date.last().week(); 99 </code></pre> 100 * 101 * @return {Date} date 102 */ 103 $D.last = $D.prev = $D.previous = function () { 104 return $D.today().last(); 105 }; 106 107 /** 108 * Performs a equality check when followed by either a month name, day name or .weekday() function. 109 * Example 110 <pre><code> 111 Date.today().is().friday(); // true|false 112 Date.today().is().fri(); 113 Date.today().is().march(); 114 Date.today().is().mar(); 115 </code></pre> 116 * 117 * @return {Boolean} true|false 118 */ 119 $P.is = function () { 120 this._is = true; 121 return this; 122 }; 123 124 /** 125 * Determines if two date objects occur on/in exactly the same instance of the subsequent date part function. 126 * The function .same() must be followed by a date part function (example: .day(), .month(), .year(), etc). 127 * 128 * An optional Date can be passed in the date part function. If now date is passed as a parameter, 'Now' is used. 129 * 130 * The following example demonstrates how to determine if two dates fall on the exact same day. 131 * 132 * Example 133 <pre><code> 134 var d1 = Date.today(); // today at 00:00 135 var d2 = new Date(); // exactly now. 136 137 // Do they occur on the same day? 138 d1.same().day(d2); // true 139 140 // Do they occur on the same hour? 141 d1.same().hour(d2); // false, unless d2 hour is '00' (midnight). 142 143 // What if it's the same day, but one year apart? 144 var nextYear = Date.today().add(1).year(); 145 146 d1.same().day(nextYear); // false, because the dates must occur on the exact same day. 147 </code></pre> 148 * 149 * Scenario: Determine if a given date occurs during some week period 2 months from now. 150 * 151 * Example 152 <pre><code> 153 var future = Date.today().add(2).months(); 154 return someDate.same().week(future); // true|false; 155 </code></pre> 156 * 157 * @return {Boolean} true|false 158 */ 159 $P.same = function () { 160 this._same = true; 161 this._isSecond = false; 162 return this; 163 }; 164 165 /** 166 * Determines if the current date/time occurs during Today. Must be preceded by the .is() function. 167 * Example 168 <pre><code> 169 someDate.is().today(); // true|false 170 new Date().is().today(); // true 171 Date.today().is().today();// true 172 Date.today().add(-1).day().is().today(); // false 173 </code></pre> 174 * 175 * @return {Boolean} true|false 176 */ 177 $P.today = function () { 178 return this.same().day(); 179 }; 180 181 /** 182 * Determines if the current date is a weekday. This function must be preceded by the .is() function. 183 * Example 184 <pre><code> 185 Date.today().is().weekday(); // true|false 186 </code></pre> 187 * 188 * @return {Boolean} true|false 189 */ 190 $P.weekday = function () { 191 if (this._is) { 192 this._is = false; 193 return (!this.is().sat() && !this.is().sun()); 194 } 195 return false; 196 }; 197 198 /** 199 * Sets the Time of the current Date instance. A string "6:15 pm" or config object {hour:18, minute:15} are accepted. 200 * Example 201 <pre><code> 202 // Set time to 6:15pm with a String 203 Date.today().at("6:15pm"); 204 205 // Set time to 6:15pm with a config object 206 Date.today().at({hour:18, minute:15}); 207 </code></pre> 208 * 209 * @return {Date} date 210 */ 211 $P.at = function (time) { 212 return (typeof time === "string") ? $D.parse(this.toString("d") + " " + time) : this.set(time); 213 }; 214 215 /** 216 * Creates a new Date() and adds this (Number) to the date based on the preceding date element function (eg. second|minute|hour|day|month|year). 217 * Example 218 <pre><code> 219 // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript. 220 (3).days().fromNow(); 221 (6).months().fromNow(); 222 223 // Declared Number variables do not require parentheses. 224 var n = 6; 225 n.months().fromNow(); 226 </code></pre> 227 * 228 * @return {Date} A new Date instance 229 */ 230 $N.fromNow = $N.after = function (date) { 231 var c = {}; 232 c[this._dateElement] = this; 233 return ((!date) ? new Date() : date.clone()).add(c); 234 }; 235 236 /** 237 * Creates a new Date() and subtract this (Number) from the date based on the preceding date element function (eg. second|minute|hour|day|month|year). 238 * Example 239 <pre><code> 240 // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript. 241 (3).days().ago(); 242 (6).months().ago(); 243 244 // Declared Number variables do not require parentheses. 245 var n = 6; 246 n.months().ago(); 247 </code></pre> 248 * 249 * @return {Date} A new Date instance 250 */ 251 $N.ago = $N.before = function (date) { 252 var c = {}; 253 c[this._dateElement] = this * -1; 254 return ((!date) ? new Date() : date.clone()).add(c); 255 }; 256 257 // Do NOT modify the following string tokens. These tokens are used to build dynamic functions. 258 // All culture-specific strings can be found in the CultureInfo files. See /trunk/src/globalization/. 140 259 var dx = ("sunday monday tuesday wednesday thursday friday saturday").split(/\s/), 141 260 mx = ("january february march april may june july august september october november december").split(/\s/), 142 261 px = ("Millisecond Second Minute Hour Day Week Month Year").split(/\s/), 262 pxf = ("Milliseconds Seconds Minutes Hours Date Week Month FullYear").split(/\s/), 263 nth = ("final first second third fourth fifth").split(/\s/), 143 264 de; 144 265 266 /** 267 * Returns an object literal of all the date parts. 268 * Example 269 <pre><code> 270 var o = new Date().toObject(); 271 272 // { year: 2008, month: 4, week: 20, day: 13, hour: 18, minute: 9, second: 32, millisecond: 812 } 273 274 // The object properties can be referenced directly from the object. 275 276 alert(o.day); // alerts "13" 277 alert(o.year); // alerts "2008" 278 </code></pre> 279 * 280 * @return {Date} An object literal representing the original date object. 281 */ 282 $P.toObject = function () { 283 var o = {}; 284 for (var i = 0; i < px.length; i++) { 285 o[px[i].toLowerCase()] = this["get" + pxf[i]](); 286 } 287 return o; 288 }; 289 290 /** 291 * Returns a date created from an object literal. Ignores the .week property if set in the config. 292 * Example 293 <pre><code> 294 var o = new Date().toObject(); 295 296 return Date.fromObject(o); // will return the same date. 297 298 var o2 = {month: 1, day: 20, hour: 18}; // birthday party! 299 Date.fromObject(o2); 300 </code></pre> 301 * 302 * @return {Date} An object literal representing the original date object. 303 */ 304 $D.fromObject = function(config) { 305 config.week = null; 306 return Date.today().set(config); 307 }; 308 145 309 // Create day name functions and abbreviated day name functions (eg. monday(), friday(), fri()). 146 310 var df = function (n) { … … 150 314 return this.getDay() == n; 151 315 } 316 if (this._nth !== null) { 317 // If the .second() function was called earlier, remove the _orient 318 // from the date, and then continue. 319 // This is required because 'second' can be used in two different context. 320 // 321 // Example 322 // 323 // Date.today().add(1).second(); 324 // Date.march().second().monday(); 325 // 326 // Things get crazy with the following... 327 // Date.march().add(1).second().second().monday(); // but it works!! 328 // 329 if (this._isSecond) { 330 this.addSeconds(this._orient * -1); 331 } 332 // make sure we reset _isSecond 333 this._isSecond = false; 334 335 var ntemp = this._nth; 336 this._nth = null; 337 var temp = this.clone().moveToLastDayOfMonth(); 338 this.moveToNthOccurrence(n, ntemp); 339 if (this > temp) { 340 throw new RangeError($D.getDayName(n) + " does not occur " + ntemp + " times in the month of " + $D.getMonthName(temp.getMonth()) + " " + temp.getFullYear() + "."); 341 } 342 return this; 343 } 152 344 return this.moveToDayOfWeek(n, this._orient); 153 345 }; 154 346 }; 155 347 156 for (var i = 0 ; i < dx.length ; i++) { 157 $D[dx[i]] = $D[dx[i].substring(0, 3)] = df(i); 348 var sdf = function (n) { 349 return function () { 350 var t = $D.today(), shift = n - t.getDay(); 351 if (n === 0 && $C.firstDayOfWeek === 1 && t.getDay() !== 0) { 352 shift = shift + 7; 353 } 354 return t.addDays(shift); 355 }; 356 }; 357 358 for (var i = 0; i < dx.length; i++) { 359 // Create constant static Day Name variables. Example: Date.MONDAY or Date.MON 360 $D[dx[i].toUpperCase()] = $D[dx[i].toUpperCase().substring(0, 3)] = i; 361 362 // Create Day Name functions. Example: Date.monday() or Date.mon() 363 $D[dx[i]] = $D[dx[i].substring(0, 3)] = sdf(i); 364 365 // Create Day Name instance functions. Example: Date.today().next().monday() 366 $P[dx[i]] = $P[dx[i].substring(0, 3)] = df(i); 158 367 } 159 368 … … 169 378 }; 170 379 171 for (var j = 0 ; j < mx.length ; j++) { 172 $D[mx[j]] = $D[mx[j].substring(0, 3)] = mf(j); 380 var smf = function (n) { 381 return function () { 382 return $D.today().set({ month: n, day: 1 }); 383 }; 384 }; 385 386 for (var j = 0; j < mx.length; j++) { 387 // Create constant static Month Name variables. Example: Date.MARCH or Date.MAR 388 $D[mx[j].toUpperCase()] = $D[mx[j].toUpperCase().substring(0, 3)] = j; 389 390 // Create Month Name functions. Example: Date.march() or Date.mar() 391 $D[mx[j]] = $D[mx[j].substring(0, 3)] = smf(j); 392 393 // Create Month Name instance functions. Example: Date.today().next().march() 394 $P[mx[j]] = $P[mx[j].substring(0, 3)] = mf(j); 173 395 } 174 396 175 397 // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()). 176 var ef = function (j) { 398 var ef = function (j) { 177 399 return function () { 178 if (j.substring(j.length - 1) != "s") { 400 // if the .second() function was called earlier, the _orient 401 // has alread been added. Just return this and reset _isSecond. 402 if (this._isSecond) { 403 this._isSecond = false; 404 return this; 405 } 406 407 if (this._same) { 408 this._same = this._is = false; 409 var o1 = this.toObject(), 410 o2 = (arguments[0] || new Date()).toObject(), 411 v = "", 412 k = j.toLowerCase(); 413 414 for (var m = (px.length - 1); m > -1; m--) { 415 v = px[m].toLowerCase(); 416 if (o1[v] != o2[v]) { 417 return false; 418 } 419 if (k == v) { 420 break; 421 } 422 } 423 return true; 424 } 425 426 if (j.substring(j.length - 1) != "s") { 179 427 j += "s"; 180 428 } 181 return this["add" + j](this._orient); 182 }; 183 }; 184 185 // Create date element functions and plural date element functions used with Number (eg. day(), days(), months()).429 return this["add" + j](this._orient); 430 }; 431 }; 432 433 186 434 var nf = function (n) { 187 435 return function () { … … 190 438 }; 191 439 }; 192 193 for (var k = 0 ; k < px.length; k++) {440 441 for (var k = 0; k < px.length; k++) { 194 442 de = px[k].toLowerCase(); 195 $D[de] = $D[de + "s"] = ef(px[k]); 443 444 // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()). 445 $P[de] = $P[de + "s"] = ef(px[k]); 446 447 // Create date element functions and plural date element functions used with Number (eg. day(), days(), months()). 196 448 $N[de] = $N[de + "s"] = nf(de); 197 449 } 450 451 $P._ss = ef("Second"); 452 453 var nthfn = function (n) { 454 return function (dayOfWeek) { 455 if (this._same) { 456 return this._ss(arguments[0]); 457 } 458 if (dayOfWeek || dayOfWeek === 0) { 459 return this.moveToNthOccurrence(dayOfWeek, n); 460 } 461 this._nth = n; 462 463 // if the operator is 'second' add the _orient, then deal with it later... 464 if (n === 2 && (dayOfWeek === undefined || dayOfWeek === null)) { 465 this._isSecond = true; 466 return this.addSeconds(this._orient); 467 } 468 return this; 469 }; 470 }; 471 472 for (var l = 0; l < nth.length; l++) { 473 $P[nth[l]] = (l === 0) ? nthfn(-1) : nthfn(l); 474 } 198 475 }()); 199 200 /**201 * Converts the current date instance into a JSON string value.202 * @return {String} JSON string of date203 */204 Date.prototype.toJSONString = function () {205 return this.toString("yyyy-MM-ddThh:mm:ssZ");206 };207 208 /**209 * Converts the current date instance to a string using the culture specific shortDatePattern.210 * @return {String} A string formatted as per the culture specific shortDatePattern211 */212 Date.prototype.toShortDateString = function () {213 return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern);214 };215 216 /**217 * Converts the current date instance to a string using the culture specific longDatePattern.218 * @return {String} A string formatted as per the culture specific longDatePattern219 */220 Date.prototype.toLongDateString = function () {221 return this.toString(Date.CultureInfo.formatPatterns.longDatePattern);222 };223 224 /**225 * Converts the current date instance to a string using the culture specific shortTimePattern.226 * @return {String} A string formatted as per the culture specific shortTimePattern227 */228 Date.prototype.toShortTimeString = function () {229 return this.toString(Date.CultureInfo.formatPatterns.shortTimePattern);230 };231 232 /**233 * Converts the current date instance to a string using the culture specific longTimePattern.234 * @return {String} A string formatted as per the culture specific longTimePattern235 */236 Date.prototype.toLongTimeString = function () {237 return this.toString(Date.CultureInfo.formatPatterns.longTimePattern);238 };239 240 /**241 * Get the ordinal suffix of the current day.242 * @return {String} "st, "nd", "rd" or "th"243 */244 Date.prototype.getOrdinal = function () {245 switch (this.getDate()) {246 case 1:247 case 21:248 case 31:249 return "st";250 case 2:251 case 22:252 return "nd";253 case 3:254 case 23:255 return "rd";256 default:257 return "th";258 }259 }; -
branches/2.4/prototype/plugins/datejs/sugarpak.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 13-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 Date.now=function(){return new Date();};Date.today=function(){return Date.now().clearTime();};Date.prototype._orient=+1;Date.prototype.next=function(){this._orient=+1;return this;};Date.prototype.last=Date.prototype.prev=Date.prototype.previous=function(){this._orient=-1;return this;};Date.prototype._is=false;Date.prototype.is=function(){this._is=true;return this;};Number.prototype._dateElement="day";Number.prototype.fromNow=function(){var c={};c[this._dateElement]=this;return Date.now().add(c);};Number.prototype.ago=function(){var c={};c[this._dateElement]=this*-1;return Date.now().add(c);};(function(){var $D=Date.prototype,$N=Number.prototype;var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),de;var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} 9 return this.moveToDayOfWeek(n,this._orient);};};for(var i=0;i<dx.length;i++){$D[dx[i]]=$D[dx[i].substring(0,3)]=df(i);} 9 (function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,$N=Number.prototype;$P._orient=+1;$P._nth=null;$P._is=false;$P._same=false;$P._isSecond=false;$N._dateElement="day";$P.next=function(){this._orient=+1;return this;};$D.next=function(){return $D.today().next();};$P.last=$P.prev=$P.previous=function(){this._orient=-1;return this;};$D.last=$D.prev=$D.previous=function(){return $D.today().last();};$P.is=function(){this._is=true;return this;};$P.same=function(){this._same=true;this._isSecond=false;return this;};$P.today=function(){return this.same().day();};$P.weekday=function(){if(this._is){this._is=false;return(!this.is().sat()&&!this.is().sun());} 10 return false;};$P.at=function(time){return(typeof time==="string")?$D.parse(this.toString("d")+" "+time):this.set(time);};$N.fromNow=$N.after=function(date){var c={};c[this._dateElement]=this;return((!date)?new Date():date.clone()).add(c);};$N.ago=$N.before=function(date){var c={};c[this._dateElement]=this*-1;return((!date)?new Date():date.clone()).add(c);};var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),pxf=("Milliseconds Seconds Minutes Hours Date Week Month FullYear").split(/\s/),nth=("final first second third fourth fifth").split(/\s/),de;$P.toObject=function(){var o={};for(var i=0;i<px.length;i++){o[px[i].toLowerCase()]=this["get"+pxf[i]]();} 11 return o;};$D.fromObject=function(config){config.week=null;return Date.today().set(config);};var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} 12 if(this._nth!==null){if(this._isSecond){this.addSeconds(this._orient*-1);} 13 this._isSecond=false;var ntemp=this._nth;this._nth=null;var temp=this.clone().moveToLastDayOfMonth();this.moveToNthOccurrence(n,ntemp);if(this>temp){throw new RangeError($D.getDayName(n)+" does not occur "+ntemp+" times in the month of "+$D.getMonthName(temp.getMonth())+" "+temp.getFullYear()+".");} 14 return this;} 15 return this.moveToDayOfWeek(n,this._orient);};};var sdf=function(n){return function(){var t=$D.today(),shift=n-t.getDay();if(n===0&&$C.firstDayOfWeek===1&&t.getDay()!==0){shift=shift+7;} 16 return t.addDays(shift);};};for(var i=0;i<dx.length;i++){$D[dx[i].toUpperCase()]=$D[dx[i].toUpperCase().substring(0,3)]=i;$D[dx[i]]=$D[dx[i].substring(0,3)]=sdf(i);$P[dx[i]]=$P[dx[i].substring(0,3)]=df(i);} 10 17 var mf=function(n){return function(){if(this._is){this._is=false;return this.getMonth()===n;} 11 return this.moveToMonth(n,this._orient);};};for(var j=0;j<mx.length;j++){$D[mx[j]]=$D[mx[j].substring(0,3)]=mf(j);} 12 var ef=function(j){return function(){if(j.substring(j.length-1)!="s"){j+="s";} 13 return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$D[de]=$D[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);}}());Date.prototype.toJSONString=function(){return this.toString("yyyy-MM-ddThh:mm:ssZ");};Date.prototype.toShortDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern);};Date.prototype.toLongDateString=function(){return this.toString(Date.CultureInfo.formatPatterns.longDatePattern);};Date.prototype.toShortTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.shortTimePattern);};Date.prototype.toLongTimeString=function(){return this.toString(Date.CultureInfo.formatPatterns.longTimePattern);};Date.prototype.getOrdinal=function(){switch(this.getDate()){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}}; 18 return this.moveToMonth(n,this._orient);};};var smf=function(n){return function(){return $D.today().set({month:n,day:1});};};for(var j=0;j<mx.length;j++){$D[mx[j].toUpperCase()]=$D[mx[j].toUpperCase().substring(0,3)]=j;$D[mx[j]]=$D[mx[j].substring(0,3)]=smf(j);$P[mx[j]]=$P[mx[j].substring(0,3)]=mf(j);} 19 var ef=function(j){return function(){if(this._isSecond){this._isSecond=false;return this;} 20 if(this._same){this._same=this._is=false;var o1=this.toObject(),o2=(arguments[0]||new Date()).toObject(),v="",k=j.toLowerCase();for(var m=(px.length-1);m>-1;m--){v=px[m].toLowerCase();if(o1[v]!=o2[v]){return false;} 21 if(k==v){break;}} 22 return true;} 23 if(j.substring(j.length-1)!="s"){j+="s";} 24 return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$P[de]=$P[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);} 25 $P._ss=ef("Second");var nthfn=function(n){return function(dayOfWeek){if(this._same){return this._ss(arguments[0]);} 26 if(dayOfWeek||dayOfWeek===0){return this.moveToNthOccurrence(dayOfWeek,n);} 27 this._nth=n;if(n===2&&(dayOfWeek===undefined||dayOfWeek===null)){this._isSecond=true;return this.addSeconds(this._orient);} 28 return this;};};for(var l=0;l<nth.length;l++){$P[nth[l]]=(l===0)?nthfn(-1):nthfn(l);}}()); -
branches/2.4/prototype/plugins/datejs/time-debug.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 12-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-04-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 9 9 10 /* 11 * TimeSpan(milliseconds); 12 * TimeSpan(days, hours, minutes, seconds); 10 13 * TimeSpan(days, hours, minutes, seconds, milliseconds); 11 * TimeSpan(milliseconds); 12 */ 13 TimeSpan = function (days, hours, minutes, seconds, milliseconds) { 14 this.days = 0; 15 this.hours = 0; 16 this.minutes = 0; 17 this.seconds = 0; 18 this.milliseconds = 0; 19 20 if (arguments.length == 5) { 21 this.days = days; 22 this.hours = hours; 23 this.minutes = minutes; 24 this.seconds = seconds; 25 this.milliseconds = milliseconds; 26 } 27 else if (arguments.length == 1 && typeof days == "number") { 14 */ 15 var TimeSpan = function (days, hours, minutes, seconds, milliseconds) { 16 var attrs = "days hours minutes seconds milliseconds".split(/\s+/); 17 18 var gFn = function (attr) { 19 return function () { 20 return this[attr]; 21 }; 22 }; 23 24 var sFn = function (attr) { 25 return function (val) { 26 this[attr] = val; 27 return this; 28 }; 29 }; 30 31 for (var i = 0; i < attrs.length ; i++) { 32 var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1); 33 TimeSpan.prototype[$a] = 0; 34 TimeSpan.prototype["get" + $b] = gFn($a); 35 TimeSpan.prototype["set" + $b] = sFn($a); 36 } 37 38 if (arguments.length == 4) { 39 this.setDays(days); 40 this.setHours(hours); 41 this.setMinutes(minutes); 42 this.setSeconds(seconds); 43 } else if (arguments.length == 5) { 44 this.setDays(days); 45 this.setHours(hours); 46 this.setMinutes(minutes); 47 this.setSeconds(seconds); 48 this.setMilliseconds(milliseconds); 49 } else if (arguments.length == 1 && typeof days == "number") { 28 50 var orient = (days < 0) ? -1 : +1; 29 this.milliseconds = Math.abs(days); 30 31 this.days = Math.floor(this.milliseconds / (24 * 60 * 60 * 1000)) * orient; 32 this.milliseconds = this.milliseconds % (24 * 60 * 60 * 1000); 33 34 this.hours = Math.floor(this.milliseconds / (60 * 60 * 1000)) * orient; 35 this.milliseconds = this.milliseconds % (60 * 60 * 1000); 36 37 this.minutes = Math.floor(this.milliseconds / (60 * 1000)) * orient; 38 this.milliseconds = this.milliseconds % (60 * 1000); 39 40 this.seconds = Math.floor(this.milliseconds / 1000) * orient; 41 this.milliseconds = this.milliseconds % 1000; 42 43 this.milliseconds = this.milliseconds * orient; 44 return this; 45 } 46 else { 47 return null; 48 } 49 }; 50 51 TimeSpan.prototype.compare = function (timeSpan) { 52 var t1 = new Date(1970, 1, 1, this.hours(), this.minutes(), this.seconds()), t2; 53 if (timeSpan === null) { 54 t2 = new Date(1970, 1, 1, 0, 0, 0); 55 } 56 else { 57 t2 = new Date(1970, 1, 1, timeSpan.hours(), timeSpan.minutes(), timeSpan.seconds()); /* t2 = t2.addDays(timeSpan.days()); */ 58 } 59 return (t1 > t2) ? 1 : (t1 < t2) ? -1 : 0; 60 }; 61 62 TimeSpan.prototype.add = function (timeSpan) { 63 return (timeSpan === null) ? this : this.addSeconds(timeSpan.getTotalMilliseconds() / 1000); 64 }; 65 66 TimeSpan.prototype.subtract = function (timeSpan) { 67 return (timeSpan === null) ? this : this.addSeconds(-timeSpan.getTotalMilliseconds() / 1000); 68 }; 69 70 TimeSpan.prototype.addDays = function (n) { 71 return new TimeSpan(this.getTotalMilliseconds() + (n * 24 * 60 * 60 * 1000)); 72 }; 73 74 TimeSpan.prototype.addHours = function (n) { 75 return new TimeSpan(this.getTotalMilliseconds() + (n * 60 * 60 * 1000)); 76 }; 77 78 TimeSpan.prototype.addMinutes = function (n) { 79 return new TimeSpan(this.getTotalMilliseconds() + (n * 60 * 1000)); 80 }; 81 82 TimeSpan.prototype.addSeconds = function (n) { 83 return new TimeSpan(this.getTotalMilliseconds() + (n * 1000)); 84 }; 85 86 TimeSpan.prototype.addMilliseconds = function (n) { 87 return new TimeSpan(this.getTotalMilliseconds() + n); 88 }; 89 90 TimeSpan.prototype.getTotalMilliseconds = function () { 91 return (this.days() * (24 * 60 * 60 * 1000)) + (this.hours() * (60 * 60 * 1000)) + (this.minutes() * (60 * 1000)) + (this.seconds() * (1000)); 92 }; 93 94 TimeSpan.prototype.get12HourHour = function () { 95 return ((h = this.hours() % 12) ? h : 12); 96 }; 97 98 TimeSpan.prototype.getDesignator = function () { 99 return (this.hours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator; 100 }; 101 102 TimeSpan.prototype.toString = function (format) { 103 function _toString() { 104 if (this.days() !== null && this.days() > 0) { 105 return this.days() + "." + this.hours() + ":" + p(this.minutes()) + ":" + p(this.seconds()); 106 } 107 else { 108 return this.hours() + ":" + p(this.minutes()) + ":" + p(this.seconds()); 109 } 110 } 111 function p(s) { 112 return (s.toString().length < 2) ? "0" + s : s; 113 } 114 var self = this; 115 return format ? format.replace(/d|dd|HH|H|hh|h|mm|m|ss|s|tt|t/g, 116 function (format) { 117 switch (format) { 118 case "d": 119 return self.days(); 120 case "dd": 121 return p(self.days()); 122 case "H": 123 return self.hours(); 124 case "HH": 125 return p(self.hours()); 126 case "h": 127 return self.get12HourHour(); 128 case "hh": 129 return p(self.get12HourHour()); 130 case "m": 131 return self.minutes(); 132 case "mm": 133 return p(self.minutes()); 134 case "s": 135 return self.seconds(); 136 case "ss": 137 return p(self.seconds()); 138 case "t": 139 return ((this.hours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator).substring(0, 1); 140 case "tt": 141 return (this.hours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator; 142 } 143 } 144 ) : this._toString(); 51 this.setMilliseconds(Math.abs(days)); 52 53 this.setDays(Math.floor(this.getMilliseconds() / 86400000) * orient); 54 this.setMilliseconds(this.getMilliseconds() % 86400000); 55 56 this.setHours(Math.floor(this.getMilliseconds() / 3600000) * orient); 57 this.setMilliseconds(this.getMilliseconds() % 3600000); 58 59 this.setMinutes(Math.floor(this.getMilliseconds() / 60000) * orient); 60 this.setMilliseconds(this.getMilliseconds() % 60000); 61 62 this.setSeconds(Math.floor(this.getMilliseconds() / 1000) * orient); 63 this.setMilliseconds(this.getMilliseconds() % 1000); 64 65 this.setMilliseconds(this.getMilliseconds() * orient); 66 } 67 68 this.getTotalMilliseconds = function () { 69 return (this.getDays() * 86400000) + (this.getHours() * 3600000) + (this.getMinutes() * 60000) + (this.getSeconds() * 1000); 70 }; 71 72 this.compareTo = function (time) { 73 var t1 = new Date(1970, 1, 1, this.getHours(), this.getMinutes(), this.getSeconds()), t2; 74 if (time === null) { 75 t2 = new Date(1970, 1, 1, 0, 0, 0); 76 } 77 else { 78 t2 = new Date(1970, 1, 1, time.getHours(), time.getMinutes(), time.getSeconds()); 79 } 80 return (t1 < t2) ? -1 : (t1 > t2) ? 1 : 0; 81 }; 82 83 this.equals = function (time) { 84 return (this.compareTo(time) === 0); 85 }; 86 87 this.add = function (time) { 88 return (time === null) ? this : this.addSeconds(time.getTotalMilliseconds() / 1000); 89 }; 90 91 this.subtract = function (time) { 92 return (time === null) ? this : this.addSeconds(-time.getTotalMilliseconds() / 1000); 93 }; 94 95 this.addDays = function (n) { 96 return new TimeSpan(this.getTotalMilliseconds() + (n * 86400000)); 97 }; 98 99 this.addHours = function (n) { 100 return new TimeSpan(this.getTotalMilliseconds() + (n * 3600000)); 101 }; 102 103 this.addMinutes = function (n) { 104 return new TimeSpan(this.getTotalMilliseconds() + (n * 60000)); 105 }; 106 107 this.addSeconds = function (n) { 108 return new TimeSpan(this.getTotalMilliseconds() + (n * 1000)); 109 }; 110 111 this.addMilliseconds = function (n) { 112 return new TimeSpan(this.getTotalMilliseconds() + n); 113 }; 114 115 this.get12HourHour = function () { 116 return (this.getHours() > 12) ? this.getHours() - 12 : (this.getHours() === 0) ? 12 : this.getHours(); 117 }; 118 119 this.getDesignator = function () { 120 return (this.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator; 121 }; 122 123 this.toString = function (format) { 124 this._toString = function () { 125 if (this.getDays() !== null && this.getDays() > 0) { 126 return this.getDays() + "." + this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds()); 127 } 128 else { 129 return this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds()); 130 } 131 }; 132 133 this.p = function (s) { 134 return (s.toString().length < 2) ? "0" + s : s; 135 }; 136 137 var me = this; 138 139 return format ? format.replace(/dd?|HH?|hh?|mm?|ss?|tt?/g, 140 function (format) { 141 switch (format) { 142 case "d": 143 return me.getDays(); 144 case "dd": 145 return me.p(me.getDays()); 146 case "H": 147 return me.getHours(); 148 case "HH": 149 return me.p(me.getHours()); 150 case "h": 151 return me.get12HourHour(); 152 case "hh": 153 return me.p(me.get12HourHour()); 154 case "m": 155 return me.getMinutes(); 156 case "mm": 157 return me.p(me.getMinutes()); 158 case "s": 159 return me.getSeconds(); 160 case "ss": 161 return me.p(me.getSeconds()); 162 case "t": 163 return ((me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator).substring(0, 1); 164 case "tt": 165 return (me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator; 166 } 167 } 168 ) : this._toString(); 169 }; 170 return this; 171 }; 172 173 /** 174 * Gets the time of day for this date instances. 175 * @return {TimeSpan} TimeSpan 176 */ 177 Date.prototype.getTimeOfDay = function () { 178 return new TimeSpan(0, this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds()); 145 179 }; 146 180 147 181 /* 148 182 * TimePeriod(startDate, endDate); 183 * TimePeriod(years, months, days, hours, minutes, seconds, milliseconds); 149 184 */ 150 185 var TimePeriod = function (years, months, days, hours, minutes, seconds, milliseconds) { 151 this.years = 0; 152 this.months = 0; 153 this.days = 0; 154 this.hours = 0; 155 this.minutes = 0; 156 this.seconds = 0; 157 this.milliseconds = 0; 158 159 // startDate and endDate as arguments 160 if (arguments.length == 2 && arguments[0] instanceof Date && arguments[1] instanceof Date) { 161 162 var date1 = years.clone(); 163 var date2 = months.clone(); 164 165 var temp = date1.clone(); 166 var orient = (date1 > date2) ? -1 : +1; 167 168 this.years = date2.getFullYear() - date1.getFullYear(); 186 var attrs = "years months days hours minutes seconds milliseconds".split(/\s+/); 187 188 var gFn = function (attr) { 189 return function () { 190 return this[attr]; 191 }; 192 }; 193 194 var sFn = function (attr) { 195 return function (val) { 196 this[attr] = val; 197 return this; 198 }; 199 }; 200 201 for (var i = 0; i < attrs.length ; i++) { 202 var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1); 203 TimePeriod.prototype[$a] = 0; 204 TimePeriod.prototype["get" + $b] = gFn($a); 205 TimePeriod.prototype["set" + $b] = sFn($a); 206 } 207 208 if (arguments.length == 7) { 209 this.years = years; 210 this.months = months; 211 this.setDays(days); 212 this.setHours(hours); 213 this.setMinutes(minutes); 214 this.setSeconds(seconds); 215 this.setMilliseconds(milliseconds); 216 } else if (arguments.length == 2 && arguments[0] instanceof Date && arguments[1] instanceof Date) { 217 // startDate and endDate as arguments 218 219 var d1 = years.clone(); 220 var d2 = months.clone(); 221 222 var temp = d1.clone(); 223 var orient = (d1 > d2) ? -1 : +1; 224 225 this.years = d2.getFullYear() - d1.getFullYear(); 169 226 temp.addYears(this.years); 170 227 171 228 if (orient == +1) { 172 if (temp > d ate2) {229 if (temp > d2) { 173 230 if (this.years !== 0) { 174 231 this.years--; … … 176 233 } 177 234 } else { 178 if (temp < d ate2) {235 if (temp < d2) { 179 236 if (this.years !== 0) { 180 237 this.years++; … … 183 240 } 184 241 185 d ate1.addYears(this.years);242 d1.addYears(this.years); 186 243 187 244 if (orient == +1) { 188 while (d ate1 < date2 && date1.clone().addDays(date1.getDaysInMonth()) < date2) {189 d ate1.addMonths(1);245 while (d1 < d2 && d1.clone().addDays(Date.getDaysInMonth(d1.getYear(), d1.getMonth()) ) < d2) { 246 d1.addMonths(1); 190 247 this.months++; 191 248 } 192 249 } 193 250 else { 194 while (d ate1 > date2 && date1.clone().addDays(-date1.getDaysInMonth()) > date2) {195 d ate1.addMonths(-1);251 while (d1 > d2 && d1.clone().addDays(-d1.getDaysInMonth()) > d2) { 252 d1.addMonths(-1); 196 253 this.months--; 197 254 } 198 255 } 199 256 200 var diff = d ate2 - date1;257 var diff = d2 - d1; 201 258 202 259 if (diff !== 0) { 203 260 var ts = new TimeSpan(diff); 204 205 this.days = ts.days; 206 this.hours = ts.hours; 207 this.minutes = ts.minutes; 208 this.seconds = ts.seconds; 209 this.milliseconds = ts.milliseconds; 210 } 211 212 // UTC Hacks required... 213 return this; 214 } 215 261 this.setDays(ts.getDays()); 262 this.setHours(ts.getHours()); 263 this.setMinutes(ts.getMinutes()); 264 this.setSeconds(ts.getSeconds()); 265 this.setMilliseconds(ts.getMilliseconds()); 266 } 267 } 268 return this; 216 269 }; -
branches/2.4/prototype/plugins/datejs/time.js
r5341 r7151 1 1 /** 2 * Version: 1.0 Alpha-1 3 * Build Date: 13-Nov-2007 4 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. 5 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 6 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ 2 * @version: 1.0 Alpha-1 3 * @author: Coolite Inc. http://www.coolite.com/ 4 * @date: 2008-05-13 5 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. 6 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 7 * @website: http://www.datejs.com/ 7 8 */ 8 TimeSpan=function(days,hours,minutes,seconds,milliseconds){this.days=0;this.hours=0;this.minutes=0;this.seconds=0;this.milliseconds=0;if(arguments.length==5){this.days=days;this.hours=hours;this.minutes=minutes;this.seconds=seconds;this.milliseconds=milliseconds;} 9 else if(arguments.length==1&&typeof days=="number"){var orient=(days<0)?-1:+1;this.milliseconds=Math.abs(days);this.days=Math.floor(this.milliseconds/(24*60*60*1000))*orient;this.milliseconds=this.milliseconds%(24*60*60*1000);this.hours=Math.floor(this.milliseconds/(60*60*1000))*orient;this.milliseconds=this.milliseconds%(60*60*1000);this.minutes=Math.floor(this.milliseconds/(60*1000))*orient;this.milliseconds=this.milliseconds%(60*1000);this.seconds=Math.floor(this.milliseconds/1000)*orient;this.milliseconds=this.milliseconds%1000;this.milliseconds=this.milliseconds*orient;return this;} 10 else{return null;}};TimeSpan.prototype.compare=function(timeSpan){var t1=new Date(1970,1,1,this.hours(),this.minutes(),this.seconds()),t2;if(timeSpan===null){t2=new Date(1970,1,1,0,0,0);} 11 else{t2=new Date(1970,1,1,timeSpan.hours(),timeSpan.minutes(),timeSpan.seconds());} 12 return(t1>t2)?1:(t1<t2)?-1:0;};TimeSpan.prototype.add=function(timeSpan){return(timeSpan===null)?this:this.addSeconds(timeSpan.getTotalMilliseconds()/1000);};TimeSpan.prototype.subtract=function(timeSpan){return(timeSpan===null)?this:this.addSeconds(-timeSpan.getTotalMilliseconds()/1000);};TimeSpan.prototype.addDays=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*24*60*60*1000));};TimeSpan.prototype.addHours=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*60*60*1000));};TimeSpan.prototype.addMinutes=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*60*1000));};TimeSpan.prototype.addSeconds=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*1000));};TimeSpan.prototype.addMilliseconds=function(n){return new TimeSpan(this.getTotalMilliseconds()+n);};TimeSpan.prototype.getTotalMilliseconds=function(){return(this.days()*(24*60*60*1000))+(this.hours()*(60*60*1000))+(this.minutes()*(60*1000))+(this.seconds()*(1000));};TimeSpan.prototype.get12HourHour=function(){return((h=this.hours()%12)?h:12);};TimeSpan.prototype.getDesignator=function(){return(this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;};TimeSpan.prototype.toString=function(format){function _toString(){if(this.days()!==null&&this.days()>0){return this.days()+"."+this.hours()+":"+p(this.minutes())+":"+p(this.seconds());} 13 else{return this.hours()+":"+p(this.minutes())+":"+p(this.seconds());}} 14 function p(s){return(s.toString().length<2)?"0"+s:s;} 15 var self=this;return format?format.replace(/d|dd|HH|H|hh|h|mm|m|ss|s|tt|t/g,function(format){switch(format){case"d":return self.days();case"dd":return p(self.days());case"H":return self.hours();case"HH":return p(self.hours());case"h":return self.get12HourHour();case"hh":return p(self.get12HourHour());case"m":return self.minutes();case"mm":return p(self.minutes());case"s":return self.seconds();case"ss":return p(self.seconds());case"t":return((this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator).substring(0,1);case"tt":return(this.hours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;}}):this._toString();};var TimePeriod=function(years,months,days,hours,minutes,seconds,milliseconds){this.years=0;this.months=0;this.days=0;this.hours=0;this.minutes=0;this.seconds=0;this.milliseconds=0;if(arguments.length==2&&arguments[0]instanceof Date&&arguments[1]instanceof Date){var date1=years.clone();var date2=months.clone();var temp=date1.clone();var orient=(date1>date2)?-1:+1;this.years=date2.getFullYear()-date1.getFullYear();temp.addYears(this.years);if(orient==+1){if(temp>date2){if(this.years!==0){this.years--;}}}else{if(temp<date2){if(this.years!==0){this.years++;}}} 16 date1.addYears(this.years);if(orient==+1){while(date1<date2&&date1.clone().addDays(date1.getDaysInMonth())<date2){date1.addMonths(1);this.months++;}} 17 else{while(date1>date2&&date1.clone().addDays(-date1.getDaysInMonth())>date2){date1.addMonths(-1);this.months--;}} 18 var diff=date2-date1;if(diff!==0){var ts=new TimeSpan(diff);this.days=ts.days;this.hours=ts.hours;this.minutes=ts.minutes;this.seconds=ts.seconds;this.milliseconds=ts.milliseconds;} 19 return this;}}; 9 var TimeSpan=function(days,hours,minutes,seconds,milliseconds){var attrs="days hours minutes seconds milliseconds".split(/\s+/);var gFn=function(attr){return function(){return this[attr];};};var sFn=function(attr){return function(val){this[attr]=val;return this;};};for(var i=0;i<attrs.length;i++){var $a=attrs[i],$b=$a.slice(0,1).toUpperCase()+$a.slice(1);TimeSpan.prototype[$a]=0;TimeSpan.prototype["get"+$b]=gFn($a);TimeSpan.prototype["set"+$b]=sFn($a);} 10 if(arguments.length==4){this.setDays(days);this.setHours(hours);this.setMinutes(minutes);this.setSeconds(seconds);}else if(arguments.length==5){this.setDays(days);this.setHours(hours);this.setMinutes(minutes);this.setSeconds(seconds);this.setMilliseconds(milliseconds);}else if(arguments.length==1&&typeof days=="number"){var orient=(days<0)?-1:+1;this.setMilliseconds(Math.abs(days));this.setDays(Math.floor(this.getMilliseconds()/86400000)*orient);this.setMilliseconds(this.getMilliseconds()%86400000);this.setHours(Math.floor(this.getMilliseconds()/3600000)*orient);this.setMilliseconds(this.getMilliseconds()%3600000);this.setMinutes(Math.floor(this.getMilliseconds()/60000)*orient);this.setMilliseconds(this.getMilliseconds()%60000);this.setSeconds(Math.floor(this.getMilliseconds()/1000)*orient);this.setMilliseconds(this.getMilliseconds()%1000);this.setMilliseconds(this.getMilliseconds()*orient);} 11 this.getTotalMilliseconds=function(){return(this.getDays()*86400000)+(this.getHours()*3600000)+(this.getMinutes()*60000)+(this.getSeconds()*1000);};this.compareTo=function(time){var t1=new Date(1970,1,1,this.getHours(),this.getMinutes(),this.getSeconds()),t2;if(time===null){t2=new Date(1970,1,1,0,0,0);} 12 else{t2=new Date(1970,1,1,time.getHours(),time.getMinutes(),time.getSeconds());} 13 return(t1<t2)?-1:(t1>t2)?1:0;};this.equals=function(time){return(this.compareTo(time)===0);};this.add=function(time){return(time===null)?this:this.addSeconds(time.getTotalMilliseconds()/1000);};this.subtract=function(time){return(time===null)?this:this.addSeconds(-time.getTotalMilliseconds()/1000);};this.addDays=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*86400000));};this.addHours=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*3600000));};this.addMinutes=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*60000));};this.addSeconds=function(n){return new TimeSpan(this.getTotalMilliseconds()+(n*1000));};this.addMilliseconds=function(n){return new TimeSpan(this.getTotalMilliseconds()+n);};this.get12HourHour=function(){return(this.getHours()>12)?this.getHours()-12:(this.getHours()===0)?12:this.getHours();};this.getDesignator=function(){return(this.getHours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;};this.toString=function(format){this._toString=function(){if(this.getDays()!==null&&this.getDays()>0){return this.getDays()+"."+this.getHours()+":"+this.p(this.getMinutes())+":"+this.p(this.getSeconds());} 14 else{return this.getHours()+":"+this.p(this.getMinutes())+":"+this.p(this.getSeconds());}};this.p=function(s){return(s.toString().length<2)?"0"+s:s;};var me=this;return format?format.replace(/dd?|HH?|hh?|mm?|ss?|tt?/g,function(format){switch(format){case"d":return me.getDays();case"dd":return me.p(me.getDays());case"H":return me.getHours();case"HH":return me.p(me.getHours());case"h":return me.get12HourHour();case"hh":return me.p(me.get12HourHour());case"m":return me.getMinutes();case"mm":return me.p(me.getMinutes());case"s":return me.getSeconds();case"ss":return me.p(me.getSeconds());case"t":return((me.getHours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator).substring(0,1);case"tt":return(me.getHours()<12)?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;}}):this._toString();};return this;};Date.prototype.getTimeOfDay=function(){return new TimeSpan(0,this.getHours(),this.getMinutes(),this.getSeconds(),this.getMilliseconds());};var TimePeriod=function(years,months,days,hours,minutes,seconds,milliseconds){var attrs="years months days hours minutes seconds milliseconds".split(/\s+/);var gFn=function(attr){return function(){return this[attr];};};var sFn=function(attr){return function(val){this[attr]=val;return this;};};for(var i=0;i<attrs.length;i++){var $a=attrs[i],$b=$a.slice(0,1).toUpperCase()+$a.slice(1);TimePeriod.prototype[$a]=0;TimePeriod.prototype["get"+$b]=gFn($a);TimePeriod.prototype["set"+$b]=sFn($a);} 15 if(arguments.length==7){this.years=years;this.months=months;this.setDays(days);this.setHours(hours);this.setMinutes(minutes);this.setSeconds(seconds);this.setMilliseconds(milliseconds);}else if(arguments.length==2&&arguments[0]instanceof Date&&arguments[1]instanceof Date){var d1=years.clone();var d2=months.clone();var temp=d1.clone();var orient=(d1>d2)?-1:+1;this.years=d2.getFullYear()-d1.getFullYear();temp.addYears(this.years);if(orient==+1){if(temp>d2){if(this.years!==0){this.years--;}}}else{if(temp<d2){if(this.years!==0){this.years++;}}} 16 d1.addYears(this.years);if(orient==+1){while(d1<d2&&d1.clone().addDays(Date.getDaysInMonth(d1.getYear(),d1.getMonth()))<d2){d1.addMonths(1);this.months++;}} 17 else{while(d1>d2&&d1.clone().addDays(-d1.getDaysInMonth())>d2){d1.addMonths(-1);this.months--;}} 18 var diff=d2-d1;if(diff!==0){var ts=new TimeSpan(diff);this.setDays(ts.getDays());this.setHours(ts.getHours());this.setMinutes(ts.getMinutes());this.setSeconds(ts.getSeconds());this.setMilliseconds(ts.getMilliseconds());}} 19 return this;};
Note: See TracChangeset
for help on using the changeset viewer.