Function.prototype.instance = function(args){
       var fn = function(){};
       fn.prototype = new this(args);
       return new fn;
}

var $H = helpers(),
    alert = $H.displayln,
    myDate = XDate( {date:new Date('2012/11/11')} ),
    today= XDate( {date:new Date, lang:'EN'} ),
    parsed = XDate( {date:'2012-12-29 20:00:00'} ),
    dyAfterTomorrow = XDate( {date:new Date, lang:'EN'} ).add('d',2);

alert(myDate.format('mydate: d MM YYYY is/was op een WD'));
alert(today.format("today (dd-mm-YYYY) it's WD"));
alert(dyAfterTomorrow.format('the day after tomorrow is dd-mm-YYYY, falling on a WD'));
alert(parsed.format('M dd'));
alert(Number(parsed.toUTCStamp()));
alert(XDate( {date: parsed.toUTCStamp()} ).dat);


/** ------------------------------------------------------------------------------- **/
/**                         XDate constructor                                       **/
/** ------------------------------------------------------------------------------- **/
function XDate(args){
    if (!(this instanceof XDate)){
        return XDate.instance(args);
    }

    var that = this;
    this.dat = parse(args ? args.date : new Date);
    this.lang = args ? args.lang || 'NL' : 'NL';

    if (!XDate.prototype.weekdays){

        var proto = XDate.prototype;
        proto.names = {
          NLweekdays:  ('Zondag,Maandag,Dinsdag,Woensdag,Donderdag,'+
                        'Vrijdag,Zaterdag'),
          NLmonths   : ('Januari,Februari,Maart,April,Mei,Juni,Juli,'+
                        'Augustus,September,Oktober,'+
                        'November,December'),
          NLwdShort  : ('Zo,Ma,Di,Wo,Do,Vr,Za'),
          NLmnthShort: ('Jan,Feb,Mrt,Apr,Mei,Jun,Jul,'+
                        'Aug,Sep,Okt,Nov,Dec'),
          ENweekdays:  ('Sunday,Monday,Tuesday,Wednessday,Thursday,'+
                        'Friday,Saturday'),
          ENmonths   : ('January,February,March,April,May,June,July,'+
                        'August,September,October,'+
                        'November,December'),
          ENwdShort  : ('Sun,Mon,Tue,Wed,Thu,Fri,Sat'),
          ENmnthShort: ('Jan,Feb,Mar,Apr,May,Jun,Jul,'+
                        'Aug,Sep,Oct,Nov,Dec')
       };
       proto.weekdays     = function(lang){ 
           return toEnum(this.names[lang+'weekdays'].split(',')); 
       };
       proto.months       = function(lang){ 
           return toEnum(this.names[lang+'months'].split(',')); 
       };
       proto.weekdayshort = function(lang){ 
           return toEnum(this.names[lang+'wdShort'].split(',')); 
       };
       proto.monthshort   = function(lang){ 
           return toEnum(this.names[lang+'mnthShort'].split(',')); 
       };
                                         
       proto.addhlpr      = {  d:   'getDate'
                              ,m:   'getMonth'
                              ,y:   'getFullYear'
                              ,h:   'getHours'
                              ,mi:  'getMinutes'
                              ,idx: ['d','m','y','h','mi']
                             };
        proto.replacer     = new RegExp(
                             ['\\byyyy\\b','\\bYYYY\\b','\\bm\\b','\\bd\\b','\\bh\\b',
                              '\\bmi\\b','\\bse\\b','\\bms\\b','\\bwd\\b','\\bmm\\b',
                              '\\bdd\\b','\\bhh\\b','\\bmi0\\b','\\bse0\\b','\\bms0\\b',
                              '\\bM\\b','\\bMM\\b','\\bwd\\b','\\bWD\\b']
                             .join('|'),'g');
        proto.format       = format;
        proto.add          = add;
        proto.toUTCStamp   = function() { // UTC with DST check
                              var jan = new Date(this.dat.getFullYear(), 0, 1).getTimezoneOffset();
                              var jul = new Date(this.dat.getFullYear(), 6, 1).getTimezoneOffset();
                              var current = new Date(this.dat);
                              current.setMinutes(current.getMinutes()+Math.max(jan,jul));
                              return current.getTime();
                             };
      }

    // private functions block
     function zeroPad(nr,base,chr){
        var  len = (String(base||10).length - String(nr).length)+1;
        return len > 0? new Array(len).join(chr||'0')+nr : nr;
     }
     function toEnum(valArr){
        var l = valArr.length, ret = {byArr: valArr};
        while (--l){
         ret[valArr[l]] = l;
        }
        return ret;
     }
     function disect(dat,lang){
         dat = dat || this.dat;
         lang = lang || this.lang;
         var base = {
             yyyy: dat.getFullYear()
            ,YYYY: dat.getFullYear()
            ,m   : dat.getMonth()+1
            ,d   : dat.getDate()
            ,h   : dat.getHours() || '0'
            ,mi  : dat.getMinutes() || '0'
            ,se  : dat.getSeconds() || '0'
            ,ms  : dat.getMilliseconds() || '0'
            ,dy  : dat.getDay() || '0'
           }
          ,ext =  {
             mm  : zeroPad(base.m,10)
            ,dd  : zeroPad(base.d,10)
            ,hh  : zeroPad(base.h,10)
            ,mi0  : zeroPad(base.mi,10)
            ,se0  : zeroPad(base.se,10)
            ,ms0  : zeroPad(base.ms,100)
            ,M    : this.monthshort(lang).byArr[base.m-1]
            ,MM   : this.months(lang).byArr[base.m-1]
            ,wd   : this.weekdayshort(lang).byArr[base.dy]
            ,WD   : this.weekdays(lang).byArr[base.dy]
          }
         ;
         for (var l in ext) {
             if (ext.hasOwnProperty(l)){
              base[l] = ext[l];
             }
         }
         //base.re = new RegExp(this.replacer,'g');
         return base;
     }
     function add(ymd,n,dat){
         dat = dat || this.dat;
         n = n || 1;
         var getaction = typeof ymd === 'number'
                       ? that.addhlpr[addhlpr.idx[ymd-1]]
                       : that.addhlpr[ymd],
             setaction = 's'+getaction.substr(1),
             addval = n;
         dat[setaction](dat[getaction]()+addval);
         return this;
     }
     function format(fstr,dat) {
       // call disect in context current instance  
       var dd = disect.call(this);
       return fstr.replace(this.replacer, function(a) { return dd[a]; } )
                  .replace(/~/g,'');
     }
     function  parse(d) {
        var getdat =
               d instanceof Date
               ? d
               : typeof d === 'string'
                 ? (new Date(d.replace(/T/,' ')
                              .replace(/Z/,'')
                              .replace(/\-/g,'/')) || new Date)
                 : !isNaN(d)
                    ? new Date(d)
                    : new Date;
         
        return isNaN(getdat) ? new Date : getdat;
     }
}

Following resources are loaded into result:

  1. core.js
  2. xdate.js

						
					
				
					
						
							
body {font:0.8em verdana, arial}