sorting AWS date format with Tablekit.js

Developers
Philippe
2009-07-02
2012-10-11
  • Philippe
    Philippe
    2009-07-02

    Hi,
    Well, I could manage to modify awstats.pl to avoid "Others" to be sorted but sorting AWS dates is a different story.
    Could anybody here tell me how should I copy.and modify a piece of tablekit.js code so that "dd MMM yyyy - HH:mm" (ie 02 Juil 2009 - 12:45) will be sorted properly when I click the "L" header!

    something like :
    new TableKit.Sortable.Type('date_aws',{
    pattern: /^\d{2}\s(?:Jan|Fév|Mar|Avr|Mai|Juin|Juil|Aoû|Sep|Oct|Nov|Déc)\s\d{4}\s-\s\d{2}\:\d{2}/, //18 Déc 1995 - 17:28
    compare : function(a,b) { // must be standard javascript date format
    if(a && b) {
    return TableKit.Sortable.Type.compare(new Date(a),new Date(b));
    } else {
    return TableKit.Sortable.Type.compare(a ? 1 : 0, b ? 1 : 0);
    }
    }}),
    does not work as it' not standard javascript date format I presume.

    TIA
    Philippe

     
    • jeradc
      jeradc
      2009-07-14

      This past week I've used the MooTools library to add sorting to most fields in AWStats:

      http://mootools.net/

      I hope to do a little clean up, and then submit the code as a patch. It required minimal changes to the code and is pretty straightforward.

       
    • Philippe
      Philippe
      2009-07-08

      Done!
      new TableKit.Sortable.Type('date-aws',{ // pour trier les dates au format AWStats dd MMM yyyy - HH:mm
      pattern: /^\d{2}\s(?:Jan|Fév|Mar|Avr|Mai|Juin|Juil|Aoû|Sep|Oct|Nov|Déc)\s\d{4}\s-\s\d{2}\:\d{2}$/, //18 Déc 1995 - 17:28
      normal : function(v) {
      if(!this.pattern.test(v)) {return 0;}
      var mois = new Array('Jan','Fév','Mar','Avr','Mai','Juin','Juil','Aoû','Sep','Oct','Nov','Déc');
      var r = v.match(/^(\d{2})\s((?:Jan|Fév|Mar|Avr|Mai|Juin|Juil|Aoû|Sep|Oct|Nov|Déc))\s(\d{4})\s-\s(\d{2})\:(\d{2})$/);
      var yr_num = r[3];
      var mo_num = mois.indexOf(r[2]);
      var day_num = r[1];
      var hr_num = r[4] ;
      var min_num = r[5] ;
      return new Date(yr_num, mo_num, day_num, hr_num, min_num).valueOf();
      }})

      Cool!