Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31962 > unrolled thread

What is wrong with this If Else construction?

Started bybart.smissaert@gmail.com
First post2016-12-26 00:05 -0800
Last post2016-12-28 22:17 +0000
Articles 12 on this page of 32 — 10 participants

Back to article view | Back to comp.lang.javascript


Contents

  What is wrong with this If Else construction? bart.smissaert@gmail.com - 2016-12-26 00:05 -0800
    Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-26 10:37 +0100
      Re: What is wrong with this If Else construction? bart.smissaert@gmail.com - 2016-12-26 03:45 -0800
        Re: What is wrong with this If Else construction? Luuk <luuk@invalid.lan> - 2016-12-26 12:59 +0100
          Re: What is wrong with this If Else construction? bart.smissaert@gmail.com - 2016-12-26 04:02 -0800
            Re: What is wrong with this If Else construction? bart.smissaert@gmail.com - 2016-12-26 04:16 -0800
        Re: What is wrong with this If Else construction? me <mu@local.local> - 2016-12-26 13:34 +0100
          Re: What is wrong with this If Else construction? Bart Smissaert <bart.smissaert@gmail.com> - 2016-12-26 05:02 -0800
            Re: What is wrong with this If Else construction? Luuk <luuk@invalid.lan> - 2016-12-26 18:32 +0100
              Re: What is wrong with this If Else construction? Bart Smissaert <bart.smissaert@gmail.com> - 2016-12-26 15:32 -0800
                Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-27 10:05 +0100
                  Re: What is wrong with this If Else construction? Bart Smissaert <bart.smissaert@gmail.com> - 2016-12-27 03:27 -0800
                    Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-27 21:46 +0100
                      Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-29 18:36 +0100
                      Re: What is wrong with this If Else construction? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-12-28 23:16 +0000
                Re: What is wrong with this If Else construction? Luuk <luuk@invalid.lan> - 2016-12-27 22:28 +0100
                  Re: What is wrong with this If Else construction? Gene Wirchenko <genew@telus.net> - 2016-12-27 15:07 -0800
                    Re: What is wrong with this If Else construction? Luuk <luuk@invalid.lan> - 2016-12-28 19:37 +0100
        Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-26 21:56 +0100
          Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-26 22:14 +0100
            Re: What is wrong with this If Else construction? Gene Wirchenko <genew@telus.net> - 2016-12-26 14:12 -0800
              Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-27 00:02 +0100
              Re: What is wrong with this If Else construction? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-12-27 22:36 +0000
                Re: What is wrong with this If Else construction? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-28 10:36 +0100
    Re: What is wrong with this If Else construction? Luuk <luuk@invalid.lan> - 2016-12-26 17:00 +0100
      OT: Leap year bug in Excel (was: What is wrong with this If Else construction?) "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-26 17:12 +0100
    Re: What is wrong with this If Else construction? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-12-27 22:52 +0000
      Re: What is wrong with this If Else construction? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-28 01:01 +0100
        Re: What is wrong with this If Else construction? $Bill <news@todbe.com> - 2016-12-27 22:19 -0800
          Re: What is wrong with this If Else construction? Tim Streater <timstreater@greenbee.net> - 2016-12-28 10:05 +0000
            Re: What is wrong with this If Else construction? [OT] $Bill <news@todbe.com> - 2016-12-28 13:59 -0800
              Re: What is wrong with this If Else construction? [OT] Tim Streater <timstreater@greenbee.net> - 2016-12-28 22:17 +0000

Page 2 of 2 — ← Prev page 1 [2]


#31991

FromGene Wirchenko <genew@telus.net>
Date2016-12-26 14:12 -0800
Message-ID<g5536cpnucefgic9328grcfd8dlehou0t7@4ax.com>
In reply to#31990
On Mon, 26 Dec 2016 22:14:20 +0100, "Evertjan."
<exxjxw.hannivoort@inter.nl.net> wrote:

[snip]

>btw, if you still want to use VBS, 
>consider this [entering now, when still alive]:
>
>function age(born,died)
>    age = DateDiff("yyyy", born, died) + 
>               (died < DateSerial(Year(died), Month(born), Day(born)))
>end function

     I do not know DateSerial(), but this code has a possible smell of
not handling a leap year correctly.  What happens if the person was
born on Leap Day and dies in a non-leap year?  (Will DateSerial()
throw an error or otherwise malfunction?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#31993

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-12-27 00:02 +0100
Message-ID<XnsA6EB74D2CDEeejj99@194.109.6.166>
In reply to#31991
Gene Wirchenko <genew@telus.net> wrote on 26 Dec 2016 in 
comp.lang.javascript:

> On Mon, 26 Dec 2016 22:14:20 +0100, "Evertjan."
> <exxjxw.hannivoort@inter.nl.net> wrote:
> 
> [snip]
> 
>>btw, if you still want to use VBS, 
>>consider this [entering now, when still alive]:
>>
>>function age(born,died)
>>    age = DateDiff("yyyy", born, died) + 
>>               (died < DateSerial(Year(died), Month(born), Day(born)))
>>end function
> 
>      I do not know DateSerial(), but this code has a possible smell of
> not handling a leap year correctly.  What happens if the person was
> born on Leap Day and dies in a non-leap year?  (Will DateSerial()
> throw an error or otherwise malfunction?

Why, oh why don't you test this for yourself?

It is so easy:

<%
function age(born,died)
    age = DateDiff("yyyy", born, died) +_
      (died < DateSerial(Year(died), Month(born), Day(born)))
end function

born = #2004/02/29#
died = #2005/02/28#
response.write age(born, died) ' 0

born = #2004/02/28#
died = #2005/02/28#
response.write age(born, died) ' 1

born = #2004/02/29#
died = #2005/03/01#
response.write age(born, died) ' 1

born = #2003/02/28#
died = #2004/02/29#
response.write age(born, died) ' 1

born = #1999/02/28#
died = #2000/02/29#
response.write age(born, died) ' 1

' error as expected: died = #2100/02/29#
%>




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#32002

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-12-27 22:36 +0000
Message-ID<7dCHSnIG0uYYFw85@invalid.uk.co.demon.merlyn.invalid>
In reply to#31991
In comp.lang.javascript message <g5536cpnucefgic9328grcfd8dlehou0t7@4ax.
com>, Mon, 26 Dec 2016 14:12:05, Gene Wirchenko <genew@telus.net>
posted:

>     I do not know DateSerial(), but this code has a possible smell of
>not handling a leap year correctly.  What happens if the person was
>born on Leap Day and dies in a non-leap year?  (Will DateSerial()
>throw an error or otherwise malfunction?

One must consider the purpose of the code, and from that what the answer
should be in awkward cases.  So, if this is required for legal purposes,
one must know the legal definition in the applicable jurisdiction.  It
is entirely possible that the "correct" answer may vary between US & CA
and MX, or even between US states and other territories.


-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#32009

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-12-28 10:36 +0100
Message-ID<XnsA6EC6BEF21C1Feejj99@194.109.6.166>
In reply to#32002
Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> wrote on 27 Dec 2016 
in comp.lang.javascript:

> In comp.lang.javascript message <g5536cpnucefgic9328grcfd8dlehou0t7@4ax.
>com>, Mon, 26 Dec 2016 14:12:05, Gene Wirchenko <genew@telus.net>
> posted:
> 
>>     I do not know DateSerial(), but this code has a possible smell of
>>not handling a leap year correctly.  What happens if the person was
>>born on Leap Day and dies in a non-leap year?  (Will DateSerial()
>>throw an error or otherwise malfunction?
> 
> One must consider the purpose of the code, and from that what the answer
> should be in awkward cases.  So, if this is required for legal purposes,
> one must know the legal definition in the applicable jurisdiction.  It
> is entirely possible that the "correct" answer may vary between US & CA
> and MX, or even between US states and other territories.

Perhaps one 'should', but 'must' not.
One should campain for the freedom of expression of all programmers, even 
the ones that lazily prefer to ask others, instead of do simple testing and 
debugging.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#31972

FromLuuk <luuk@invalid.lan>
Date2016-12-26 17:00 +0100
Message-ID<58613e92$0$21413$e4fe514c@news.xs4all.nl>
In reply to#31962
On 26-12-16 14:46, Stefan Ram wrote:
> bart.smissaert@gmail.com writes:
>> New to JavaScript and trying to calculate the date of birth
>>from an Excel date, provided as an integer value (1 Jan 1900
>> = 1).
>
>   IIRC, Excel had or has a leap day in 1900. So, it is
>
> 58   1900-02-27 00:00
> 59   1900-02-28 00:00
> 60   1900-02-29 00:00
> 61   1900-03-01 00:00
> 62   1900-03-02 00:00
>
>   in Excel (or /was/in older versions of Excel?). But 1900 was
>   /not/ a leap year. Conversion software might have to take
>   this into account.
>

hmm, just tested, this bug still exists in excel 2013
(and proably will be fro some time , because of backward compatability)

[toc] | [prev] | [next] | [standalone]


#31973 — OT: Leap year bug in Excel (was: What is wrong with this If Else construction?)

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2016-12-26 17:12 +0100
SubjectOT: Leap year bug in Excel (was: What is wrong with this If Else construction?)
Message-ID<o3rfg3$c62$1@solani.org>
In reply to#31972
On 26.12.2016 at 17:00, Luuk wrote:

> On 26-12-16 14:46, Stefan Ram wrote:
>
>> bart.smissaert@gmail.com writes:
>>
>>> New to JavaScript and trying to calculate the date of birth
>>> from an Excel date, provided as an integer value (1 Jan 1900
>>> = 1).
>>
>>   IIRC, Excel had or has a leap day in 1900. So, it is
>>
>> 58   1900-02-27 00:00
>> 59   1900-02-28 00:00
>> 60   1900-02-29 00:00
>> 61   1900-03-01 00:00
>> 62   1900-03-02 00:00
>>
>>   in Excel (or /was/in older versions of Excel?). But 1900 was
>>   /not/ a leap year. Conversion software might have to take
>>   this into account.
>>
> 
> hmm, just tested, this bug still exists in excel 2013
> (and proably will be fro some time , because of backward compatability)

See <https://support.microsoft.com/en-us/kb/214326>.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#32003

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-12-27 22:52 +0000
Message-ID<sM+SWgK3CvYYFwu7@invalid.uk.co.demon.merlyn.invalid>
In reply to#31962
In comp.lang.javascript message <47744619-426f-4af1-8376-e2935a2570db@go
oglegroups.com>, Mon, 26 Dec 2016 00:05:46, bart.smissaert@gmail.com
posted:

>New to JavaScript and trying to calculate the date of birth from an
>Excel date, provided as an integer value (1 Jan 1900 = 1).

Your inability is profound.

Firstly, correct the Excel date (by +1 or -1, to allow for the idiot
Californians not understanding the Gregorian calendar) as necessary;
call that CXLD.

Then consider

        CXLD = 42345
        new Date(Date.UTC(1900, 0, CXLD))

which shows __me__
        Tue Dec 08 2015 00:00:00 GMT+0000 (GMT Standard Time)

The Date.UTC(...) eliminates concern about possible effects of Time Zone
and Summer Time.

In JavaScript, always use UTC within calendar-type calculations; use
local date/time, *where*needed*, for I/O.

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#32004

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2016-12-28 01:01 +0100
Message-ID<o3uvb1$gso$1@solani.org>
In reply to#32003
On 27.12.2016 at 23:52, Dr J R Stockton wrote:

> In comp.lang.javascript message <47744619-426f-4af1-8376-e2935a2570db@go
> oglegroups.com>, Mon, 26 Dec 2016 00:05:46, bart.smissaert@gmail.com
> posted:
> 
>> New to JavaScript and trying to calculate the date of birth from an
>> Excel date, provided as an integer value (1 Jan 1900 = 1).
> 
> Firstly, correct the Excel date (by +1 or -1, to allow for the idiot
> Californians not understanding the Gregorian calendar) as necessary;
> call that CXLD.

Are you referring to Redmond, CA?

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#32007

From$Bill <news@todbe.com>
Date2016-12-27 22:19 -0800
Message-ID<o3vle1$tnq$1@dont-email.me>
In reply to#32004
On 12-27-16 16:01, Christoph M. Becker wrote:
> On 27.12.2016 at 23:52, Dr J R Stockton wrote:
>
>> In comp.lang.javascript message <47744619-426f-4af1-8376-e2935a2570db@go
>> oglegroups.com>, Mon, 26 Dec 2016 00:05:46, bart.smissaert@gmail.com
>> posted:
>>
>>> New to JavaScript and trying to calculate the date of birth from an
>>> Excel date, provided as an integer value (1 Jan 1900 = 1).
>>
>> Firstly, correct the Excel date (by +1 or -1, to allow for the idiot
>> Californians not understanding the Gregorian calendar) as necessary;
>> call that CXLD.
>
> Are you referring to Redmond, CA?

There happens to be a Redmond Oregon and another in Washington.  I think
he means the one in Washington, but you never know.  I don't like having
my entire state dissed - esp when it's for the wrong reason.  At least
we have decent weather down here.


[toc] | [prev] | [next] | [standalone]


#32010

FromTim Streater <timstreater@greenbee.net>
Date2016-12-28 10:05 +0000
Message-ID<281220161005279279%timstreater@greenbee.net>
In reply to#32007
In article <o3vle1$tnq$1@dont-email.me>, $Bill <news@todbe.com> wrote:

>my entire state dissed - esp when it's for the wrong reason.  At least
>we have decent weather down here.

No, you have dull, tedious, and boring weather. I should know: I lived
in it for 12 years.

-- 
"If you're not able to ask questions and deal with the answers without feeling 
that someone has called your intelligence or competence into question, don't 
ask questions on Usenet where the answers won't be carefully tailored to avoid
tripping your hair-trigger insecurities."                  - D M Procida, UCSM

[toc] | [prev] | [next] | [standalone]


#32018 — Re: What is wrong with this If Else construction? [OT]

From$Bill <news@todbe.com>
Date2016-12-28 13:59 -0800
SubjectRe: What is wrong with this If Else construction? [OT]
Message-ID<o41ci2$bu0$1@dont-email.me>
In reply to#32010
On 12-28-16 02:05, Tim Streater wrote:
> In article <o3vle1$tnq$1@dont-email.me>, $Bill <news@todbe.com> wrote:
>
>> my entire state dissed - esp when it's for the wrong reason.  At least
>> we have decent weather down here.
>
> No, you have dull, tedious, and boring weather. I should know: I lived
> in it for 12 years.

I'll take our 260 days of straight sunshine and no rain any day over cold,
rain, sleet and snow.  We're in our rainy/windy season right now, but it's
still above 60 F and you can actually do stuff outside.  If I want snow,
I drive a few miles to the mountains and can sky/board my ass off if I so
wish.  If I want to fish in the ocean, it's only 15 miles.  If I want to
dune buggy in the desert, less than 50 miles.

Nothing tedious and boring about that, but the more people that think it is,
the more room for the rest of us.  ;)

PS: Micro$oft does not live here, but we do have those Apple assholes.








[toc] | [prev] | [next] | [standalone]


#32020 — Re: What is wrong with this If Else construction? [OT]

FromTim Streater <timstreater@greenbee.net>
Date2016-12-28 22:17 +0000
SubjectRe: What is wrong with this If Else construction? [OT]
Message-ID<281220162217170217%timstreater@greenbee.net>
In reply to#32018
In article <o41ci2$bu0$1@dont-email.me>, $Bill <news@todbe.com> wrote:

>On 12-28-16 02:05, Tim Streater wrote:
>> In article <o3vle1$tnq$1@dont-email.me>, $Bill <news@todbe.com> wrote:
>>
>>> my entire state dissed - esp when it's for the wrong reason.  At least
>>> we have decent weather down here.
>>
>> No, you have dull, tedious, and boring weather. I should know: I lived
>> in it for 12 years.
>
>I'll take our 260 days of straight sunshine and no rain any day ...

Oh so utterly UTTERLY dull and tedious, my dear.

> ... over cold, rain, sleet and snow.

I had all of those when I lived in Menlo Park. My nephew, then living
somewhere on the East Coast (y'know, one of those places where they get
30 feet of snow in winter), decided to come to nice California for a
gentle winter with me. Hah! Boy, did he get a surprise! Temps in the
25-30F range for the two weeks he was here.

> ... my ass off ...
>...  assholes.

Why have you got this donkey fixation?

-- 
"People don't buy Microsoft for quality, they buy it for compatibility
with what Bob in accounting bought last year. Trace it back - they buy
Microsoft because the IBM Selectric didn't suck much" - P Seebach, afc

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web