Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33408
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: convert dob into days |
| Date | 2017-05-25 13:45 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1695443.taCxCBeP46@PointedEars.de> (permalink) |
| References | <d839a415-1bb6-485b-a72d-ca9cd4984b52@googlegroups.com> <3168351.R56niFO833@PointedEars.de> <zSmVA.27368$Qg.7212@fx14.iad> <3278626.MHq7AAxBmi@PointedEars.de> <tFpVA.38624$8c1.28455@fx19.iad> |
Mark Lloyd wrote: > On 05/24/2017 06:00 PM, Thomas 'PointedEars' Lahn wrote: >> Mark Lloyd wrote: >>> On 05/24/2017 01:06 PM, Thomas 'PointedEars' Lahn wrote: >>>> That aside, as you are looking for days and are rounding anyway, >>>> so that DST does not matter, the basic approach is correct. >>> There is still a possibility of an error here, if you run this >>> calculation late in the day. >> With rounding? > > Maybe not, but setting the time to noon makes it even less likely. I > know some people don't see things that way, With rounding to integer, as the OP did, it is not possible to get the wrong *number of days*, which the OP was looking for. If DST switches occurred in-between, the calculated difference in milliseconds could be off by at most 3'600'000 (1 standard hour) which amounts to about 0.04167 times the standard day of 86'400'000 milliseconds that they used. | > new Date(2017, 2, 25) | <- Sat Mar 25 2017 00:00:00 GMT+0100 (CET) | | > new Date(2017, 2, 26) | <- Sun Mar 26 2017 00:00:00 GMT+0100 (CET) | | > new Date(2017, 2, 27) | <- Mon Mar 27 2017 00:00:00 GMT+0200 (CEST) | | > new Date(2017, 2, 26) - new Date(2017, 2, 25) | <- 86400000 | | > new Date(2017, 2, 27) - new Date(2017, 2, 26) | <- 82800000 | | > (new Date(2017, 2, 27) - new Date(2017, 2, 26)) / 864e5 | <- 0.9583333333333334 | | > new Date(2017, 9, 28) | <- Sat Oct 28 2017 00:00:00 GMT+0200 (CEST) | | > new Date(2017, 9, 29) | <- Sun Oct 29 2017 00:00:00 GMT+0200 (CEST) | | > new Date(2017, 9, 30) | <- Mon Oct 30 2017 00:00:00 GMT+0100 (CET) | | > new Date(2017, 9, 29) - new Date(2017, 9, 28) | <- 86400000 | | > new Date(2017, 9, 30) - new Date(2017, 9, 29) | <- 90000000 | | > (new Date(2017, 9, 30) - new Date(2017, 9, 29))/864e5 | <- 1.0416666666666667 | | > navigator.userAgent | <- "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) | Chrome/57.0.2987.98 Safari/537.36" > but a little work here can prevent an unanticipated error later. Premature optimization is the root of all evil. Suppose the OP bought into that approach and concluded that this would mean that they would never have to do the rounding, someone in the country of Absurdistan[tm] where clocks are switched at noon (when people would have siesta anyway) would get the wrong value for their age in days if an odd number of DST switches would lie between the dates. >> Your From header field value is disregarding Netiquette. > > I haven't heard that one before. What about it to you consider > undesirable? Use of the “invalid” TLD by you is blocking the private e-mail feedback channel which is an important part of Usenet communication. See also <http://www.interhack.net/pubs/munging-harmful/>. -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
convert dob into days negisunny38@gmail.com - 2017-05-24 09:58 -0700
Re: convert dob into days "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-24 19:16 +0200
Re: convert dob into days negisunny38@gmail.com - 2017-05-24 10:31 -0700
Re: convert dob into days "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-24 23:08 +0200
Re: convert dob into days Mark Lloyd <not@mail.invalid> - 2017-05-24 16:33 -0500
Re: convert dob into days "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-25 16:29 +0200
Re: convert dob into days Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-24 20:06 +0200
Re: convert dob into days Mark Lloyd <not@mail.invalid> - 2017-05-24 16:24 -0500
Re: convert dob into days Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-25 01:00 +0200
Re: convert dob into days Mark Lloyd <not@mail.invalid> - 2017-05-24 19:35 -0500
Re: convert dob into days Jon Ribbens <jon+usenet@unequivocal.eu> - 2017-05-25 11:27 +0000
Re: convert dob into days Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-25 13:45 +0200
Re: convert dob into days Mark Lloyd <not@mail.invalid> - 2017-05-25 13:35 -0500
Re: convert dob into days Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-26 00:35 +0200
Re: convert dob into days Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-25 15:45 -0700
Re: convert dob into days "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-26 09:12 +0200
Re: convert dob into days Dr J R Stockton <reply1700@merlyn.demon.co.uk.invalid> - 2017-05-26 18:40 +0100
Re: convert dob into days Sam E <why.should.this@be.email.invalid> - 2017-05-27 10:14 -0500
Re: convert dob into days Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-24 14:36 -0700
csiph-web