actionscript 3 - january 31 2012 UTC time jump -
i'm working on flash project uses xml-data database through php generate graphs. draw on right spot want convert dates numbers , thought date.utc(yyyy,mm,dd) answer. reason doesn't convert linearly. as3-code:
private function valuedispatcher(e:event):void { debugfield.appendtext("succes= "+e.target.data.succes); if (e.target.data.succes) { var myxml:xml = new xml(e.target.data.xml); var mylist:xmllist = new xmllist(myxml.children()); debugfield.appendtext("\nxml[0]= " + mylist[0]); debugfield.appendtext("\nxml[0].time= "+mylist[0].time); (var i:int = 0; < mylist.length(); i++) { var splitter:array = string(mylist[i].time).split("-"); var seconds:number = date.utc(int(splitter[0]),int(splitter[1]),int(splitter[2]),1,0,0,0); var ar:array = [mylist[i].time, seconds, mylist[i].verbruik, mylist[i].corr]; debugfield.appendtext("\nar= "+ar); maxtot = math.max(maxtot,mylist[i].verbruik,mylist[i].corr); values.push(ar); if(mylist[i].corr!=null){ comparenr++; cumul1 += mylist[i + 365].verbruik; cumul2 += mylist[i].corr; } } } else { fakedata(); debugfield.appendtext("\n values= "+values); } } private function fakedata():void { var date: date = new date(2012, 01, 28); var first:boolean = true; var corr; (var i:int = 0; <= 500; i++) { var datestring:string = "" + date.getfullyear() + "-" + date.getmonth() + "-" + date.getdate(); var utcseconds:number = date.utc(date.getfullyear(), date.getmonth(), date.getdate()); var gebr:number; if (first) { gebr = math.round((2.3 + math.random() * 40) * 1000) / 1000; first = false; } else { gebr = math.round((math.max(4, math.min(47, values[i - 1][2] - 5 + math.random() * 10)))*1000)/1000; } corr = 10; if (i > 134) corr = -1; var ar:array = [datestring, utcseconds, gebr, corr]; values.push(ar); maxtot = math.max(maxtot, gebr, corr); if(corr!=-1){ comparenr++; } date.date++; } (var j:int = 0; j < comparenr; j++) { corr = values[j][2] * 0.6 + values[j + 365][2] * 0.4; values[j][3] = corr; cumul1 += values[j + 365][2]; cumul2 += values[j][3]; } }
so function fakedata() called when i'm operating offline otherwise should use xml data.
the problem seem have in 'web-mode': date.utc(2012,1,31) = 1330646400000 > date.utc(2012,2,1) = 1330560000000 while equal date.utc(2012,2,2) = 1330646400000
while in off-line mode line date.date++ seems make go straight 2012|1|29 2012|2|2
what happening here???
debugfield output online:
succes= true xml[0]= <tag> <time>2012-01-31</time> <verbruik>51.413</verbruik> <corr>41.239</corr> </tag> xml[0].time= 2012-01-31 ar= 2012-01-31,1330650000000,51.413,41.239 ar= 2012-02-01,1330563600000,44.178,43.196 ar= 2012-02-02,1330650000000,24.790,42.459 ar= 2012-02-03,1330736400000,51.494,57.789 ar= 2012-02-04,1330822800000,36.498,43.010 ar= 2012-02-05,1330909200000,32.483,40.951 ar= 2012-02-06,1330995600000,32.347,31.762 ar= 2012-02-07,1331082000000,47.655,45.023 ar= 2012-02-08,1331168400000,44.164,39.372 ar= 2012-02-09,1331254800000,44.016,52.159 ar= 2012-02-10,1331341200000,48.150,50.561 ar= 2012-02-11,1331427600000,59.129,59.882 ar= 2012-02-12,1331514000000,52.112,43.381 ar= 2012-02-13,1331600400000,44.064,41.240 ar= 2012-02-14,1331686800000,47.609,55.833 ar= 2012-02-15,1331773200000,40.153,55.569 ar= 2012-02-16,1331859600000,51.860,43.342 ar= 2012-02-17,1331946000000,40.252,30.049 ar= 2012-02-18,1332032400000,32.464,26.127
debugfield output offline
succes= undefined values= 2012-1-28,1330387200000,36.374,27.516000000000002,2012-1-29,1330473600000,33.566,24.077600000000004,2012-2-1,1330560000000,30.34,23.54,2012-2-2,1330646400000,29.529,21.6454,2012-2-3,1330732800000,29.413,22.931,2012-2-4,1330819200000,30.146,22.745199999999997,2012-2-5,1330905600000,27.961,20.565399999999997,2012-2-6,1330992000000,25.279,20.3054,2012-2-7,1331078400000,25.454,22.2524,2012-2-8,1331164800000,23.905,22.4102,2012-2-9,1331251200000,19.356,20.044400000000003,2012-2-10,1331337600000,18.32,17.900399999999998,2012-2-11,1331424000000,15.984,16.8312,2012-2-12,1331510400000,11.598,14.224400000000001,2012-2-13,1331596800000,13.081,16.643,2012-2-14,1331683200000,13.842,18.5728,2012-2-15,1331769600000,13.669,17.867,2012-2-16,1331856000000,17.472,20.4096,2012-2-17,1331942400000,17.512,18.714,2012-2-18,1332028800000,18.39,18.971200000000003,2012-2-19,1332115200000,21.985,19.235799999999998,2012-2-20,1332201600000,18.049,18.2298,2012-2-21,1332288000000,20.269,18.0362,2012-2-22,1332374400000,19.88,15.9452,2012-2-23,1332460800000,17.259,16.1194,2012-2-24,1332547200000,13.054,14.1248,2012-2-25,1332633600000,8.401,10.4042,2012-2-26,1332720000000,7.112,11.0588,2012-2-27,1332806400000,5.487,9.2158,2012-2-
as always, incorrectly read manual. 01
month february, not january. january, use 0.
Comments
Post a Comment