:: Forum >>

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)
Friday, May 28, 2004
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
Friday, October 1, 2004
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
Monday, October 4, 2004
Agree, it's time to make a bugfix release.
Alex (ActiveWidgets)
Thursday, October 7, 2004
Bump...
bugfix realease please!
Giovanni
Friday, December 10, 2004
sure
da
Tuesday, December 14, 2004
Bug fix ready yet?
Thursday, January 27, 2005
No bug fix?
Tuesday, February 15, 2005
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
Friday, February 18, 2005
This code is now released in version 1.0.1
Alex (ActiveWidgets)
Wednesday, May 11, 2005
I believe you mean ISO8601 instead of 8061; tha latter concerns the bindings of ski boots; whereas 8601 is for date formats.
Deron Meranda
Friday, May 13, 2005
!!!!!!

Thank you Deron (and shame on me). Will correct this :-(
Alex (ActiveWidgets)
Saturday, May 14, 2005
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
Friday, September 2, 2005
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
Saturday, September 3, 2005
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
Monday, September 5, 2005
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
Wednesday, November 23, 2005
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
Wednesday, November 23, 2005

This topic is archived.


Back to support forum

Forum search