Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
sopport for "Microsoft" date format: "/Date(1285128000000)/"
23/09/2010
00:14
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony!

From time to time somebody ask why the date format like "/Date(1285128000000)/" are not suported by jqGrid. Today I answerd one more time on the question on the stackoverflow.

Why not make a small modification of the jquery.fmatter.js to support this? It seems to me that one need to add only two lines of code for example atfter the line 144:

if(date.constructor === Number) {
    timestamp = new Date(date);
} else if (typedef date === "string" && /^\/Date\(\d+\)\/$/.test(date)) {
    // Microsoft serialization format for date: "/Date()/"
    timestamp = new Date(parseInt(date.substr(6,date.length-8),10));
} else if(date.constructor === Date) {
    timestamp = date;

Bold text are the suggested lines. What do you think about this?

Best regards
Oleg

09/12/2010
14:55
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony!

I made some more tests and improved my suggestion to have full support of the DateTime .NET format used by Microsoft for serialization in WFC, ASP.NET MVC or ASMX Web Services (so in all kinds of JSON DateTime serialization). The serialized format of DateTime class is described in the section "DateTime Wire Format" of http://msdn.microsoft.com/en-u.....12170.aspx.

The corresponding changes in the jquery.fmatter.js can be following. The lines 142-146

if(date.constructor === Number) {
    timestamp = new Date(date);
} else if(date.constructor === Date) {
    timestamp = date;
} else {

should be replaced to the following

var msDateRegExp = new RegExp("^/Date\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\)/$");
    // the definition of msDateRegExp can be changed to static
var msMatch = date.match(msDateRegExp);
if(date.constructor === Number) {
    timestamp = new Date(date);
} else if(date.constructor === Date) {
    timestamp = date;
} else if (msMatch !== null) {
    // The serialized format of DateTime class is described in the section
    // "DateTime Wire Format" of http://msdn.microsoft.com/en-us/library/bb412170.aspx
    // The date can be sent in one of the following form
    // 1) UTC time will be sent as "/Date(1291813200000)/" or "/Date(-167443200000)/"
    //    (created for example like new DateTime(1964,09,11,0,0,0,0,DateTimeKind.Utc))
    // 2) the local time from a time zone as "/Date(1291813200000+0100)/"
    //    or "/Date(-167443200000+0000)/"
    //
    // msMatch will be array with the following contain
    // msMatch[0] - the string itself
    // msMatch[1] - the number of milliseconds since midnight, January 1, 1970
    //              (may be negative to represent earlier times)
    // msMatch[2] - '' or '-'. '-' if the time is before January 1, 1970
    // msMatch[3] - '' or string like '+0100'
    // msMatch[4] - '' or '+' if d[3]==='+0100'
    // msMatch[5] - '' or '01' if d[3]==='+0100'
    // msMatch[6] - '' or '00' if d[3]==='+0100'
    timestamp = new Date(parseInt(msMatch[1], 10));
    if (msMatch[3]) { // if timezone defined so the time is local and not Utc
        var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
        offset *= ((msMatch[4] == '-') ? 1 : -1);
        offset -= timestamp.getTimezoneOffset();
        timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
    }
} else {

The changes will be useful for all .NET developers. How you can see I use in the code RegExp matching, so I can really sure that the new piece of code will be executed only if the input is exactly in the correct "DateTime Wire Format" used Microsoft.

Best regards
Oleg

19/12/2010
20:04
Avatar
zippy1981
Queens, NY USA
New Member
Members
Forum Posts: 2
Member Since:
19/12/2010
sp_UserOfflineSmall Offline

Tony,

I would really like to see this feature too.

Oleg,

Thanks for writing this patch.

20/12/2010
01:16
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello zippy1981,

Thanks for your assistance. Tony not wrote this information here, but he made the fix which I suggested (see here) and the corresponding feature is already a part of jqGrid 3.8.2 (see the last line in the list of "additions and changes" of the jqGrid 3.8.1 here).

Best regards
Oleg 

04/01/2011
09:15
Avatar
sugden
Member
Members
Forum Posts: 5
Member Since:
04/01/2011
sp_UserOfflineSmall Offline

Hi Tony/Oleg,

jqGrid 3.8.1 is not working with the .Net DateTime for me. I think your line:

var msDateRegExp = new RegExp("^/Date\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\)/$");

should be:

var msDateRegExp = new RegExp("^/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)/$");

Note the extra escape characters - let me know what you think.

Regards,

Scott

04/01/2011
14:33
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Sorry Scott,

but if you will read carefully the current thread, .NET DateTime format are supported starting with jqGrid 3.8.2 and not exist in jqGrid 3.8.1 which you use. Moreover in the code which I suggested and which is included in jqGrid 3.8.2 the msDateRegExp is already defined as

var msDateRegExp = new RegExp("^/Date\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\)/$");

So it seems to me you should just use jqGrid 3.8.2.

Best regards
Oleg

04/01/2011
21:28
Avatar
sugden
Member
Members
Forum Posts: 5
Member Since:
04/01/2011
sp_UserOfflineSmall Offline

Hi Oleg

My apologies - a late night.

I am using jqGrid 3.8.2 and it is not working with a .Net DateTime. I get NaN/NaN/NaN.

When I posted the reg expression I did not notice that the forum was trimming a "".

I feel it should be - note the double "\" before the the "(":

var msDateRegExp = new RegExp("^/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)/$")

Thanks,
Scott
04/01/2011
21:29
Avatar
sugden
Member
Members
Forum Posts: 5
Member Since:
04/01/2011
sp_UserOfflineSmall Offline

Ah – Its done it again. Lets try:

var msDateRegExp = new RegExp("^/Date\\\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\\\)/$");
04/01/2011
23:39
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Thank you very much Scott!

It is very hard to here, but the forum software has really hard and evil bug. I tested carefully my code before past it here. Of cause I didn't verify the code character per character after the pasting. Not I see that from the original RegEx

"^\\/Date\\\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\\\)\\\/$"

4 characters (4 backslashes) was cut and we have the text

"^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"

in the code of jqGrid 3.8.2. Please try one more time with the RegEx

"^\\/Date\\\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\\\)\\\/$".

I don't verified other parts of the code. I'm really frustrated. Moreover curently I have less free time as before.
It all will works OK.
I hope Tony will read the post and fix the code of jqGrid. If he write no comments in the next 7 days I'll post a new bug report.

Best regards and thanks one more time
Oleg

05/01/2011
00:27
Avatar
sugden
Member
Members
Forum Posts: 5
Member Since:
04/01/2011
sp_UserOfflineSmall Offline

Oleg,

I agree - very frustrating

Many thanks,

Scott

09/01/2011
14:25
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Will be fixed. Thanks.

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

11/01/2011
16:16
Avatar
typhoon1978
Milan, Italy
New Member
Members
Forum Posts: 1
Member Since:
11/01/2011
sp_UserOfflineSmall Offline

Hi all !

I'm using jqGrid 3.8.2 to show data coming from a ASP.NET web service.

As far as I understood jqGrid natively understands MS DateTime Wire Format by default (since 3.8.2) and this is good, but it renders something like:

NaN/NaN/NaN

Probably I have to set some "magic" string to make jqGrid understand it is reading a MS DateTime ? Is there any particular configuration ?

Or probably we are talking about an open issue (because I read "will be fixed") ?

Thanks in advance,

Alex

13/01/2011
03:16
Avatar
sugden
Member
Members
Forum Posts: 5
Member Since:
04/01/2011
sp_UserOfflineSmall Offline

It's the same (open) issue. Tony has noted that it will be fixed.

Scott

15/01/2011
15:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Also fixed in GitHub. 

Hope in the future to use GitHub for such kind of patches Wink

Thanks again to all.

P.S. It is quite possible that this is not the last fix Laugh

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

16/01/2011
20:01
Avatar
nowol
Member
Members
Forum Posts: 3
Member Since:
16/01/2011
sp_UserOfflineSmall Offline

Hi,

I checked the RegEx code in GitHub and there is an error in the regular expression. 

You only need one backslash before the parentheses instead of two.

Cheers,

NoWoL

16/01/2011
23:59
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi NoWoL,

do you tested the code published from in GitHub or it seems to you that the RegEx is wrong? I don't yet tested the code one more time, but now the RegEx is exactly like in the version which I used and tested many times with different data before I posted the information here.

Probably you use frequently the form /pattern/modifier of RegEx and not constructor of RegEx with the string literal. There are some difference in coding of backslashes in the two forms. See for example "How to Use The JavaScript RegExp Object" section of this.

If you will find a bug in the code you are welcome, but please test the code and post exactly which input data will be wrong converted by the code. Which result should be and which wrong result produce the code.

Best regards
Oleg 

17/01/2011
04:11
Avatar
nowol
Member
Members
Forum Posts: 3
Member Since:
16/01/2011
sp_UserOfflineSmall Offline

Hi Oleg,

You are correct, I did not expect the code to change from the /pattern/modifier to the RexExp object.

Is there a design document for this grid?  I just upgraded from 3.6.4 to 3.8.2 for the new date formatter and I found a bug and I would like to try my hand at fixing it.  This is the bug: if the value of index in a colModel contains a period e.g.: "Person.Name" the value passed (sidx) to the web service contains only "Name".  It worked in 3.6.4 but it was broken in 3.6.5.

Best regards,

NoWoL

17/01/2011
07:14
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi NoWoL,

The problem, which you describe with index having period seems for me a bug. The same problem are described here and here. I can imagine that having periods in the index can be important if database schema used on the database, but having index with period in case of pure local data (not "json" datatype and loadonce:true) and can be replaced with jsonmap. So the bug in the case makes have a simple workaround. Which scenario has you?

Nevertheless it is absolutely another problem not connected with the "Microsoft" data format. You can post additional information to the bug report to remind Tony about the problem. I am not a developer of jqGrid and I am additionally busy for at least next two weeks. So please contact Tony about the problem yourself.

Best regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
60 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information