Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26110 > unrolled thread
| Started by | Swifty <steve.j.swift@gmail.com> |
|---|---|
| First post | 2014-11-11 12:38 +0000 |
| Last post | 2014-11-14 04:34 +0100 |
| Articles | 20 on this page of 97 — 16 participants |
Back to article view | Back to comp.lang.javascript
Date arithmetic Swifty <steve.j.swift@gmail.com> - 2014-11-11 12:38 +0000
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-11 15:10 +0100
Re: Date arithmetic Swifty <steve.j.swift@gmail.com> - 2014-11-11 22:07 +0000
Re: Date arithmetic Tim Streater <timstreater@greenbee.net> - 2014-11-11 22:37 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-12 02:40 +0100
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-12 08:21 +0100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 15:27 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 21:26 +0100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-14 14:16 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-15 07:13 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-15 19:36 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-16 17:24 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-16 18:49 +0100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-17 00:14 +0100
Re: Date arithmetic Dr J R Stockton <J.R.Stockton@physics.org> - 2014-11-16 10:51 -0800
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-16 20:17 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-17 00:52 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-17 01:11 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-18 16:18 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-19 11:00 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-21 22:58 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-22 18:33 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-23 19:38 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-24 01:14 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-25 21:17 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-26 18:25 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-27 19:34 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-28 01:25 +0100
Re: Date arithmetic Dr J R Stockton <J.R.Stockton@physics.org> - 2014-11-28 05:29 -0800
Re: Date arithmetic Andrew Poulos <ap_prog@hotmail.com> - 2014-11-28 11:44 +1100
Re: Date arithmetic Dr J R Stockton <J.R.Stockton@physics.org> - 2014-11-28 04:52 -0800
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-28 14:24 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-28 14:47 +0100
Re: Date arithmetic Dr J R Stockton <J.R.Stockton@physics.org> - 2014-11-28 06:12 -0800
Re: Date arithmetic Andrew Poulos <ap_prog@hotmail.com> - 2014-11-29 16:59 +1100
Re: Date arithmetic John Harris <niam@jghnorth.org.uk.invalid> - 2014-11-29 20:05 +0000
Re: Date arithmetic Joao Rodrigues <groups_jr-1@yahoo.com> - 2014-11-29 23:47 -0200
Re: Date arithmetic Andrew Poulos <ap_prog@hotmail.com> - 2014-12-01 10:44 +1100
Re: Date arithmetic Tim Streater <timstreater@greenbee.net> - 2014-11-30 23:54 +0000
Re: Date arithmetic Andrew Poulos <ap_prog@hotmail.com> - 2014-12-01 13:01 +1100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-17 01:34 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-17 01:41 +0100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-18 19:06 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-18 16:26 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-19 17:52 +0100
Re: Date arithmetic Gene Wirchenko <genew@telus.net> - 2014-11-19 09:44 -0800
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-19 19:34 +0100
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-19 19:13 +0000
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-19 22:18 +0100
Re: Date arithmetic Gene Wirchenko <genew@telus.net> - 2014-11-19 13:43 -0800
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-19 22:40 +0000
Re: Date arithmetic Tim Streater <timstreater@greenbee.net> - 2014-11-19 22:51 +0000
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-19 23:35 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-19 23:10 +0100
Re: Date arithmetic Tim Streater <timstreater@greenbee.net> - 2014-11-19 22:32 +0000
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-19 23:26 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-20 00:47 +0100
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-20 00:17 +0000
Re: Date arithmetic Dr J R Stockton <J.R.Stockton@physics.org> - 2014-11-20 01:18 -0800
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-20 13:47 +0000
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-21 22:29 +0000
Re: Date arithmetic Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-11-19 19:24 -0200
Re: Date arithmetic Gene Wirchenko <genew@telus.net> - 2014-11-19 13:40 -0800
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-19 23:40 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-18 16:44 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-19 11:20 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-14 20:45 +0000
Re: Date arithmetic "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-11-15 14:13 -0800
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-15 23:42 +0100
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-11-12 00:23 +0100
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-12 13:24 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-12 14:43 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-12 19:48 +0100
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 01:18 +0100
Re: Date arithmetic Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-11-12 20:19 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 03:42 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-12 20:06 +0000
Re: Date arithmetic RobG <rgqld@iinet.net.au> - 2014-11-23 20:51 -0800
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-25 20:08 +0000
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-26 01:31 +0100
Re: Date arithmetic RobG <rgqld@iinet.net.au> - 2014-12-08 19:42 -0800
Re: Date arithmetic "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-26 01:40 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-26 22:07 +0100
Re: Date arithmetic RobG <rgqld@iinet.net.au> - 2014-12-08 21:41 -0800
Re: Date arithmetic "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-12-09 09:47 +0100
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-09 14:17 +0100
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-12-10 23:34 +0000
Re: Date arithmetic RobG <rgqld@iinet.net.au> - 2014-12-10 17:21 -0800
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-12-13 17:19 +0000
Re: Date arithmetic RobG <rgqld@iinet.net.au> - 2014-12-10 18:35 -0800
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-11 22:29 +0100
Re: Date arithmetic Swifty <steve.j.swift@gmail.com> - 2014-11-11 21:53 +0000
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-11 23:43 +0100
Re: Date arithmetic John Harris <niam@jghnorth.org.uk.invalid> - 2014-11-12 15:49 +0000
Re: Date arithmetic Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-11-12 19:58 +0000
Re: Date arithmetic Dr.Kral@nyc.rr.com - 2014-11-13 20:24 -0500
Re: Date arithmetic Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-14 04:34 +0100
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-11-21 22:29 +0000 |
| Message-ID | <xb2UNwM8y7bUFwEZ@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #26171 |
In comp.lang.javascript message <191120142232431812%timstreater@greenbee
.net>, Wed, 19 Nov 2014 22:32:43, Tim Streater
<timstreater@greenbee.net> posted:
>In article <877fyr3sxr.fsf@bsb.me.uk>, Ben Bacarisse
><ben.usenet@bsb.me.uk> wrote:
>> ECMAScript does not have a separate integer type. You can represent
>>any
>> integer in (2^53, 2^53) exactly (and zero twice!) using the built-in
>> Number type, but you are still using a floating point type as far as the
>> language definition goes.
>
>Why twice? is the javascript VM a ones-complement machine?
JavaScript Numbers are IEEE-754 binary doubles, which use sign+magnitude
notation. So every representable number, from Zero to Infinity but not
including NaN, occurs in two distinguishable forms; one positive and one
negative. Only in the first case, zero, do the forms have the same
numerical value.
For X having any Number value except NaN, the expression
X = -X ;
always changes the sign of X; never changes the magnitude of X, and
changes the value of X unless X has a zero value initially. The
expression might change the sign bit of NaN, but that change is not
observable in JavaScript.
--
(c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2014-11-19 19:24 -0200 |
| Message-ID | <m4j1pi$g1i$1@speranza.aioe.org> |
| In reply to | #26164 |
Evertjan wrote: > Gene Wirchenko <genew@telus.net> wrote on 19 nov 2014 in > comp.lang.javascript: > >> On Wed, 19 Nov 2014 17:52:40 +0100, "Christoph M. Becker" >> <cmbecker69@arcor.de> wrote: >> >> [snip] >> >>> ACK -- assuming that there are no implementation errors. I rarely do >>> float calculations in ECMAScript implementations, so I don't know if >>> this assumption is reasonable. Probably it is. >> >> Since it is the only number type available for variables, > > What about integers? > >> how do you avoid it? >> Integers are used in ECMAScript under some circumstances. See: <http://www.2ality.com/2014/02/javascript-integers.html> -- Joao Rodrigues
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2014-11-19 13:40 -0800 |
| Message-ID | <qg3q6atilaqcesbfvuse0bd85aph0utv39@4ax.com> |
| In reply to | #26167 |
On Wed, 19 Nov 2014 19:24:09 -0200, Joao Rodrigues
<groups_jr-1@yahoo.com.br> wrote:
>Evertjan wrote:
>> Gene Wirchenko <genew@telus.net> wrote on 19 nov 2014 in
>> comp.lang.javascript:
>>
>>> On Wed, 19 Nov 2014 17:52:40 +0100, "Christoph M. Becker"
>>> <cmbecker69@arcor.de> wrote:
>>>
>>> [snip]
>>>
>>>> ACK -- assuming that there are no implementation errors. I rarely do
>>>> float calculations in ECMAScript implementations, so I don't know if
>>>> this assumption is reasonable. Probably it is.
>>>
>>> Since it is the only number type available for variables,
>>
>> What about integers?
>>
>>> how do you avoid it?
>Integers are used in ECMAScript under some circumstances. See:
><http://www.2ality.com/2014/02/javascript-integers.html>
Sure, but variables are one type only, and that is floating-point.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-11-19 23:40 +0100 |
| Message-ID | <m4j68h$3d2$1@solani.org> |
| In reply to | #26163 |
Gene Wirchenko wrote: > On Wed, 19 Nov 2014 17:52:40 +0100, "Christoph M. Becker" > <cmbecker69@arcor.de> wrote: > > [snip] > >> ACK -- assuming that there are no implementation errors. I rarely do >> float calculations in ECMAScript implementations, so I don't know if >> this assumption is reasonable. Probably it is. > > Since it is the only number type available for variables, how do > you avoid it? I meant "I rarely do divisions, that need to be exact, in ECMAScript implementations" (and should have written that -- sorry). Either a potentially unexact result wouldn't do harm (for instance, when setting certain CSS properties) or I deliberately round the result. Furthermore I do the server-side programming in PHP, so some of the calculations are redone there, anyway, so I don't mind potentially unexact temporary results in buggy ECMAScript implementations. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-11-18 16:44 +0000 |
| Message-ID | <WMFt4Qg1d3aUFwoE@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #26150 |
In comp.lang.javascript message <5371045.XxPr97Xf0d@PointedEars.de>, Mon, 17 Nov 2014 00:52:45, Thomas 'PointedEars' Lahn <PointedEars@web.de> posted: >Dr J R Stockton wrote: > >> […] Christoph M. Becker wrote: >>> Dr J R Stockton wrote: >>> > […] Christoph M. Becker posted: >>> >> The calculation in jsx.date.dateOfYear() is rather intriguing; I >>> >> wasn't aware of that formula. >>> > >>> > What formula? >>> >>> The formula to calculate the day of the year for days between march and >>> december that is used in jsx.date.dateOfYear()[1]: >>> >>> Math.floor(30.6 * (month + 1) - 91.4) + dayOfMonth >>> + (jsx.date.isLeapYear(date.getFullYear()) ? 60 : 59); >>> >>> [1] <http://pointedears.de/wsvn/JSX/trunk/date.js> >> >> You mean days between February and January in that order. > >No, he means what he wrote, and, with the exception of the use of >“between” >(which should be “from”, You are half right. The expression "from March" includes the days of March, but "from March and December" is ridiculous here, and the meaning of "to December" is commonly taken as not including December. Remember that there are no days between March and April, and each extra month adds about 30 days. > and month names are always capitalized), I concur. >The numbers of the days in January are covered by Date.prototype.getDate(), >and the numbers of the days in February by addition of 31, the number of >days in every January. The formula is only the last part of the approach. > >> Unsubtle. The first part of the expression seems derived from, but does >> not take full benefit from, Zeller's Congruence > >Interesting. If it has not already happened and proves to be correct, this >information should be added as reference to the Wikipedia article I took the >approach from. In that case you could do the addition yourself. But, as you are manifestly not an expert, you should have given the URL of the page so that others can if necessarily act. >> [I believe Zeller to have been a non-concurrent compatriot of yours (and >> that his children's marriages had an uncommon property)]. > >Figures; you concern yourself too much with the people, their ancestry, >relationships and descendants, and too little with the topic of the >discussion: It is always well to read publications in the original language, and indicating that Chr. Zeller was German suggests that CMB can read most of Zeller's relevant works in the original German - and could check my translations, though I have fair confidence in them. Remember that, like so many of us here, CMB is more intelligent than you are. >> My website has [I think all of] Zeller's relevant papers in the original >> and in English translation. By considering Zeller to the full, one easily >> enough gets an expression for the daycount from an Epoch. > >(Interesting, too, although not applicable here.) It is very applicable. Swifty needs to convert each date into a daycount (but can do it more briefly using a Date Object). I have a Daycount web page. -- (c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05. Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-11-19 11:20 +0100 |
| Message-ID | <1824940.D5HniJcg4W@PointedEars.de> |
| In reply to | #26157 |
Dr J R Stockton wrote: > Thomas 'PointedEars' Lahn posted: >> Dr J R Stockton wrote: >>> […] Christoph M. Becker wrote: >>>> Dr J R Stockton wrote: >>>> > […] Christoph M. Becker posted: >>>> >> […] I wasn't aware of [The formula to calculate the day of the year >>>> >> for days between march and december that is used in >>>> >> jsx.date.dateOfYear()[1]]: >>>> […] >>>> [1] <http://pointedears.de/wsvn/JSX/trunk/date.js> >>> You mean days between February and January in that order. >> No, he means what he wrote, and, with the exception of the use of >> “between” (which should be “from”, > > You are half right. The expression "from March" includes the days of > March, but "from March and December" is ridiculous here, and the meaning > of "to December" is commonly taken as not including December. I expected the reader to be intelligent enough to assume that I did mean “from … to …”. I know from more careful reading that Christoph did, and conveyed the intended meaning to the rest of the readership by posting it. So there is really no need for you to stress it. But ISTM you like to argue just for the sake of it. > Remember that there are no days between March and April, and each extra > month adds about 30 days. I know that. >>> […] The first part of the expression seems derived from, but does >>> not take full benefit from, Zeller's Congruence >> Interesting. If it has not already happened and proves to be correct, >> this information should be added as reference to the Wikipedia article I >> took the approach from. > > In that case you could do the addition yourself. I am not the one making the assertion above, you are. > But, as you are manifestly not an expert, You are correct that I am not an expert on calendar calculation. That is why I did a Web search and found the Wikipedia article. Testing proved its assertions to be correct. Your wording suggests that you deem yourself an expert in this area, so go ahead and edit Wikipedia. > you should have given the URL of the page so that others can if > necessarily act. UTSL. >>> By considering Zeller to the full, one easily enough gets an expression >>> for the daycount from an Epoch. >> (Interesting, too, although not applicable here.) > > It is very applicable. I do not think so. It is not reasonable to assume that his visitors would stay longer than two years. -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-11-14 20:45 +0000 |
| Message-ID | <GhE5j4S+nmZUFwgq@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #26133 |
In comp.lang.javascript message <6814026.8sujcrue1K@PointedEars.de>, Thu, 13 Nov 2014 21:26:22, Thomas 'PointedEars' Lahn <PointedEars@web.de> posted: > Rounding should also be >considered because those values are internally represented as floating-point >values. JavaScript dates are indeed represented by IEEE 754 binary doubles of milliseconds from Epoch 1970.0Z; but the range of allowable date/times has been chosen to lie within a little under 2^53 ms from Epoch, so all date/times are represented exactly. Date differences are only represented exactly if they are an even number of milliseconds or less than about 250,000 years or both. Check those figures if detail matters; I only intend to assert the principle. So Swifty should be safe enough. -- (c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05. Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2014-11-15 14:13 -0800 |
| Message-ID | <494ffadf-db0a-4bbf-8ecb-c65e8abc9a95@googlegroups.com> |
| In reply to | #26133 |
On Thursday, November 13, 2014 2:26:36 PM UTC-6, Thomas 'PointedEars' Lahn wrote: > I use RegExp.prototype.exec() only in loops, such as with > parsers, because with global matching there is no other way to get at the > submatches. You could use the String.prototype.replace(...) with a function to access submatches as well if you recall; though we know efficiency and flexibility with that approach is inferior to using exec(). There are also the deprecated properties of the RegExp object ($1..$9) which may be usable.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-11-15 23:42 +0100 |
| Message-ID | <1810660.TcCviKiKNp@PointedEars.de> |
| In reply to | #26142 |
Michael Haufe (TNO) wrote:
> […] Thomas 'PointedEars' Lahn wrote:
>> I use RegExp.prototype.exec() only in loops, such as with parsers,
>> because with global matching there is no other way to get at the
>> submatches.
>
> You could use the String.prototype.replace(...) with a function to access
> submatches as well if you recall;
Now that you mention it, I am doing that in JSX:regexp.js to extend the
RegExp syntax: <http://PointedEars.de/scripts/test/regexp>
> though we know efficiency and flexibility with that approach is inferior
> to using exec().
Depends.
> There are also the deprecated properties of the RegExp object ($1..$9)
^^^^^^^^^^
> which may be usable.
… but SHOULD NOT be used.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-11-12 00:23 +0100 |
| Message-ID | <XnsA3E34005CAF1eejj99@194.109.133.133> |
| In reply to | #26115 |
Swifty <steve.j.swift@gmail.com> wrote on 11 nov 2014 in comp.lang.javascript: > On 11/11/2014 14:10, Evertjan. wrote: >> Please consider doing this serverside, >> at least do not depend on the user client browser for your money. > > Ah, but recall, *I'm* the user client in this case. No you are not, if you plan the page to rent out accomodation. So my request for concideration stands. > I can trust my own > browsers (mostly Chrome these days). You seem to forget this is usenet, not email, Steve, so the responses are not only to you, but to the whole group. > What I can't trust is my puny > JavaScript skill (intentionally singular, to emphasize the lack). So please comment on the javascript I showed. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-11-12 13:24 +0000 |
| Message-ID | <87d28szh5a.fsf@bsb.me.uk> |
| In reply to | #26115 |
Swifty <steve.j.swift@gmail.com> writes:
> On 11/11/2014 14:10, Evertjan. wrote:
>> Please consider doing this serverside,
>> at least do not depend on the user client browser for your money.
>
> Ah, but recall, *I'm* the user client in this case. I can trust my own
> browsers (mostly Chrome these days). What I can't trust is my puny
> JavaScript skill (intentionally singular, to emphasize the lack).
>
> If the browser screws up our JavaScript efforts, then I'll fall back
> on calculating the amount myself. But it always pains me to have such
> a good computer, but still having to do the work myself. :-)
>
> The effect I'm looking for is that the ID=amount field will populate
> automatically the instant there is data in the three fields "from",
> "to", and "profile" contain values other than blank.
You might add a listener to the change event for these three fields (you
might even listen for key presses to get more immediate results). This
listener function (the some one will do for all three) checks the fields
for having usable values and fills in the fourth when that condition is
met.
For small bits of code like this, I like to use this pattern:
window.addEventListener(
'load',
function () {
var from = document.getElementById('from');
var to = document.getElementById('to');
var cost = document.getElementById('cost');
var rate = document.getElementById('rate');
function checkAndCalc() {
var rateVal = parseFloat(rate.value)
if (!isNaN(rateVal) &&
from.valueAsDate !== null &&
to.valueAsDate !== null) {
var weeks = Math.abs(to.valueAsDate - from.valueAsDate) /
(7*24*60*60*1000);
cost.value = (rateVal * weeks).toFixed(2);
}
};
from.addEventListener('change', checkAndCalc, false);
to. addEventListener('change', checkAndCalc, false);
rate.addEventListener('change', checkAndCalc, false);
}, false
);
Note: this is only a sketch (but I did test that it). It uses the new
HTML5 API (valueAsDate) so the date input elements should have
type=date.
As for getting the rate/week from a profile name, that is better done
on the server. I'd have the profiles in a file and have some server
script (PHP?) generate a select item like this:
<select id="profile">
<option value="4.5">a name</option>
<option value="1">another name</option>
...
</select>
Then you could replace the "rate" input element with the profile menu.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-11-12 14:43 +0100 |
| Message-ID | <m3vo5a$g5i$1@solani.org> |
| In reply to | #26122 |
Ben Bacarisse wrote: > You might add a listener to the change event for these three fields (you > might even listen for key presses to get more immediate results). The input event[1] might come in handy here. [1] <https://developer.mozilla.org/en-US/docs/Web/Events/input> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-11-12 19:48 +0100 |
| Message-ID | <5785626.gmMvSiFopG@PointedEars.de> |
| In reply to | #26123 |
Christoph M. Becker wrote: > Ben Bacarisse wrote: >> You might add a listener to the change event for these three fields (you >> might even listen for key presses to get more immediate results). > > The input event[1] might come in handy here. > > [1] <https://developer.mozilla.org/en-US/docs/Web/Events/input> Given that this would run in Chrome, which does support HTML5, the “input” event should suffice. Otherwise, mouse and keyboard events and the “change” event should be considered; see also <9271849.S5ITpJ9GIt@PointedEars.de>. -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-11-13 01:18 +0100 |
| Message-ID | <m40tct$q60$1@solani.org> |
| In reply to | #26125 |
Thomas 'PointedEars' Lahn wrote: > Christoph M. Becker wrote: > >> Ben Bacarisse wrote: >>> You might add a listener to the change event for these three fields (you >>> might even listen for key presses to get more immediate results). >> >> The input event[1] might come in handy here. >> >> [1] <https://developer.mozilla.org/en-US/docs/Web/Events/input> > > Given that this would run in Chrome, which does support HTML5, the “input” > event should suffice. Otherwise, mouse and keyboard events and the “change” > event should be considered; see also <9271849.S5ITpJ9GIt@PointedEars.de>. AFAIK, the "input" event is available in several other browsers (actually, DOM implementations) as well, see <https://developer.mozilla.org/en-US/docs/Web/Events/input#Browser_compatibility>. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-11-12 20:19 +0000 |
| Message-ID | <87wq70w4rd.fsf@bsb.me.uk> |
| In reply to | #26123 |
"Christoph M. Becker" <cmbecker69@arcor.de> writes: > Ben Bacarisse wrote: > >> You might add a listener to the change event for these three fields (you >> might even listen for key presses to get more immediate results). > > The input event[1] might come in handy here. > > [1] <https://developer.mozilla.org/en-US/docs/Web/Events/input> Agreed. Where available, that's often more appropriate (being more general) than using key events. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-11-13 03:42 +0100 |
| Message-ID | <1500286.HrVzhaJXa2@PointedEars.de> |
| In reply to | #26126 |
Ben Bacarisse wrote: > "Christoph M. Becker" <cmbecker69@arcor.de> writes: >> Ben Bacarisse wrote: >>> You might add a listener to the change event for these three fields (you >>> might even listen for key presses to get more immediate results). >> >> The input event[1] might come in handy here. >> >> [1] <https://developer.mozilla.org/en-US/docs/Web/Events/input> > > Agreed. Where available, that's often more appropriate (being more > general) than using key events. … and mouse events. Most notably, pointer and clipboard actions can be handled this way, too. However, in most cases you need to combine them because you do not know if the “input” event is supported, unless you find a reliable way to detect that, in which case at least the non-input event listeners could be added dynamically. -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-11-12 20:06 +0000 |
| Message-ID | <uRAzvdlo27YUFweJ@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #26111 |
In comp.lang.javascript message <XnsA3E29A540A77Feejj99@194.109.133.133>
, Tue, 11 Nov 2014 15:10:15, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:
>Swifty <steve.j.swift@gmail.com> wrote on 11 nov 2014 in
>comp.lang.javascript:
>function dateDifference(d0, d1) {
>
> var msPerDay = 8.64e7;
or 864e5;.
> // make dates from string parameters
> var x0 = new Date(d0);
> var x1 = new Date(d1);
>
> // Set to noon - avoid DST errors
Swifty does not have DST; he has BST.
> x0.setHours(12,0,0);
There is no need to set the minutes and seconds, when using Math.round
later; but, if one does, perhaps one should set the milliseconds for
completeness.
--
(c) John Stockton, nr London UK. Mail, see Homepage. BP7, Delphi 3 & 2006.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
[toc] | [prev] | [next] | [standalone]
| From | RobG <rgqld@iinet.net.au> |
|---|---|
| Date | 2014-11-23 20:51 -0800 |
| Message-ID | <0d947d29-c683-4417-b081-983f18bb11bf@googlegroups.com> |
| In reply to | #26111 |
On Wednesday, November 12, 2014 12:10:50 AM UTC+10, Evertjan. wrote:
> Swifty <steve...com> wrote on 11 nov 2014 in
> comp.lang.javascript:
>
> [..]
> > In simple English:
> > We have visitors to our holiday cottage.
> > They each have a different weekly rate (different by pennies, the
> > difference allows me to track payments in my bank statement, and know
> > who paid what)
> > After I've entered the "from" and "to" and "profile" fields, I want the
> > "Amount" field to be populated with the charge, based on the number of
> > days of the visit.
>
> I presume you want the number of nights.
>
> > I prefer to do this in stages as, capable or not, I'd still like to
> > understand how the result is achieved. I can probably fathom the
> > individual steps.
>
> Please consider doing this serverside,
> at least do not depend on the user client browser for your money.
>
> <script type='text/javascript'>
>
> function dateDifference(d0, d1) {
>
> var msPerDay = 8.64e7;
>
> // make dates from string parameters
> var x0 = new Date(d0);
> var x1 = new Date(d1);
Please don't suggest using the Date constructor to parse strings, it's unreliable. For example, '2014-10-10' will be treated differently in Chrome to most other browsers, and IE 8 will return NaN. Also, where a pre-ES5 browser does successfully parse the string, it may not highlight invalid dates (e.g. given 2014-02-29 it may return a Date for 2014-03-01, whereas ES5 compliant browsers will return NaN).
ES5 requires ISO 8601 conforming strings without a timezone to be treated as UTC, however the ES 6 draft says to treat them as UTC (which is consistent with ISO 8601). Chrome has implemented that already, other browsers have not.
> // Set to noon - avoid DST errors
An alternative is to use UTC.
Consider:
// Parse a y-m-d string as UTC
// Value separator can be any non-digit (e.g. / or .)
// Return NaN if invalid date
function parseUTCymd(s) {
var b = s.split(/\D/);
var d = new Date(Date.UTC(b[0], --b[1], b[2]));
return d.getFullYear() == b[0] && d.getDate() == b[2]? d : NaN;
}
// Return difference in days given string dates
// in format y-m-d.
// If either date is invalid, returns NaN
function daysDiff(d0, d1) {
var a = parseUTCymd(d0);
var b = parseUTCymd(d1);
return isNaN(a) || isNaN(b) ? NaN : Math.round((b - a)/8.64e7);
}
// If first date is after second, returns -ve value
console.log(daysDiff('2016-11-11','2015-06-11')); // -365
console.log(daysDiff('2016-11-11','2016-11-12')); // 1
This approach only works for whole days. Math.round is probably not required, but provides comfort should there be an insignificant error in the time values.
--
RobG
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-11-25 20:08 +0000 |
| Message-ID | <5Q3mfA3jGOdUFwl3@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #26204 |
In comp.lang.javascript message <0d947d29-c683-4417-b081-983f18bb11bf@go
oglegroups.com>, Sun, 23 Nov 2014 20:51:34, RobG <rgqld@iinet.net.au>
posted:
>ES5 requires ISO 8601 conforming strings without a timezone to be
>treated as UTC,
> however the ES 6 draft says to treat them as UTC
Those seem to mean the same thing.
> (which is consistent with ISO 8601).
I have not yet found ISO 8601:2004 to say that; Z is for UTC, so I
suppose not-Z should be different.
In my opinion, the authors of ECMA 262 have been hoping to implement ISO
8601 without troubling to read and understand ISO 8601.
>> // Set to noon - avoid DST errors
>
>An alternative is to use UTC.
>
>Consider:
>
> // Parse a y-m-d string as UTC
> // Value separator can be any non-digit (e.g. / or .)
> // Return NaN if invalid date
> function parseUTCymd(s) {
> var b = s.split(/\D/);
> var d = new Date(Date.UTC(b[0], --b[1], b[2]));
> return d.getFullYear() == b[0] && d.getDate() == b[2]? d : NaN;
That will fail on two-digit years (to be exact, years in -0 to +99).
Swifty seems confident that he, being sagacious, will always give a
4-digit year; but some historians should be careful. For them, an easy
solution is to add 400 to the year and subtract 4800 from the month - in
so far as I have tested.
In general, I would split with a RegExp, which can then verify a
"dddd*dd*dd" pattern where each d is in 0-9. When that is done, then
(as previously discussed in the group) it is only necessary to check
that the months match.
As you have it, the above generates 'var d' in UTC, but verifies it in
LCT. For that to be reliable, one should live in somewhere like
Iceland. It should be wrong about 40% of the time for those who live in
Hawaii or New South Wales. But I have not actually tested that, for
which the reason should be evident.
> }
> ...
>This approach only works for whole days. Math.round is probably not
>required, but provides comfort should there be an insignificant error
>in the time values.
Every millisecond in more than +-250000 years from Epoch can be stored
*exactly* in a Date Object, as an IEEE-754 binary floating-point
encoding of an integer value; and addition & subtraction of those
millisecond counts is exact provided that (1) the answer is in -2^53 to
+2^53, (2) the FPU is not broken.
--
(c) John Stockton, nr London, UK. Mail via homepage. Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Mail no News.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-11-26 01:31 +0100 |
| Message-ID | <m5370t$2jd$1@solani.org> |
| In reply to | #26210 |
Dr J R Stockton wrote: > In comp.lang.javascript message <0d947d29-c683-4417-b081-983f18bb11bf@go > oglegroups.com>, Sun, 23 Nov 2014 20:51:34, RobG <rgqld@iinet.net.au> > posted: > >> ES5 requires ISO 8601 conforming strings without a timezone to be >> treated as UTC, > >> however the ES 6 draft says to treat them as UTC > > Those seem to mean the same thing. The ES 6 draft currently specifies[1]: | If the time zone offset is absent, the date-time is interpreted as a | local time. I assume that is what Rob actually wanted to say. >> (which is consistent with ISO 8601). > > I have not yet found ISO 8601:2004 to say that; Z is for UTC, so I > suppose not-Z should be different. > > In my opinion, the authors of ECMA 262 have been hoping to implement ISO > 8601 without troubling to read and understand ISO 8601. Most likely not. ES 5.1 as well as the current ES 6 draft say: | ECMAScript defines a string interchange format for date-times based | upon a simplification of the ISO 8601 Extended Format. Note the term "simplification". Anyway, the issue regarding a missing time zone specifier might be regarded as a bug in ES 5.1. [1] <https://people.mozilla.org/~jorendorff/es6-draft.html#sec-date-time-string-format> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web