From: David Boyd Date: 2005-11-18T20:01:02+09:00 Subject: Re: Ordinal Date String to Standard Date String for a Beginner ------=_Part_1791_22148151.1132311659984 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Yeah, it's backwards in the PS -- just noticed it. (str.reverse won't help!!!) On 11/18/05, David Boyd wrote: > > Botp, Todd, > Thanks. Since I had already parsed the ordinal date's year and day to ge= t > them in string sortable order, I just had to take your examples and do th= is: > require 'date' ... od =3D Date.ordinal (strYear.to_i, strOrdn.to_i ) and > then od.to_s gives the sortable (and readable) yyyy-mm-dd string. > Wow, Ruby is powerful, but the documentation on Date (and perhaps other > gem filled libraries) is hard for a beginner to grok. I found Date's ordi= nal > with a Google search, which gave me the built-in documentation, but no > examples. So, if I need at least the APIs for a library such as Date I us= e > "ri"? > Thanks again, > Dave > PS Here's the beginner's way I used to parse the ordinal date string (eg > "2005/17"): > > strYear =3D strDate[strDate.index("/")+1, strDate.length] > strOrdn =3D strDate[0, strDate.index("/")] > On 11/18/05, Pe=F1a, Botp wrote: > > > > davyb [mailto:david.a.boyd@gmail.com] > > > > #I have an ordinal date string and I want to change it to an ordinary > > #date string. For example: 2005/1 should give January 1, 2005. I see > > #ordinal in the Date class but I need a simple example. Thanks, > > > > i hope this is simple enough. > > > > # we want to get the year and day values fr your string > > > > > re =3D /(\d+)\/(\d+)/ =3D> /(\d+)\/(\d+)/ > > > rs =3D "2005/1" =3D> "2005/1" > > > > > y,d=3Dre.match(rs)[1..2] =3D> ["2005", "1"] > > > > # we need to convert them to integers since ordinal wants num > > > > > y =3D y.to_i =3D> 2005 > > > d =3D d.to_i =3D> 1 > > > > > od =3D Date.ordinal(y,d) =3D> # > > > > # we got a date object > > # fr here we can do anything > > > > > od.year =3D> 2005 > > > od.month =3D> 1 > > > od.day =3D> 1 > > > nd_str1 =3D od.to_s =3D> "2005-01-01" > > > nd_str2 =3D od.strftime("%B %e, %Y") =3D> "January 1, 2005" > > > nd_str3 =3D nd_str2.squeeze(" ") =3D> "January 1, 2005" > > > > hth. > > > > kind regards > > -botp > > > > #Dave > > > > > ------=_Part_1791_22148151.1132311659984--