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


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

Date false

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2014-05-09 14:18 +1000
Last post2014-05-09 18:05 -0300
Articles 8 — 4 participants

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


Contents

  Date false Andrew Poulos <ap_prog@hotmail.com> - 2014-05-09 14:18 +1000
    Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-09 10:46 +0200
    Re: Date false "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-09 10:58 +0200
    Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-09 11:01 +0200
    Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 17:27 -0300
      Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 17:32 -0300
      Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-10 10:36 +0200
    Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 18:05 -0300

#24051 — Date false

FromAndrew Poulos <ap_prog@hotmail.com>
Date2014-05-09 14:18 +1000
SubjectDate false
Message-ID<1JidnUNwV7viyvHOnZ2dnUVZ_t6dnZ2d@westnet.com.au>
I'm use JScript with ASP to read a db

// if there's no error, d can either be a date or 0 (zero)
var d = e = rs("ExpiryDay").value;

Then I use it in an if statement

if (d) {
   // 'do something'
}

even when
   window.alert(d +" + "+ (typeof d));
displays
   Thu May 14 00:00:00 UTC 1000 2015 + date
'do something' never happens.

I'm confused. Can a date be false?

Andrew Poulos

[toc] | [next] | [standalone]


#24055

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-05-09 10:46 +0200
Message-ID<2257287.d1qsfXZ9WQ@PointedEars.de>
In reply to#24051
Andrew Poulos wrote:

> I'm use JScript with ASP to read a db
> 
> // if there's no error, d can either be a date or 0 (zero)

No.

> var d = e = rs("ExpiryDay").value;
> 
> Then I use it in an if statement
> 
> if (d) {
>    // 'do something'
> }
> 
> even when
>    window.alert(d +" + "+ (typeof d));
> displays
>    Thu May 14 00:00:00 UTC 1000 2015 + date
> 'do something' never happens.
> 
> I'm confused. Can a date be false?

rs("ExpiryDay").value does not store a reference to a Date instance, but to 
a host object.  Otherwise the “typeof” operation would have resulted in 
"object", not "date".

The return value of rs("ExpiryDay") probably also refers to a host object, 
and using a host object or a host object’s property in a type-converting 
test can be error-prone.

Using the (binary) “+” operator with at least one string value as operand 
converts the other, non-string operand to the String type, and concatenates 
the resulting values.  "Thu May 14 00:00:00 UTC 1000 2015" indicates “not a 
proper DateTime value in the database”.  It makes sense that this is type-
converted to “false”.

-- 
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]


#24056

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-05-09 10:58 +0200
Message-ID<XnsA3286FB6919EBeejj99@194.109.133.133>
In reply to#24051
Andrew Poulos <ap_prog@hotmail.com> wrote on 09 mei 2014 in 
comp.lang.javascript:

> I'm use JScript with ASP to read a db
> 
> // if there's no error, d can either be a date or 0 (zero)
> var d = e = rs("ExpiryDay").value;

I hope you did not mean to write:

var d = e == rs("ExpiryDay").value;


Try:

var d = new Date(rs("ExpiryDay"));

[if rs() is a database field, the .value is default
on most engines under ASP.]



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

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


#24057

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-05-09 11:01 +0200
Message-ID<4029002.xjOkqY7oij@PointedEars.de>
In reply to#24051
Stefan Ram wrote:

> Andrew Poulos <ap_prog@hotmail.com> writes:
>> Can a date be false?
> 
>   The six falsy values are:
> 
>       undefined
>       null
>       NaN
>       0
>       ""
>       false

Which is irrelevant here as the value is not likely to be of the type of one 
of these values, given its string representation that was posted.
 
>>if (d) {
>>   // 'do something'
>>}
>>even when
>>   window.alert(d +" + "+ (typeof d));
>>displays
>>   Thu May 14 00:00:00 UTC 1000 2015 + date
>>'do something' never happens.
> 
>   If you write it behind »//«, then 'do something' is part
>   of a comment, and comments never happen.

Oh for crying out loud … please adjust your posting parser.  He *quite* 
*obviously* used the comment to replace code that he thought would not be 
relevant here.  And he was right.
 
>   The error might be in some part not shown in your post.

There is no error.

>   Maybe you can prepare an SSCCE.

Maybe you can learn to read or go away.
 
> var d = new Date( 2015, 4, 14 ); if( d )document.writeln( d );

…

-- 
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]


#24063

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2014-05-09 17:27 -0300
Message-ID<lkjdnp$rfg$1@speranza.aioe.org>
In reply to#24051
Em 09/05/2014 02:02, Stefan Ram escreveu:
> Andrew Poulos <ap_prog@hotmail.com> writes:
>> Can a date be false?
>
>    The six falsy values are:
>
>        undefined
>        null
>        NaN
>        0
>        ""
>        false
>

There are seven "falsy" values indeed: false, +0, -0, "", NaN, null, and 
undefined, according to ES 5.1, § 9.2 (ToBoolean):
<http://ecma-international.org/ecma-262/5.1/#sec-9.2>

>> if (d) {
>>    // 'do something'
>> }
>> even when
>>    window.alert(d +" + "+ (typeof d));
>> displays
>>    Thu May 14 00:00:00 UTC 1000 2015 + date
>> 'do something' never happens.
>
>    If you write it behind »//«, then 'do something' is part
>    of a comment, and comments never happen.

"\\" was a comment by the OP.


-- 
Joao Rodrigues (J.R.)

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


#24064

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2014-05-09 17:32 -0300
Message-ID<lkje0o$sar$1@speranza.aioe.org>
In reply to#24063
Em 09/05/2014 17:27, Joao Rodrigues escreveu:
> Em 09/05/2014 02:02, Stefan Ram escreveu:
>> Andrew Poulos <ap_prog@hotmail.com> writes:
>>> Can a date be false?
>>
>>    The six falsy values are:
>>
>>        undefined
>>        null
>>        NaN
>>        0
>>        ""
>>        false
>>
>
> There are seven "falsy" values indeed: false, +0, -0, "", NaN, null, and
> undefined, according to ES 5.1, § 9.2 (ToBoolean):
> <http://ecma-international.org/ecma-262/5.1/#sec-9.2>
>
>>> if (d) {
>>>    // 'do something'
>>> }
>>> even when
>>>    window.alert(d +" + "+ (typeof d));
>>> displays
>>>    Thu May 14 00:00:00 UTC 1000 2015 + date
>>> 'do something' never happens.
>>
>>    If you write it behind »//«, then 'do something' is part
>>    of a comment, and comments never happen.
>
> "\\" was a comment by the OP.
>
>
  Oops, "//" was a comment, not "\\".

-- 
Joao Rodrigues (J.R.)

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


#24069

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-05-10 10:36 +0200
Message-ID<9594146.3ms6Ipm6O6@PointedEars.de>
In reply to#24063
Stefan Ram wrote:

>   Since the OP apparently had an object, I wondered whether an object
>   can be made falsy somehow. The following did not work:
> 
> if( { valueOf: function (){ return false; }})document.writeln( 'a' );
> 
>   . »Not work« means that it wrote »a«.
> 
>   In fact, »9.2 ToBoolean« says that any object always is converted
>   to true,

No, it says that any *value of the Object type* is converted to “true”.

>   so I really do not understand how in the OP's
> 
> if( d )do_something();
> 
>   it is possible that »do_something();« is not executed, when d is
>   either a string (that is not equal to »""«) or an object.

As the “typeof” operation (§11.4.3) resulted in "date" – neither "object" 
nor "function" – we must assume that the value is of an additional type for 
which the “ToBoolean” algorithm has been augmented in the used 
implementation, according to §2 “Conformance”.

-- 
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]


#24065

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2014-05-09 18:05 -0300
Message-ID<lkjftq$1m8$1@speranza.aioe.org>
In reply to#24051
Em 09/05/2014 01:18, Andrew Poulos escreveu:
> I'm use JScript with ASP to read a db
>
> // if there's no error, d can either be a date or 0 (zero)
> var d = e = rs("ExpiryDay").value;

Unless you have declared the "e" variable previously, the above code 
would declare a new global variable named "e". E.g.

function doSomething() {
   var i = j = 0;
   var len = len2 = 0;
   var aux = aux2 = '';

   // i, len and aux are local variables (function scope),
   // whereas j, len2 and aux2 are global variables (declared implicitly)
   // ...
}


>
> Then I use it in an if statement
>
> if (d) {
>    // 'do something'
> }
>
> even when
>    window.alert(d +" + "+ (typeof d));
> displays
>    Thu May 14 00:00:00 UTC 1000 2015 + date
> 'do something' never happens.
>
> I'm confused. Can a date be false?

I have found weird errors / problems in classic ASP with JScript and 
mySQL. For instance, if I don't use CursorLocation = 3 (adUseClient), 
RecordCount would always return -1.

var rset = Server.CreateObject("ADODB.Recordset");
rset.CursorLocation = 3; // avoids RecordCount returning -1

So, I'd suggest using a specific function to test for valid dates:

   if (isDate(rs("ExpiryDay").Value)) { }


-- 
Joao Rodrigues (J.R.)

[toc] | [prev] | [standalone]


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


csiph-web