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


Groups > comp.lang.javascript > #14521

Re: the if condition not workiong properly

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: the if condition not workiong properly
Date 2012-06-15 19:23 +0200
Organization albasani.net
Message-ID <jrfr23$k6$1@news.albasani.net> (permalink)
References (3 earlier) <n1BUf3GqMg1PFwpq@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD> <d4joHGNgn51PFwfh@invalid.uk.co.demon.merlyn.invalid> <ov2gt7p84ffdfdd7krf601rnt49cgemfuv@4ax.com> <LgOtRBDYQi2PFwVE@invalid.uk.co.demon.merlyn.invalid> <ddblt7lefbg6p8tnbkqpdsksjtk0vtv1hu@4ax.com>

Show all headers | View raw


On 2012-06-15 05:45, Gene Wirchenko wrote:
>>>On Tue, 12 Jun 2012 20:34:56 +0100, Dr J R Stockton
>>><reply1224@merlyn.demon.co.uk.not.invalid> wrote:
>>
>>>>It can also work unreliably.  Consider
>>>>
>>>>        D = new Date() ; D.setMonth(5)
>>>> 
>>>> which has about a 1 in 52 chance of doing what probably was not
>>>> expected; and consider the careless implementation of Zeller's
...
>      I did see the possibility reading your previous post, but I did
> not look to see where the 52 comes from.  There are seven months that
> have 31 days.

And that's where the 52 comes from: 365/7 ~ 52

> If the current date is the 31st of one of those months,
> trying to set a June 31st is going to be interesting.  I do not care
> what happens, because whatever it is, it is going to be wrong.

You say it's wrong, Dr Stockton says it's probably unexpected. The real
problem is giving a calculator an ambiguous task (add "a month"), and
expecting it to solve the task according to each user's expectations of
what is correct.

According to the specs, there's exactly one outcome in this situation
(month with 30 days, day-of-month set to 31). If that result is not what
the users expect, it's a user error. These cases can be trivially
anticipated and handled so that the result is more in line with what the
user needs.

There are several possible outcomes for an operation like this, e.g.
- move the additional day into the next month (like the Date object)
- limit the day-of-month to the highest valid number for that month
- cause the operation to fail

None of these will satisfy all users, and each has problems of its own.
I'm afraid this will continue to be the case until we finally move to a
decimal time system. Unfortunately, for the ideal case, that involves
slowing Earth's orbit around the sun so that it always takes exactly
1000 days. Another solution would be to increase the Earth's speed of
rotation so that the days are shorter. For best results, use a
combination of both approaches.

- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

the if condition not workiong properly Ganesh <ganesh.vemakoti45@gmail.com> - 2012-06-10 22:54 -0700
  Re: the if condition not workiong properly Jason C <jwcarlton@gmail.com> - 2012-06-11 02:27 -0700
  Re: the if condition not workiong properly "Tom de Neef" <tdeneef@qolor.nl> - 2012-06-11 11:35 +0200
    Re: the if condition not workiong properly Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-11 13:12 +0200
      Re: the if condition not workiong properly John G Harris <john@nospam.demon.co.uk> - 2012-06-11 15:39 +0100
        Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-12 20:34 +0100
          Re: the if condition not workiong properly Gene Wirchenko <genew@ocis.net> - 2012-06-12 20:47 -0700
            Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-14 18:49 +0100
              Re: the if condition not workiong properly Gene Wirchenko <genew@ocis.net> - 2012-06-14 20:45 -0700
                Re: the if condition not workiong properly "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-15 06:30 +0000
                Re: the if condition not workiong properly Gene Wirchenko <genew@ocis.net> - 2012-06-15 09:42 -0700
                Re: the if condition not workiong properly "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-15 18:38 +0000
                Re: the if condition not workiong properly Stefan Weiss <krewecherl@gmail.com> - 2012-06-15 19:23 +0200
                Re: the if condition not workiong properly Gene Wirchenko <genew@ocis.net> - 2012-06-15 12:54 -0700
                Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-16 21:46 +0100
                Re: the if condition not workiong properly "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-17 08:03 +0000
          Re: the if condition not workiong properly John G Harris <john@nospam.demon.co.uk> - 2012-06-14 11:08 +0100
            Re: the if condition not workiong properly Gene Wirchenko <genew@ocis.net> - 2012-06-14 09:23 -0700
            Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-15 19:56 +0100
              Re: the if condition not workiong properly Andrew Poulos <ap_prog@hotmail.com> - 2012-06-16 13:26 +1000
                Re: the if condition not workiong properly John G Harris <john@nospam.demon.co.uk> - 2012-06-16 11:33 +0100
                Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-17 19:42 +0100
      Re: the if condition not workiong properly Dr J R Stockton <reply1224@merlyn.demon.co.uk.not.invalid> - 2012-06-12 20:10 +0100

csiph-web