DP_DateExtensions

The DP_DateExtensions library extends the JavaScript Date object with new features and functionality.

  • The addition of feature-rich timeFormat() and dateFormat() methods allowing you detailed control over the display of your date and time values.
  • Easy manipulation of date math via the add(), diff(), round(), floor() and ceil() methods with an extended selection of standardized date parts.
  • Simplified comparision of dates using the compare() method.
  • Many convience functions for dealing with Daylight Savings Time and various common needs.
  • The ability to parse several ISO 8601 standard format dates as described in the Date and Time Formats W3C note.

This component requires a JavaScript (ECMAScript) 1.3 (or better) environment and has been tested successfully on Internet Explorer 6+, Firefox 1+ and Opera 9+.

Download

The component is available from GitHub:

All downloads and code are covered by our Source Code Policy.

Usage

The library consists of a single JavaScript file with a .JS extension.

Importing the Library

The library must be imported before it is used. To import the library use the <script> tag. For example:

<script type="text/javascript" src="DP_DateExtension.js"></script>

Your path may vary depending on the location of the script on your server.

Using the Library

Once the library has been imported you may access any of the functions within it. Some of the functions are extensions of the Date Object while others are extensions of the Date Object prototype. Extensions to the Date Object are accessible via the Date object like so:

var MyFormattedDate = Date.parseIso8601(new Date());

Extensions to the Date Object prototype are accessible directly as methods of any instantiated date object:

	var MyDate = new Date();
	var MyFormattedDate = MyDate.dateFormat("mmm d, yyyy");
	

Methods and Properties

Static properties of Date:

  • Date.DP_DateExtensions: The value of the property is “true”. This property is useful to determine, at a “quick-and-dirty” level, if DP_DateExtensions has been loaded.
  • Date.FirstDayOfWeek: A number from zero (Sunday, the default) to six (Saturday) that indicates which day should be considered the start of the week. Value will be considered when the round(), floor(), ceil() and diff() functions are used.
  • Date.Factors: An object containing multiplication factors for the available unambigious date parts (factor multiplied by milliseconds equals datepart). Used primarily internally.
    • Date.Factors.milliseconds: 1 (1 ms to the ms).
    • Date.Factors.seconds: 1000 (1000 ms to the second or [1 * 1000]).
    • Date.Factors.minutes: 60000 (60 seconds to the minute or [1 * 1000 * 60]).
    • Date.Factors.quarterhours: 900000 (15 minutes to the quarter hour or [1 * 1000 * 60 * 15]).
    • Date.Factors.warhols: 900000 (15 minutes of fame or [1 * 1000 * 60 * 15]).
    • Date.Factors.halfhours: 1800000 (30 minutes to the half hour or [1 * 1000 * 60 * 15]).
    • Date.Factors.hours: 3600000 (60 minutes to the hour or [1 * 1000 * 60 * 60]).
    • Date.Factors.days: 86400000 (24 hours to the day or [1 * 1000 * 60 * 60 * 24]).
    • Date.Factors.weeks : 604800000 (7 days per week or [1 * 1000 * 60 * 60 * 24 * 7]).

Static methods of Date:

Instance methods of Date objects:

Note that in method signatures a pipe (“|”) indicates “OR” while arguments in square brackets are optional.

Date.is()

This static method returns “true” if the passed value is a JavaScript Date object.

Method Signature

Date.is(Input)

Arguments

This method has one argument:

  • Input: Any, Required. A JavaScript value.

Return

Boolean. Returns true of the passed value is a JacaScript Date object, false if not.

Date.parseFormat()

This static method accepts a date/time mask and a string value. The passed value is first checked against the mask; if it matches then the value is converted to a native JavaScript date object.

When creating the date any ambigious or unsupplied values will use default values (as defined by the Default parameter). Some mask parts (such as “DDD”, “DDDD”, “TT”, etc) are ambigious by nature and will not inform the date creation. They are useful for recognizing the date format however (allowing this function to parse any output of the dateFormat() and timeFormat() functions with no manipulation). Also note that the mask must match the input exactly, including any spaces, for the conversion step to be attempted.

Method Signature

Date.parseFormat(Input, Mask, Default, CenturyMark)

Arguments

This method has three arguments:

  • Input: String, Required. A string representing the date you wish to parse.
  • Mask: String, Required. A mask representing the date format to convert. All mask characters used by the dateFormat() and timeFormat() functions are accepted:
    • D: The day of the month as a number.
    • DD: The day of the month as a number with, if applicable, a leading zero.
    • DDD: The day of the week as a three-character abbreviation (for example “Tue”).
    • DDDD: The full name of the day of the week (for example “Tuesday”).
    • M: The month as a number.
    • MM: The month as a number with, if applicable, a leading zero.
    • MMM: The month as a three-character abbreviation (for example “Jan”).
    • MMMM: The full name of the month (for example “January”).
    • YY: The last two digits of the year.
    • YYYY: The four-digit year.
    • h: Hours. 12-hour clock.
    • hh: Hours with, if applicable, a leading zero. 12-hour clock.
    • H: Hours. 24-hour clock.
    • HH: Hours with, if applicable, a leading zero. 24-hour clock.
    • m: Minutes.
    • mm: Minutes with, if applicable, a leading zero.
    • s: Seconds.
    • ss: Seconds with, if applicable, a leading zero.
    • l: Milliseconds.
    • t: Produces a single, lowercase character (“a” or “p”) for ante meridiem and post meridiem.
    • tt: Produces a two, lowercase characters (“am” or “pm”) for ante meridiem and post meridiem.
    • T: Produces a single, uppercase character (“A” or “P”) for ante meridiem and post meridiem.
    • TT: Produces a two, uppercase characters (“AM” or “PM”) for ante meridiem and post meridiem.
  • Default: Integer, Optional. Defaults to 0. Specifies which values to use as defaults for date parts which are not specified in the specified format.
    • 0: Default. Use JavaScript’s default values (null). This will generally result in values at the beginning of the acceptable date range (for example January 1, 1899).
    • 1: Use the current date/time as default values.
    • 2: Use the current UTC date/time as default values.
  • CenturyMark: Integer (0-99), Optional. Defaults to 50. Used when parsing two-digit years. Values less than the CenturyMark will be set as 21st century (2000’s) and values greater than will be set as 20th century (1900’s).

Return

Date or Null. If the passed information can be converted to a date the method returns a native JavaScript date object. If not a null value is returned.

Date.parseIso8601()

This static method converts compliant ISO 8601 date strings into native JavaScript Date objects. The formats allowed are described in the Date and Time Formats W3C note.

Method Signature

Date.parseIso8601(Input)

Arguments

This method has one argument:

  • Input: String, Required. A string representing the date you wish to convert.

Return

Date or Null. If the passed information can be converted to a date the method returns a native JavaScript date object. If not a null value is returned.

Date.parseHttpTimeFormat()

This static conveinence method converts HTTP dates (specified in RFC 822) date strings into native JavaScript Date objects. Identical to Date.parseFormat(CurDate, “DDD, D MMM YYYY HH:mm:ss z”).

Method Signature

Date.parseHttpTimeFormat(Input)

Arguments

This method has one argument:

  • Input: String, Required. A string representing the date you wish to convert.

Return

Date or Null. If the passed information can be converted to a date the method returns a native JavaScript date object. If not a null value is returned.

Date.getUSDST()

This static method accepts a four-digit year and attempts to return an array containing the start and end dates for United States Daylight Saving Time (DST).

The method cannot return values for years before 1987 and will return values for all future years using 2007 rules.

Method Signature

Date.getUSDST(Year)

Arguments

This method has one argument:

  • Year: Number, Required. A four-digit year.

Return

An array of two Date objects (beginning and end of US DST) or Null (if the date passed is prior to 1987 or is not understandable).

DateInstance.add()

Adds a specified number of the specified date units to the date.

Method Signature

DateInstance.add([Amount], [DatePart], [Destructive])

Arguments

This method has three arguments:

  • Amount: Integer, Optional. Defaults to “1”. The number of units by which to modify the date. Positive numbers will result in future dates; negative numbers will result in past dates.
  • DatePart: String, Optional. Defaults to “milliseconds”. The unit to add to the date. The following date parts are supported:
    • milliseconds: Milliseconds.
    • seconds: Seconds.
    • minutes: Minutes.
    • quarterhours: 15 minutes.
    • warhols: 15 minutes (of fame).
    • halfhours: 30 minutes.
    • hours: Hours.
    • days: Days.
    • weeks: Weeks (periods of 7 days).
    • businessdays: Days excluding Saturday and Sunday. Note that holidays are NOT considered.
    • months: Months. The date (day of month) may change (to the last day of the new month) if months have an incompatible number of days. For example adding one month to March 31 will result in April 30.
    • years: Years. If the date is February 29th (a leap year) it may be changed to March 1st if the resulting year is not a leap year.
  • Destructive: Boolean, Optional. Defaults to false. If false (the default) the method will return a new date object with the results; if true the method will update the date in place and return a reference to the original date.

Return

Date.

DateInstance.ceil()

Similar to the Math.ceil() method this method will round the date upward to the next significant value of the selected date part.

Method Signature

DateInstance.ceil([DatePart], [Destructive])

Arguments

This method has two arguments:

  • DatePart: String, Optional. Defaults to “Seconds”. The precision to use for the operation (all date parts smaller than the selected will be set to the default value). The following date parts are supported:
    • milliseconds: Milliseconds.
    • seconds: Seconds.
    • minutes: Minutes.
    • quarterhours: 15 minutes.
    • warhols: 15 minutes (of fame).
    • halfhours: 30 minutes.
    • hours: Hours.
    • days: Days.
    • weeks: Weeks. Defaults to using Sunday as the first day of the week but this can be changed by changing the Date.FirstDayOfWeek property.
    • businessdays: Days excluding Saturday and Sunday. Note that holidays are NOT considered.
    • months: Months.
    • years: Years.
  • Destructive: Boolean, Optional. Defaults to false. If false (the default) the method will return a new date object with the results; if true the method will update the date in place and return a reference to the original date.

Return

Date.

DateInstance.compare()

Does a comparison of two dates to an optionally specified precision.

Method Signature

DateInstance.compare([Date], [Precision])

Arguments

This method has two arguments:

  • Date: Date, Optional. Defaults to current instant. The date to compare.
  • Precision: String, Optional. Defaults to “millisecond”. Acceptable values are:
    • millisecond: (The default.) Comparison precise to the millisecond.
    • second: Comparison precise to the second.
    • minute: Comparison precise to the minute.
    • hour: Comparison precise to the hour.
    • day: Comparison precise to the day.
    • month: Comparison precise to the month.
    • year: Comparison precise to the year.

Return

Integer. The method returns zero (“0”) if the dates are equal, negative one (“-1”) if the original date falls prior to the passed date or positive one (“1”) if the original date falls after the passed date.

DateInstance.dateFormat()

Formats a date using a supplied format mask.

Method Signature

DateInstance.dateFormat(Mask)

Arguments

This method has one argument:

  • Mask: String, Required. The mask to apply to the date. The following case-sensitive mask values are supported:
    • D: The day of the month as a number.
    • DD: The day of the month as a number with, if applicable, a leading zero.
    • DDD: The day of the week as a three-character abbreviation (for example “Tue”).
    • DDDD: The full name of the day of the week (for example “Tuesday”).
    • M: The month as a number.
    • MM: The month as a number with, if applicable, a leading zero.
    • MMM: The month as a three-character abbreviation (for example “Jan”).
    • MMMM: The full name of the month (for example “January”).
    • YY: The last two digits of the year.
    • YYYY: The four-digit year.

    In addition the following case-sensitive short-hand values are also acceptable:

    • short: Identical to “M/D/YY”.
    • medium: Identical to “MMM D, YYYY”.
    • long: Identical to “MMMM D, YYYY”.
    • full: Identical to “DDDD, MMMM D, YYYY”.

    These short-hand values cannot be mixed with other mask values.

Return

String. The formatted date as described by the specified mask.

DateInstance.dayOfYear()

This function returns the ordinal day of the year.

Method Signature

DateInstance.dayOfYear()

Arguments

This method has no arguments:

Return

Integer. The day of year (1-366).

DateInstance.diff()

Returns the number of specified date units between two dates.

Method Signature

DateInstance.diff([Date], [DatePart], [CompareMethod], [NormalizeDST])

Arguments

This method has two arguments:

  • Date: Date, Optional. Defaults to current instant. The date to calculate the difference from.
  • DatePart: String, Optional. Defaults to “Milliseconds”. The kind of unit to count (see CompareMethod below for details). The following date parts are supported:
    • milliseconds: Milliseconds.
    • seconds: Seconds.
    • minutes: Minutes.
    • quarterhours: 15 minutes.
    • warhols: 15 minutes (of fame).
    • halfhours: 30 minutes.
    • hours: Hours.
    • days: Days.
    • weeks: Weeks.
    • businessdays: Days excluding Saturday and Sunday. Note that holidays are NOT considered.
    • months: Months.
    • years: Years.
  • CompareMethod: String, Optional. Defaults to “Actual”. The method to use for comparison. The following methods are supported:
    • Actual: Compares entire units; generally returns the “common sense” result. For purposes of this comparison date parts are defined as follows:
      • milliseconds: Unambigious.
      • seconds: Unambigious, 1000 ms to the second.
      • minutes: Unambigious, 60 seconds to the minute (60,000ms).
      • quarterhours: Unambigious, 15 minutes to the quarter hour (900,000ms)
      • warhols: Same as quarterhours.
      • halfhours: Unambigious, 30 minutes to the half hour (1,800,000ms)
      • hours: Unambigious, 60 minutes to the hour (3,600,000ms)
      • days: Unambigious, 24 hours to the day (86,400,000ms)
      • weeks: Unambigious, 7 days per week (604,800,000ms)
      • businessdays: Same as Days, but eliminates Saturday and Sunday from consideration.
      • months: A change in the ordinal month.
      • years: Periods of 12 months.
    • Logical: Any change in the ordinal unit will be counted as a difference (does the comparison using a precison equal to the selected date part). For purposes of this comparison date parts are defined as follows:
      • milliseconds: Same results as if the “Actual” compare method was used.
      • seconds: A change in the ordinal second.
      • minutes: A change in the ordinal minute.
      • quarterhours: 15-minute divisions of ordinal hours beginning at the 00, 15, 30 and 45 minute marks.
      • warhols: Same as quarterhours.
      • halfhours: 30-minute divisions of ordinal hours beginning at the 00 and 30 minute marks.
      • hours: A change in the ordinal hour.
      • days: A change in the ordinal day.
      • weeks: A change in the ordinal week as starting on the first day of the week. Defaults to using Sunday as the first day of the week but this can be changed by changing the Date.FirstDayOfWeek property.
      • businessdays: Same as days, but eliminates Saturday and Sunday from consideration.
      • months: A change in the ordinal month.
      • years: A change in the ordinal year.
    • Complete: Using this method only entire, complete instances of the selected unit will be counted as a difference. For purposes of this comparison date parts are defined as follows:
      • milliseconds: Same results as if the “Actual” compare method was used.
      • seconds: Complete ordinal seconds.
      • minutes: Complete ordinal minutes.
      • quarterhours: Complete 15-minute divisions of ordinal hours beginning at the 00, 15, 30 and 45 minute marks.
      • warhols: Same as quarterhours.
      • halfhours: Complete 30-minute divisions of ordinal hours beginning at the 00 and 30 minute marks.
      • hours: Complete ordinal hours.
      • days: Complete calendar days.
      • weeks: Complete weeks. Defaults to using Sunday as the first day of the week but this can be changed by changing the Date.FirstDayOfWeek property.
      • businessdays: Complete days, excluding Sunday and Saturday.
      • months: Complete calendar months.
      • years: Complete calendar years.
  • NormalizeDST: Boolean, Optional. Defaults to true. If true dates that have different time zone offsets due to DST will first be normalized to elimaite DST-based differences.

Return

Integer. The number of whole units between the two dates (no fractions will be returned).

DateInstance.floor()

Similar to the Math.floor() method this method will round the date down to the default value of the selected date part.

Method Signature

DateInstance.floor([DatePart], [Destructive])

Arguments

This method has two arguments:

  • DatePart: String, Optional. Defaults to “Seconds”.The precision to use for the operation (all date parts smaller than the selected will be set to the default value). The following date parts are supported:
    • milliseconds: Milliseconds.
    • seconds: Seconds.
    • minutes: Minutes.
    • quarterhours: 15 minutes.
    • warhols: 15 minutes (of fame).
    • halfhours: 30 minutes.
    • hours: Hours.
    • days: Days.
    • weeks: Weeks. Defaults to using Sunday as the first day of the week but this can be changed by changing the Date.FirstDayOfWeek property.
    • businessdays: Days excluding Saturday and Sunday. Note that holidays are NOT considered.
    • months: Months.
    • years: Years.
  • Destructive: Boolean, Optional. Defaults to false. If false (the default) the method will return a new date object with the results; if true the method will update the date in place and return a reference to the original date.

Return

Date.

DateInstance.httpTimeFormat()

A convenience method which generates HTTP dates (specified in RFC 822) for output. For example “Sun, 13 May 2007 18:05:45 -0400”.

Method Signature

DateInstance.httpTimeFormat(isUTC)

Arguments

This method has one argument:

  • isUTC: Boolean, Optional. Defaults to “false”. Pass “true” if the datetime is UTC, “false” if the datetime is local time.

Return

String. An date formatted accorded to RFC 822.

DateInstance.isLeapYear()

Returns true if the datetime falls within a Leap Year.

Method Signature

DateInstance.isLeapYear()

Arguments

This method has no arguments:

Return

Boolean. True if the datetime is within a Leap Year, false if not.

DateInstance.isDST()

Returns true if the datetime appears to fall within the local regions daylight saving time (DST) observance.

(Note that this function should be considered a “best guess” as the method used to make the determination is a general comparison of timezone offsets for the region rather than any specific DST rules or guidelines.)

Method Signature

DateInstance.isDST()

Arguments

This method has no arguments:

Return

Boolean. True if the datetime appears fall with DST for the region, false if not.

DateInstance.isWeekday()

Returns true if the datetime falls on a weekday (monday through friday, inclusive).

Method Signature

DateInstance.isWeekday()

Arguments

This method has no arguments:

Return

Boolean. True if the datetime falls on a weekday, false if not.

DateInstance.iso8601Format()

A convenience method which generates ISO 8601 formatted dates for output.

Method Signature

DateInstance.iso8601Format(Style, [isUTC])

Arguments

This method has two arguments:

  • Style: String, Optional. Defaults to “YMDHMSM”. The style of the date to be output. Can be any of the following:
    • Y or 1: “Year”. Equivalent to dateFormat(“yyyy”).
    • YM or 2: “Year and Month”. Equivalent to dateFormat(“yyyy-mm”).
    • YMD or 3: “Year, Month and Day”. Equivalent to dateFormat(“yyyy-mm-dd”).
    • YMDHM or 4: “Year, Month, Day, Hours and Minutes”. Equivalent to dateFormat(“yyyy-mm-dd”) + “T” + timeFormat(“HH:mm”) plus timezone information.
    • YMDHMS or 5: “Year, Month, Day, Hours, Minutes and Seconds”. Equivalent to dateFormat(“yyyy-mm-dd”) + “T” + timeFormat(“HH:mm:ss”) plus timezone information.
    • YMDHMSM or 6: “Year, Month, Day, Hours, Minutes, Seconds and Milliseconds”. Equivalent to dateFormat(“yyyy-mm-dd”) + “T” + timeFormat(“HH:mm:ss.l”) plus timezone information.
  • isUTC: Boolean, Optional. Default to “false”. Specifies if the date is to be treated as a UTC date or not. If “true” the UTC indicator will be appended to the dates with time values, if “false” timezone information will be appended to dates with time values.

Return

String. An ISO 8601 formatted date.

DateInstance.round()

Similar to the Math.round() method this method rounds the date up or down dependent on the value of the selected date part.

Method Signature

DateInstance.round([DatePart], [Destructive])

Arguments

This method has two arguments:

  • DatePart: String, Optional. Defaults to “Seconds”. The precision to use for the operation (all date parts smaller than the selected will be set to the default value). The following date parts are supported:
    • milliseconds: Milliseconds.
    • seconds: Seconds.
    • minutes: Minutes.
    • quarterhours: 15 minutes.
    • warhols: 15 minutes (of fame).
    • halfhours: 30 minutes.
    • hours: Hours.
    • days: Days.
    • weeks: Weeks. Defaults to using Sunday as the first day of the week but this can be changed by changing the Date.FirstDayOfWeek property.
    • businessdays: Days excluding Saturday and Sunday. Note that holidays are NOT considered.
    • months: Months.
    • years: Years.
  • Destructive: Boolean, Optional. Defaults to false. If false (the default) the method will return a new date object with the results; if true the method will update the date in place and return a reference to the original date.

Return

Date.

DateInstance.timeFormat()

Formats the time portion of a date using a supplied mask.

Method Signature

DateInstance.timeFormat(Mask)

Arguments

This method has one argument:

  • Mask: String, Required. The mask to apply to the time. The following case-sensitive mask values are supported:
    • h: Hours. 12-hour clock.
    • hh: Hours with, if applicable, a leading zero. 12-hour clock.
    • H: Hours. 24-hour clock.
    • HH: Hours with, if applicable, a leading zero. 24-hour clock.
    • m: Minutes.
    • mm: Minutes with, if applicable, a leading zero.
    • s: Seconds.
    • ss: Seconds with, if applicable, a leading zero.
    • l: Milliseconds.
    • t: Produces a single, lowercase character (“a” or “p”) for ante meridiem and post meridiem.
    • tt: Produces a two, lowercase characters (“am” or “pm”) for ante meridiem and post meridiem.
    • T: Produces a single, uppercase character (“A” or “P”) for ante meridiem and post meridiem.
    • TT: Produces a two, uppercase characters (“AM” or “PM”) for ante meridiem and post meridiem.

    In addition the following case-sensitive short-hand values are also acceptable:

    • short: Identical to “h:mm tt”.
    • medium: Identical to “h:mm:ss tt”.
    • long: Identical to “h:mm:ss.l tt”.
    • full: Identical to “long” (reserved).

    These short-hand values cannot be mixed with other mask values.

Return

String. The formatted date as described by the specified mask.

DateInstance.weekOfYear()

Returns the week of year on which the datetime falls, from 1 to 52.

Method Signature

DateInstance.weekOfYear()

Arguments

This method has no arguments:

Return

Integer. The week of the year.

Examples

Examples of DP_DateExtensions (examples will open in a new window):

Revision History

July 23, 2014

  • My initial GitHub release reintroduced the error I solved last February… so I solved it again. The add() method was broken using when using the “businessdays” datepart and is fixed now. In addition the “QuarterHours” and “HalfHours” dateparts for the same method were actually adding quarter minutes and half minutes. Thanks to @denndk on Twitter for pointing out that I did something stupid… twice.

June 8, 2013

  • Initial GITHUB release.

February 17, 2013

  • Thanks to Joe for his email letting me know that the add() method was broken using when using the “businessdays” datepart. In service to full disclosure this was because, upon close examination, there was no “businessdays” logic at all – it was using the exact same code as “days”. Yes, this was stupid. “businessdays” should now function correctly.

October 2, 2012

Added the ability to specify any day as the first day of the week via a new property, Date.FirstDayOfWeek. Thanks to Neil Cresswell (of cresswell.net) for the idea. Here are some specifics:

  • The property can be set to any ordinal day from 0 (Sunday, the default) to 6 (Saturday).
  • The round(), ceil(), floor() and diff() methods will all take this setting into account when used.

September 15, 2012

  • Fixed (another) significant bug in Date.parseFormat which arose when dealing with am/pm indicator parsing and could result in noon and midnight getting reversed.

August 11, 2012

  • Added the Date.DP_DateExtensions static property to make determining if DP_DateExtensions has been loaded simpler.

June 21, 2012

  • Fixed a significant bug in Date.parseFormat which arose when dealing with am/pm indicator parsing and could result in returned dates being incorrect. Thanks to Kevin Warnke for pointing this out.

March 24, 2012

  • Corrected many documentation issues with the method signatures (thanks Brian Hendel for pointing this out).

March 22, 2012

There are some major changes in this version which may invalidate existing code. Please read the change log carefully.

Thanks to Alexey Vassiliev for pointing out a relatively minor DST bug that snowballed into this major revision.

A large-scale near-complete rewrite of all the date-math code has been introduced. Available date parts have been normalized across all functions as: milliseconds, seconds, minutes, quarterhours, warhols, halfhours, hours, days, weeks, businessdays, months and years.

  • Added the round(), ceil() and floor() methods.
  • Rewrote the add() method.
    • Default JavaScript addition is now used (which will change leap-year processing from the original).
    • The “wholeweeks” and “businessweeks” date parts have been eliminated.
    • Made the parameters “Amount” and “DatePart” optional with appropriate defaults.
  • Rewrote the diff() method.
    • Added the “method” parameter allowing for multiple styles of difference determination.
    • Added the “NormalizeDST” parameter. Default is to enable this functionality.
    • The “wholeweeks” and “businessweeks” date parts have been eliminated.
    • Made the “Date” and “Datepart” parameters optional with appropriate defaults.
  • Rewrote the compare() method.
    • Made the “CompareDate” and “DatePart” parameters optional with appropriate defaults.

Several changes have been added to provide support for Daylight Savings Time calculations:

  • Added the getUSDST() method.
  • Added the isDST() method.

February 07, 2012

  • In the finest tradition of coding my last fix created another problem (by eliminating the ability to add negative date parts). I’ve fixed this now. Thanks to Scott McCandless for finding the problem.

January 01, 2012

  • Fixed a pretty major “how-in-the-hell-did-I-miss-that?!” bug in the diff() and add() functions that could generate an endless loop. Basically the add() function was doing full processing even when the amount given was zero and this was creating a loop situation when the code tried to adjust for leap-years. The function now essentially ignores zero amounts (it will return the date unchanged). Thanks to Nathan Moinvaziri for pointing this out.

September 16, 2011

  • Added the CenturyMark parameter to the parseFormat() function allowing for fine-grain control over the disposition of parsed two-digit years.
  • Fixed a small bug in the parseFormat() function related to validation of the default parameter.

March 14, 2011

  • Rewrote documentation and reworked all examples.
  • Fixed a bug in the timeFormat() function related to am/pm display.

April 15, 2008

  • Fixed several regular expression bugs in the new parseFormat() function.
  • The new parseHttpTimeFormat() function was mistakenly made an instance function. It’s now a static function as intended.

April 15, 2008

  • Fixed several bugs related to the new Mask characters.
  • Fixed several regular expression bugs in the new parseFormat() function.
  • Added a parameter to the parseFormat() function allowing the developer to choose from several default values for missing date parts.
  • Added the parseHttpTimeFormat() function.

April 13, 2008

There are some major changes in this version which may invalidate existing code. Please read the change log carefully.

  • Added a new parseFormat() function which accepts a data/time mask and a string value. If the mask matches the input will be converted to a date and returned.
  • Changed the mask characters used in the dateFormat() function to make the characters used unique across the date and time functions (allowing them to be used in the new parseFormat() function). All of the dateFormat() characters are uppercase and MOST of the timeFormat() characters are lowercase. See the documentation for specifics.
  • The lowercase “t” and the space have been added as seperator characters to the parseIso8601() function. This does represent a break from the standard (the ISO 8601 standard only allows for a captital “T”) but has been requested by several users and does not affect processing of standard values.

June 25, 2007

  • iso8601Format() nows accepts, as alternative input, the numbers 1-6 which correspond to the (sometimes cumbersome) letter codes.
  • The iso8601Format() “Style” parameter is now optional and will default to “YMDHMSM” if not present.

May 13, 2007

  • Added the httpTimeFormat() method.
  • Added the isLeapYear() method.
  • Added the isWeekday() method.
  • Added the weekOfYear() method.

February 19, 2007

  • Fixed a bug in the dateFormat() and timeFormat() methods concerning masks with concatinated date parts.

October 19, 2006

  • Added the Date.is() method.

September 28, 2006

  • Fixed a bug in the “add()” method concerning businessdays… it didn’t work. It does now. Thanks to Jonathan Hicks for pointing out my stupidity.

September 20, 2006

  • Added the ability to recogonize a space or a lowercase “t” as a date/time separator in the parseIso8601() method. In other words in addition to “2006-06-21T14:46:34-05:00” the method will now also recognize “2006-06-21 14:46:34-05:00” and “2006-06-21t14:46:34-05:00”.

July 12, 2006

  • Added the “quarterhours” (or, if you’d like to be cute, the “warhols”) and “halfhours” timespans to the add() and diff() methods.

July 10, 2006

  • Added the add(), diff(), compare() and dayOfYear() methods.
  • Fixed several small bugs.

June 21, 2006

  • Initial Release.

20 Comments

Comments are closed.