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


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

Date Conversion ?

Started by"Mel Smith" <med_cutout_syntel@aol.com>
First post2013-12-16 15:55 -0700
Last post2013-12-22 09:52 -0700
Articles 4 on this page of 24 — 9 participants

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


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#22368

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-12-19 20:21 +0000
Message-ID<K5f01p0$U1sSFwA4@invalid.uk.co.demon.merlyn.invalid>
In reply to#22362
In comp.lang.javascript message <bhckeoFed4lU1@mid.individual.net>, Tue,
17 Dec 2013 20:51:48, Mel Smith <med_cutout_syntel@aol.com> posted:

>Hi :
>
>    Thank you all for these enlightening lessons !
>
>    My date probs are now solved.

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


-- 
 (c) John Stockton, nr London, UK.  Mail via homepage.  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
  No Encoding. Quotes before replies. Snip well. Write clearly. Mail no News.

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


#22370

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-12-20 09:52 -0700
Message-ID<bhjavfFre0kU1@mid.individual.net>
In reply to#22368
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();
}


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


#22372

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-12-21 20:41 +0000
Message-ID<RmsCCZj0zftSFwL8@invalid.uk.co.demon.merlyn.invalid>
In reply to#22370
In comp.lang.javascript message <bhjavfFre0kU1@mid.individual.net>, Fri,
20 Dec 2013 09:52:57, Mel Smith <med_cutout_syntel@aol.com> posted:

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

JJ is inept. That function accepts dates before and after the end of the
month named.  Date checking is in the newsgroup FAQ, and on my Web site.
Form numbers for Y M' D, use nD = new Date(Date.UTC(Y, M', D)), and
check whether nD.getUTCMonth() agrees with M'.  IIRC, that method fails
for the end of February in Year Zero.  That's written from memory but is
at least about right - it assumes the date field is assuredly of no more
than two digits.

The original article did not mention date checking; if it is machine-
generated or already checked, there should be no need to check it again.

Your code uses local date routines.  Those, in temperate countries, are
substantially slower than UTC routines, since the date offset from GMT
must be found and used.

The Date Object is not needed, and its creation wastes time.  You can
extract the Mmm dd yy fields, convert Mmm to a number mm as already
described, and form  (yy*100+mm)*100+dd  which is easily seen to be an
integer rising by at least 1 at each midnight.  But, if you do check
with a Date Object, use its value for comparisons.

I do not know whether it will be quicker to load those into an array and
then use Math.(min|max).apply, or to just watch for increased or
decreased values.  If speed matters to you, you should test that and
report the result to enlighten the rest of us.

Your code is not executable as posted, for at least two reasons.  Never
allow your posting agent to line-wrap code.

I'm still not clear as to whether you want to find the values or the
positions or both for the earliest and latest dates.


-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

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


#22373

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-12-22 09:52 -0700
Message-ID<bhojmuFi41U1@mid.individual.net>
In reply to#22372
Dr Stockton said:

> JJ is inept. That function accepts dates before and after the end of the
> month named.  Date checking is in the newsgroup FAQ, and on my Web site.
> Form numbers for Y M' D, use nD = new Date(Date.UTC(Y, M', D)), and
> check whether nD.getUTCMonth() agrees with M'.  IIRC, that method fails
> for the end of February in Year Zero.  That's written from memory but is
> at least about right - it assumes the date field is assuredly of no more
> than two digits.
>
> The original article did not mention date checking; if it is machine-
> generated or already checked, there should be no need to check it again.
>
> Your code uses local date routines.  Those, in temperate countries, are
> substantially slower than UTC routines, since the date offset from GMT
> must be found and used.
>
> The Date Object is not needed, and its creation wastes time.  You can
> extract the Mmm dd yy fields, convert Mmm to a number mm as already
> described, and form  (yy*100+mm)*100+dd  which is easily seen to be an
> integer rising by at least 1 at each midnight.  But, if you do check
> with a Date Object, use its value for comparisons.
>
> I do not know whether it will be quicker to load those into an array and
> then use Math.(min|max).apply, or to just watch for increased or
> decreased values.  If speed matters to you, you should test that and
> report the result to enlighten the rest of us.
>
> Your code is not executable as posted, for at least two reasons.  Never
> allow your posting agent to line-wrap code.
>
> I'm still not clear as to whether you want to find the values or the
> positions or both for the earliest and latest dates.
>

Because of Christmas coming fast at us and because of guests arriving at my 
winter home in Arizona, I must wait a week or so before I delve deeper into 
your critique.

Bur, thank you for your analysis, and ...

Merry Christmas to you and all the folks here on this ng !

-Mel Smith

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

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


csiph-web