3.0.5

Active.Formats.Date fix

Here is the corrected code for Active.Formats.Date class. It fixes the bug where the months were offset by 1 when formatted as number ('m' and 'mm' tokens). It also allows to specify error value (was ignored previously) so you can push the non-dates on top or bottom when sorted.

/*****************************************************************

    ActiveWidgets Grid 1.0.1 (Free Edition).
    Copyright (C) 2004 ActiveWidgets Ltd. All Rights Reserved.
    More information at http://www.activewidgets.com/

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*****************************************************************/

Active.Formats.Date = Active.System.Format.subclass();

Active.Formats.Date.create = function(){

/****************************************************************

    Date formatting class.

*****************************************************************/

    var obj = this.prototype;

    obj.date = new Date();

    obj.digits = [];
    obj.shortMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
    obj.longMonths = ["January","February","March","April","May","June","July","August","September","October","November","December"];
    obj.shortWeekdays = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
    obj.longWeekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

    for(var i=0; i<100; i++){obj.digits[i] = i<10 ? "0" + i : "" + i}

    var tokens = {
        "hh"	: "this.digits[this.date.getUTCHours()]",
        ":mm"	: "':'+this.digits[this.date.getUTCMinutes()]",
        "mm:"	: "this.digits[this.date.getUTCMinutes()]+':'",
        "ss"	: "this.digits[this.date.getUTCSeconds()]",
        "dddd"	: "this.longWeekdays[this.date.getUTCDay()]",
        "ddd"	: "this.shortWeekdays[this.date.getUTCDay()]",
        "dd"	: "this.digits[this.date.getUTCDate()]",
        "d"		: "this.date.getUTCDate()",
        "mmmm"	: "this.longMonths[this.date.getUTCMonth()]",
        "mmm"	: "this.shortMonths[this.date.getUTCMonth()]",
        "mm"	: "this.digits[this.date.getUTCMonth()+1]",
        "m"		: "(this.date.getUTCMonth()+1)",
        "yyyy"	: "this.date.getUTCFullYear()",
        "yy"    : "this.digits[this.date.getUTCFullYear()%100]" };

    var match = "";
    for(i in tokens){
        if (typeof(i) == "string"){
            match += "|" + i;
        }
    }
    var re = new RegExp(match.replace("|", "(")+")", "gi");

/****************************************************************

    Allows to specify the format for the text output.

    @param	format	(String) Format pattern.

*****************************************************************/

    obj.setTextFormat = function(format){
        format = format.replace(re, function(i){return "'+" + tokens[i.toLowerCase()] + "+'"});
        format = "if (isNaN(value) || (value === this._valueError)) return this._textError;" +
                 "this.date.setTime(value + this._textTimezoneOffset);" +
                ("return '" + format + "'").replace(/(''\+|\+'')/g, "");
        this.valueToText = new Function("value", format);
    };

    var xmlExpr = /^(....).(..).(..).(..).(..).(..)........(...).(..)/;
    var xmlOut = "$1/$2/$3 $4:$5:$6 GMT$7$8";

    var auto = function(data){
        var value = Date.parse(data + this._dataTimezoneCode);
        return isNaN(value) ? this._valueError : value;
    };

    var RFC822 = function(data){
        var value = Date.parse(data);
        return isNaN(value) ? this._valueError : value;
    };

    var ISO8061 = function(data){
        var value = Date.parse(data.replace(xmlExpr, xmlOut));
        return isNaN(value) ? this._valueError : value;
    };

/****************************************************************

    Allows to specify the wire format for data input.

    @param	format	(String) Format pattern.

*****************************************************************/

    obj.setDataFormat = function(format){
        if (format == "RFC822") {
            this.dataToValue = RFC822;
        }
        else if (format == "ISO8061") {
            this.dataToValue = ISO8061;
        }
        else {
            this.dataToValue = auto;
        }
    };

/****************************************************************

    Allows to specify the timezone used for the text output.

    @param	value	(Number) Timezone offset.

*****************************************************************/

    obj.setTextTimezone = function(value){
        this._textTimezoneOffset = value;
    };

/****************************************************************

    Allows to specify the timezone used for the data input.

    @param	value	(Number) Timezone offset.

*****************************************************************/

    obj.setDataTimezone = function(value){
        if (!value) {
            this._dataTimezoneCode = " GMT";
        }
        else {
            this._dataTimezoneCode = " GMT" +
                (value>0 ? "+" : "-") +
                this.digits[Math.floor(Math.abs(value/3600000))] +
                this.digits[Math.abs(value/60000)%60];
        }
    };

    var localTimezone = - obj.date.getTimezoneOffset() * 60000;

    obj.setTextTimezone(localTimezone);
    obj.setDataTimezone(localTimezone);

    obj.setTextFormat("d mmm yy");
    obj.setDataFormat("default");
};

Active.Formats.Date.create();
Alex (ActiveWidgets)
May 28,
Alex, This bug still exists in current release :-( I downloaded the latest and verified it.

Wouldn’t be it better if you integrate bug-fix (es) into latest release? Else people will discover same bug after spending many un-fruitful hours.

Request.response() - is another bug on the top of my head.

ref: http://www.activewidgets.com/messages/1788-14.htm

also

ref: http://www.activewidgets.com/messages/1608-2.htm

Other people are requested to contribute what I have missed here.
Sudhaker Raj
October 1,
Until the latest version of the runtime is updated, make the following changes.

Change from:
<script src="../../../runtime/lib/grid.js"></script>

To:
<script src="../../../source/lib/grid.js"></script>

Joe
October 4,
Agree, it's time to make a bugfix release.
Alex (ActiveWidgets)
October 7,
Bump...
bugfix realease please!
Giovanni
December 10,
sure
da
December 14,
Bug fix ready yet?
January 27,
No bug fix?
February 15,
Hai,
I am new to this forum and to JavaScript as well.
I have hyperlinks called "start Date" and "End Date".
(I use uparrow.gif for sorting in Ascending Order and downarrow.gif for sorting in Descending order)
when I am clicking "Start Date" it should sort the items in "Ascending order" by default. This is same for "End Date" also.
After clicking "Start Date", I would like to click the "End Date", then the image for "Start Date" should be vanished and the image for "End Date" should appear with the "End Date" hyperlink.
(Like the one we see in "Date" in Yahoo Mail).

I tried to work out this, but not getting the correct code.

Can anyone help me to place the image nearer the selected hyperlink?

It would be very helpful.
Thanking You.
Yogesh
February 18,
This code is now released in version 1.0.1
Alex (ActiveWidgets)
May 11,
I believe you mean ISO8601 instead of 8061; tha latter concerns the bindings of ski boots; whereas 8601 is for date formats.
Deron Meranda
May 13,
!!!!!!

Thank you Deron (and shame on me). Will correct this :-(
Alex (ActiveWidgets)
May 14,
I just downloaded the latest grid version and the date sorting problem is still there.

The sorting function does not seem to know the difference between year, month, and day, and that they should always be sorted in that order. The problem also presents itself when sorting IP addresses. The last octet is sorted in a random order.

As for blank cells messing up the date sorting, I partially solved this by replacing any blank or null cell with &nbsp;. Now at least all the blank dates go to the top or to the bottom, but the dates themselves are not sorted correctly no matter what I try.

Hope this sheds some light into what the right solution should be.
Jorge
September 2,
Have same Date sorting problem. Starts with 01.09.05, 01.08.05 etc 02.06.05, 02.07....

Anyone seen an example of date sorting working?

Chrs.
ZMax
September 3,
Want a complete example to sort date or how to disable particular column since i dont want users to click date column alone to be sorted. how to acheive this
Satish
September 5,
Some great products here,

Shame it looks like a one man show with little support. Based on the length of this outstanding issue, don't see how I can ask my company to purchase this product.

The example on the website doesn't even sort dates properly.

http://www.activewidgets.com/grid/

I guess i'll have to wait and see what happens.
Dale Fraser
November 23,
with an the xml based table (possibly others too but that i don't know) it is possible to sort on dates correctly, without the bug (using version 2). I am using the dd-mm-yyyy format.
Rik Smith
November 23,

This topic is archived.

See also:


Back to support forum