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


Groups > comp.lang.javascript > #22370

Re: Date Conversion ?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From "Mel Smith" <med_cutout_syntel@aol.com>
Newsgroups comp.lang.javascript
Subject Re: Date Conversion ?
Date Fri, 20 Dec 2013 09:52:57 -0700
Lines 116
Message-ID <bhjavfFre0kU1@mid.individual.net> (permalink)
References <bh9en6Foh76U1@mid.individual.net> <j5A+FiEA$JsSFwlR@invalid.uk.co.demon.merlyn.invalid> <bhckeoFed4lU1@mid.individual.net> <K5f01p0$U1sSFwA4@invalid.uk.co.demon.merlyn.invalid>
X-Trace individual.net 9CkIsof+XpS2kBZy28gHSQcYeQgo0l0cCGuFuCYqVJX9liy6+G
Cancel-Lock sha1:CiRJpef0fqo722coB1dn9+VUkJM=
X-Priority 3
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE Produced By Microsoft MimeOLE V6.00.2900.6157
X-RFC2646 Format=Flowed; Original
Xref csiph.com comp.lang.javascript:22370

Show key headers only | View raw


Dr. J said:

> Show us your code, and we can think about whether they are reliably
> solved.

Hi Dr Stockton:

    Here's my latest iteration of my date checking function (which includes 
JJ's parsedate() function and Thomas' Math function usage to find lows and 
highs.

-Mel Smith

*********************************

function chkdate(stnd,cdate) {
// where stnd is either "ST" or "ND" and
// where cdate is in the form: mm-dd-yyyy or mm/dd/yyyy (read/write)
// global scrcols is currently 13
// global playdatecol is currently the third column (i.e., 2)

var lok = true ;
var i,j,scrtable,rows,cells,cell,numrows;
var playdatestr,playdateval ;
var datearray = [] ;
var low,high,nlen ;
var yr,mth,day ;  // generalized checking for a modified date
var lowdate,nlowyr,clowyr,nlowmth,clowmth,nlowday,clowday ;
var highdate,nhighyr,chighyr,nhighmth,chighmth,nhighday,chighday ;

if (partof("mm",cdate) && partof("dd",cdate) ) { // then no date was 
entered -- so start searching
   scrtable = getobj("iscrtable") ;
   rows = scrtable.rows ;
   numrows = rows.length ;

   for (i=4;i<numrows;i++) {
      cells = rows[i].cells ;
      if (cells.length < scrcols) continue ;  // some rows are separators 
and are one column wide
      cell = cells[playdatecol] ;
      playdatestr = cell.innerHTML ;
      // now convert this string to a numeric javascript date value
      playdateval = parseDate(playdatestr) ; // from JJ of my JS/ES group
      if (isNaN(playdateval)) {
         alert("Faulty PlayDate Value ?? at row: "+ i) ;
         continue ;
         }
      datearray.push(playdateval) ;
      }
   low  = Math.min.apply(Math,datearray) ;  // from Thomas Lahn of JS/ES 
group
   high = Math.max.apply(Math,datearray) ;  // ditto

   // now re-make this into a date vrbl -- rather than just a vrbl
   lowdate = new Date(low) ;
   highdate = new Date(high) ;

   // Now convert back into yr,mth, and cday

   nlowyr = lowdate.getFullYear() ;
   clowyr = nlowyr.toString() ;
   nlowmth = lowdate.getMonth() + 1 ;
   clowmth = strzero(nlowmth,2) ;   // width of 2
   nlowday = lowdate.getDate() ;
   clowday = strzero(nlowday,2) ;

   nhighyr = highdate.getFullYear() ;
   chighyr = nhighyr.toString() ;
   nhighmth = highdate.getMonth() + 1 ;
   chighmth = strzero(nhighmth,2) ;
   nhighday = highdate.getDate() ;
   chighday = strzero(nhighday,2) ;

   // Now replace dates in box with actual date in table
   if (stnd === "ST") {
      startdateinp.value = clowmth+"-"+clowday+"-"+clowyr ;
      }
   if (stnd === "ND") {
      enddateinp.value = chighmth+"-"+chighday+"-"+chighyr ;
      }
   return lok ;
   }

// Else we have a modified date field to examine

mth = +cdate.substr(0,2) ;
if (mth < 1 || mth > 12) return !lok ;

day = +cdate.substr(3,2) ;
if (day < 1 || day > 31) return !lok ;
// the above is not a complete check -- do better later

yr = +cdate.substr(6,4) ;
// today is a global date object of current day
if (yr < 2000 || yr > today.getFullYear()) return !lok ;

// now check presence of separators and allow '/' or '-'
if (!partof(cdate.substr(2,1),"/-")) return !lok ;
if (!partof(cdate.substr(5,1),"/-")) return !lok ;

return lok ;
}

function parseDate(dateStr) {
// by JJ of JS/ES group
// for "Mmm dd/yy" format, year 20nn only.
// converts to "Mmm dd yyyy" (good for FF, IE8, Chrome, Opera).
// returns NaN if dateStr is in invalid format.

var date = dateStr.replace(/([a-z]+ \d+)\/(\d+)/,"$1 20$2");
return (new Date(date)).valueOf();
}


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


Thread

Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-16 15:55 -0700
  Re: Date Conversion ? Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-17 01:06 +0100
    Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-19 12:34 +0100
      Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-20 22:29 +0100
        Re: Date Conversion ? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-23 10:00 -0200
  Re: Date Conversion ? JJ <duh@nah.meh> - 2013-12-17 07:06 +0700
    Re: Date Conversion ? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-17 00:35 +0000
      Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-16 18:16 -0700
      Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-17 10:09 +0100
        Re: Date Conversion ? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-17 17:02 +0000
        Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-18 19:14 +0000
          Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-19 15:42 +0100
            Re: Date Conversion ? "Michael F. Stemper" <michael.stemper@gmail.com> - 2013-12-19 09:20 -0600
              Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-20 10:04 +0100
      Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-17 15:12 +0100
        Re: Date Conversion ? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-17 18:10 -0200
          Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-17 21:42 +0100
    Re: Date Conversion ? Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-18 13:36 +0100
  Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-17 19:02 +0000
    Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-17 20:51 -0700
      Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-19 20:21 +0000
        Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-20 09:52 -0700
          Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-21 20:41 +0000
            Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-22 09:52 -0700

csiph-web