1

How can I remove time from displaying along with dates in our query?

flag
Can't you just narrow the column? – Michel de Ruiter Feb 11 2011 at 22:35

2 Answers

2

Hi Lewis!

I have a BugMonkey script that removes the time from (most) dates (e.g. 1/1/2010 becomes 1/1/10). For things that happened "today", it shows only the time (e.g. 2/11/2011 (Today) 12:34 PM becomes 12:34 PM).

Here's the script:

name:          Short Dates
description:   Shortens dates so you can fit more on the page.
author:        Tyler Hicks-Wright
version:       1.0.0.0

js:

function getDateColumns() {
  var hs = $('#groupHeader_1 th.c-h').find('a[title="Date Closed"],a[title="Date Opened"],a[title="Date Resolved"],a[title="Last Updated"],a[title="Last viewed by me"],a[title="Due"]');
  if(hs.length == 0) return null;
  return hs.map(function (i, e) {return '.' + $(e).parent().parent().parent().attr('class').match(/col_\d+/)[0];}).get();
}
var cols;
if((cols = getDateColumns())) {
    $(cols.join()).each(function(i, e) {
        var span = $(e).find('span');
        var date = span.text();
        if(date.trim()) {
            var tooltip;
            var m = date.match(/(\d+\/\d+\/\d+) (\(.*\) )?(.*)/);
            if (m) {
                console.log(date + ' ' + m);
                if(m[2]) {
                    date = m[2].replace(/[\(\)]/g, '').trim();
                    if (date == 'Today')
                        date = m[3];
                    tooltip = m[1] + ' ' + m[3];
                }
                else {
                    date = m[1].replace(/\/20(\d\d)/, '/$1');
                    tooltip = m[1] + ' ' + m[3];
                }
                console.log(date + ' ' + tooltip);
                span.text(date).attr({title: tooltip});
            }
        }
    });
}

Hope that helps!

link|flag
This won't work correctly with European date formats like 13-02-2011, does it? – Michel de Ruiter Feb 11 2011 at 22:36
@Michel Probably not. This was just something I hacked together for my own uses (I'm not even on the FogBugz team) but figured might be useful for other people. That said, it should just be a matter of tweaking the date.match() regex. – tghw Feb 12 2011 at 0:01
Right. Would be nice to have some generic way of parsing a displayed date. – Michel de Ruiter Feb 14 2011 at 8:46
I was not able to get the example working as I had hoped, but it sent me in a good direction. This is what I ended up using.. function getDateColumns() { ... } var datelist=""; var cols; if((cols = getDateColumns())) { $(cols.join()).each(function(i, e) { var span = $(e).find('span'); var date = span.text(); if(date.length>0) { var tooltip; tooltip = date; arrDate=date.split(" "); datelist = arrDate[0] + "\n" + datelist; span.text(arrDate[0]).attr({title: tooltip}); } }); } – Lewis Agosta Feb 15 2011 at 18:15
0

Thanks - With your help, I settled on this...

function getDateColumns() {
  var hs = $('#groupHeader_1 th.c-h').find('a[title="Date Closed"],a[title="Date Opened"],a[title="Date Resolved"],a[title="Last Updated"],a[title="Last viewed by me"],a[title="Due"]');
  if(hs.length == 0) return null;
  return hs.map(function (i, e) {return '.' + $(e).parent().parent().parent().attr('class').match(/col_\d+/)[0];}).get();
}
var datelist="";
var cols;
if((cols = getDateColumns())) {
  $(cols.join()).each(function(i, e) {
    var span = $(e).find('span');
    var date = span.text();

    if(date.length>0) {
      var tooltip;
      tooltip = date;
      arrDate=date.split(" ");    
      span.text(arrDate[0]).attr({title: tooltip});
    }
  });
}
link|flag

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.