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 20 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 1 of 2  [1] 2  Next page →


#22351 — Date Conversion ?

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-12-16 15:55 -0700
SubjectDate Conversion ?
Message-ID<bh9en6Foh76U1@mid.individual.net>
Hi:

    Environment:

    I have an approx 300-row table with 13 columns.  Column 3 of this table 
contains abbreviated date strings in the following format:

            'Mmm dd/yy' (examples:   May 31/13   Jan 1/11, etc)

    (All dates are current or in the past with all dates in the 21st 
Century, and IE8 must be accommodated)

    I would like to find the *oldest* date and the *newest* date in this 
column.

    for (i=0;i<rows.length;i++) {
        // get the date string here for each row and date column
        // using an innerHTML operation on the cell.
        // Then, rip out the month, day, and year strings from the date 
string,
        // then convert these strings to integers, then ...
        // combine intgers into a JS/ECMAScript date *value* ...
        // i.e., into millisecs.  Then save lowest and newest values away.

        // Need some elegance here and above please ?
    }

Suggestion or Code very welcome.

btw, I can supply *my* code down to producing a correect date value, but it 
is clumsy and embarassing. But I will if you insist.

Thanks,
-- 
Mel Smith

[toc] | [next] | [standalone]


#22352

FromBjoern Hoehrmann <bjoern@hoehrmann.de>
Date2013-12-17 01:06 +0100
Message-ID<5f4va916l0r2qoto1r4iq5dh0i0dnqthnv@hive.bjoern.hoehrmann.de>
In reply to#22351
* Mel Smith wrote in comp.lang.javascript:
>    I have an approx 300-row table with 13 columns.  Column 3 of this table 
>contains abbreviated date strings in the following format:
>
>            'Mmm dd/yy' (examples:   May 31/13   Jan 1/11, etc)
>
>    (All dates are current or in the past with all dates in the 21st 
>Century, and IE8 must be accommodated)
>
>    I would like to find the *oldest* date and the *newest* date in this 
>column.

A simple solution would be to use a Regex to split the value into its
components and converting into a form like `yyyymmdd`. You can then use
string comparison to find the minimum and maximum value (you could sort
the values but that has non-linear worst case behavior). In Perl,

  my ($m, $d, $y) = m#(\S+)\s+(\d+)/(\d+)#;
  $m = {
    Jan => 1,
    Feb => 2,
    ...
  }->{$m};

  my $comparable = sprintf "%04u%02u%02u", $y, $m, $d;

In JavaScript you can use the `map` and `reduce` functions to map each
value to the comparable value and then finding the maximum and minimum
values in the mapped array,

  var mapped = mmmddyy_strings.map(function(e) {
    ...
    return comparable;
  });
  var minimum = mapped.reduce(...);
  var maximum = mapped.reduce(...);
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

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


#22365

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-12-19 12:34 +0100
Message-ID<3082498.rgpu3afg7L@PointedEars.de>
In reply to#22352
Bjoern Hoehrmann wrote:

> * Mel Smith wrote in comp.lang.javascript:
>>    I have an approx 300-row table with 13 columns.  Column 3 of this
>>    table
>> contains abbreviated date strings in the following format:
>>
>>            'Mmm dd/yy' (examples:   May 31/13   Jan 1/11, etc)
>>
>>    (All dates are current or in the past with all dates in the 21st
>> Century, and IE8 must be accommodated)
>>
>>    I would like to find the *oldest* date and the *newest* date in this
>> column.
> 
> A simple solution would be to use a Regex to split the value into its
> components and converting into a form like `yyyymmdd`. You can then use
> string comparison to find the minimum and maximum value (you could sort
> the values but that has non-linear worst case behavior). In Perl,
> 
>   my ($m, $d, $y) = m#(\S+)\s+(\d+)/(\d+)#;
>   $m = {
>     Jan => 1,
>     Feb => 2,
>     ...
>   }->{$m};
> 
>   my $comparable = sprintf "%04u%02u%02u", $y, $m, $d;
> 
> In JavaScript you can use the `map` and `reduce` functions to map each
> value to the comparable value and then finding the maximum and minimum
> values in the mapped array,
> 
>   var mapped = mmmddyy_strings.map(function(e) {
>     ...
>     return comparable;
>   });
>   var minimum = mapped.reduce(...);
>   var maximum = mapped.reduce(...);

In JavaScript 1.5 and later, as in other implementations of ECMAScript, you 
can do much the same as in Perl:

  var matches = input.match(/(\S+)\s+(\d+)\/(\d+)/);
  var m = ({
    "Jan": 1,
    "Feb": 2,
    …
  })[m];

sprintf() is not a built-in, and you would have to implement it yourself 
(like I do in JSX:string.js [1]), but it is not necessary because Date 
instances – especially under these conditions – are easily constructed and 
comparable:

  var mapped = mmmddyy_strings.map(function (e) {
    /* 
     * or
      
         var matches = new jsx.regexp.String(e)
           .match(new jsx.regexp.RegExp(
             "(?<m>\\S+)\\s+(?<d>\\d+)/(?<y>\\d+)"));
     */
    var matches = input.match(/(\S+)\s+(\d+)\/(\d+)/);

    /*
     * or

         var m = ({
           "Jan": 1,
           "Feb": 2,
           …
         })[matches.groups["m"]];

     * with JSX:regexp.js [2]
     */
    var m = ({
      "Jan": 1,
      "Feb": 2,
      …
    })[matches[0]];

    return new Date("20" + matches[2], m - 1, matches[1]);
  });

It is, however, more memory-efficient to create the mapping object only 
once.

_______
[1] <http://pointedears.de/wsvn/JSX/trunk/string.js>
[2] <http://PointedEars.de/scripts/test/regexp>
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


#22371

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-12-20 22:29 +0100
Message-ID<23946178.EFlsh5Ejh5@PointedEars.de>
In reply to#22365
Thomas 'PointedEars' Lahn wrote:

> Bjoern Hoehrmann wrote:
>> A simple solution would be to use a Regex to split the value into its
>> components and converting into a form like `yyyymmdd`. You can then use
>> string comparison to find the minimum and maximum value (you could sort
>> the values but that has non-linear worst case behavior). In Perl,
>> 
>>   my ($m, $d, $y) = m#(\S+)\s+(\d+)/(\d+)#;
>>   $m = {
>>     Jan => 1,
>>     Feb => 2,
>>     ...
>>   }->{$m};
>> 
>>   my $comparable = sprintf "%04u%02u%02u", $y, $m, $d;
>> 
>> […]
> 
> In JavaScript 1.5 and later, as in other implementations of ECMAScript

Edition _3_ and later,

> you can do much the same as in Perl:
> 
>   […]
>     /*
>      * or
> 
>          var m = ({
>            "Jan": 1,
>            "Feb": 2,
>            …
>          })[matches.groups["m"]];
> 
>      * with JSX:regexp.js [2]
>      */
>     var m = ({
>       "Jan": 1,
>       "Feb": 2,
>       …
>     })[matches[0]];

    var m = {
      "Jan": 1,
      "Feb": 2,
      …
    }[matches[0]];

(and similar; without parentheses) suffices because the right-hand side of 
the assignment is evaluated in Expression context, not Statement context.

This is different with

  var s = '{"foo": "bar"}';
  
  /* Syntax error in the /Program/ parsed by eval() */
  var o = eval(s):

  /* Correct syntax in the /Program/ parsed by eval() */
  var o = eval("(" + s + ")"):

– as an insecure but backwards-compatible stand-in for JSON.parse() – and 
when for some reason you want to access a specific object referred by 
another object's property, based on a name:

  var s = "foo";

  {
    "foo": ["baz", "bar"]
  }[s].sort();
 
is a Syntax error;

  var s = "foo";

  ({
    "foo": ["baz", "bar"]
  })[s].sort();

is not.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


#22374

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2013-12-23 10:00 -0200
Message-ID<l998k2$rhr$1@speranza.aioe.org>
In reply to#22371
On 20/12/2013 19:29, Thomas 'PointedEars' Lahn wrote:
> Thomas 'PointedEars' Lahn wrote:
>
>> Bjoern Hoehrmann wrote:

<snip>

>> you can do much the same as in Perl:
>>
>>    […]
>>      /*
>>       * or
>>
>>           var m = ({
>>             "Jan": 1,
>>             "Feb": 2,
>>             …
>>           })[matches.groups["m"]];
>>
>>       * with JSX:regexp.js [2]
>>       */
>>      var m = ({
>>        "Jan": 1,
>>        "Feb": 2,
>>        …
>>      })[matches[0]];
>
>      var m = {
>        "Jan": 1,
>        "Feb": 2,
>        …
>      }[matches[0]];
>
> (and similar; without parentheses) suffices because the right-hand side of
> the assignment is evaluated in Expression context, not Statement context.
>
> This is different with
>
>    var s = '{"foo": "bar"}';
>
>    /* Syntax error in the /Program/ parsed by eval() */
>    var o = eval(s):
>
>    /* Correct syntax in the /Program/ parsed by eval() */
>    var o = eval("(" + s + ")"):
>
> – as an insecure but backwards-compatible stand-in for JSON.parse() – and
> when for some reason you want to access a specific object referred by
> another object's property, based on a name:
>
>    var s = "foo";
>
>    {
>      "foo": ["baz", "bar"]
>    }[s].sort();
>
> is a Syntax error;
>
>    var s = "foo";
>
>    ({
>      "foo": ["baz", "bar"]
>    })[s].sort();
>
> is not.

It is so because an Expression cannot start with "function " or "{"
<http://ecma-international.org/ecma-262/5.1/#sec-12.4>

Besides the surrounding parentheses, we can use the comma operator:
<http://ecma-international.org/ecma-262/5.1/#sec-11.14>

var s = '{"foo": "bar"}';
var o = eval("1," + s);

Or:

var s = "foo";
1, {
      "foo": ["baz", "bar"]
    }[s].sort();

-- 
Joao Rodrigues (J.R.)

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


#22353

FromJJ <duh@nah.meh>
Date2013-12-17 07:06 +0700
Message-ID<1l7578dngtzld$.19qzw1e0gy93t$.dlg@40tude.net>
In reply to#22351
On Mon, 16 Dec 2013 15:55:32 -0700, Mel Smith wrote:
> Hi:
> 
>     Environment:
> 
>     I have an approx 300-row table with 13 columns.  Column 3 of this table 
> contains abbreviated date strings in the following format:
> 
>             'Mmm dd/yy' (examples:   May 31/13   Jan 1/11, etc)
> 
>     (All dates are current or in the past with all dates in the 21st 
> Century, and IE8 must be accommodated)
> 
>     I would like to find the *oldest* date and the *newest* date in this 
> column.
> 
>     for (i=0;i<rows.length;i++) {
>         // get the date string here for each row and date column
>         // using an innerHTML operation on the cell.
>         // Then, rip out the month, day, and year strings from the date 
> string,
>         // then convert these strings to integers, then ...
>         // combine intgers into a JS/ECMAScript date *value* ...
>         // i.e., into millisecs.  Then save lowest and newest values away.
> 
>         // Need some elegance here and above please ?
>     }
> 
> Suggestion or Code very welcome.
> 
> btw, I can supply *my* code down to producing a correect date value, but it 
> is clumsy and embarassing. But I will if you insist.

Fix the date string then make them to a Date object so that you can get the
timestamp integer value.

function parseDate(dateStr) {
  //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]


#22354

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-12-17 00:35 +0000
Message-ID<l8o67q$tli$1@dont-email.me>
In reply to#22353
On Tue, 17 Dec 2013 07:06:55 +0700, JJ wrote:

>> Suggestion or Code very welcome.
>> 
>> btw, I can supply *my* code down to producing a correect date value,
>> but it is clumsy and embarassing. But I will if you insist.
> 
> Fix the date string then make them to a Date object so that you can get
> the timestamp integer value.
> 
> function parseDate(dateStr) {
>   //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();
> }

To walk an array of numbers once to find the min and max values:

var low, high, i;
low = high = arr[0];
for( i = 1; i < arr.length; i++ ) {
	if ( arr[i] < low ) low = arr[i];
	if ( arr[i] > high ) high = arr[i];
}

// low and high are now the minimum and maximum values from the array

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#22355

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-12-16 18:16 -0700
Message-ID<bh9mvfFq42dU1@mid.individual.net>
In reply to#22354
Bjoern, JJ & Denis:

    Thanks for the suggestions and code.

    I'll digest them tomorrow.

    ( Now *my* stuff looks really bad :(   )

-Mel 

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


#22356

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-12-17 10:09 +0100
Message-ID<XnsA299674D3AA55eejj99@194.109.133.133>
In reply to#22354
Denis McMahon wrote on 17 dec 2013 in comp.lang.javascript:

>> function parseDate(dateStr) {
>>   //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();
>> }
> 
> To walk an array of numbers once to find the min and max values:
> 

1 There is no need for conversion into a date object value,
[ and fearing a DST-change during the code's execution perhaps ;-) ]
Putting these numbers in the below array will do fine as well:

(year * 10000) + (month * 100) + (day * 1)

===================================

> var low, high, i;
> low = high = arr[0];
> for( i = 1; i < arr.length; i++ ) {
> 	if ( arr[i] < low ) low = arr[i];
> 	if ( arr[i] > high ) high = arr[i];
> }

2 You can just store the pointers, 
supposedly those results are what you need in the html.

Try [not tested]:

var arr = [ -1, .... ];
var low = 0, high = 0, arrlen = arr.length, i;

for( i = 1; i < arrlen; i++ ) {
   if ( arr[i] < arr[low] ) low = i;
   if ( arr[i] > arr[high] ) high = i;
};

-- 
Evertjan.

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


#22358

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-12-17 17:02 +0000
Message-ID<l8q03k$fid$1@dont-email.me>
In reply to#22356
On Tue, 17 Dec 2013 10:09:17 +0100, Evertjan. wrote:

> Denis McMahon wrote on 17 dec 2013 in comp.lang.javascript:
> 
>>> function parseDate(dateStr) {
>>>   //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();
>>> }
>> 
>> To walk an array of numbers once to find the min and max values:
>> 
>> 
> 1 There is no need for conversion into a date object value,
> [ and fearing a DST-change during the code's execution perhaps ;-) ]
> Putting these numbers in the below array will do fine as well:
> 
> (year * 10000) + (month * 100) + (day * 1)
> 
> ===================================
> 
>> var low, high, i;
>> low = high = arr[0];
>> for( i = 1; i < arr.length; i++ ) {
>> 	if ( arr[i] < low ) low = arr[i]; if ( arr[i] > high ) high = arr
[i];
>> }
> 
> 2 You can just store the pointers,
> supposedly those results are what you need in the html.
> 
> Try [not tested]:
> 
> var arr = [ -1, .... ];
> var low = 0, high = 0, arrlen = arr.length, i;
> 
> for( i = 1; i < arrlen; i++ ) {
>    if ( arr[i] < arr[low] ) low = i; if ( arr[i] > arr[high] ) high = i;
> };

I think there's a flaw in the logic. If arr[0] is -1 and all the numbers 
in the array are +ve, you'll never change the low index, because no 
numbers in the array are less than arr[0] and low starts as 0. If you 
don't stick the -1 value in as the zeroth element, however, it should 
work fine.

My assumption is that either the first number in the array is the 
lowest / highest number, or another number in the array is lower / higher 
than the first number.

Taking arr.length will probably see a performance improvement over my 
code, I assume that's why you did it.

Looking at performance though, my variant does one array lookup unless it 
needs to change the low or high value, yours does a lookup for every 
comparison. Probably not going to be noticeable on arrays of a few 
thousand members or less though.

Finally, Having set both low and high to the same values initially, it 
might be slightly quicker if we assume that for any existing pair of high 
and low values, where low <= high, no new value can be both < low and > 
high, so that if we find a new low value, we can skip the "is this a new 
high value" test:

If you want the values:

var low, high, i;
var low = high = arr[0], arrlen = arr.length;
for( i = 1; i < arrlen; i++ ) {
	if ( arr[i] < low ) low = arr[i];
	else if ( arr[i] > high ) high = arr[i];
}

Or if we're looking for the indexes (possibly slower) a slight variant of 
your code:

var low, high, i;
var low = high = 0, arrlen = arr.length;
for( i = 1; i < arrlen; i++ ) {
	if ( arr[i] < arr[low] ) low = i;
	else if ( arr[i] > arr[high] ) high = i;
}

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#22364

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-12-18 19:14 +0000
Message-ID<A5x2VScFQfsSFwgW@invalid.uk.co.demon.merlyn.invalid>
In reply to#22356
In comp.lang.javascript message <XnsA299674D3AA55eejj99@194.109.133.133>
, Tue, 17 Dec 2013 10:09:17, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:

>1 There is no need for conversion into a date object value,
>[ and fearing a DST-change during the code's execution perhaps ;-) ]

(1) The correct term, in European English, is "[the state of] Summer
Time".  For Daylight Saving, Google swiftly for   cucumber Laputa   , or
even for   Laputa komkommer site:.nl   .

(2) Are there any locations in which a change to/from Summer Time
occurs, and can cause the DATE to change, when no time was specifically
given?  Maybe the Azores, and perhaps a modicum of Greenland?

However, all work with the Date Object in which differences from UTC are
not significant should use the UTC routines, since those are faster and
cause less confusion.

-- 
 (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]


#22366

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-12-19 15:42 +0100
Message-ID<XnsA29B9FC30FA3Beejj99@194.109.133.133>
In reply to#22364
Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> wrote on 18 dec 2013 
in comp.lang.javascript:

> In comp.lang.javascript message <XnsA299674D3AA55eejj99@194.109.133.133>
> , Tue, 17 Dec 2013 10:09:17, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> posted:
> 
>>1 There is no need for conversion into a date object value,
>>[ and fearing a DST-change during the code's execution perhaps ;-) ]
> 
> (1) The correct term, in European English, is "[the state of] Summer
> Time".  For Daylight Saving, Google swiftly for   cucumber Laputa   , or
> even for   Laputa komkommer site:.nl   .

The transponsers idea is that "summertime" is something Guerswinian.

I would call it British English, given the senseless struggle of British 
politics to define Britain as not being part of Europe.

> (2) Are there any locations in which a change to/from Summer Time
> occurs, and can cause the DATE to change, when no time was specifically
> given?  Maybe the Azores, and perhaps a modicum of Greenland?

I was therefore just talking about "the fear", even though unrealistic.
 
> However, all work with the Date Object in which differences from UTC are
> not significant should use the UTC routines, since those are faster and
> cause less confusion.

I just said that there is no need for conversion into a Date Object, why do 
you think there is? Or perhaps you don't?
 
I don't say NOT using the Date Object is better, but then, we Europeans 
[including the British here] are more of the fearless type.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


#22367

From"Michael F. Stemper" <michael.stemper@gmail.com>
Date2013-12-19 09:20 -0600
Message-ID<l8v2rf$73l$1@dont-email.me>
In reply to#22366
On 12/19/2013 08:42 AM, Evertjan. wrote:
> Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> wrote on 18 dec 2013
> in comp.lang.javascript:
>
>> In comp.lang.javascript message <XnsA299674D3AA55eejj99@194.109.133.133>
>> , Tue, 17 Dec 2013 10:09:17, Evertjan. <exxjxw.hannivoort@inter.nl.net>
>> posted:
>>
>>> 1 There is no need for conversion into a date object value,
>>> [ and fearing a DST-change during the code's execution perhaps ;-) ]
>>
>> (1) The correct term, in European English, is "[the state of] Summer
>> Time".  For Daylight Saving, Google swiftly for   cucumber Laputa   , or
>> even for   Laputa komkommer site:.nl   .
>
> The transponsers idea is that "summertime" is something Guerswinian.
>
> I would call it British English, given the senseless struggle of British
> politics to define Britain as not being part of Europe.

Well, if they ever decide to cut you off 
(<http://freeglot.wordpress.com/2013/04/21/fog-in-channel-continent-cut-off/>), 
you can feel free
to use US English. We won't mind -- even if you get bits of it wrong.

-- 
Michael F. Stemper
A preposition is something you should never end a sentence with.

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


#22369

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-12-20 10:04 +0100
Message-ID<XnsA29C6667746E3eejj99@194.109.133.133>
In reply to#22367
"Michael F. Stemper" <michael.stemper@gmail.com> wrote on 19 dec 2013 in
comp.lang.javascript: 

> Well, if they ever decide to cut you off 
> (<http://freeglot.wordpress.com/2013/04/21/fog-in-channel-continent-cut-o
> ff/>), you can feel free
> to use US English. We won't mind -- even if you get bits of it wrong.
> 
> -- 
> Michael F. Stemper
> A preposition is something you should never end a sentence with.

You mean well, I would never, however, accept such final proposition,
the virtual fog on the big pond, the mathematical unitarian devide, being 
more of a hindrance.

Who is "we", btw, Michael?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


#22357

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-12-17 15:12 +0100
Message-ID<1744237.gKV8rdnPMv@PointedEars.de>
In reply to#22354
Denis McMahon wrote:

> On Tue, 17 Dec 2013 07:06:55 +0700, JJ wrote:
>>> Suggestion or Code very welcome.
>>> 
>>> btw, I can supply *my* code down to producing a correect date value,
>>> but it is clumsy and embarassing. But I will if you insist.
>> 
>> Fix the date string then make them to a Date object so that you can get
>> the timestamp integer value.
>> 
>> function parseDate(dateStr) {
>>   //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();
>> }
> 
> To walk an array of numbers once to find the min and max values:
> 
> var low, high, i;
> low = high = arr[0];
> for( i = 1; i < arr.length; i++ ) {
> if ( arr[i] < low ) low = arr[i];
> if ( arr[i] > high ) high = arr[i];
> }
> 
> // low and high are now the minimum and maximum values from the array

In implementations of ECMAScript Ed. 3, it is easier and probably more 
efficient to use the built-in Math.min() and Math.max() methods:

  var low = Math.min.apply(Math, arr);
  var high = Math.max.apply(Math, arr);

They also work for Date instances as Array elements because they convert the 
arguments to Number before comparison.  In general, if these methods are 
implemented, it is easiest to overwrite the “valueOf” property of the 
prototype object of the objects for the call – or provide the objects 
themselves with one –, which is triggered first by the internal ToNumber 
algorithm when called with hint Number.

<http://ecma-international.org/ecma-262/5.1/#sec-15.8.2.11>
<http://ecma-international.org/ecma-262/5.1/#sec-9.3>
<http://ecma-international.org/ecma-262/5.1/#sec-9.1>
<http://ecma-international.org/ecma-262/5.1/#sec-8.12.8>
<http://ecma-international.org/ecma-262/5.1/#sec-15.9.5.8>

One can also access the first and last element of a sorted array:

  var sortedCopy = arr.slice().sort(function (a, b) { return a - b; });
  var low = sortedCopy[0];
  var high = sortedCopy[sortedCopy.length - 1];

<http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.11>

Finally, all implementations of ECMAScript Ed. 5 – not just JavaScript 
anymore – provide Array.prototype.reduce(), as mentioned by Björn:

  var low = arr.reduce(
    function (accumulator, e, i, a) {
      if (е < accumulator)
      {
        return e;
      }

      return accumulator;
    },
    arr[0]);

<http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.21>

There appears to be no point to use .map() here because if you have .map() 
you have .reduce() and can thereby shorten the scope chain.
  
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


#22359

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2013-12-17 18:10 -0200
Message-ID<l8qb46$me$1@speranza.aioe.org>
In reply to#22357
On 17/12/2013 12:12, Thomas 'PointedEars' Lahn wrote:

>> // low and high are now the minimum and maximum values from the array
>
> In implementations of ECMAScript Ed. 3, it is easier and probably more
> efficient to use the built-in Math.min() and Math.max() methods:
>
>    var low = Math.min.apply(Math, arr);
>    var high = Math.max.apply(Math, arr);

Brilliant!

> They also work for Date instances as Array elements because they convert the
> arguments to Number before comparison.  In general, if these methods are
> implemented, it is easiest to overwrite the “valueOf” property of the
> prototype object of the objects for the call – or provide the objects
> themselves with one –, which is triggered first by the internal ToNumber
> algorithm when called with hint Number.
>
> <http://ecma-international.org/ecma-262/5.1/#sec-15.8.2.11>
> <http://ecma-international.org/ecma-262/5.1/#sec-9.3>
> <http://ecma-international.org/ecma-262/5.1/#sec-9.1>
> <http://ecma-international.org/ecma-262/5.1/#sec-8.12.8>
> <http://ecma-international.org/ecma-262/5.1/#sec-15.9.5.8>
>
> One can also access the first and last element of a sorted array:
>
>    var sortedCopy = arr.slice().sort(function (a, b) { return a - b; });
>    var low = sortedCopy[0];
>    var high = sortedCopy[sortedCopy.length - 1];
>
> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.11>

or

var low = sortedCopy.shift();
var high = sortedCopy.pop();

>
> Finally, all implementations of ECMAScript Ed. 5 – not just JavaScript
> anymore – provide Array.prototype.reduce(), as mentioned by Björn:
>
>    var low = arr.reduce(
>      function (accumulator, e, i, a) {
>        if (е < accumulator)
>        {
>          return e;
>        }
>
>        return accumulator;
>      },
>      arr[0]);
>
> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.21>

'accumulator' is a bad name, as you are not accumulating anything in 
that function.

>
> There appears to be no point to use .map() here because if you have .map()
> you have .reduce() and can thereby shorten the scope chain.
>

ACK.


-- 
Joao Rodrigues (J.R.)

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


#22360

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-12-17 21:42 +0100
Message-ID<1693047.RCSKjYtSyA@PointedEars.de>
In reply to#22359
Joao Rodrigues wrote:

> On 17/12/2013 12:12, Thomas 'PointedEars' Lahn wrote:
>> One can also access the first and last element of a sorted array:
>>
>>    var sortedCopy = arr.slice().sort(function (a, b) { return a - b; });
>>    var low = sortedCopy[0];
>>    var high = sortedCopy[sortedCopy.length - 1];
>>
>> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.11>
> 
> or
> 
> var low = sortedCopy.shift();
> var high = sortedCopy.pop();

If you do not need the original copy later.  Because the property accessor 
does not modify the array like these two methods do.

>> Finally, all implementations of ECMAScript Ed. 5 – not just JavaScript
>> anymore – provide Array.prototype.reduce(), as mentioned by Björn:
>>
>>    var low = arr.reduce(
>>      function (accumulator, e, i, a) {
>>        if (е < accumulator)
>>        {
>>          return e;
>>        }
>>
>>        return accumulator;
>>      },
>>      arr[0]);
>>
>> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.21>
> 
> 'accumulator' is a bad name, as you are not accumulating anything in
> that function.

The name fits.  An accumulator in computer science is a container that 
stores an intermediate value (remember the processor registers)?  As you
can see, it is directly from the Specification.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


#22363

FromBjoern Hoehrmann <bjoern@hoehrmann.de>
Date2013-12-18 13:36 +0100
Message-ID<2753b91uue8cq1nb77864ase37q4h69idl@hive.bjoern.hoehrmann.de>
In reply to#22353
* JJ wrote in comp.lang.javascript:
>Fix the date string then make them to a Date object so that you can get the
>timestamp integer value.
>
>function parseDate(dateStr) {
>  //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();
>}

Based on

  http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.4.2
  http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15

it seems to me that the code above is not guaranteed to work.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

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


#22361

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-12-17 19:02 +0000
Message-ID<j5A+FiEA$JsSFwlR@invalid.uk.co.demon.merlyn.invalid>
In reply to#22351
In comp.lang.javascript message <bh9en6Foh76U1@mid.individual.net>, Mon,
16 Dec 2013 15:55:32, Mel Smith <med_cutout_syntel@aol.com> posted:

>
>    I have an approx 300-row table with 13 columns.  Column 3 of this table
>contains abbreviated date strings in the following format:
>
>            'Mmm dd/yy' (examples:   May 31/13   Jan 1/11, etc)
>
>    (All dates are current or in the past with all dates in the 21st
>Century, and IE8 must be accommodated)
>
>    I would like to find the *oldest* date and the *newest* date in this
>column.


Firstly, convert the dates into ISO 8601 [yy]mmdd form.
Secondly, seek the largest and the smallest by string comparison.
Thirdly, convert the two results to the inane input format, if needed.

You could, I think, put each ISO date as a property of its table row,
then, when seeking, remember not only the value but also the row of the
highest and lowest so far.  You can then recover the quaint input format
by re-reading the row.

One way of converting the months is to have a string
"xxxJanFeb ... NovDec", use indexOf, and divide by three.   Used, IIRC.

Another is to construct an Object with properties Jan, Feb, etc., with
corresponding values "01", "02", etc., and 'index' the Object with the
month to be converted.  Untested.

If speed matters, use a new Object to point to only the rows with the
highest year, then go for the highest month, and day; lowest likewise.

-- 
 (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]


#22362

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-12-17 20:51 -0700
Message-ID<bhckeoFed4lU1@mid.individual.net>
In reply to#22361
Hi :

    Thank you all for these enlightening lessons !

    My date probs are now solved.

-Mel 

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web