Date problems in Safari Browser only

Discussion in 'Javascript' started by ipy2006, Dec 26, 2006.

  1. ipy2006

    ipy2006 Guest

    Only in Safari browser the current year shows as 1970. Also "Non digits
    found in year" is triggered in the Safari broswer. Please help.
    Thanks,
    Yasaswi

    function verifyYear( field )
    {
    var _x = field.value;

    var _exp = new RegExp(/^\d+$/);
    var _test=_exp.test(_x);

    var _currentDate = new Date();

    var yy = _currentDate.getUTCFullYear();

    alert("entered year is : " + _x + " current year is : " + yy );

    if(_x.length!=4) {
    alert("Please enter four digit year.");
    return false;
    }
    else if(!_test) {
    alert("Non digits found in year.");
    return false;
    }
    else if( _x > yy ) {
    alert("You entered a year in the future. Please enter valid year."
    );
    return false;
    }
    else {
    return true;
    }

    }
    ipy2006, Dec 26, 2006
    #1
    1. Advertising

  2. ipy2006

    Evertjan. Guest

    ipy2006 wrote on 26 dec 2006 in comp.lang.javascript:

    > Only in Safari browser the current year shows as 1970. Also "Non
    > digits found in year" is triggered in the Safari broswer. Please help.
    > Thanks,
    > Yasaswi
    >
    > function verifyYear( field )
    > {
    > var _x = field.value;
    >
    > var _exp = new RegExp(/^\d+$/);
    > var _test=_exp.test(_x);
    >
    > var _currentDate = new Date();
    >
    > var yy = _currentDate.getUTCFullYear();
    >
    > alert("entered year is : " + _x + " current year is : " + yy );
    >
    > if(_x.length!=4) {
    > alert("Please enter four digit year.");
    > return false;
    > }
    > else if(!_test) {
    > alert("Non digits found in year.");
    > return false;
    > }
    > else if( _x > yy ) {
    > alert("You entered a year in the future. Please enter valid
    > year."
    > );
    > return false;
    > }
    > else {
    > return true;
    > }
    >
    >}


    I don't know Safari,
    but .getUTCFullYear() should be valid from Safari 1.2.


    You make a rather complex code,
    with al those spurious "else" clauses after a return.
    [Please do not use tab chars in a code on usenet]
    try:


    function verifyYear( field ) {
    var x = field.value;
    var y = new Date().getUTCFullYear();
    alert("entered year is : " + x + " current year is : " + y );

    if( x.length != 4 ) {
    alert("Please enter four digit year.");
    return false;
    };

    if(/[^\d]/.test(x)) {
    alert("Non digits found in year.");
    return false;
    };

    if( x > y ) {
    alert("You entered a year in the future. Please enter valid year.");
    return false;
    };

    return true;
    }



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Dec 26, 2006
    #2
    1. Advertising

  3. In comp.lang.javascript message <
    glegroups.com>, Tue, 26 Dec 2006 12:38:59, ipy2006 <>
    posted:
    >Only in Safari browser the current year shows as 1970.


    Then you should alert(_currentDate) to see what you are getting.

    > Also "Non digits
    >found in year" is triggered in the Safari broswer.


    Then you should alert(_x) to see what you are getting.

    >function verifyYear( field )
    >{
    > var _x = field.value;
    >
    > var _exp = new RegExp(/^\d+$/);


    or. reversing logic, /\D/

    > var _test=_exp.test(_x);
    >
    > var _currentDate = new Date();
    >
    > var yy = _currentDate.getUTCFullYear();
    >
    > alert("entered year is : " + _x + " current year is : " + yy );


    Entered year is by local civil time. Current year is UTC. They should,
    generally, not be compared.

    > if(_x.length!=4) {
    > alert("Please enter four digit year.");
    > return false;
    > }
    > else if(!_test) {
    > alert("Non digits found in year.");
    > return false;
    > }
    > else if( _x > yy ) {
    > alert("You entered a year in the future. Please enter valid year."
    >);
    > return false;
    > }
    > else {
    > return true;
    > }
    >
    >}


    An "else" is nor needed after "if ... return ...".


    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
    Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
    Dr J R Stockton, Dec 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    597
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,250
    Michael Borgwardt
    May 30, 2004
  3. Steve K
    Replies:
    3
    Views:
    651
    Steve K
    Jun 24, 2005
  4. bala2008
    Replies:
    0
    Views:
    646
    bala2008
    Jun 27, 2008
  5. Lance Dyas
    Replies:
    4
    Views:
    100
    Randy Webb
    Oct 6, 2005
Loading...

Share This Page