Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

documentation improvements. Formatting changes. Update min.js

  • Loading branch information...
commit 88e1e38d21c30ebcd79ac613f79a84ece3066893 1 parent a31d4bf
Ken Snyder authored

Showing 4 changed files with 434 additions and 415 deletions. Show diff stats Hide diff stats

  1. +5 6 Date.min.js
  2. +31 17 css/general.css
  3. +376 370 reference.html
  4. +22 22 src/Date.js
11 Date.min.js
... ... @@ -1,9 +1,8 @@
1 1 /**
2   - * Date instance methods
  2 + * JavaScript Date instance methods
3 3 *
4   - * @author Ken Snyder (kendsnyder at gmail dot com)
5   - * @date December 2011
6   - * @version 3.3 (http://sandbox.kendsnyder.com/date)
7   - * @license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0)
  4 + * @copyright 2012 Ken Snyder (kendsnyder at gmail dot com)
  5 + * @version 3.4, April 2012 (http://sandbox.kendsnyder.com/date)
  6 + * @license MIT http://www.opensource.org/licenses/MIT
8 7 */
9   -;(function(h){var j=24*60*60*1000;function zeroPad(a,b){a=a+'';var c=b-a.length;if(c<=0){return a}return Array(c+1).join('0')+a}function extend(d,s){for(var p in s){if(Object.prototype.hasOwnProperty.call(s,p)){d[p]=s[p]}}}var k={millisecond:1,second:1000,minute:60*1000,hour:60*60*1000,day:j,week:7*j,month:{add:function(d,a){var b=d.getDate();k.year.add(d,Math[a>0?'floor':'ceil'](a/12));var c=d.getMonth()+(a%12);if(c==12){c=0;d.setYear(d.getFullYear()+1)}else if(c==-1){c=11;d.setYear(d.getFullYear()-1)}d.setMonth(c);if(d.getDate()!=b){d.add(-1,'month');d.setDate(d.daysInMonth())}},diff:function(a,b){var c=a.getFullYear()-b.getFullYear();var d=a.getMonth()-b.getMonth()+(c*12);var e=a.getDate()-b.getDate();return d+(e/30)}},year:{add:function(d,a){d.setYear(d.getFullYear()+Math[a>0?'floor':'ceil'](a))},diff:function(a,b){return k.month.diff(a,b)/12}}};var m=k;m.milliseconds=m.millisecond;m.seconds=m.second;m.minutes=m.minute;m.hours=m.hour;m.weeks=m.week;m.days=m.day;m.months=m.month;m.years=m.year;var l={succ:function(a){return this.clone().add(1,a)},add:function(a,b){var c=k[b]||k.day;if(typeof c=='number'){this.setTime(this.getTime()+(c*a))}else{c.add(this,a)}return this},diff:function(a,b,c){var d;a=Date.create(a);if(a===null){return NaN}var e=k[b]||k.day;if(typeof e=='number'){d=(this.getTime()-a.getTime())/e}else{d=e.diff(this,a)}return(c?d:Math[d>0?'floor':'ceil'](d))},_applyFormat:function(a,b){var c=a||b.defaultFormat,result='',match;while(c.length>0){if((match=c.match(b.matcher))){result+=c.slice(0,match.index);result+=(match[1]||'')+this._applyFormatChar(match[2],b);c=c.slice(match.index+match[0].length)}else{result+=c,c=''}}return result},_applyFormatChar:function(a,b){if(b.shortcuts&&b.shortcuts[a]){return this._applyFormat(b.shortcuts[a],b)}else if(b.codes&&b.codes[a]){var c=b.codes[a].split('.');var d=this['get'+c[0]]?this['get'+c[0]]():'';if(c[1]){d=zeroPad(d,c[1])}return d}return a},format:function(a){a=a||Date.formatting.strftime.defaultFormat;if(a.indexOf('%')>-1){return this.strftime(a)}return this.formatPhp(a)},getShortYear:function(){return this.getYear()%100},getMonthNumber:function(){return this.getMonth()+1},getMonthName:function(){return Date.MONTHNAMES[this.getMonth()]},getAbbrMonthName:function(){return Date.ABBR_MONTHNAMES[this.getMonth()]},getDayName:function(){return Date.DAYNAMES[this.getDay()]},getAbbrDayName:function(){return Date.ABBR_DAYNAMES[this.getDay()]},getDayOrdinal:function(){return Date.ORDINALNAMES[this.getDate()%10]},getHours12:function(){var a=this.getHours();return a>12?a-12:(a==0?12:a)},getAmPm:function(){return this.getHours()>=12?'PM':'AM'},getAmPmLower:function(){return this.getHours()>=12?'pm':'am'},getUnix:function(){return Math.round(this.getTime()/1000,0)},getUTCOffset:function(){var a=this.getTimezoneOffset()/60;var b=a<0?'+':'-';a=Math.abs(a);return b+zeroPad(Math.floor(a),2)+':'+zeroPad((a%1)*60,2)},setUTCOffset:function(a){var b=this.getTimezoneOffset();var c=this.getTime()+(b*60000);this.setTime(c-(a*60000));return this},setUTCOffsetString:function(a){var b=a.match(/([+-]?)([01]\d|2[0-3])\:?([0-5]\d)/);if(b){var c=parseFloat(b[2])*60;c+=parseFloat(b[3]);if(b[1]=='-'){c*=-1}this.setUTCOffset(c)}return this},getUTCOffsetNumber:function(){return this.getUTCOffset().replace(':','')},getTimezoneName:function(){var a=/(?:\((.+)\)$| ([A-Z]{3}) )/.exec(this.toString());return a[1]||a[2]||'GMT'+this.getUTCOffset()},toYmdInt:function(){return(this.getFullYear()*10000)+(this.getMonthNumber()*100)+this.getDate()},clone:function(){return new Date(this.getTime())},diffText:function(a){var b=this.diff(a||Date.current(),'seconds');var c=Math.abs(b);var d;if(c<120){return b>=0?'in a moment':'moments ago'}else if(c<3600){d=floor(c/60)+" minutes"}else if(c<86400){var e=floor(c/3600);var s=hour==1?'':'s';d=e+" hour"+s+" ago"}else if(c<172800){return b>0?'tomorrow':'yesterday'}else if(c<604800){d=floor(c/86400)+" days"}else if(c<1209600){return b>0?'next week':'last week'}else if(c<2419200){d=floor(c/604800)+" weeks"}else if(c<5184000){return b>0?'next month':'last month'}else if(c<31536000){d=floor(c/2592000)+" months"}else if(c<63072000){return b>0?'next year':'last year'}else{d=floor(c/31536000)+" years"}return(b>0?'in '+d:d+' ago')},daysInMonth:function(){return Date.daysInMonth(this.getFullYear(),this.getMonth()+1)},isLeapYear:function(){return Date.daysInMonth(this.getFullYear(),1)==29?1:0}};extend(Date.prototype,l);if(!Date.prototype.toISOString){Date.prototype.toISOString=function(){return this.setUTCOffset(0).strftime(Date.ISO)}}var n={create:function(b){if(typeof b=='undefined'){return Date.current()}if(b instanceof Date){return b}var a=arguments;switch(a.length){case 1:if(Object.prototype.toString.call(b)=='[object Number]'){return new Date(b)}b=String(b).replace(/^\s*(.*)\s*$/,'$1');if(b===''){return Date.current()}var i=0,pattern,ms,obj,match,regex,fn;while((pattern=Date.create.patterns[i++])){if(typeof pattern[0]=='string'){regex=pattern[1];fn=pattern[2]}else{regex=pattern[0];fn=pattern[1]}if(!(match=b.match(regex))){continue}if(typeof fn=='function'){obj=fn(match,b);if(obj instanceof Date){return obj}}else{ms=Date.parse(b.replace(regex,fn));if(!isNaN(ms)){return new Date(ms)}}}return NaN;case 2:return new Date(a[0],a[1],1);case 3:return new Date(a[0],a[1],a[2]);case 4:return new Date(a[0],a[1],a[2],a[3]);case 5:return new Date(a[0],a[1],a[2],a[3],a[4]);case 6:return new Date(a[0],a[1],a[2],a[3],a[4],a[5]);default:return new Date(a[0],a[1],a[2],a[3],a[4],a[5],a[6])}},MONTHNAMES:'January February March April May June July August September October November December'.split(' '),ABBR_MONTHNAMES:'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '),DAYNAMES:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' '),ABBR_DAYNAMES:'Sun Mon Tue Wed Thu Fri Sat'.split(' '),ORDINALNAMES:'th st nd rd th th th th th th'.split(' '),ISO:'%Y-%m-%dT%H:%M:%S.%N%G',SQL:'%Y-%m-%d %H:%M:%S',SCRIPT_LOAD:new Date,daysInMonth:function(a,b){if(b==2){return new Date(a,1,29).getDate()==29?29:28}return[undefined,31,undefined,31,30,31,30,31,31,30,31,30,31][b]},autoFormat:function(b,c){b=(typeof b=='string'?document.getElementById(b):b);function correct(){var a=Date.create(b.value);if(a){b.value=a.format(c)}}if(typeof b.attachEvent=='function'){b.attachEvent('onblur',correct)}else if(typeof b.addEventListener=='function'){b.addEventListener('blur',correct,false)}else{b.onblur=correct}return b},addFormat:function(b,c){Date.prototype[b]=function(a){return this._applyFormat(a,c)};return this},addPattern:function(a,b){if(b){var i=0,pattern;while((pattern=Date.create.patterns[i++])){if(pattern[0]==b||pattern[1]==b){Date.create.patterns.splice(i,0,a);return this}}}Date.create.patterns.unshift(a);return this},removePattern:function(a){var i=0,pattern;while((pattern=Date.create.patterns[i++])){if(pattern[0]==a||pattern[1]==a){return Date.create.patterns.splice(i-1,1)[0]}}return false},current:function(){return new Date}};extend(Date,n);if(!('now'in Date)){Date.now=function(){return Date.current().setUTCOffset(0).getTime()}}Date.addFormat('strftime',{matcher:/()%(#?(%|[a-z]))/i,defaultFormat:'%Y-%m-%d %H:%M:%s',codes:{Y:'FullYear',y:'ShortYear.2',m:'MonthNumber.2','#m':'MonthNumber',B:'MonthName',b:'AbbrMonthName',d:'Date.2','#d':'Date',e:'Date',A:'DayName',a:'AbbrDayName',w:'Day',o:'DayOrdinal',H:'Hours.2','#H':'Hours',I:'Hours12.2','#I':'Hours12',P:'AmPmLower',p:'AmPm',M:'Minutes.2','#M':'Minutes',S:'Seconds.2','#S':'Seconds',s:'Unix',N:'Milliseconds.3','#N':'Milliseconds',O:'TimezoneOffset',Z:'TimezoneName',G:'UTCOffset'},shortcuts:{F:'%Y-%m-%d',T:'%H:%M:%S',X:'%H:%M:%S',x:'%m/%d/%y',D:'%m/%d/%y','#c':'%a %b %e %H:%M:%S %Y',v:'%e-%b-%Y',R:'%H:%M',r:'%I:%M:%S %p',t:'\t',n:'\n','%':'%'}});Date.addFormat('formatPhp',{matcher:/(\\)?([a-z])/i,defaultFormat:'Y-m-d H:i:s',codes:{Y:'FullYear',y:'ShortYear.2',L:'isLeapYear',m:'MonthNumber.2',n:'MonthNumber',F:'MonthName',M:'AbbrMonthName',t:'daysInMonth',d:'Date.2',j:'Date',l:'DayName',D:'AbbrDayName',w:'Day',S:'DayOrdinal',H:'Hours.2',G:'Hours',h:'Hours12.2',g:'Hours12',a:'AmPmLower',A:'AmPm',i:'Minutes.2',s:'Seconds.2',U:'Unix',Z:'TimezoneOffset',e:'TimezoneName',P:'UTCOffset',O:'UTCOffsetNumber'},shortcuts:{c:'Y-m-d\\TH:i:sP',r:'D, j M Y H:i:s O'}});var o={matcher:/()(mi|am|pm|ss|yyyy|yy|m{1,4}|d{1,4}|w|hh?24|hh?12)/i,defaultFormat:'yyyy-mm-dd hh24:mi:ss',codes:{yyyy:'FullYear',yy:'ShortYear.2',mm:'MonthNumber.2',m:'MonthNumber',mmm:'AbbrMonthName',mmmm:'MonthName',dd:'Date.2',d:'Date',ddd:'AbbrDayName',dddd:'DayName',w:'Day',hh24:'Hours.2',h24:'Hours',hh:'Hours12.2',hh12:'Hours12.2',h12:'Hours12',am:'AmPm',pm:'AmPm',mi:'Minutes.2',ss:'Seconds.2'},shortcuts:{}};var q='yyyy yy mm m mmm mmmm dd d ddd dddd w hh24 h24 hh12 h12 am pm mi ss'.split(' '),i=0,key;while((key=q[i++])){o.codes[key.toUpperCase()]=o.codes[key]}Date.addFormat('formatSql',o);Date.create.patterns=[['iso_8601',/^([1-9]\d{3})\s*-\s*(1[0-2]|0?[1-9])\s*-\s*(3[01]|[12]\d|0?[1-9])$/,'$2/$3/$1'],['us',/^(1[0-2]|0?[1-9])\s*[\/-]\s*(3[01]|[12]\d|0?[1-9])\s*[\/-]\s*([1-9]\d{3})$/,'$1/$2/$3'],['world',/^(3[01]|[12]\d|0?[1-9])\s*([\.\/])s*(1[0-2]|0?[1-9])\s*\2\s*([1-9]\d{3})$/,'$3/$1/$4'],['chicago',/^(?:(?:mon|tue|wed|thu|fri|sat|sun),\s+)?(3[01]|[0-2]\d|\d)\s*([ -])\s*(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*)\s*\2\s*([1-9]\d{3})$/i,'$3 $1, $4'],['conversational',/^(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*)\s+(3[01]|[0-2]\d|\d),?\s*([1-9]\d{3})$/i,'$1 $2, $3'],['unix',/^@(-?\d+)$/,function(a){return Date.create(a[1]*1000)}],['24_hour',/^(?:(.+?)(?:\s+|T))?([01]\d|2[0-3])(?:\s*\:\s*([0-5]\d))(?:\s*\:\s*([0-5]\d))?\s*(?:\.(\d+))?(\s*[+-](?:[01]\d|2[0-3])\:?[0-5]\d)?$/i,function(a){var d;if(a[1]){d=Date.create(a[1]);if(isNaN(d)){return false}}else{d=Date.current();d.setMilliseconds(0)}d.setHours(parseFloat(a[2]),parseFloat(a[3]),parseFloat(a[4]||0));if(a[5]){d.setMilliseconds(a[5])}if(a[6]){d.setUTCOffsetString(a[6])}return d}],['12_hour',/^(?:(.+)\s+)?(0?[1-9]|1[012])(?:\s*\:\s*([0-5]\d))?(?:\s*\:\s*([0-5]\d))?\s*(am|pm)\s*$/i,function(a){var d;if(a[1]){d=Date.create(a[1]);if(isNaN(d)){return false}}else{d=Date.current();d.setMilliseconds(0)}var b=parseFloat(a[2]);b=a[5].toLowerCase()=='am'?(b==12?0:b):(b==12?12:b+12);d.setHours(b,parseFloat(a[3]||0),parseFloat(a[4]||0));return d}],['weeks_months_before_after',/^(\d+)\s+(year|month|week|day|hour|minute|second)s?\s+(before|from|after)\s+(.+)$/i,function(a){var b=Date.create(a[4]);if(b instanceof Date){return b.add((a[3].toLowerCase()=='before'?-1:1)*a[1],a[2])}return false}],['time_ago',/^(\d+)\s+(year|month|week|day|hour|minute|second)s?\s+ago$/i,function(a){return Date.current().add(-1*a[1],a[2])}],['in_time',/^in\s+(\d+)\s+(year|month|week|day|hour|minute|second)s?$/i,function(a){return Date.current().add(a[1],a[2])}],['today_tomorrow',/^(tod|now|tom|yes)/i,function(a){var b=Date.current();switch(a[1].toLowerCase()){case'tod':case'now':return b;case'tom':return b.add(1,'day');case'yes':return b.add(-1,'day')}}],['this_next_last',/^(this|next|last)\s+(?:(year|month|week|day|hour|minute|second)|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)|(sun|mon|tue|wed|thu|fri|sat))/i,function(a){var b=a[1].toLowerCase()=='last'?-1:1;var c=Date.current();var d=Date.ABBR_MONTHNAMES;var i;if(a[2]){return c.add(b,a[2])}else if(a[3]){var e=a[3].toLowerCase(),diff;for(i=0;i<d.length;i++){if(e==d[i].toLowerCase()){diff=12-(c.getMonth()-i);diff=diff>12?diff-12:diff;return c.add(b*diff,'month')}}}else if(a[4]){var f=a[4].toLowerCase();var g=Date.ABBR_DAYNAMES;for(i=0;i<g.length;i++){if(f==g[i].toLowerCase()){diff=c.getDay()-i+7;return c.add(b*(diff==0?7:diff),'day')}}}return false}],['conversational_sans_year',/^(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+)(?:the\s+)?(\d+)(?:st|nd|rd|th)?$/i,function(a){var d=Date.current();if(a[1]){var i=Date.ABBR_MONTHNAMES.length;while(i--){if(Date.ABBR_MONTHNAMES[i].toLowerCase()==a[1].toLowerCase()){d.setMonth(i);break}}}d.setDate(a[2]);return d}]];h.$D=h.$D||Date.create})(this);
  8 +;(function(){var h=24*60*60*1000;function e(m,n){m=m+"";var i=n-m.length;if(i<=0){return m}return Array(i+1).join("0")+m}function f(n,i){for(var m in i){if(Object.prototype.hasOwnProperty.call(i,m)){n[m]=i[m]}}}var b={millisecond:1,second:1000,minute:60*1000,hour:60*60*1000,day:h,week:7*h,month:{add:function(o,m){var i=o.getDate();b.year.add(o,Math[m>0?"floor":"ceil"](m/12));var n=o.getMonth()+(m%12);if(n==12){n=0;o.setYear(o.getFullYear()+1)}else{if(n==-1){n=11;o.setYear(o.getFullYear()-1)}}o.setMonth(n);if(o.getDate()!=i){o.add(-1,"month");o.setDate(o.daysInMonth())}},diff:function(p,n){var i=p.getFullYear()-n.getFullYear();var m=p.getMonth()-n.getMonth()+(i*12);var o=p.getDate()-n.getDate();return m+(o/30)}},year:{add:function(m,i){m.setYear(m.getFullYear()+Math[i>0?"floor":"ceil"](i))},diff:function(m,i){return b.month.diff(m,i)/12}}};var a=b;a.milliseconds=a.millisecond;a.seconds=a.second;a.minutes=a.minute;a.hours=a.hour;a.weeks=a.week;a.days=a.day;a.months=a.month;a.years=a.year;var g={succ:function(i){return this.clone().add(1,i)},add:function(n,m){var i=b[m]||b.day;if(typeof i=="number"){this.setTime(this.getTime()+(i*n))}else{i.add(this,n)}return this},diff:function(m,p,i){var o;m=Date.create(m);if(m===null){return NaN}var n=b[p]||b.day;if(typeof n=="number"){o=(this.getTime()-m.getTime())/n}else{o=n.diff(this,m)}return(i?o:Math[o>0?"floor":"ceil"](o))},_applyFormat:function(m,n){var p=m||n.defaultFormat,i="",o;while(p.length>0){if((o=p.match(n.matcher))){i+=p.slice(0,o.index);i+=(o[1]||"")+this._applyFormatChar(o[2],n);p=p.slice(o.index+o[0].length)}else{i+=p,p=""}}return i},_applyFormatChar:function(o,m){if(m.shortcuts&&m.shortcuts[o]){return this._applyFormat(m.shortcuts[o],m)}else{if(m.codes&&m.codes[o]){var i=m.codes[o].split(".");var n=this["get"+i[0]]?this["get"+i[0]]():"";if(i[1]){n=e(n,i[1])}return n}}return o},format:function(i){i=i||Date.formatting.strftime.defaultFormat;if(i.indexOf("%")>-1){return this.strftime(i)}return this.formatPhp(i)},getShortYear:function(){return this.getYear()%100},getMonthNumber:function(){return this.getMonth()+1},getMonthName:function(){return Date.MONTHNAMES[this.getMonth()]},getAbbrMonthName:function(){return Date.ABBR_MONTHNAMES[this.getMonth()]},getDayName:function(){return Date.DAYNAMES[this.getDay()]},getAbbrDayName:function(){return Date.ABBR_DAYNAMES[this.getDay()]},getDayOrdinal:function(){return Date.ORDINALNAMES[this.getDate()%10]},getHours12:function(){var i=this.getHours();return i>12?i-12:(i==0?12:i)},getAmPm:function(){return this.getHours()>=12?"PM":"AM"},getAmPmLower:function(){return this.getHours()>=12?"pm":"am"},getUnix:function(){return Math.round(this.getTime()/1000,0)},getUTCOffset:function(){var i=this.getTimezoneOffset()/60;var m=i<0?"+":"-";i=Math.abs(i);return m+e(Math.floor(i),2)+":"+e((i%1)*60,2)},setUTCOffset:function(n){var m=this.getTimezoneOffset()*-1;var i=this.getTime()+(m*60000);this.setTime(i-(n*60000));return this},setUTCOffsetString:function(n){var i=n.match(/([+-]?)([01]\d|2[0-3])\:?([0-5]\d)/);if(i){var m=parseFloat(i[2])*60;m+=parseFloat(i[3]);if(i[1]=="-"){m*=-1}this.setUTCOffset(m)}return this},getUTCOffsetNumber:function(){return this.getUTCOffset().replace(":","")},getTimezoneName:function(){var i=/(?:\((.+)\)$| ([A-Z]{3}) )/.exec(this.toString());return i[1]||i[2]||"GMT"+this.getUTCOffset()},toYmdInt:function(){return(this.getFullYear()*10000)+(this.getMonthNumber()*100)+this.getDate()},clone:function(){return new Date(this.getTime())},diffText:function(o){var q=this.diff(o||Date.current(),"seconds");var p=Math.abs(q);var m;if(p<120){return q>=0?"in a moment":"moments ago"}else{if(p<3600){m=floor(p/60)+" minutes"}else{if(p<86400){var i=floor(p/3600);var n=hour==1?"":"s";m=i+" hour"+n+" ago"}else{if(p<172800){return q>0?"tomorrow":"yesterday"}else{if(p<604800){m=floor(p/86400)+" days"}else{if(p<1209600){return q>0?"next week":"last week"}else{if(p<2419200){m=floor(p/604800)+" weeks"}else{if(p<5184000){return q>0?"next month":"last month"}else{if(p<31536000){m=floor(p/2592000)+" months"}else{if(p<63072000){return q>0?"next year":"last year"}else{m=floor(p/31536000)+" years"}}}}}}}}}}return(q>0?"in "+m:m+" ago")},daysInMonth:function(){return Date.daysInMonth(this.getFullYear(),this.getMonth()+1)},isLeapYear:function(){return Date.daysInMonth(this.getFullYear(),1)==29?1:0}};f(Date.prototype,g);if(!Date.prototype.toISOString){Date.prototype.toISOString=function(){return this.setUTCOffset(0).strftime(Date.ISO)}}var c={create:function(n){if(typeof n=="undefined"){return Date.current()}if(n instanceof Date){return n}var u=arguments;switch(u.length){case 1:if(Object.prototype.toString.call(n)=="[object Number]"){return new Date(n)}n=String(n).replace(/^\s*(.*)\s*$/,"$1");if(n===""){return Date.current()}var p=0,r,m,o,q,t,s;while((r=Date.create.patterns[p++])){if(typeof r[0]=="string"){t=r[1];s=r[2]}else{t=r[0];s=r[1]}if(!(q=n.match(t))){continue}if(typeof s=="function"){o=s(q,n);if(o instanceof Date){return o}}else{m=Date.parse(n.replace(t,s));if(!isNaN(m)){return new Date(m)}}}return NaN;case 2:return new Date(u[0],u[1],1);case 3:return new Date(u[0],u[1],u[2]);case 4:return new Date(u[0],u[1],u[2],u[3]);case 5:return new Date(u[0],u[1],u[2],u[3],u[4]);case 6:return new Date(u[0],u[1],u[2],u[3],u[4],u[5]);default:return new Date(u[0],u[1],u[2],u[3],u[4],u[5],u[6])}},MONTHNAMES:"January February March April May June July August September October November December".split(" "),ABBR_MONTHNAMES:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),DAYNAMES:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ABBR_DAYNAMES:"Sun Mon Tue Wed Thu Fri Sat".split(" "),ORDINALNAMES:"th st nd rd th th th th th th".split(" "),ISO:"%Y-%m-%dT%H:%M:%S.%N%G",SQL:"%Y-%m-%d %H:%M:%S",SCRIPT_LOAD:new Date,daysInMonth:function(i,m){if(m==2){return new Date(i,1,29).getDate()==29?29:28}return[undefined,31,undefined,31,30,31,30,31,31,30,31,30,31][m]},autoFormat:function(m,i){m=(typeof m=="string"?document.getElementById(m):m);function n(){var o=Date.create(m.value);if(o){m.value=o.format(i)}}if(typeof m.attachEvent=="function"){m.attachEvent("onblur",n)}else{if(typeof m.addEventListener=="function"){m.addEventListener("blur",n,false)}else{m.onblur=n}}return m},addFormat:function(i,m){Date.prototype[i]=function(n){return this._applyFormat(n,m)};return this},addPattern:function(m,o){if(o){var n=0,p;while((p=Date.create.patterns[n++])){if(p[0]==o||p[1]==o){Date.create.patterns.splice(n,0,m);return this}}}Date.create.patterns.unshift(m);return this},removePattern:function(m){var n=0,o;while((o=Date.create.patterns[n++])){if(o[0]==m||o[1]==m){return Date.create.patterns.splice(n-1,1)[0]}}return false},current:function(){return new Date}};f(Date,c);if(!("now" in Date)){Date.now=function(){return Date.current().setUTCOffset(0).getTime()}}Date.addFormat("strftime",{matcher:/()%(#?(%|[a-z]))/i,defaultFormat:"%Y-%m-%d %H:%M:%s",codes:{Y:"FullYear",y:"ShortYear.2",m:"MonthNumber.2","#m":"MonthNumber",B:"MonthName",b:"AbbrMonthName",d:"Date.2","#d":"Date",e:"Date",A:"DayName",a:"AbbrDayName",w:"Day",o:"DayOrdinal",H:"Hours.2","#H":"Hours",I:"Hours12.2","#I":"Hours12",P:"AmPmLower",p:"AmPm",M:"Minutes.2","#M":"Minutes",S:"Seconds.2","#S":"Seconds",s:"Unix",N:"Milliseconds.3","#N":"Milliseconds",O:"TimezoneOffset",Z:"TimezoneName",G:"UTCOffset"},shortcuts:{F:"%Y-%m-%d",T:"%H:%M:%S",X:"%H:%M:%S",x:"%m/%d/%y",D:"%m/%d/%y","#c":"%a %b %e %H:%M:%S %Y",v:"%e-%b-%Y",R:"%H:%M",r:"%I:%M:%S %p",t:"\t",n:"\n","%":"%"}});Date.addFormat("formatPhp",{matcher:/(\\)?([a-z])/i,defaultFormat:"Y-m-d H:i:s",codes:{Y:"FullYear",y:"ShortYear.2",L:"isLeapYear",m:"MonthNumber.2",n:"MonthNumber",F:"MonthName",M:"AbbrMonthName",t:"daysInMonth",d:"Date.2",j:"Date",l:"DayName",D:"AbbrDayName",w:"Day",S:"DayOrdinal",H:"Hours.2",G:"Hours",h:"Hours12.2",g:"Hours12",a:"AmPmLower",A:"AmPm",i:"Minutes.2",s:"Seconds.2",U:"Unix",Z:"TimezoneOffset",e:"TimezoneName",P:"UTCOffset",O:"UTCOffsetNumber"},shortcuts:{c:"Y-m-d\\TH:i:sP",r:"D, j M Y H:i:s O"}});var j={matcher:/()(mi|am|pm|ss|yyyy|yy|m{1,4}|d{1,4}|w|hh?24|hh?12)/i,defaultFormat:"yyyy-mm-dd hh24:mi:ss",codes:{yyyy:"FullYear",yy:"ShortYear.2",mm:"MonthNumber.2",m:"MonthNumber",mmm:"AbbrMonthName",mmmm:"MonthName",dd:"Date.2",d:"Date",ddd:"AbbrDayName",dddd:"DayName",w:"Day",hh24:"Hours.2",h24:"Hours",hh:"Hours12.2",hh12:"Hours12.2",h12:"Hours12",am:"AmPm",pm:"AmPm",mi:"Minutes.2",ss:"Seconds.2"},shortcuts:{}};var l="yyyy yy mm m mmm mmmm dd d ddd dddd w hh24 h24 hh12 h12 am pm mi ss".split(" "),d=0,k;while((k=l[d++])){j.codes[k.toUpperCase()]=j.codes[k]}Date.addFormat("formatSql",j);Date.create.patterns=[["iso_8601",/^([1-9]\d{3})\s*-\s*(1[0-2]|0?[1-9])\s*-\s*(3[01]|[12]\d|0?[1-9])$/,"$2/$3/$1"],["us",/^(1[0-2]|0?[1-9])\s*[\/-]\s*(3[01]|[12]\d|0?[1-9])\s*[\/-]\s*([1-9]\d{3})$/,"$1/$2/$3"],["world",/^(3[01]|[12]\d|0?[1-9])\s*([\.\/])s*(1[0-2]|0?[1-9])\s*\2\s*([1-9]\d{3})$/,"$3/$1/$4"],["chicago",/^(?:(?:mon|tue|wed|thu|fri|sat|sun)[a-z]*,?\s+)?(3[01]|[0-2]\d|\d)\s*([ -])\s*(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*)\s*\2\s*([1-9]\d{3})$/i,"$3 $1, $4"],["conversational",/^(?:(?:mon|tue|wed|thu|fri|sat|sun)[a-z]*,?\s+)?(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*)\s+(3[01]|[0-2]\d|\d),?\s*([1-9]\d{3})$/i,"$1 $2, $3"],["unix",/^@(-?\d+)$/,function(i){return Date.create(i[1]*1000)}],["24_hour",/^(?:(.+?)(?:\s+|T))?([01]\d|2[0-3])(?:\s*\:\s*([0-5]\d))(?:\s*\:\s*([0-5]\d))?\s*(?:\.(\d+))?(\s*(?:GMT)?[+-](?:[01]\d|2[0-3])\:?[0-5]\d)?(?: \(.+?\))?$/i,function(i){var m;if(i[1]){m=Date.create(i[1]);if(isNaN(m)){return false}}else{m=Date.current();m.setMilliseconds(0)}m.setHours(parseFloat(i[2]),parseFloat(i[3]),parseFloat(i[4]||0));if(i[5]){m.setMilliseconds(i[5])}if(i[6]){m.setUTCOffsetString(i[6])}return m}],["12_hour",/^(?:(.+)\s+)?(0?[1-9]|1[012])(?:\s*\:\s*([0-5]\d))?(?:\s*\:\s*([0-5]\d))?\s*(am|pm)\s*$/i,function(m){var n;if(m[1]){n=Date.create(m[1]);if(isNaN(n)){return false}}else{n=Date.current();n.setMilliseconds(0)}var i=parseFloat(m[2]);i=m[5].toLowerCase()=="am"?(i==12?0:i):(i==12?12:i+12);n.setHours(i,parseFloat(m[3]||0),parseFloat(m[4]||0));return n}],["weeks_months_before_after",/^(\d+)\s+(year|month|week|day|hour|minute|second|millisecond)s?\s+(before|from|after)\s+(.+)$/i,function(i){var m=Date.create(i[4]);if(m instanceof Date){return m.add((i[3].toLowerCase()=="before"?-1:1)*i[1],i[2])}return false}],["time_ago",/^(\d+)\s+(year|month|week|day|hour|minute|second|millisecond)s?\s+ago$/i,function(i){return Date.current().add(-1*i[1],i[2])}],["in_time",/^in\s+(\d+)\s+(year|month|week|day|hour|minute|second|millisecond)s?$/i,function(i){return Date.current().add(i[1],i[2])}],["plus_minus",/^([+-])\s*(\d+)\s+(year|month|week|day|hour|minute|second|millisecond)s?$/i,function(i){var m=i[1]=="-"?-1:1;return Date.current().add(m*i[2],i[3])}],["asp_json",/^\/Date\((\d+)([+-]\d{4})?\)\/$/i,function(i){var m=new Date;m.setTime(i[1]);if(i[2]){m.setUTCOffsetString(i[2])}return m}],["today_tomorrow",/^(tod|now|tom|yes)/i,function(m){var i=Date.current();switch(m[1].toLowerCase()){case"tod":case"now":return i;case"tom":return i.add(1,"day");case"yes":return i.add(-1,"day")}}],["this_next_last",/^(this|next|last)\s+(?:(year|month|week|day|hour|minute|second|millisecond)|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)|(sun|mon|tue|wed|thu|fri|sat))/i,function(p){var u=p[1].toLowerCase()=="last"?-1:1;var m=Date.current();var n=Date.ABBR_MONTHNAMES;var o;if(p[2]){return m.add(u,p[2])}else{if(p[3]){var r=p[3].toLowerCase(),s;for(o=0;o<n.length;o++){if(r==n[o].toLowerCase()){s=12-(m.getMonth()-o);s=s>12?s-12:s;return m.add(u*s,"month")}}}else{if(p[4]){var q=p[4].toLowerCase();var t=Date.ABBR_DAYNAMES;for(o=0;o<t.length;o++){if(q==t[o].toLowerCase()){s=m.getDay()-o+7;return m.add(u*(s==0?7:s),"day")}}}}}return false}],["conversational_sans_year",/^(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+)(?:the\s+)?(\d+)(?:st|nd|rd|th)?$/i,function(m){var o=Date.current();if(m[1]){var n=Date.ABBR_MONTHNAMES.length;while(n--){if(Date.ABBR_MONTHNAMES[n].toLowerCase()==m[1].toLowerCase()){o.setMonth(n);break}}}o.setDate(m[2]);return o}]];if(typeof module!="undefined"&&module.exports){module.exports=Date.create}else{if(typeof window!="undefined"){window.$D=Date.create}}})();
48 css/general.css
... ... @@ -1,23 +1,37 @@
1   -body, input, select { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
  1 +body { margin: 0; padding: 0; font: 14px/135% Arial, Helvetica, sans-serif; color: #000; }
  2 +input { font: 17px/135% Calibri, Arial, Helvetica, sans-serif; padding: 3px 8px; margin: 0; box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3) inset; }
  3 +.demo { font: 17px/135% Calibri, Arial, Helvetica, sans-serif; }
  4 +.content { padding: 0 35px 35px 35px; }
  5 +.archive { font-style: italic; color: #444; }
  6 +select { font: 16px/135% Calibri, Arial, Helvetica, sans-serif; margin: 0; }
2 7 #testcss1 { font-size:11px; color: #f00; }
3 8 #testcss2 { font-size:12px; color: #0f0; display: none; }
4 9 #testlog { height: 300px; overflow: auto; font-size: 11px; }
5 10 .result { color: #880000; }
6 11 input { padding: 0 2px; border: 1px solid #ccc; }
7 12 select { padding: 0; border: 1px solid #ccc; }
8   -input:hover, select:hover { border: 1px dotted red; }
9   -h2, h3 { padding: 1em 0 0.25em 0; color: #000088; border-bottom: 1px solid #3333cc; }
10   -a { color: #000000; text-decoration: underline; }
11   -a:visited { color: #444444; }
12   -a:hover { color: #000088; }
13   -table { background-color: #999999; }
14   -th { text-align: left; background-color: #000088; color: #ffffff; padding: 2px 6px; }
15   -th.section { text-align: center; background-color: #0000ff; }
16   -th a, th a:visited, th a:hover { color: #ffffff; }
17   -td { background-color: #ffffff; padding: 2px 6px; }
18   -td.minihead { text-align: center; font-style: italic; }
19   -.back { float: right; font-size: 11px; padding-top: 8px; }
20   -.back a { text-decoration: none; color: #0000cc; }
21   -.back a:visited { color: #0000cc; }
22   -.back a:hover { background-color: #0000cc; color: #ffffff; }
23   -pre { background-color: #f3f3f3; padding: 2px 6px; margin: 4px 0 0 0; border: 1px dotted #999; font-family: Consolas, "Courier New", monospace; font-size: 11px; }
  13 +input:hover,
  14 +input:focus,
  15 +select:hover,
  16 +select:focus { border: 1px dotted red; }
  17 +h1 { font: 24px/125% Exo, "Times New Roman", Times, serif; font-weight: 600; text-shadow: -1px -1px 1px rgba(0,0,0,0.8); margin: 0; padding: 1em 2em; background-color: #005AFF; color: #fff; }
  18 +h2,
  19 +h3 { font: 18px/125% "News Cycle", Tahoma, sans-serif; padding: 1em 0 0.25em 0; color: #0053EB; border-bottom: 1px solid #A5C5FF; }
  20 +a { color: #0053EB; text-decoration: underline; }
  21 +a:visited { color: #4876CB; }
  22 +a:hover { color: #000; }
  23 +table { border-collapse: collapse; }
  24 +th { border: 1px solid #0053EB; text-align: left; background-color: #ccc; padding: 2px 6px; }
  25 +th.section { text-align: center; background-color: #005AFF; color: #fff; }
  26 +th a,
  27 +th a:visited,
  28 +th a:hover { color: #ffffff; }
  29 +td { border: 1px solid #0053EB; padding: 2px 6px; }
  30 +tr:nth-child(2n) td { background-color: #f1f1f1; }
  31 +td.minihead { text-align: center; font-style: italic; background-color: #005AFF !important; color: #fff; font-weight: bold; }
  32 +.back a { float: right; font-size: 14px; padding-top: 28px; text-decoration: none !important; }
  33 +.back a:visited { color: #0053EB; }
  34 +pre { background-color: #f3f3f3; padding: 10px 15px; margin: 4px 0 0 0; border: 1px dotted #999; font: 12px/135% Monaco, "Bitstream Vera Sans Mono", Consolas, "Courier New", monospace; }
  35 +code,
  36 +.signature { background-color: #f3f3f3; font: 12px/135% Monaco, "Bitstream Vera Sans Mono", Consolas, "Courier New", monospace; }
  37 +.signature { background-color: transparent; }
746 reference.html
@@ -4,389 +4,395 @@
4 4 <title>JavaScript Date Instance Methods</title>
5 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 6 <script src="src/Date.js" type="text/javascript"></script>
  7 + <link href="http://fonts.googleapis.com/css?family=News+Cycle|Exo" rel="stylesheet" type="text/css">
7 8 <link rel="stylesheet" href="css/general.css" type="text/css" />
8 9 </head>
9 10 <body>
10 11 <h1>JavaScript Date Instance Methods (v3.4 April 2012)</h1>
11 12
12   -<p><em>Looking for <a href="http://sandbox.kendsnyder.com/date2">version 2?</a></em></p>
13   -
14   -<h2 id="contents">Contents</h2>
15   -<ol>
16   - <li><a href="#intro">Introduction</a></li>
17   - <li><a href="#demonstration">Demo</a></li>
18   - <li><a href="https://github.com/kensnyder/date-prototype">Github Repository</a></li>
19   - <li><a href="#src">Download</a></li>
20   - <li><a href="#examples">Examples</a></li>
21   - <li><a href="#ref">Method Reference</a></li>
22   - <li><a href="#parse">Parsable Formats</a></li>
23   - <li><a href="#codes">Format Codes</a></li>
24   - <li><a href="#custom">Customization and I18n</a></li>
25   - <li><a href="unit-tests.html">Unit Tests</a></li>
26   -</ol>
27   -
28   -<p class="back"><a href="#contents">contents ^</a></p>
29   -<h3 id="intro">Introduction</h3>
30   -
31   -<p>This script provides JavaScript Date instance methods for parsing, formatting, and calculating dates.
32   - It leverages the existing functionality of the native Date.parse method
33   - and uses a concise and configurable algorithm for interpreting format codes.</p>
34   -
35   -<p>Contributions are welcome through my <a href="https://github.com/kensnyder/date-prototype">Github Repository</a></p>
36   -
37   -<p><strong>Features include:</strong></p>
38   -<ol>
39   - <li>Parse various formats with ability to register custom format parsing.</li>
40   - <li>Format dates using the well-known percent-letter formatting options with the ability to register custom formating.</li>
41   - <li>Add and subtract years, months, days, hours, minutes or seconds.</li>
42   - <li>Calculate differences between dates in the given unit.</li>
43   - <li>Methods are available on all Date Objects.</li>
44   -</ol>
45   -
46   -<p class="back"><a href="#contents">contents ^</a></p>
47   -<h3 id="demonstration">Demo</h3>
48   -
49   -<div>
50   - <form name="demo" action="">
51   - <p>
52   - $D(&quot;<input type="text" name="fdate" value="2008-03-18 15:33:21" size="20" onblur="formatDate();" />&quot;).strftime(&quot;<input type="text" name="fformat" value="%#m-%d-%Y" size="17" onblur="formatDate();" />&quot;)
53   - = <span class="result" id="fresult"></span>
54   - </p>
55   - <p>
56   - $D(&quot;<input type="text" name="adate" value="2008-03-18 3:33:21PM" size="20" onblur="addDate();" />&quot;).add(<input type="text" name="aadd" value="-5" size="4" onblur="addDate();" />, &quot;<select name="aunit" onchange="addDate();">
57   - <option value="seconds">seconds</option>
58   - <option value="minutes">minutes</option>
59   - <option value="hours">hours</option>
60   - <option value="days" selected="selected">days</option>
61   - <option value="weeks">weeks</option>
62   - <option value="months">months</option>
63   - <option value="years">years</option>
64   - </select>&quot;).strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)
65   - = <span class="result" id="aresult"></span>
66   - </p>
67   - <p>
68   - $D(&quot;<input type="text" name="ddate1" value="2008-03-18 8pm" size="20" onblur="diffDate();" />&quot;).diff(&quot;<input type="text" name="ddate2" value="2008-03-17 2pm" size="20" onblur="diffDate();" />&quot;, &quot;<select name="dunit" onchange="diffDate();">
69   - <option value="seconds">seconds</option>
70   - <option value="minutes">minutes</option>
71   - <option value="hours">hours</option>
72   - <option value="days" selected="selected">days</option>
73   - <option value="weeks">weeks</option>
74   - <option value="months">months</option>
75   - <option value="years">years</option>
76   - </select>&quot;, <select name="dround" onchange="diffDate()"><option value="0" selected="selected">false</option><option value="1">true</option></select>)
77   - = <span class="result" id="dresult"></span>
78   - </p>
79   - </form>
80   -</div>
81   -
82   -
83   -<script>
84   -var demo = document.forms.demo;
85   -function formatDate() {
86   - var date = $D(demo.fdate.value);
87   - document.getElementById('fresult').innerHTML = date instanceof Date ? date.strftime(demo.fformat.value) : '(unrecognized)';
88   -}
89   -function addDate() {
90   - var date = $D(demo.adate.value);
91   - var amount = demo.aadd.value;
92   - var unit = demo.aunit.options[demo.aunit.selectedIndex].value;
93   - document.getElementById('aresult').innerHTML = date instanceof Date ? date.add(amount, unit).strftime('%Y-%m-%d %H:%M:%S') : '(unrecognized)';
94   -}
95   -function diffDate() {
96   - var date1 = $D(demo.ddate1.value);
97   - var date2 = $D(demo.ddate2.value);
98   - var unit = demo.dunit.options[demo.dunit.selectedIndex].value;
99   - var round = Number(demo.dround.options[demo.dround.selectedIndex].value);
100   - document.getElementById('dresult').innerHTML = date1 instanceof Date && date2 instanceof Date ? date1.diff(date2, unit, round) : '(unrecognized)';
101   -}
102   -formatDate();
103   -addDate();
104   -diffDate();
105   -</script>
106   -
107   -
108   -
109   -<p class="back"><a href="#contents">contents ^</a></p>
110   -<h3 id="src">Download</h3>
111   -
112   -<ul>
113   - <li><a href="src/Date.js" target="blank">Date.js (source)</a></li>
114   - <li><a href="Date.min.js" target="blank">Date.min.js (minified)</a></li>
115   -</ul>
116   -
117   -<p class="back"><a href="#contents">contents ^</a></p>
118   -<h3 id="examples">Examples</h3>
119   -
120   -<pre>
121   -$D('2006-09-20').strftime('%m/%d/%Y'); // "09/20/2006"
  13 +<div class="content">
  14 + <p class="archive">Looking for <a href="http://sandbox.kendsnyder.com/date2">version 2?</a></p>
  15 +
  16 + <h2 id="contents">Contents</h2>
  17 + <ol>
  18 + <li><a href="#intro">Introduction</a></li>
  19 + <li><a href="#demonstration">Demo</a></li>
  20 + <li><a href="https://github.com/kensnyder/date-prototype">Github Repository</a></li>
  21 + <li><a href="#src">Download</a></li>
  22 + <li><a href="#examples">Examples</a></li>
  23 + <li><a href="#ref">Method Reference</a></li>
  24 + <li><a href="#parse">Parsable Formats</a></li>
  25 + <li><a href="#codes">Format Codes</a></li>
  26 + <li><a href="#custom">Customization and I18n</a></li>
  27 + <li><a href="unit-tests.html">Unit Tests</a></li>
  28 + <li><a href="http://www.opensource.org/licenses/MIT">MIT License</a></li>
  29 + </ol>
  30 +
  31 + <p class="back"><a href="#contents">contents ^</a></p>
  32 + <h3 id="intro">Introduction</h3>
  33 +
  34 + <p>This script provides JavaScript Date instance methods for parsing, formatting, and calculating dates.
  35 + It leverages the existing functionality of the native Date.parse method
  36 + and uses a concise and configurable algorithm for interpreting format codes.</p>
  37 +
  38 + <p>Contributions and bug reports are welcome on the <a href="https://github.com/kensnyder/date-prototype">Github Repository</a></p>
  39 +
  40 + <p><strong>Features include:</strong></p>
  41 + <ol>
  42 + <li>Parse various formats with ability to register custom format parsing.</li>
  43 + <li>Format dates using the well-known percent-letter formatting options with the ability to register custom formating.</li>
  44 + <li>Add and subtract years, months, days, hours, minutes, seconds, or milliseconds.</li>
  45 + <li>Calculate differences between dates in the given unit.</li>
  46 + <li>Methods are available on all Date Objects.</li>
  47 + </ol>
  48 +
  49 + <p class="back"><a href="#contents">contents ^</a></p>
  50 + <h3 id="demonstration">Demo</h3>
  51 +
  52 + <div class="demo">
  53 + <form name="demo" action="">
  54 + <p><code>$D</code> can parse almost any format you can think of. Then use the <code>strftime</code> you know to specify date format.</p>
  55 + <p>
  56 + $D(&quot;<input type="text" name="fdate" value="2008-03-18 15:33:21" size="23" onblur="formatDate()" />&quot;).strftime(&quot;<input type="text" name="fformat" value="%#m-%d-%Y" size="17" onblur="formatDate();" />&quot;)
  57 + = <span class="result" id="fresult"></span>
  58 + </p>
  59 + <p>Use the <code>add()</code> method to add or subtract a unit of time.</p>
  60 + <p>
  61 + $D(&quot;<input type="text" name="adate" value="2008-03-18 3:33:21PM" size="23" onblur="addDate()" />&quot;).add(<input type="text" name="aadd" value="-5" size="4" onblur="addDate();" />, &quot;<select name="aunit" onchange="addDate();">
  62 + <option value="milliseconds">milliseconds</option>
  63 + <option value="seconds">seconds</option>
  64 + <option value="minutes">minutes</option>
  65 + <option value="hours">hours</option>
  66 + <option value="days" selected="selected">days</option>
  67 + <option value="weeks">weeks</option>
  68 + <option value="months">months</option>
  69 + <option value="years">years</option>
  70 + </select>&quot;).strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)
  71 + = <span class="result" id="aresult"></span>
  72 + </p>
  73 + <p>Use the <code>diff()</code> method to find out the amount of time between two dates.
  74 + <p>
  75 + $D(&quot;<input type="text" name="ddate1" value="2008-03-18 8pm" size="23" onblur="diffDate()" />&quot;).diff(&quot;<input type="text" name="ddate2" value="2008-03-17 2pm" size="20" onblur="diffDate();" />&quot;, &quot;<select name="dunit" onchange="diffDate();">
  76 + <option value="milliseconds">milliseconds</option>
  77 + <option value="seconds">seconds</option>
  78 + <option value="minutes">minutes</option>
  79 + <option value="hours">hours</option>
  80 + <option value="days" selected="selected">days</option>
  81 + <option value="weeks">weeks</option>
  82 + <option value="months">months</option>
  83 + <option value="years">years</option>
  84 + </select>&quot;, <select name="dround" onchange="diffDate()"><option value="0" selected="selected">false</option><option value="1">true</option></select>)
  85 + = <span class="result" id="dresult"></span>
  86 + </p>
  87 + <p>And see all the useful methods in the <a href="#ref">Reference</a> section.</p>
  88 + </form>
  89 + </div>
  90 +
  91 +
  92 + <script>
  93 + var demo = document.forms.demo;
  94 + function formatDate() {
  95 + var date = $D(demo.fdate.value);
  96 + document.getElementById('fresult').innerHTML = date instanceof Date ? date.strftime(demo.fformat.value) : '(unrecognized)';
  97 + }
  98 + function addDate() {
  99 + var date = $D(demo.adate.value);
  100 + var amount = demo.aadd.value;
  101 + var unit = demo.aunit.options[demo.aunit.selectedIndex].value;
  102 + document.getElementById('aresult').innerHTML = date instanceof Date ? date.add(amount, unit).strftime('%Y-%m-%d %H:%M:%S') : '(unrecognized)';
  103 + }
  104 + function diffDate() {
  105 + var date1 = $D(demo.ddate1.value);
  106 + var date2 = $D(demo.ddate2.value);
  107 + var unit = demo.dunit.options[demo.dunit.selectedIndex].value;
  108 + var round = Number(demo.dround.options[demo.dround.selectedIndex].value);
  109 + document.getElementById('dresult').innerHTML = date1 instanceof Date && date2 instanceof Date ? date1.diff(date2, unit, round) : '(unrecognized)';
  110 + }
  111 + formatDate();
  112 + addDate();
  113 + diffDate();
  114 + </script>
  115 +
  116 +
  117 +
  118 + <p class="back"><a href="#contents">contents ^</a></p>
  119 + <h3 id="src">Download</h3>
  120 +
  121 + <ul>
  122 + <li><a href="src/Date.js" target="blank">Date.js (source - 12kb)</a></li>
  123 + <li><a href="Date.min.js" target="blank">Date.min.js (minified - 5kb)</a></li>
  124 + </ul>
  125 +
  126 + <p class="back"><a href="#contents">contents ^</a></p>
  127 + <h3 id="examples">Examples</h3>
  128 +
  129 + <pre>$D('2006-09-20').strftime('%m/%d/%Y'); // "09/20/2006"
122 130 $D('Sep 20 2006').add(3).strftime('%Y-%m-%d'); // "2006-09-23"
123 131 $D('09/20/2006').add(4, 'years').strftime('%Y-%m-%d'); // "2010-09-20"
124 132 $D('09/20/2006 20:15:00').add(4, 'hours').format('%Y-%m-%d %H:%M:%S'); // "2006-09-21 00:15:00"
125 133 $D('2006-09-20').format('m/d/Y'); // "09/20/2006"
126   -$D('2006.09.28').diff('20 Sep, 2006', 'days'); // 8
127   -</pre>
128   -
129   -
130   -<p class="back"><a href="#contents">contents ^</a></p>
131   -<h3 id="ref">Full Reference</h3>
132   -
133   -<table cellspacing="1">
134   - <tr><th colspan="2" class="section">New Date Instance Methods</th></tr>
135   - <tr><th>Method</th><th>Description</th></tr>
136   - <tr><td>Date#add(iAmount[, sUnit='day']) -&gt; Date</td><td>Alters the date by adding an amount expressed in the given unit.</td></tr>
137   - <tr><td>Date#strftime(sFormat) -&gt; String</td><td>Returns the date expressed in a string according to the given format.</td></tr>
138   - <tr><td>Date#diff(date[, sUnit='day'][, bAllowDecimal=false]) -&gt; Number</td><td>Returns the amount difference between the given date in the given format. Round toward zero unless <em>bAllowDecimal</em> is true.</td></tr>
139   - <tr><td>Date#diffText() -&gt; String</td><td>Returns a string with a conversational date string such as "5 days ago".</td></tr>
140   - <tr><td>Date#clone() -&gt; Date</td><td>Returns a date object with the same value.</td></tr>
141   - <tr><td>Date#succ([sUnit='day']) -&gt; Date</td><td>Returns a copy of the date incremented by one day (or any other unit).</td></tr>
142   - <tr><td>Date#getShortYear() -&gt; Number</td><td>Returns number of years past the century (one or two digit year).</td></tr>
143   - <tr><td>Date#getMonthNumber() -&gt; Number</td><td>Returns the number of the month 1-12.</td></tr>
144   - <tr><td>Date#getMonthName() -&gt; String</td><td>Returns the name of the month as defined in Date.MONTHNAMES.</td></tr>
145   - <tr><td>Date#getAbbrMonthName() -&gt; String</td><td>Returns the abreviated name of the month as defined in Date.ABBR_MONTHNAMES.</td></tr>
146   - <tr><td>Date#getDayName() -&gt; String</td><td>Returns the name of the day of the week as defined in Date.DAYNAMES.</td></tr>
147   - <tr><td>Date#getAbbrDayName() -&gt; String</td><td>Returns the abbreviated name of the day of the week as defined in Date.ABBR_DAYNAMES.</td></tr>
148   - <tr><td>Date#getDayOrdinal() -&gt; String</td><td>Returns the ordinal suffix for the day of the month as defined in Date.ORDINALNAMES.</td></tr>
149   - <tr><td>Date#getHours12() -&gt; String</td><td>Returns hours in 12-hour format.</td></tr>
150   - <tr><td>Date#getAmPm() -&gt; String</td><td>Returns AM or PM for the date.</td></tr>
151   - <tr><td>Date#getUnix() -&gt; Number</td><td>Returns the number of seconds past 1970-01-01-00:00:00.</td></tr>
152   - <tr><td>Date#getGmtOffset() -&gt; String</td><td>Returns the minutes and seconds offset from GMT.</td></tr>
153   - <tr><td>Date#getTimezoneName() -&gt; String</td><td>Returns the browser-reported name of the timezone.</td></tr>
154   - <tr><td>Date#toYmdInt() -&gt; Number</td><td>Returns an integer in the format YYYYMMDD (useful for quickly sorting by date)</td></tr>
155   - <tr><td>Date#setUTCOffsetString(sOffset) -&gt; Date</td><td>Set the UTC offset with a four-digit string such as `+04:00` or `-0700`</td></tr>
156   -
157   - <tr><th colspan="2" class="section">New Date Static Properties</th></tr>
158   - <tr><th>Property</th><th>Description</th></tr>
159   - <tr><td>Date.create(date) -&gt; Date</td><td><code>date</code> can be a <a href="#parse">parsable</a> string, a unix timestamp or a Date object.</td></tr>
160   - <tr><td>Date.MONTHNAMES</td><td>An array of the month names</td></tr>
161   - <tr><td>Date.ABBR_MONTHNAMES</td><td>An array of the abbreviated month names</td></tr>
162   - <tr><td>Date.DAYNAMES</td><td>An array of the names of the days of the week</td></tr>
163   - <tr><td>Date.ABBR_DAYNAMES</td><td>An array of the abbreviated names of the days of the week</td></tr>
164   - <tr><td>Date.ORDINALNAMES</td><td>An array of the ordinal suffixes for digits 0-9</td></tr>
165   - <tr><td>Date.ISO</td><td>A shortcut for ISO-8601 date format (%Y-%m-%dT%H:%M:%S.%s%G)</td></tr>
166   - <tr><td>Date.SQL</td><td>A shortcut for SQL date format (%Y-%m-%d %H:%M:%S)</td></tr>
167   - <tr><td>Date.SCRIPT_LOAD</td><td>A date object representing when the script was loaded</td></tr>
168   - <tr><td>Date.daysInMonth(iYear, iMonth) -&gt; Number</td><td>Given a four digit year and a month 1-12, how many days are in that month</td></tr>
169   - <tr><td>Date.autoFormat(sInput, sFormatStr) -&gt; HTMLElement</td><td>Given an element id or object, make an input auto-format input into a date on blur</td></tr>
170   - <tr><td>Date.addFormat(sName, oRules) -&gt; Object</td><td>Add a set of format codes and a method called sName to accept the rules (see <a href="#custom">customization</a>)</td></tr>
171   - <tr><td>Date.current() -&gt; Date</td><td>Return a Date object representing the date at that moment</td></tr>
172   - <tr><td>Date.create.patterns</td><td>An object with pairs defining parsers for custom formats (see <a href="#custom">customization</a>)</td></tr>
173   - <tr><th colspan="2" class="section">Native Date Instance Methods (from <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">w3schools.com</a>)</th></tr>
174   - <tr><th>Method</th><th>Description</th></tr>
175   - <tr><td>Date#getDate() -&gt; Number</td><td>Returns the day of the month from a Date object (from 1-31)</td></tr>
176   - <tr><td>Date#getDay() -&gt; Number</td><td>Returns the day of the week from a Date object (from 0-6)</td></tr>
177   - <tr><td>Date#getMonth() -&gt; Number</td><td>Returns the month from a Date object (from 0-11)</td></tr>
178   - <tr><td>Date#getFullYear() -&gt; Number</td><td>Returns the year, as a four-digit number, from a Date object</td></tr>
179   - <tr><td>Date#getYear() -&gt; Number</td><td>Returns the year, as a two-digit or a four-digit number, from a Date object. Use Date#getFullYear instead !!</td></tr>
180   - <tr><td>Date#getHours() -&gt; Number</td><td>Returns the hour of a Date object (from 0-23)</td></tr>
181   - <tr><td>Date#getMinutes() -&gt; Number</td><td>Returns the minutes of a Date object (from 0-59)</td></tr>
182   - <tr><td>Date#getSeconds() -&gt; Number</td><td>Returns the seconds of a Date object (from 0-59)</td></tr>
183   - <tr><td>Date#getMilliseconds() -&gt; Number</td><td>Returns the milliseconds of a Date object (from 0-999)</td></tr>
184   - <tr><td>Date#getTime() -&gt; Number</td><td>Returns the number of milliseconds since midnight Jan 1, 1970</td></tr>
185   - <tr><td>Date#getTimezoneOffset() -&gt; Number</td><td>Returns the difference in minutes between local time and Greenwich Mean Time (GMT)</td></tr>
186   - <tr><td>Date#getUTCDate() -&gt; Number</td><td>Returns the day of the month from a Date object according to universal time (from 1-31)</td></tr>
187   - <tr><td>Date#getUTCDay() -&gt; Number</td><td>Returns the day of the week from a Date object according to universal time (from 0-6)</td></tr>
188   - <tr><td>Date#getUTCMonth() -&gt; Number</td><td>Returns the month from a Date object according to universal time (from 0-11)</td></tr>
189   - <tr><td>Date#getUTCFullYear() -&gt; Number</td><td>Returns the four-digit year from a Date object according to universal time</td></tr>
190   - <tr><td>Date#getUTCHours() -&gt; Number</td><td>Returns the hour of a Date object according to universal time (from 0-23)</td></tr>
191   - <tr><td>Date#getUTCMinutes() -&gt; Number</td><td>Returns the minutes of a Date object according to universal time (from 0-59)</td></tr>
192   - <tr><td>Date#getUTCSeconds() -&gt; Number</td><td>Returns the seconds of a Date object according to universal time (from 0-59)</td></tr>
193   - <tr><td>Date#getUTCMilliseconds() -&gt; Number</td><td>Returns the milliseconds of a Date object according to universal time (from 0-999)</td></tr>
194   - <tr><td>Date#setDate(iDayOfMonth) -&gt; Number</td><td>Sets the day of the month in a Date object (from 1-31)</td></tr>
195   - <tr><td>Date#setMonth(iMonth) -&gt; Number</td><td>Sets the month in a Date object (from 0-11)</td></tr>
196   - <tr><td>Date#setFullYear(iYear) -&gt; Number</td><td>Sets the year in a Date object (four digits)</td></tr>
197   - <tr><td>Date#setYear(sYear) -&gt; Number</td><td>Sets the year in the Date object (two or four digits). Use Date#setFullYear instead !!</td></tr>
198   - <tr><td>Date#setHours(iHour[, iMinute][, iSecond][, iMillisecond]) -&gt; Number</td><td>Sets the hour in a Date object (from 0-23)</td></tr>
199   - <tr><td>Date#setMinutes(iMinute[, iSecond][, iMillisecond]) -&gt; Number</td><td>Set the minutes in a Date object (from 0-59)</td></tr>
200   - <tr><td>Date#setSeconds(iSecond[, iMillisecond]) -&gt; Number</td><td>Sets the seconds in a Date object (from 0-59)</td></tr>
201   - <tr><td>Date#setMilliseconds(iMillisecond) -&gt; Number</td><td>Sets the milliseconds in a Date object (from 0-999)</td></tr>
202   - <tr><td>Date#setTime(iMillisecond) -&gt; Number</td><td>Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970</td></tr>
203   - <tr><td>Date#toISOString() -&gt; String</td><td>ES5. Date converted to UTC time and formatted as ISO-8601 string (%Y-%m-%dT%H:%M:%S.%N%G)</td></tr>
204   - <tr><td>Date#setUTCDate(iDay) -&gt; Number</td><td>Sets the day of the month in a Date object according to universal time (from 1-31)</td></tr>
205   - <tr><td>Date#setUTCMonth(iMonth) -&gt; Number</td><td>Sets the month in a Date object according to universal time (from 0-11)</td></tr>
206   - <tr><td>Date#setUTCFullYear(iYear) -&gt; Number</td><td>Sets the year in a Date object according to universal time (four digits)</td></tr>
207   - <tr><td>Date#setUTCHours(iHour[, iMinute][, iSecond][, iMillisecond]) -&gt; Number</td><td>Sets the hour in a Date object according to universal time (from 0-23)</td></tr>
208   - <tr><td>Date#setUTCMinutes(iMinute[, iSecond][, iMillisecond]) -&gt; Number</td><td>Set the minutes in a Date object according to universal time (from 0-59)</td></tr>
209   - <tr><td>Date#setUTCSeconds(iSecond[, iMillisecond]) -&gt; Number</td><td>Set the seconds in a Date object according to universal time (from 0-59)</td></tr>
210   - <tr><td>Date#setUTCMilliseconds(iMillisecond) -&gt; Number</td><td>Sets the milliseconds in a Date object according to universal time (from 0-999)</td></tr>
211   - <tr><td>Date#toString() -&gt; String</td><td>Converts a Date object to a string</td></tr>
212   - <tr><td>Date#toGMTString() -&gt; String</td><td>Converts a Date object, according to Greenwich time, to a string. Use Date#toUTCString instead !!</td></tr>
213   - <tr><td>Date#toUTCString() -&gt; String</td><td>Converts a Date object, according to universal time, to a string</td></tr>
214   - <tr><td>Date#toLocaleString() -&gt; String</td><td>Converts a Date object, according to local time, to a string</td></tr>
215   - <tr><td>Date#valueOf() -&gt; Number</td><td>Returns the number of milliseconds since midnight Jan 1, 1970 (same as Date#getTime)</td></tr>
216   - <tr><td colspan="2"><em>Note: the Number returned by native Date setters is the number of milliseconds since midnight Jan 1, 1970.</em></td></tr>
217   -
218   - <tr><th colspan="2" class="section">Native Date Static Methods (from <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">w3schools.com</a>)</th></tr>
219   - <tr><th>Method</th><th>Description</th></tr>
220   - <tr><td>Date.parse(sDate) -&gt; Number</td><td>Takes a date string and returns the number of milliseconds since midnight of January 1, 1970</td></tr>
221   - <tr><td>Date.UTC(year,month,day,hours,minutes,seconds,ms) -&gt; Number</td><td>Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time</td></tr>
222   -</table>
223   -
224   -
225   -<p class="back"><a href="#contents">contents ^</a></p>
226   -<h3 id="parsable">Parsable Formats</h3>
227   -
228   -<ul>
229   - <li>5/29/2007</li>
230   - <li>05/29/2007</li>
231   - <li>5-29-2007</li>
232   - <li>05-29-2007</li>
233   - <li>Oct 29, 2007</li>
234   - <li>October 29, 2007</li>
235   - <li>October the 29th</li>
236   - <li>October 29th</li>
237   - <li>29 Oct 2007</li>
238   - <li>29-Oct-2007</li>
239   - <li>29 October 2007</li>
240   - <li>29-October-2007</li>
241   - <li>2007-10-29</li>
242   - <li>29.10.2007</li>
243   - <li>29/10/2007</li>
244   - <li><code>date</code> 02:30:59.005</li>
245   - <li><code>date</code> 02:30:59</li>
246   - <li><code>date</code> 02:30</li>
247   - <li><code>date</code> 2:30:59am</li>
248   - <li><code>date</code> 2:30am</li>
249   - <li><code>date</code> 2am</li>
250   - <li>2:30:59am</li>
251   - <li>2:30am</li>
252   - <li>2am</li>
253   - <li>2010-03-15T12:34:56.005</li>
254   - <li>Thu, 21 Dec 2000 16:01:07 +0200 <em>(RFC 2822 format)</em></li>
255   - <li>2010-03-15T12:34:56+01:00 <em>(full ISO 8601)</em></li>
256   - <li>Sat Apr 14 2012 09:45:25 GMT-0600 (MDT)</li>
257   - <li>@1312132465 <em>(Unix Timestamp)</em></li>
258   - <li>/Date(1296824894000)/ <em>(ASP JSON)</em></li>
259   - <li>/Date(1296824894000-0700)/ <em>(ASP JSON)</em></li>
260   - <li>2 weeks before <code>date</code></li>
261   - <li>2 years after <code>date</code></li>
262   - <li>2 days ago</li>
263   - <li>in 2 months</li>
264   - <li>+2 months</li>
265   - <li>-2 days</li>
266   - <li>now</li>
267   - <li>yesterday</li>
268   - <li>today</li>
269   - <li>tomorrow</li>
270   - <li>last Thursday</li>
271   - <li>this Thursday</li>
272   - <li>last month</li>
273   -</ul>
274   -<p>Note: all formats are case insensitive.</p>
275   -
276   -<p class="back"><a href="#contents">contents ^</a></p>
277   -<h3 id="cones">Format Codes</h3>
278   -
279   -<table cellspacing="1">
280   - <tr><th>#strftime()</th><th>#formatPhp()</th><th>#formatSql()*</th><th>Example</th><th>Meaning</th></tr>
281   - <tr><td colspan="5" class="minihead">Year</td></tr>
282   - <tr><td>%Y</td><td>Y</td><td>yyyy</td><td>2008</td><td>Four-digit year</td></tr>
283   - <tr><td>%y</td><td>y</td><td>yy</td><td>08</td><td>Two-digit year</td></tr>
284   - <tr><td colspan="5" class="minihead">Month</td></tr>
285   - <tr><td>%m</td><td>m</td><td>mm</td><td>09</td><td>Two-digit month</td></tr>
286   - <tr><td>%#m</td><td>n</td><td>m</td><td>9</td><td>One or two-digit month</td></tr>
287   - <tr><td>%B</td><td>F</td><td>mmmm</td><td>September</td><td>Full month name</td></tr>
288   - <tr><td>%b</td><td>M</td><td>mmm</td><td>Sep</td><td>Abbreviated month name</td></tr>
289   - <tr><td colspan="5" class="minihead">Day</td></tr>
290   - <tr><td>%d</td><td>d</td><td>dd</td><td>05</td><td>Two-digit day of month</td></tr>
291   - <tr><td>%#d</td><td>j</td><td>d</td><td>5</td><td>One or two-digit day of month</td></tr>
292   - <tr><td>%e</td><td> </td><td> </td><td>5</td><td>One or two-digit day of month</td></tr>
293   - <tr><td>%A</td><td>l</td><td>dddd</td><td>Sunday</td><td>Full name of the day of the week</td></tr>
294   - <tr><td>%a</td><td>D</td><td>ddd</td><td>Sun</td><td>Abbreviated name of the day of the week</td></tr>
295   - <tr><td>%w</td><td>w</td><td>w</td><td>0</td><td>Number of the day of the week (0 = Sunday, 6 = Saturday)</td></tr>
296   - <tr><td>%o</td><td>D</td><td> </td><td>th</td><td>The ordinal suffix string following the day of the month</td></tr>
297   - <tr><td colspan="5" class="minihead">Hour</td></tr>
298   - <tr><td>%H</td><td>H</td><td>hh24</td><td>23</td><td>Hours in 24-hour format (two digits)</td></tr>
299   - <tr><td>%#H</td><td>G</td><td>h24</td><td>3</td><td>Hours in 24-hour integer format (one or two digits)</td></tr>
300   - <tr><td>%I</td><td>h</td><td>hh <em>or</em> hh12</td><td>11</td><td>Hours in 12-hour format (two digits)</td></tr>
301   - <tr><td>%#I</td><td>g</td><td>h12</td><td>3</td><td>Hours in 12-hour integer format (one or two digits)</td></tr>
302   - <tr><td>%p</td><td>A</td><td>am <em>or</em> pm</td><td>PM</td><td>AM or PM</td></tr>
303   - <tr><td></td><td>a</td><td></td><td>pm</td><td>am or pm</td></tr>
304   - <tr><td colspan="5" class="minihead">Minute</td></tr>
305   - <tr><td>%M</td><td>i</td><td>mi</td><td>09</td><td>Minutes (two digits)</td></tr>
306   - <tr><td>%#M</td><td> </td><td> </td><td>9</td><td>Minutes (one or two digits)</td></tr>
307   - <tr><td colspan="5" class="minihead">Second</td></tr>
308   - <tr><td>%S</td><td>s</td><td>ss</td><td>02</td><td>Seconds (two digits)</td></tr>
309   - <tr><td>%#S</td><td> </td><td> </td><td>2</td><td>Seconds (one or two digits)</td></tr>
310   - <tr><td>%s</td><td>U</td><td> </td><td>1206567625723</td><td>Unix timestamp (Seconds past 1970-01-01 00:00:00)</td></tr>
311   - <tr><td colspan="5" class="minihead">Millisecond</td></tr>
312   - <tr><td>%N</td><td> </td><td> </td><td>008</td><td>Milliseconds (three digits)</td></tr>
313   - <tr><td>%#N</td><td> </td><td> </td><td>8</td><td>Milliseconds (one to three digits)</td></tr>
314   - <tr><td colspan="5" class="minihead">Timezone</td></tr>
315   - <tr><td>%O</td><td>Z</td><td> </td><td>360</td><td>difference in minutes between local time and GMT</td></tr>
316   - <tr><td>%Z</td><td>E</td><td> </td><td>Mountain Standard Time</td><td>Name of timezone as reported by browser</td></tr>
317   - <tr><td>%G</td><td>P</td><td> </td><td>-06:00</td><td>Hours and minutes between GMT</td></tr>
318   - <tr><td colspan="5" class="minihead">Shortcuts</td></tr>
319   - <tr><td>%F</td><td> </td><td> </td><td>2008-03-26</td><td>%Y-%m-%d</td></tr>
320   - <tr><td>%T</td><td> </td><td> </td><td>05:06:30</td><td>%H:%M:%S</td></tr>
321   - <tr><td>%X</td><td> </td><td> </td><td>05:06:30</td><td>%H:%M:%S</td></tr>
322   - <tr><td>%x</td><td> </td><td> </td><td>03/26/08</td><td>%m/%d/%y</td></tr>
323   - <tr><td>%D</td><td> </td><td> </td><td>03/26/08</td><td>%m/%d/%y</td></tr>
324   - <tr><td>%#c</td><td> </td><td> </td><td>Wed Mar 26 15:31:00 2008</td><td>%a %b %e %H:%M:%S %Y</td></tr>
325   - <tr><td>%v</td><td> </td><td> </td><td>3-Sep-2008</td><td>%e-%b-%Y</td></tr>
326   - <tr><td>%R</td><td> </td><td> </td><td>15:31</td><td>%H:%M</td></tr>
327   - <tr><td>%r</td><td> </td><td> </td><td>3:31:00 PM</td><td>%I:%M:%S %p</td></tr>
328   - <tr><td> </td><td>c</td><td> </td><td>2008-03-26T15:31:00-07:00</td><td>Y-m-d\TH:i:sP (iso 8601)</td></tr>
329   - <tr><td> </td><td>r</td><td> </td><td>Sat, 23 Oct 2010 14:46:03 -0600</td><td>D, j M Y H:i:s O (rfc 2822 - Internet Message Format)</td></tr>
330   - <tr><td colspan="5" class="minihead">Characters</td></tr>
331   - <tr><td>%n</td><td> </td><td> </td><td>\n</td><td>Newline</td></tr>
332   - <tr><td>%t</td><td> </td><td> </td><td>\t</td><td>Tab</td></tr>
333   - <tr><td>%%</td><td> </td><td> </td><td>%</td><td>Percent Symbol</td></tr>
334   -</table>
335   -
336   -<p>*<em>Note: formatSql() codes may be uppercase or lowercase.</em></p>
337   -
338   -<p class="back"><a href="#contents">contents ^</a></p>
339   -<h3 id="custom">Customization</h3>
340   -
341   -<p>This library allows you to customize month/day names, parsing patterns and format characters.</p>
342   -
343   -<h4>Parsing patterns</h4>
344   -<p>Add new pattern strings or functions to the array defined in Data.create.patterns. See source for more examples.</p>
  134 +$D('2006.09.28').diff('20 Sep, 2006', 'days'); // 8</pre>
  135 +
  136 +
  137 + <p class="back"><a href="#contents">contents ^</a></p>
  138 + <h3 id="ref">Full Reference</h3>
  139 +
  140 + <table class="reference" cellspacing="0">
  141 + <tr><th colspan="2" class="section">New Date Instance Methods</th></tr>
  142 + <tr><th>Method</th><th>Description</th></tr>
  143 + <tr><td class="signature">Date#add(iAmount[, sUnit='day']) -&gt; Date</td><td>Alters the date by adding an amount expressed in the given unit.</td></tr>
  144 + <tr><td class="signature">Date#strftime(sFormat) -&gt; String</td><td>Returns the date expressed in a string according to the given format.</td></tr>
  145 + <tr><td class="signature">Date#diff(date[, sUnit='day'][, bAllowDecimal=false]) -&gt; Number</td><td>Returns the amount difference between the given date in the given format. Round toward zero unless <em>bAllowDecimal</em> is true.</td></tr>
  146 + <tr><td class="signature">Date#diffText() -&gt; String</td><td>Returns a string with a conversational date string such as "5 days ago".</td></tr>
  147 + <tr><td class="signature">Date#clone() -&gt; Date</td><td>Returns a date object with the same value.</td></tr>
  148 + <tr><td class="signature">Date#succ([sUnit='day']) -&gt; Date</td><td>Returns a copy of the date incremented by one day (or any other unit).</td></tr>
  149 + <tr><td class="signature">Date#getShortYear() -&gt; Number</td><td>Returns number of years past the century (one or two digit year).</td></tr>
  150 + <tr><td class="signature">Date#getMonthNumber() -&gt; Number</td><td>Returns the number of the month 1-12.</td></tr>
  151 + <tr><td class="signature">Date#getMonthName() -&gt; String</td><td>Returns the name of the month as defined in Date.MONTHNAMES.</td></tr>
  152 + <tr><td class="signature">Date#getAbbrMonthName() -&gt; String</td><td>Returns the abreviated name of the month as defined in Date.ABBR_MONTHNAMES.</td></tr>
  153 + <tr><td class="signature">Date#getDayName() -&gt; String</td><td>Returns the name of the day of the week as defined in Date.DAYNAMES.</td></tr>
  154 + <tr><td class="signature">Date#getAbbrDayName() -&gt; String</td><td>Returns the abbreviated name of the day of the week as defined in Date.ABBR_DAYNAMES.</td></tr>
  155 + <tr><td class="signature">Date#getDayOrdinal() -&gt; String</td><td>Returns the ordinal suffix for the day of the month as defined in Date.ORDINALNAMES.</td></tr>
  156 + <tr><td class="signature">Date#getHours12() -&gt; String</td><td>Returns hours in 12-hour format.</td></tr>
  157 + <tr><td class="signature">Date#getAmPm() -&gt; String</td><td>Returns AM or PM for the date.</td></tr>
  158 + <tr><td class="signature">Date#getUnix() -&gt; Number</td><td>Returns the number of seconds past 1970-01-01-00:00:00.</td></tr>
  159 + <tr><td class="signature">Date#getGmtOffset() -&gt; String</td><td>Returns the minutes and seconds offset from GMT.</td></tr>
  160 + <tr><td class="signature">Date#getTimezoneName() -&gt; String</td><td>Returns the browser-reported name of the timezone.</td></tr>
  161 + <tr><td class="signature">Date#toYmdInt() -&gt; Number</td><td>Returns an integer in the format YYYYMMDD (useful for quickly sorting by date)</td></tr>
  162 + <tr><td class="signature">Date#setUTCOffsetString(sOffset) -&gt; Date</td><td>Set the UTC offset with a four-digit string such as `+04:00` or `-0700`</td></tr>
  163 +
  164 + <tr><th colspan="2" class="section">New Date Static Properties</th></tr>
  165 + <tr><th>Property</th><th>Description</th></tr>
  166 + <tr><td class="signature">Date.create(date) -&gt; Date</td><td><code>date</code> can be a <a href="#parse">parsable</a> string, a unix timestamp or a Date object.</td></tr>
  167 + <tr><td class="signature">Date.MONTHNAMES</td><td>An array of the month names</td></tr>
  168 + <tr><td class="signature">Date.ABBR_MONTHNAMES</td><td>An array of the abbreviated month names</td></tr>
  169 + <tr><td class="signature">Date.DAYNAMES</td><td>An array of the names of the days of the week</td></tr>
  170 + <tr><td class="signature">Date.ABBR_DAYNAMES</td><td>An array of the abbreviated names of the days of the week</td></tr>
  171 + <tr><td class="signature">Date.ORDINALNAMES</td><td>An array of the ordinal suffixes for digits 0-9</td></tr>
  172 + <tr><td class="signature">Date.ISO</td><td>A shortcut for ISO-8601 date format (%Y-%m-%dT%H:%M:%S.%s%G)</td></tr>
  173 + <tr><td class="signature">Date.SQL</td><td>A shortcut for SQL date format (%Y-%m-%d %H:%M:%S)</td></tr>
  174 + <tr><td class="signature">Date.SCRIPT_LOAD</td><td>A date object representing when the script was loaded</td></tr>
  175 + <tr><td class="signature">Date.daysInMonth(iYear, iMonth) -&gt; Number</td><td>Given a four digit year and a month 1-12, how many days are in that month</td></tr>
  176 + <tr><td class="signature">Date.autoFormat(sInput, sFormatStr) -&gt; HTMLElement</td><td>Given an element id or object, make an input auto-format input into a date on blur</td></tr>
  177 + <tr><td class="signature">Date.addFormat(sName, oRules) -&gt; Object</td><td>Add a set of format codes and a method called sName to accept the rules (see <a href="#custom">customization</a>)</td></tr>
  178 + <tr><td class="signature">Date.current() -&gt; Date</td><td>Return a Date object representing the date at that moment</td></tr>
  179 + <tr><td class="signature">Date.create.patterns</td><td>An object with pairs defining parsers for custom formats (see <a href="#custom">customization</a>)</td></tr>
  180 + <tr><th colspan="2" class="section">Native Date Instance Methods (from <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">w3schools.com</a>)</th></tr>
  181 + <tr><th>Method</th><th>Description</th></tr>
  182 + <tr><td class="signature">Date#getDate() -&gt; Number</td><td>Returns the day of the month from a Date object (from 1-31)</td></tr>
  183 + <tr><td class="signature">Date#getDay() -&gt; Number</td><td>Returns the day of the week from a Date object (from 0-6)</td></tr>
  184 + <tr><td class="signature">Date#getMonth() -&gt; Number</td><td>Returns the month from a Date object (from 0-11)</td></tr>
  185 + <tr><td class="signature">Date#getFullYear() -&gt; Number</td><td>Returns the year, as a four-digit number, from a Date object</td></tr>
  186 + <tr><td class="signature">Date#getYear() -&gt; Number</td><td>Returns the year, as a two-digit or a four-digit number, from a Date object. Use Date#getFullYear instead !!</td></tr>
  187 + <tr><td class="signature">Date#getHours() -&gt; Number</td><td>Returns the hour of a Date object (from 0-23)</td></tr>
  188 + <tr><td class="signature">Date#getMinutes() -&gt; Number</td><td>Returns the minutes of a Date object (from 0-59)</td></tr>
  189 + <tr><td class="signature">Date#getSeconds() -&gt; Number</td><td>Returns the seconds of a Date object (from 0-59)</td></tr>
  190 + <tr><td class="signature">Date#getMilliseconds() -&gt; Number</td><td>Returns the milliseconds of a Date object (from 0-999)</td></tr>
  191 + <tr><td class="signature">Date#getTime() -&gt; Number</td><td>Returns the number of milliseconds since midnight Jan 1, 1970</td></tr>
  192 + <tr><td class="signature">Date#getTimezoneOffset() -&gt; Number</td><td>Returns the difference in minutes between local time and Greenwich Mean Time (GMT)</td></tr>
  193 + <tr><td class="signature">Date#getUTCDate() -&gt; Number</td><td>Returns the day of the month from a Date object according to universal time (from 1-31)</td></tr>
  194 + <tr><td class="signature">Date#getUTCDay() -&gt; Number</td><td>Returns the day of the week from a Date object according to universal time (from 0-6)</td></tr>
  195 + <tr><td class="signature">Date#getUTCMonth() -&gt; Number</td><td>Returns the month from a Date object according to universal time (from 0-11)</td></tr>
  196 + <tr><td class="signature">Date#getUTCFullYear() -&gt; Number</td><td>Returns the four-digit year from a Date object according to universal time</td></tr>
  197 + <tr><td class="signature">Date#getUTCHours() -&gt; Number</td><td>Returns the hour of a Date object according to universal time (from 0-23)</td></tr>
  198 + <tr><td class="signature">Date#getUTCMinutes() -&gt; Number</td><td>Returns the minutes of a Date object according to universal time (from 0-59)</td></tr>
  199 + <tr><td class="signature">Date#getUTCSeconds() -&gt; Number</td><td>Returns the seconds of a Date object according to universal time (from 0-59)</td></tr>
  200 + <tr><td class="signature">Date#getUTCMilliseconds() -&gt; Number</td><td>Returns the milliseconds of a Date object according to universal time (from 0-999)</td></tr>
  201 + <tr><td class="signature">Date#setDate(iDayOfMonth) -&gt; Number</td><td>Sets the day of the month in a Date object (from 1-31)</td></tr>
  202 + <tr><td class="signature">Date#setMonth(iMonth) -&gt; Number</td><td>Sets the month in a Date object (from 0-11)</td></tr>
  203 + <tr><td class="signature">Date#setFullYear(iYear) -&gt; Number</td><td>Sets the year in a Date object (four digits)</td></tr>
  204 + <tr><td class="signature">Date#setYear(sYear) -&gt; Number</td><td>Sets the year in the Date object (two or four digits). Use Date#setFullYear instead !!</td></tr>
  205 + <tr><td class="signature">Date#setHours(iHour[, iMinute][, iSecond][, iMillisecond]) -&gt; Number</td><td>Sets the hour in a Date object (from 0-23)</td></tr>
  206 + <tr><td class="signature">Date#setMinutes(iMinute[, iSecond][, iMillisecond]) -&gt; Number</td><td>Set the minutes in a Date object (from 0-59)</td></tr>
  207 + <tr><td class="signature">Date#setSeconds(iSecond[, iMillisecond]) -&gt; Number</td><td>Sets the seconds in a Date object (from 0-59)</td></tr>
  208 + <tr><td class="signature">Date#setMilliseconds(iMillisecond) -&gt; Number</td><td>Sets the milliseconds in a Date object (from 0-999)</td></tr>
  209 + <tr><td class="signature">Date#setTime(iMillisecond) -&gt; Number</td><td>Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970</td></tr>
  210 + <tr><td class="signature">Date#toISOString() -&gt; String</td><td>ES5. Date converted to UTC time and formatted as ISO-8601 string (%Y-%m-%dT%H:%M:%S.%N%G)</td></tr>
  211 + <tr><td class="signature">Date#setUTCDate(iDay) -&gt; Number</td><td>Sets the day of the month in a Date object according to universal time (from 1-31)</td></tr>
  212 + <tr><td class="signature">Date#setUTCMonth(iMonth) -&gt; Number</td><td>Sets the month in a Date object according to universal time (from 0-11)</td></tr>
  213 + <tr><td class="signature">Date#setUTCFullYear(iYear) -&gt; Number</td><td>Sets the year in a Date object according to universal time (four digits)</td></tr>
  214 + <tr><td class="signature">Date#setUTCHours(iHour[, iMinute][, iSecond][, iMillisecond]) -&gt; Number</td><td>Sets the hour in a Date object according to universal time (from 0-23)</td></tr>
  215 + <tr><td class="signature">Date#setUTCMinutes(iMinute[, iSecond][, iMillisecond]) -&gt; Number</td><td>Set the minutes in a Date object according to universal time (from 0-59)</td></tr>
  216 + <tr><td class="signature">Date#setUTCSeconds(iSecond[, iMillisecond]) -&gt; Number</td><td>Set the seconds in a Date object according to universal time (from 0-59)</td></tr>
  217 + <tr><td class="signature">Date#setUTCMilliseconds(iMillisecond) -&gt; Number</td><td>Sets the milliseconds in a Date object according to universal time (from 0-999)</td></tr>
  218 + <tr><td class="signature">Date#toString() -&gt; String</td><td>Converts a Date object to a string</td></tr>
  219 + <tr><td class="signature">Date#toGMTString() -&gt; String</td><td>Converts a Date object, according to Greenwich time, to a string. Use Date#toUTCString instead !!</td></tr>
  220 + <tr><td class="signature">Date#toUTCString() -&gt; String</td><td>Converts a Date object, according to universal time, to a string</td></tr>
  221 + <tr><td class="signature">Date#toLocaleString() -&gt; String</td><td>Converts a Date object, according to local time, to a string</td></tr>
  222 + <tr><td class="signature">Date#valueOf() -&gt; Number</td><td>Returns the number of milliseconds since midnight Jan 1, 1970 (same as Date#getTime)</td></tr>
  223 + <tr><td colspan="2"><em>Note: the Number returned by native Date setters is the number of milliseconds since midnight Jan 1, 1970.</em></td></tr>
  224 +
  225 + <tr><th colspan="2" class="section">Native Date Static Methods (from <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">w3schools.com</a>)</th></tr>
  226 + <tr><th>Method</th><th>Description</th></tr>
  227 + <tr><td class="signature">Date.parse(sDate) -&gt; Number</td><td>Takes a date string and returns the number of milliseconds since midnight of January 1, 1970</td></tr>
  228 + <tr><td class="signature">Date.UTC(year,month,day,hours,minutes,seconds,ms) -&gt; Number</td><td>Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time</td></tr>
  229 + </table>
  230 +
  231 +
  232 + <p class="back"><a href="#contents">contents ^</a></p>
  233 + <h3 id="parsable">Parsable Formats</h3>
  234 +
  235 + <ul>
  236 + <li>5/29/2007</li>
  237 + <li>05/29/2007</li>
  238 + <li>5-29-2007</li>
  239 + <li>05-29-2007</li>
  240 + <li>Oct 29, 2007</li>
  241 + <li>October 29, 2007</li>
  242 + <li>October the 29th</li>
  243 + <li>October 29th</li>
  244 + <li>29 Oct 2007</li>
  245 + <li>29-Oct-2007</li>
  246 + <li>29 October 2007</li>
  247 + <li>29-October-2007</li>
  248 + <li>2007-10-29</li>
  249 + <li>29.10.2007</li>
  250 + <li>29/10/2007</li>
  251 + <li><code>date</code> 02:30:59.005</li>
  252 + <li><code>date</code> 02:30:59</li>
  253 + <li><code>date</code> 02:30</li>
  254 + <li><code>date</code> 2:30:59am</li>
  255 + <li><code>date</code> 2:30am</li>
  256 + <li><code>date</code> 2am</li>
  257 + <li>2:30:59am</li>
  258 + <li>2:30am</li>
  259 + <li>2am</li>
  260 + <li>2010-03-15T12:34:56.005</li>
  261 + <li>Thu, 21 Dec 2000 16:01:07 +0200 <em>(RFC 2822 format)</em></li>
  262 + <li>2010-03-15T12:34:56+01:00 <em>(full ISO 8601)</em></li>
  263 + <li>Sat Apr 14 2012 09:45:25 GMT-0600 (MDT)</li>
  264 + <li>@1312132465 <em>(Unix Timestamp)</em></li>
  265 + <li>/Date(1296824894000)/ <em>(ASP JSON)</em></li>
  266 + <li>/Date(1296824894000-0700)/ <em>(ASP JSON)</em></li>
  267 + <li>2 weeks before <code>date</code></li>
  268 + <li>2 years after <code>date</code></li>
  269 + <li>2 days ago</li>
  270 + <li>in 2 months</li>
  271 + <li>+2 months</li>
  272 + <li>-2 days</li>
  273 + <li>now</li>
  274 + <li>yesterday</li>
  275 + <li>today</li>
  276 + <li>tomorrow</li>
  277 + <li>last Thursday</li>
  278 + <li>this Thursday</li>
  279 + <li>last month</li>
  280 + </ul>
  281 + <p>Note: all formats are case insensitive.</p>
  282 +
  283 + <p class="back"><a href="#contents">contents ^</a></p>
  284 + <h3 id="cones">Format Codes</h3>
  285 +
  286 + <table cellspacing="1">
  287 + <tr><th>#strftime()</th><th>#formatPhp()</th><th>#formatSql()&dagger;</th><th>Example</th><th>Meaning</th></tr>
  288 + <tr><td colspan="5" class="minihead">Year</td></tr>
  289 + <tr><td>%Y</td><td>Y</td><td>yyyy</td><td>2008</td><td>Four-digit year</td></tr>
  290 + <tr><td>%y</td><td>y</td><td>yy</td><td>08</td><td>Two-digit year</td></tr>
  291 + <tr><td colspan="5" class="minihead">Month</td></tr>
  292 + <tr><td>%m</td><td>m</td><td>mm</td><td>09</td><td>Two-digit month</td></tr>
  293 + <tr><td>%#m</td><td>n</td><td>m</td><td>9</td><td>One or two-digit month</td></tr>
  294 + <tr><td>%B</td><td>F</td><td>mmmm</td><td>September</td><td>Full month name</td></tr>
  295 + <tr><td>%b</td><td>M</td><td>mmm</td><td>Sep</td><td>Abbreviated month name</td></tr>
  296 + <tr><td colspan="5" class="minihead">Day</td></tr>
  297 + <tr><td>%d</td><td>d</td><td>dd</td><td>05</td><td>Two-digit day of month</td></tr>
  298 + <tr><td>%#d</td><td>j</td><td>d</td><td>5</td><td>One or two-digit day of month</td></tr>
  299 + <tr><td>%e</td><td> </td><td> </td><td>5</td><td>One or two-digit day of month</td></tr>
  300 + <tr><td>%A</td><td>l</td><td>dddd</td><td>Sunday</td><td>Full name of the day of the week</td></tr>
  301 + <tr><td>%a</td><td>D</td><td>ddd</td><td>Sun</td><td>Abbreviated name of the day of the week</td></tr>
  302 + <tr><td>%w</td><td>w</td><td>w</td><td>0</td><td>Number of the day of the week (0 = Sunday, 6 = Saturday)</td></tr>
  303 + <tr><td>%o</td><td>D</td><td> </td><td>th</td><td>The ordinal suffix string following the day of the month</td></tr>
  304 + <tr><td colspan="5" class="minihead">Hour</td></tr>
  305 + <tr><td>%H</td><td>H</td><td>hh24</td><td>23</td><td>Hours in 24-hour format (two digits)</td></tr>
  306 + <tr><td>%#H</td><td>G</td><td>h24</td><td>3</td><td>Hours in 24-hour integer format (one or two digits)</td></tr>
  307 + <tr><td>%I</td><td>h</td><td>hh <em>or</em> hh12</td><td>11</td><td>Hours in 12-hour format (two digits)</td></tr>
  308 + <tr><td>%#I</td><td>g</td><td>h12</td><td>3</td><td>Hours in 12-hour integer format (one or two digits)</td></tr>
  309 + <tr><td>%p</td><td>A</td><td>am <em>or</em> pm</td><td>PM</td><td>AM or PM</td></tr>
  310 + <tr><td></td><td>a</td><td></td><td>pm</td><td>am or pm</td></tr>
  311 + <tr><td colspan="5" class="minihead">Minute</td></tr>
  312 + <tr><td>%M</td><td>i</td><td>mi</td><td>09</td><td>Minutes (two digits)</td></tr>
  313 + <tr><td>%#M</td><td> </td><td> </td><td>9</td><td>Minutes (one or two digits)</td></tr>
  314 + <tr><td colspan="5" class="minihead">Second</td></tr>
  315 + <tr><td>%S</td><td>s</td><td>ss</td><td>02</td><td>Seconds (two digits)</td></tr>
  316 + <tr><td>%#S</td><td> </td><td> </td><td>2</td><td>Seconds (one or two digits)</td></tr>
  317 + <tr><td>%s</td><td>U</td><td> </td><td>1206567625723</td><td>Unix timestamp (Seconds past 1970-01-01 00:00:00)</td></tr>
  318 + <tr><td colspan="5" class="minihead">Millisecond</td></tr>
  319 + <tr><td>%N</td><td> </td><td> </td><td>008</td><td>Milliseconds (three digits)</td></tr>
  320 + <tr><td>%#N</td><td> </td><td> </td><td>8</td><td>Milliseconds (one to three digits)</td></tr>
  321 + <tr><td colspan="5" class="minihead">Timezone</td></tr>
  322 + <tr><td>%O</td><td>Z</td><td> </td><td>360</td><td>difference in minutes between local time and GMT</td></tr>
  323 + <tr><td>%Z</td><td>E</td><td> </td><td>EST</td><td>Name of timezone as reported by browser</td></tr>
  324 + <tr><td>%G</td><td>P</td><td> </td><td>-06:00</td><td>Hours and minutes between GMT</td></tr>
  325 + <tr><td colspan="5" class="minihead">Shortcuts</td></tr>
  326 + <tr><td>%F</td><td> </td><td> </td><td>2008-03-26</td><td>%Y-%m-%d</td></tr>
  327 + <tr><td>%T</td><td> </td><td> </td><td>05:06:30</td><td>%H:%M:%S</td></tr>
  328 + <tr><td>%X</td><td> </td><td> </td><td>05:06:30</td><td>%H:%M:%S</td></tr>
  329 + <tr><td>%x</td><td> </td><td> </td><td>03/26/08</td><td>%m/%d/%y</td></tr>
  330 + <tr><td>%D</td><td> </td><td> </td><td>03/26/08</td><td>%m/%d/%y</td></tr>
  331 + <tr><td>%#c</td><td> </td><td> </td><td>Wed Mar 26 15:31:00 2008</td><td>%a %b %e %H:%M:%S %Y</td></tr>
  332 + <tr><td>%v</td><td> </td><td> </td><td>3-Sep-2008</td><td>%e-%b-%Y</td></tr>
  333 + <tr><td>%R</td><td> </td><td> </td><td>15:31</td><td>%H:%M</td></tr>
  334 + <tr><td>%r</td><td> </td><td> </td><td>3:31:00 PM</td><td>%I:%M:%S %p</td></tr>
  335 + <tr><td> </td><td>c</td><td> </td><td>2008-03-26T15:31:00-07:00</td><td>Y-m-d\TH:i:sP (iso 8601)</td></tr>
  336 + <tr><td> </td><td>r</td><td> </td><td>Sat, 23 Oct 2010 14:46:03 -0600</td><td>D, j M Y H:i:s O (rfc 2822 - Internet Message Format)</td></tr>
  337 + <tr><td colspan="5" class="minihead">Literals</td></tr>
  338 + <tr><td>%n</td><td> </td><td> </td><td>\n</td><td>Newline</td></tr>
  339 + <tr><td>%t</td><td> </td><td> </td><td>\t</td><td>Tab</td></tr>
  340 + <tr><td>%%</td><td> </td><td> </td><td>%</td><td>Percent Symbol</td></tr>
  341 + </table>
  342 +
  343 + <p class="footnote">&dagger;<code>formatSql()</code> codes may be uppercase or lowercase.</p>
  344 +
  345 + <p class="back"><a href="#contents">contents ^</a></p>
  346 + <h3 id="custom">Customization</h3>
  347 +
  348 + <p>The Date Prototype library allows you to customize month/day names, parsing patterns and format characters.</p>
  349 +
  350 + <h4>Parsing patterns</h4>
  351 + <p>Add new pattern strings or functions to the array defined in Data.create.patterns. See source for more examples.</p>
345 352 <pre>Date.addPattern(['month-year', /^(\d{1,2})-(\d{4})$/, '$1/01/$2']); // match month-year
346   -Date.addPattern(['hoy', /^hoy$/i, function(match) { return new Date(); }], 'iso_8601'); // match Spanish word for `today`
347   -</pre>
348   -<p>Remove a pattern</p>
  353 +Date.addPattern(['hoy', /^hoy$/i, function(match) { return new Date(); }], 'iso_8601'); // match Spanish word for `today`</pre>
  354 + <p>Remove a pattern</p>
349 355 <pre>Date.removePattern('us'); // us-style m/d/Y dates no longer recognized
350   -
351 356 var us = Date.removePattern('us');
352   -Date.addPattern(us, 'world'); // prefer world-style d/m/Y dates over us-style m/d/Y dates
353   -</pre>
354   -
355   -<h4>Internationalize Month/day names</h4>
356   -<p>Simply set the static members of the Date object.</p>
357   -<pre>Date.MONTHNAMES = 'Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre'.split(' '),
358   -Date.DAYNAMES = 'Domingo Lunes Martes Miércoles Jueves Viernes Sábado'.split(' '),
359   -</pre>
360   -
361   -<h4>Format characters</h4>
362   -<p>Add new characters and character patterns and a method to call them. Here is a snippet from the source.</p>
  357 +Date.addPattern(us, 'world'); // prefer world-style d/m/Y dates over us-style m/d/Y dates</pre>
  358 +
  359 + <h4>Internationalize Month/day names</h4>
  360 + <p>Simply set the static members of the Date object.</p>
  361 +<pre>Date.MONTHNAMES = 'Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre'.split(' ');
  362 +Date.DAYNAMES = 'Domingo Lunes Martes Miércoles Jueves Viernes Sábado'.split(' ');</pre>
  363 +
  364 + <h4>Format characters</h4>
  365 + <p>Add new characters and character patterns and a method to call them. Here is a snippet from the source.</p>
363 366 <pre>Date.addFormat('formatPhp', {
364   -//
365   -// 2-part regex matcher for format codes
366   -//
367   -// first match must be the character before the code (to account for escaping)
368   -// second match must be the format code character(s)
369   -//
370   -matcher: /(\\)?([a-z])/i,
371   -defaultFormat: 'Y-m-d H:i:s',
372   -codes: {
373   - // year
374   - Y: 'FullYear',
375   - // ...
376   - O: 'UTCOffsetNumber'
377   -},
378   -//
379   -// shortcuts that will be translated into their longer version
380   -//
381   -// be sure that format shortcuts do not refer to themselves: this will cause an infinite loop
382   -//
383   -shortcuts: {
384   - // iso
385   - c: 'Y-m-d\\TH:i:sP',
386   - // rfc 2822
387   - r: 'D, j M Y H:i:s O'
388   -}
  367 + //
  368 + // 2-part regex matcher for format codes
  369 + //
  370 + // first match must be the character before the code (to account for escaping)
  371 + // second match must be the format code character(s)
  372 + //
  373 + matcher: /(\\)?([a-z])/i,
  374 + defaultFormat: 'Y-m-d H:i:s',
  375 + codes: {
  376 + // year
  377 + Y: 'FullYear',
  378 + // ...
  379 + O: 'UTCOffsetNumber'
  380 + },
  381 + //
  382 + // shortcuts that will be translated into their longer version
  383 + //
  384 + // be sure that format shortcuts do not refer to themselves: this will cause an infinite loop
  385 + //
  386 + shortcuts: {
  387 + // iso
  388 + c: 'Y-m-d\\TH:i:sP',
  389 + // rfc 2822
  390 + r: 'D, j M Y H:i:s O'
  391 + }
389 392 });</pre>
  393 +
  394 + <p>&copy; 2012 Ken Snyder, <a href="http://kendsnyder.com">kendsnyder.com</a></p>
  395 +</div>
390 396
391 397 <script type="text/javascript">
392 398 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
@@ -399,5 +405,5 @@ <h3 id="custom">Customization</h3>
399 405 } catch(err) {}
400 406 </script>
401 407
  408 +</html>
402 409 </body>
403   -</html>
44 src/Date.js
... ... @@ -1,12 +1,11 @@
1 1 /**
2   - * Date instance methods
  2 + * JavaScript Date instance methods
3 3 *
4   - * @author Ken Snyder (kendsnyder at gmail dot com)
5   - * @date April 2012
6   - * @version 3.4 (http://sandbox.kendsnyder.com/date)
7   - * @license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0)
  4 + * @copyright 2012 Ken Snyder (kendsnyder at gmail dot com)
  5 + * @version 3.4, April 2012 (http://sandbox.kendsnyder.com/date)
  6 + * @license MIT http://www.opensource.org/licenses/MIT
8 7 */
9   -;(function(exports) {
  8 +;(function() {
10 9 //
11 10 // pre-calculate the number of milliseconds in a day
12 11 //
@@ -726,12 +725,12 @@
726 725 y: 'ShortYear.2',
727 726 // month
728 727 m: 'MonthNumber.2',
729   - '#m': 'MonthNumber',
  728 + '#m': 'MonthNumber',
730 729 B: 'MonthName',
731 730 b: 'AbbrMonthName',
732 731 // day
733 732 d: 'Date.2',
734   - '#d': 'Date',
  733 + '#d': 'Date',
735 734 e: 'Date',
736 735 A: 'DayName',
737 736 a: 'AbbrDayName',
@@ -739,21 +738,21 @@
739 738 o: 'DayOrdinal',
740 739 // hours
741 740 H: 'Hours.2',
742   - '#H': 'Hours',
  741 + '#H': 'Hours',
743 742 I: 'Hours12.2',
744   - '#I': 'Hours12',
  743 + '#I': 'Hours12',
745 744 P: 'AmPmLower',
746 745 p: 'AmPm',
747 746 // minutes
748 747 M: 'Minutes.2',
749   - '#M': 'Minutes',
  748 + '#M': 'Minutes',
750 749 // seconds
751 750 S: 'Seconds.2',
752   - '#S': 'Seconds',
  751 + '#S': 'Seconds',
753 752 s: 'Unix',
754 753 // milliseconds
755 754 N: 'Milliseconds.3',
756   - '#N': 'Milliseconds',
  755 + '#N': 'Milliseconds',
757 756 // timezone
758 757 O: 'TimezoneOffset',
759 758 Z: 'TimezoneName',
@@ -774,7 +773,7 @@
774 773 x: '%m/%d/%y',
775 774 D: '%m/%d/%y',
776 775 // local format extended
777   - '#c': '%a %b %e %H:%M:%S %Y',
  776 + '#c': '%a %b %e %H:%M:%S %Y',
778 777 // local format short
779 778 v: '%e-%b-%Y',
780 779 R: '%H:%M',
@@ -782,7 +781,7 @@
782 781 // tab and newline
783 782 t: '\t',
784 783 n: '\n',
785   - '%': '%'
  784 + '%': '%'
786 785 }
787 786 });
788 787 Date.addFormat('formatPhp', {
@@ -887,7 +886,7 @@
887 886 shortcuts: {}
888 887 };
889 888
890   - // add uppercase versions of each code
  889 + // add uppercase versions of each sql code
891 890 var keys = 'yyyy yy mm m mmm mmmm dd d ddd dddd w hh24 h24 hh12 h12 am pm mi ss'.split(' '), i = 0, key;
892 891 while ((key = keys[i++])) {
893 892 formatSql.codes[key.toUpperCase()] = formatSql.codes[key];
@@ -1095,10 +1094,11 @@
1095 1094 ];
1096 1095
1097 1096 // add $D shortcut to window or module.exports
1098   - exports.$D = Date.create;
  1097 + if (typeof module != 'undefined' && module.exports) {
  1098 + module.exports = Date.create;
  1099 + }
  1100 + else if (typeof window != 'undefined') {
  1101 + window.$D = Date.create;
  1102 + }
1099 1103
1100   -})(
1101   - typeof module != 'undefined' && module.exports ? module.exports :
1102   - typeof window != 'undefined' ? window :
1103   - {}
1104   -);
  1104 +})();

0 comments on commit 88e1e38

Please sign in to comment.
Something went wrong with that request. Please try again.