From: "Aleksi Niemelä" Date: 2000-05-12T19:20:08+02:00 Subject: [ruby-talk:02794] Re: Time Conversions This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01BFBC36.52C6727A Content-Type: text/plain; charset="iso-8859-1" Sorry if this is in some ugly html or something, this just looks like I'm using "I LOVE YOU"-mailing system again... Dave: >>t = Time.local(*parsedate("Fri May 12 2000 10:48a")[0,6]) >>p t # => Fri May 12 10:48:00 CDT 2000 David Douthitt: >What does the * in *parsedate do? parsedate returns array full of parsed date&time attributes. The first five are year, month, day, hour and min (probably the next is seconds and the seventh millisecs). This is clear from Matz-version of the code: year, month, day, hour, min = ParseDate.parsedate("Fri May 12 2000 10:48a") The Dave-version star ('*') indicates that the array should be flattened before call to Time.local. So we would call Time.local(2000, 5, 12, 10, 48, 0) # passes 6 arguments instead of Time.local( [ 2000, 5, 12, 10, 48, 0] ) # passes one argument, one array I'm not sure what's your second question but > You use the array subscript [0,6] (which I read as > the zeroth element and the sixth element....) Means is subscripting elements [0,1,2,3,4,5]. > Matz uses [0..4] (which I read as the zeroth element > THROUGH the fourth element.) Is subscripting [0,1,2,3,4]. Version with three dots [0...4] would have been [0,1,2,3]. - Aleksi ------_=_NextPart_001_01BFBC36.52C6727A Content-Type: text/html; charset="iso-8859-1"
Sorry if this is in some ugly html or something, this just looks like I'm using "I LOVE YOU"-mailing system again...
 
Dave:
>>t = Time.local(*parsedate("Fri May 12 2000 10:48a")[0,6])
>>p t  # => Fri May 12 10:48:00 CDT 2000
David Douthitt:
>
What does the * in *parsedate do?
 
parsedate returns array full of parsed date&time attributes. The first five are year, month, day, hour and min (probably the next is seconds and the seventh millisecs). This is clear from Matz-version of the code:
 
  year, month, day, hour, min = ParseDate.parsedate("Fri May 12 2000 10:48a")
The Dave-version star ('*') indicates that the array should be flattened before call to Time.local. So we would call
 
  Time.local(2000, 5, 12, 10, 48, 0)     # passes 6 arguments
 
instead of
 
  Time.local( [ 2000, 5, 12, 10, 48, 0] )   # passes one argument, one array
 
I'm not sure what's your second question but
 
> You use the array subscript [0,6] (which I read as
> the zeroth element and the sixth element....) 
 
Means is subscripting elements [0,1,2,3,4,5].
 
> Matz uses [0..4] (which I read as the zeroth element
> THROUGH the fourth element.) 
 
Is subscripting [0,1,2,3,4]. Version with three dots [0...4] would have been [0,1,2,3].
 
    - Aleksi
------_=_NextPart_001_01BFBC36.52C6727A--