P
pcx99
Dr said:In comp.lang.javascript message
It is not an arbitrary date; it is a reasonably well-chosen date.
Still arbitrarily set. It could have been 01/01/1969 or 10/25/1955,
from a coding perspective there's no difference between the two.
Evidently you do not know the proper meaning of Julian Date. Of course,
you are not alone; IBM do not either. Julian Date is a count of days
from Julian Calendar BC 4713-01-01 12:00:00 GMT.
Evidently you're not aware of the function of Julian dates in the
computer sciences. COBOL uses 01/01/1601. NASA uses 5/24/1968. The
PICK OS used 01/01/1965. Astronomers have their own julian system and
there are various other niche systems. These are all Julian date
systems which represents the passage of time with a simple integer.
There is no single Julian date, there is an original Julian calendar and
there are a plethora of additional Julian systems with different
starting dates. The selection of 1/1/1970 was an arbitrary decision by
the developers of the language, 1/2/1970 would have worked just as well
as far as javascript is concerned.
It does not matter for the user's coding.
It DOES matter that you have, either through carelessness or through
lack of understanding, made a false statement which might deceive
innocent readers of your article.
Not. There's no error with the code. It will parse both dates
perfectly great providing differing time zones are not inserted into the
string being parsed which, given the original data, is not a factor.
Which means the browser's time-zones will be used which means the
relative check between date1 and date2 will be flawless. Even if the
original data originated in a different time zone it still does not
matter because the code is only doing a relative check between the two
dates.
The time zone is simply not a factor in the problem or solution.
Incorrect. It is an addition operator where both operands are Number;
if it has a single argument, it yields a Number; if both operands are
Boolean, it coverts them to Number and adds them. If just one argument
is a String, it converts the other to String and concatenates, If both
are strings, it concatenates. Its results are fully defined by
ECMA-262, and I know of no case in which a reputable recent browser gets
it wrong.
This is the relevant part from your quote. This is what I was avoiding
by using multiplication instead of addition...
If just one argument
is a String, it converts the other to String and concatenates
The problem is that date1 is not an integer, it is an object. The
multiplication forced it to behave as an integer for the purpose of the
demonstration, however if + is used to force the transformation the
example risked failing because document.writeln('testing: '+date1) would
return a date string and not a date integer which is what I was discussing.
I didn't assume the end user would enter the example as entered, I
assumed that while exploring new code the user would expand on the
document.write string for debugging purposes which means using +date1
would yield unpredictable results if the user went from...
document.writeln(+date1); (shows integer value)
to
document.writeln('testing: '+date1); (shows string value, not what we
wanted).
By using multiplication in my example, I used javascript's order of
operation to my advantage since multiplication takes priority over
addition (and concatenation) which means that even if the user expands
on my original example, it will still work.
document.writeln('testing: '+date1*1); (still an integer).
Randy Webb correctly noted that
document.writeln('testing: '+(+date1)); (still an integer)
would resolve everything to the satisfaction of the great and holy faqs,
but as I said, I deliberately chose multiplication to contain any chance
of concatenation and to simplify the readability of the code for people
learning a new concept.
I think we've all agreed that next time I'll just use date1.getTime()
which will avoid this sort of totally pointless nitpicking.
That proves nothing. A reversible conversion is not necessarily a
correct conversion.
To which I can only conclude you have no understanding of how the
internal julian system works and any further discussion is pointless
until you make an effort to learn it. Suffice it to say that given any
starting date and a julian integer I can calculate the exact destination
date both forward and reverse and any other element you would like from
number of days, weeks, years, even the number of leap years between the
two dates.
How do I know this is true? Because to javascript all date/time are
julian integers and from that it calculates the day of the week, the
week of the year, and tons of other nifty, useful information regardless
of leap years, and other uncertainties in our real world calendars. It
does all this millions of time every single day, every time someone does
ANYTHING with a date object.
That leaves you with only the resource of appealing to your own
authority or that of the unfortunate who had the task of teaching you.
You should also read ECMA-232.
Did your FAQs and ECMA-232 teach you the following?
The ignorant should be unformed that the inner parentheses above are
computationally superfluous. Some may consider that they aid
legibility.
Unformed is right
seeing how superfluous they really are -- oh and don't go thinking
++date1 is going to make things right with the world either
So pardon me if I continue to march to my own drummer because books are
tools to serve us, if books are our masters then we are the tools