html form: date field auto-adjust

D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 15 Mar 2005
20:00:09, seen in Matt Kruse
Martin Herrman wrote:
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:

Unfortunately, the Americans think that the word "foreign" is spelt
i n t e r n a t i o n a l .

The international formats are yyyy-mm-dd and certain others derived from
that, such as yyyymmdd; they are given by the internationally-agreed
standard ISO 8601.

Those that followed were multi-national formats.

There is always a risk with code that is willing to accept either, say,
25/12/2004 or 12/25/2004 may be employed without testing that it gives
the right result for days before the 13th of the month with D!=M.
(2) Always validate on the server-side if your code depends on a certain
format.

Never make rash assumptions; there may not *be* server side processing;
there may be nothing sent from the reader's copy of a Web page back over
the Internet, or the javascript may be executed by WSH on the machine
where it resides.

Final validation should be on a machine under the control of those who
use the values in question. Validation at data entry may well be
helpful to those who enter data. That, I think, covers everything.
 
M

Matt Kruse

Dr said:
Unfortunately, the Americans think that the word "foreign" is spelt
i n t e r n a t i o n a l .
The international formats are yyyy-mm-dd and certain others derived
from that, such as yyyymmdd; they are given by the
internationally-agreed standard ISO 8601.

International means:
1. Of, relating to, or involving two or more nations
2. Extending across or transcending national boundaries

A list of "international" formats, to me, means those date formats used
across various nations.

But if you want to play semantics games, go ahead...
 
R

rh

Dr John Stockton wrote:

function FudgeDate(S) { var A, m = "-", O = '0'
if (/^(\d\d)(\d\d)(\d\d\d\d)$/.test(S))
with (RegExp) return $1 + m + $2 + m + $3
if (/^(\d)(\d)(\d\d)$/.test(S)) // ?
with (RegExp) return O + $1 + m + O + $2 + m + "20" + $3 // ?
A = S.split(/\D+/)
if (A.length!=3) return
if (+A[2]<100) A[2] = +A[2] + 2000
if (A[1].length<2) A[1] = O + A[1]
if (A[0].length<2) A[0] = O + A[0]
return A[0] + m + A[1] + m + A[2] }


There's something better than using test & $1 $2 $3 that way; but I
don't recall it at the moment.

You may have been thinking of "match" where the captures are available
in the resulting array (provided the "g" modifier is not used), e.g.:

function FudgeDate( v ) {
var x;
v = v.replace( /^\s+|\s+$/g, "" );
if ( x = v.match( /^(\d\d)(\d\d)(\d\d\d\d)$/ ) );
else if( x = v.match( /^(\d)(\d)(\d\d)$/ ) );
if ( x ) x.shift( );
else {
x = v.split( /\D+/ );
if ( x.length < 3 ) return;
}
if ( x[ 2 ] < 100 ) x[ 2 ] = + x[ 2 ] + 2000;
return ( "0"+x.join( "-0" ) ).replace( /0(\d{2})/g, "$1" );
}


As some are "shift" deficient:

Array.prototype.shift = ( function ( ) {
if ( Array.prototype.shift ) return Array.prototype.shift;
return function( ) {
var ret;
if( this.length ) {
ret = this[ 0 ];
for ( var k = 1; k < this.length; k++ ) this[ k-1 ] = this[
k ];
this.length--;
}
return ret;
}
}
) ( );

../rh
 
L

Lee

Matt Kruse said:
My response took about 1 minute to post, and it seems to address the
poster's request perfectly.
I even added some disclaimers.
And I wasn't an ass about it.

So you've sent the OP off to implement your solution with
the thought, somewhere in the back of his mind, that it may
not work all the time, and that there is something about doing
it on the server that might be important, too. Congratulations
on not being an ass.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 16 Mar 2005
21:53:32, seen in Matt Kruse
International means:

Insert : In the American dialect
1. Of, relating to, or involving two or more nations
2. Extending across or transcending national boundaries

A list of "international" formats, to me, means those date formats used
across various nations.

That's because you know American, not English.
But if you want to play semantics games, go ahead...

However, many here have been taught properly - probably almost all of
those educated in mainland Europe, and the Scots of course, and some of
those educated not-too-recently in England too - and it will be helpful
for them to realise that what you appear to mean is not what you
actually mean. The OP, apparently a student in the Netherlands, may
well be one such.

To see the standard use of the word "international", see how it is used
in International Standards - if you can find copies in the USA.

Your meaning is AIUI that customary in the US computer industry.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Wed, 16 Mar 2005 21:22:08, seen in rh
You may have been thinking of "match" where the captures are available
in the resulting array (provided the "g" modifier is not used)

In principle, yes (and that might be better) : but a search of my site
suggests I was actually thinking of "exec" as in


function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
with (new Date(y, m, d))
return (getMonth()==m && getDate()==d) /* was y, m */ }

function ReadISO8601date(Q) { var T // adaptable for other layouts
if ((T = /^(\d+)([-\/])(\d\d)(\2)(\d\d)$/.exec(Q)) == null)
{ return -2 } // bad format
for (var j=1; j<=5; j+=2) T[j] = +T[j] // some use needs numbers
if (!ValidDate(T[1], T[3]-1, T[5])) { return -1 } // bad value
return [ T[1], T[3], T[5] ] }


which latter reads and validates an ISO date (being a little liberal as
regards separators, and only after Year -1) and returns either a
negative error number or an array [Y, M, D].

A version which if successful returns the Date Object generated in
ValidDate else undefined or NaN might be worth having.

+ + +

I now have parameterised javascript for all the sorts of week number
that I can think of which have Week 1 near January 1, not just the
International Standard one (Week 1 starts on a fixed day of a fixed
month, can be trivially derived from code for Inland Revenue weeks) -
see <URL:http://www.merlyn.demon.co.uk/weekcalc.htm#NIC>.
 
L

Lasse Reichstein Nielsen

Matt Kruse said:
International means:
1. Of, relating to, or involving two or more nations
2. Extending across or transcending national boundaries

A list of "international" formats, to me, means those date formats used
across various nations.

I.e., any format used in more than one nation. I.e., any format :)

/L
 
R

rh

Dr said:
JRS: In article
, dated Wed, 16 Mar 2005 21:22:08, seen in news:comp.lang.javascript, rh

In principle, yes (and that might be better) : but a search of my site
suggests I was actually thinking of "exec" as in

Take your choice. According to ECMA 262/3 - 15.5.4.10, in the absence
of the "g" modifier on the RegExp, use of "exec" and "match" should
provide identical results.

If there are browser exceptions, I'm not aware.

<..>

../rh
 
R

Randy Webb

Dr said:
JRS: In article <[email protected]>, dated Wed, 16 Mar 2005
21:53:32, seen in Matt Kruse



Insert : In the American dialect

Insert: In the opinion of John Stockton, that is what it means "In the
American dialect".

If you were as educated on the dialects as you seem to think you are
then you would be well aware that there are at minimum 5 distinct
dialects in the USA.
That's because you know American, not English.

Hmmm. Official Language of the USA: English.
However, many here have been taught properly

Are you that ignorant to imply that those taught in the American schools
were not "taught properly"? They *were* taught properly, they just
weren't taught what you think they should have been taught.


- probably almost all of
those educated in mainland Europe, and the Scots of course, and some of
those educated not-too-recently in England too - and it will be helpful
for them to realise that what you appear to mean is not what you
actually mean.

Insert: In the opinion of John Stockton.

But, how do you know what he meant to say? Are you a psychic Jackass now
or still just a Jackass?
To see the standard use of the word "international", see how it is used
in International Standards - if you can find copies in the USA.

The "standard" use is dependent on who you let define that standard. I
am unaware of *any* authority that gives a "standard" definition for
*any* word.
Your meaning is AIUI that customary in the US computer industry.

Among other places.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 17 Mar
2005 20:11:00, seen in Randy Webb
Dr John Stockton wrote:

Hmmm. Official Language of the USA: English.

Only in the American language.
The proper term, in English, is American English.
There are resemblances; but there are definite differences, one of which
is the meaning of that word.

The "standard" use is dependent on who you let define that standard. I
am unaware of *any* authority that gives a "standard" definition for
*any* word.

Yes, most Americans are sadly ignorant of the Oxford English Dictionary
in particular, and of International Standards in general.

The undeniable point remains : that the way in which most Americans, or
at least most American technicians, use the word "International" is
liable to deceive people in other parts of the world.

Evidently you now know the meaning of the word "International" as used
in "International Organization for Standards", often called
"International Standards Organization" or just ISO : is there an
American word that expresses that meaning, as opposed to the US
customary one, or is their language deficient because Americans don't
have the concept?
 
J

John W. Kennedy

Dr said:
JRS: In article <[email protected]>, dated Thu, 17 Mar
2005 20:11:00, seen in Randy Webb
Yes, most Americans are sadly ignorant of the Oxford English Dictionary
in particular, and of International Standards in general.

If you are under the curious impression that all the words of English
(or any other language, for that matter) are univocal, as you seem to be
pronouncing, I suggest you spend a little time with that magisterial
work, yourself. "Set" is instructive, but "cleave" is more amusing.

By the way, British educational standards are at least as debased as
American, these days; see
<URL:http://www.timesonline.co.uk/article/0,,1059-1530304,00.html> for a
grim example.

---
John W. Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
 
D

Douglas Crockford

The "standard" use is dependent on who you let define that standard. I
Yes, most Americans are sadly ignorant of the Oxford English Dictionary
in particular, and of International Standards in general.

This ain't France, bub. The OED is definitive on the evolution of the
language, but like most good dictionaries it is descriptive, not
prescriptive, when it comes to current usage.

'When _I_ use a word,' Humpty Dumpty said, in rather a scornful tone,
'it means just what I choose it to mean -- neither more nor less.'

'The question is,' said Alice, `whether you _can_ make words mean so
many different things.'

'The question is,' said Humpty Dumpty, 'which is to be master -- that's
all.'

http://www.amazon.com/exec/obidos/ASIN/0393048470/wrrrldwideweb
 
J

John W. Kennedy

Douglas said:
This ain't France, bub. The OED is definitive on the evolution of the
language, but like most good dictionaries it is descriptive, not
prescriptive, when it comes to current usage.

'When _I_ use a word,' Humpty Dumpty said, in rather a scornful tone,
'it means just what I choose it to mean -- neither more nor less.'

'The question is,' said Alice, `whether you _can_ make words mean so
many different things.'

'The question is,' said Humpty Dumpty, 'which is to be master -- that's
all.'

http://www.amazon.com/exec/obidos/ASIN/0393048470/wrrrldwideweb

"Let no one say, and say it to your shame,
That there was meaning here before you came."
-- C. S. Lewis
 
R

Randy Webb

Dr said:
JRS: In article <[email protected]>, dated Thu, 17 Mar
2005 20:11:00, seen in Randy Webb



Only in the American language.

There is no such thing as "American Language". It may very well be a set
of dialects of a dialect of the original English Language but it is not
a Language in, and of, itself.
The proper term, in English, is American English.

British English, American English, Austrailian English, or what specific
"English" are you referring to?
There are resemblances; but there are definite differences, one of which
is the meaning of that word.

There are definite differences in the meaning of *any* word, and not
even across languages. Sometimes, even within a dialect words have
different meanings.
Yes, most Americans are sadly ignorant of the Oxford English Dictionary
in particular, and of International Standards in general.

Thats asinine.
The undeniable point remains : that the way in which most Americans, or
at least most American technicians, use the word "International" is
liable to deceive people in other parts of the world.

No, the undeniable point is that you are trying to enforce your personal
preferences about the definition of the word "International" to fit your
own beliefs.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Fri, 18 Mar
2005 22:38:06, seen in Randy Webb

I note that you have chickened out of answering my question :
Evidently you now know the meaning of the word "International" as used
in "International Organization for Standards", often called
"International Standards Organization" or just ISO : is there an
American word that expresses that meaning, as opposed to the US
customary one, or is their language deficient because Americans don't
have the concept?
 
D

Dr John Stockton

JRS: In article <[email protected]
m>, dated Fri, 18 Mar 2005 17:41:59, seen in
Douglas Crockford said:
This ain't France, bub. The OED is definitive on the evolution of the
language, but like most good dictionaries it is descriptive, not
prescriptive, when it comes to current usage.

I do not have a full OED here.

No doubt it describes, as it should, all usage that a reader may come
across. But ISTR that, read with reasonable care, it provides an
adequate indication of which meanings are appropriate for use when
writing good current English, and which are not.

But I grant that the Academie Francaise, which I remembered too late, is
a more definitive example.

Nevertheless, one should note that ISO uses the word International with
a definite meaning - the one I agree with - and who should know better?
I would not be at all surprised to learn that there is an ISO 0 or 1
which defines authoritatively how to read and write International
Standards, including what such words mean.
 
M

Matt Kruse

Randy said:
Thats asinine.

Yes, John is.

Everyone knows that a 'standard' only has meaning if people decide to follow
it.
"International" means whatever people agree that it means.
 
R

Randy Webb

Dr said:
JRS: In article <[email protected]>, dated Fri, 18 Mar
2005 22:38:06, seen in Randy Webb



I note that you have chickened out of answering my question :

Now thats as ludicrous as you have asked/accused in a long time. I
chickened out of nothing. I chose to ignore a question/comment that in
my opinion was intended to do nothing more than annoy me. But it didn't
work.
Evidently you now know the meaning of the word "International" as used
in "International Organization for Standards", often called
"International Standards Organization" or just ISO :

Yep, I know what the word International means. And I know what it means
in the context of ISO.

is there an American word that expresses that meaning, as opposed to the US
customary one, or is their language deficient because Americans don't have
the concept?

I am not sure what you are intending to ask here. Is that to imply that
the US doesn't know what the word "International" means? Yes, there is a
word for that - "International". Just because you don't seem to accept
that many US citizens know the meaning of the word does *not* mean they
"don't have the concept".
 
R

Randy Webb

Dr said:
JRS: In article <[email protected]
m>, dated Fri, 18 Mar 2005 17:41:59, seen in


I do not have a full OED here.

Then you should not use it as a defense of your stance.
No doubt it describes, as it should, all usage that a reader may come
across.

That is very highly doubtful, but the reason for that would elude you.
But ISTR that, read with reasonable care, it provides an adequate
indication of which meanings are appropriate for use when writing good
current English, and which are not.

Which is totally, and 100%, dependent upon the interpretation of the
reader, which makes it totally useless for that point.
But I grant that the Academie Francaise, which I remembered too late, is
a more definitive example.

Hindsight is *always* 20/20, is it not?
Nevertheless, one should note that ISO uses the word International with
a definite meaning - the one I agree with - and who should know better?

The fact that you agree with it is irrelevant.
I would not be at all surprised to learn that there is an ISO 0 or 1
which defines authoritatively how to read and write International
Standards, including what such words mean.

Then perhaps you should find where it defines what it means when the ISO
says it is "International" and report back to us.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top