Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff@coolite.com committed Nov 5, 2008
1 parent 4b8868c commit 7bdddb5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
47 changes: 27 additions & 20 deletions src/core.js
Expand Up @@ -200,22 +200,29 @@
$P.isBefore = function (date) {
return (this.compareTo(date || new Date()) === -1);
};

/**
* Determines if the current Date instance occurs today.
* @return {Boolean} true if this date instance is 'today', otherwise false.
*/

$P.isToday = function () {
return this.isSameDay(new Date());
/**
* Determines if the current Date instance occurs on the same Date as the supplied 'date'.
* If no 'date' to compare to is provided, the current Date instance is compared to 'today'.
* @param {date} Date object to compare. If no date to compare, the current Date ("now") is used.
* @return {Boolean} true if this Date instance occurs on the same Day as the supplied 'date'.
*/
$P.isToday = $P.isSameDay = function (date) {
return this.clone().clearTime().equals((date || new Date()).clone().clearTime());
};

$P.isSameDay = function (date) {
return this.clone().clearTime().equals(date.clone().clearTime());
};

/**
* Adds the specified number of milliseconds to this instance.
* @param {Number} The number of milliseconds to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addMilliseconds = function (value) {
this.setMilliseconds(this.getMilliseconds() + value);
this.setMilliseconds(this.getMilliseconds() + value * 1);
return this;
};

Expand Down Expand Up @@ -252,7 +259,7 @@
* @return {Date} this
*/
$P.addDays = function (value) {
this.setDate(this.getDate() + value);
this.setDate(this.getDate() + value * 1);
return this;
};

Expand All @@ -273,7 +280,7 @@
$P.addMonths = function (value) {
var n = this.getDate();
this.setDate(1);
this.setMonth(this.getMonth() + value);
this.setMonth(this.getMonth() + value * 1);
this.setDate(Math.min(n, $D.getDaysInMonth(this.getFullYear(), this.getMonth())));
return this;
};
Expand Down Expand Up @@ -404,7 +411,7 @@
};

// private
$D._validate = function (n, min, max, name) {
var validate = function (n, min, max, name) {
if (typeof n == "undefined") {
return false;
} else if (typeof n != "number") {
Expand All @@ -421,7 +428,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMillisecond = function (value) {
return $D._validate(value, 0, 999, "millisecond");
return validate(value, 0, 999, "millisecond");
};

/**
Expand All @@ -430,7 +437,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateSecond = function (value) {
return $D._validate(value, 0, 59, "second");
return validate(value, 0, 59, "second");
};

/**
Expand All @@ -439,7 +446,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMinute = function (value) {
return $D._validate(value, 0, 59, "minute");
return validate(value, 0, 59, "minute");
};

/**
Expand All @@ -448,7 +455,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateHour = function (value) {
return $D._validate(value, 0, 23, "hour");
return validate(value, 0, 23, "hour");
};

/**
Expand All @@ -457,7 +464,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateDay = function (value, year, month) {
return $D._validate(value, 1, $D.getDaysInMonth(year, month), "day");
return validate(value, 1, $D.getDaysInMonth(year, month), "day");
};

/**
Expand All @@ -466,7 +473,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMonth = function (value) {
return $D._validate(value, 0, 11, "month");
return validate(value, 0, 11, "month");
};

/**
Expand All @@ -475,7 +482,7 @@
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateYear = function (value) {
return $D._validate(value, 0, 9999, "year");
return validate(value, 0, 9999, "year");
};

/**
Expand Down Expand Up @@ -528,7 +535,7 @@
this.setTimezoneOffset(config.timezoneOffset);
}

if (config.week && $D._validate(config.week, 0, 53, "week")) {
if (config.week && validate(config.week, 0, 53, "week")) {
this.setWeek(config.week);
}

Expand Down Expand Up @@ -631,8 +638,8 @@
* Indicates whether this Date instance is within the Daylight Saving Time range for the current time zone.
* @return {Boolean} true|false
*/
$P.isDaylightSavingTime = function () {
return (this.hasDaylightSavingTime() && new Date().getTimezoneOffset() === Date.today().set({month: 6, day: 1}).getTimezoneOffset());
$P.isDaylightSavingTime = function () {
return Date.today().set({month: 0, day: 1}).getTimezoneOffset() != this.getTimezoneOffset();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/parser.js
Expand Up @@ -9,7 +9,7 @@

(function () {
Date.Parsing = {
Exception: function (s) {
Exception: function (s) {
this.message = "Parse error at '" + s.substring(0, 10) + " ...'";
}
};
Expand Down

0 comments on commit 7bdddb5

Please sign in to comment.