Path: csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.38.237.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Measuring time (was: Random numbers) Date: Sun, 29 Oct 2017 17:56:25 +0100 Organization: PointedEars Software (PES) Lines: 66 Message-ID: <5089967.DvuYhMxLoT@PointedEars.de> References: <2345791.k3LOHGUjKi@PointedEars.de> <2876676.AJdgDx1Vlc@PointedEars.de> <8f442f26-987b-4482-bf5f-775856a0a3b8@googlegroups.com> <5883795.4vTCxPXJkl@PointedEars.de> <7b7114cd-8e1a-49f3-b69f-9a23e95d280c@googlegroups.com> <4045820.LvFx2qVVIh@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="38.237.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch:178.197.237.38"; logging-data="29930"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.2 Cancel-Lock: sha1:0wBNgnsNFyDUqJMP9pPtl1Fm6eQ= X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. […] Thomas 'PointedEars' Lahn wrote: >> > On Tue, 24 Oct 2017 13:05:49 -0700 (PDT), Dr J R Stockton wrote: >> >> IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for >> >> most of Year 0. >> >> AFAICS, the result for Y === 0 is only wrong (not as specified) if N < >> 366 and one expects a date that is not in 1900 CE. > > There is only one such date; No, I meant if one expected a date in 1 BCE instead of 1900 CE. > there was no 1900-02-29. | -> new Date(0, 0, 1) | <- Mon Jan 01 1900 00:00:00 GMT+0100 (CET) | | -> new Date(0, 1, 29) | <- Thu Mar 01 1900 00:00:00 GMT+0100 (CET) > But the following code yields merely 59 :- > S = "" > for (N=1 ; N<400 ; N++) { > D1 = new Date(0e3, 0, N).getDate() > D2 = new Date(2e3, 0, N).getDate() Undeclared variable, unwise identifiers. > S += "+" + +(D1==D2) } An Array instance is a lot more efficient for this: var a = []; for (…) { a.push("…"); } var s = a.join("+"); > eval(S) Please don’t. var count = 0; for (var n = 1; n < 400; ++n) { var d1 = (new Date(0e3, 0, n)).getDate(); var d2 = (new Date(2e3, 0, n)).getDate(); count += +(d1 == d2); } console.log(count); > In a normal year, January+February is 59 days; the rest are wrong. I do not see your point. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.