PDA

View Full Version : JS Binary Date Format



828
20 Feb 2009, 10:22 AM
What is everyone doing to convert the Microsoft Serialized dates? ie: \/Date(12321323143)\/

Currently, we have to data fields. One with that date and the other as a string of that date. However, when we try and populate the grid with the serialized date, nothing shows up in the grid. If we load the string date into the gird, we can't remote sort the column.

I have seen some people use reg expressions to change the serialized date into a useable date in the convert() method, however, is this the proper way to do it? Where would that go (column model, Ext.Record, etc.)?

20 Feb 2009, 10:23 AM
What is everyone doing to convert the Microsoft Serialized dates? ie: \/Date(12321323143)\/

Currently, we have to data fields. One with that date and the other as a string of that date. However, when we try and populate the grid with the serialized date, nothing shows up in the grid. If we load the string date into the gird, we can't remote sort the column.

I have seen some people use reg expressions to change the serialized date into a useable date in the convert() method, however, is this the proper way to do it? Where would that go (column model, Ext.Record, etc.)?

that look slike the unix date model, not binary dates.

binary means 1 and 0s

828
20 Feb 2009, 10:26 AM
Microsoft Serialized Dates? Is that a bit better? I have seen you comment on a few other posts about it, but I feel like I never got a correct solution.

One guy said to use string dates because of the time zone differences, but then you can't remote sort a string date from the server... right?

mystix
20 Feb 2009, 10:55 AM
some possible solutions:
http://extjs.com/forum/showthread.php?t=6149
http://extjs.com/forum/showthread.php?t=41182

828
20 Feb 2009, 11:17 AM
Thanks mystix. I did see those two/three posts before, however they were posted months ago. Thought things could have changed since then.

So, if I use the regex version, I would use the convert() method in my Record.create?

Where would that go?


([{name:'someDate', type:'date'}]) - ??? Or

would I have to just format it when the date comes in right after the call -
this.Data = DeserializeJSON(response.responseText); Wouldn't that mess up the rest of the response?

mystix
21 Feb 2009, 7:15 AM
the convert config goes in the column definition:


{name:'someDate', type:'date', convert: function(dateStr) {
// perform regex replacement here
}}

see the docs for Ext.data.Record.create() for more info on the convert config.

828
10 Mar 2009, 10:56 AM
my regex just converts the date to look like this: /Date(628318530718)/ - how can I use that? I just get 'Invalid Date' in FF or 'Nan' in IE.

http://weblogs.asp.net/bleroy/archiv...-and-json.aspx (http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx)
https://extjs.com/forum/showthread.php?t=31599&page=2

I tried to slice the ticks out of the date: new Date(parseInt("\/Date(628318530718)\/".slice(6,18)))

I got a date to display in the grid. A wrong date, but a date was displayed.

828
10 Mar 2009, 12:23 PM
Nevermind - this seems to work:
http://extjs.com/forum/showthread.php?t=31599&page=2


function convertDate(v, mix) {
return new Date(parseFloat(v.slice(6, 19))).toLocaleString();
}

var contentStore = new Ext.data.WCFJsonStore({
url: 'Services/ContentManagementService.svc/getContents',
baseParams: { channelSlug: '' },
fields: ['Title', { name: 'DateModified', convert: convertDate }, 'ModifiedBy', { name: 'DateCreated', convert: convertDate }, 'CreatedBy']
});
contentStore.load();

Not sure if it's the right way, but it works.

mystix
10 Mar 2009, 5:47 PM
your regex is most likely incorrect. use this regex:
http://extjs.com/forum/showthread.php?p=179327#post179327 (i think i referred to it at least twice in the links i posted)

828
11 Mar 2009, 6:48 AM
Mystix,

I tried that regEx and it returned a date format of "/Date(342342321121)/". I tried a bunch of regEx and got the same result - some with "()" around the whole date, some without.

Either way, it seems like the slice method works out just fine. Thanks for the help. It was a pain but it seems to work now.

mystix
11 Mar 2009, 10:35 AM
i don't know which regex you were referring to, but this is what i'm talking about:


function convertM$Date(v) {
var msdateRe = /\/Date\((\d+)\)\//;

return new Date(parseInt(v.replace(msdateRe, '$1')))
}

// returns the Date object representing "Wed Nov 29 1989 12:55:30 GMT+0800 (MALST)" on my box
convertM$Date('\/Date(628318530718)\/');

i should think the regex method is safer because it makes no assumptions about the length of the integer value you're attempting to parse out of the m$ date string.