From: Damphyr Date: 2005-09-28T17:47:10+09:00 Subject: Re: [REXML] Wierd behaviour with Date --------------020808070807060205090301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Damphyr wrote: > Robert Klemme wrote: > snip >> >>>> Date.strptime(date_txt,"%d.%m.%Y") >> >> >> => # >> >> What did you do? >> > That's my question. And I think I found it: If I do class Article > include REXML ... ... end > > I get the error with strptime. > > If I use REXML::Document and don't include, then everything is fine. > So REXML does something to Date. > I run ruby 1.8.2 (2004-12-25) [i386-mswin32] Since I cannot duplicate the problem in irb with a simple include, here's the code that duplicates this, maybe someone can see what's wrong. Cheers, V.- ____________________________________________________________________ http://www.freemail.gr - ������ �������� ������������ ������������. http://www.freemail.gr - free email service for the Greek-speaking. --------------020808070807060205090301 Content-Type: text/xml;name="example.xml" Content-Transfer-Encoding: 8bit Content-Disposition: inline;filename="example.xml" ���
Title 10.05.06 el Some text in UTF8, ������������
--------------020808070807060205090301 Content-Type: text/plain;name="test.rb" Content-Transfer-Encoding: 7bit Content-Disposition: inline;filename="test.rb" require 'rexml/document' class Article include REXML ITEM_TITLE="title" ITEM_CREATION="date" ITEM_TEXT="text" ITEM_LASTMODIFIED="lastmodified" attr_reader :language,:text,:title,:created,:section,:filename,:last_modified attr_writer :section def initialize title,filename,text,creation_date,lastmodified="",language="el" @title=title @filename=filename @text=text @created=creation_date @last_modified=last_modified @language=language @section="" end def to_s return "#{@created} - #{@title}" end #Creates an Article instance from an XML file # # Raises BadArticleException if the file is malformed def Article.generate filename begin xmldoc=Document.new( File.new(filename) ) filename=File.basename(filename).chomp(".xml") title=xmldoc.root.elements[ITEM_TITLE].collect{|el| el.to_s }.join date_txt=xmldoc.root.elements[ITEM_CREATION].text #convert the date begin created=Date.strptime(date_txt,"%d.%m.%Y") rescue ArgumentError end text=xmldoc.root.elements[ITEM_TEXT].collect{|el| el.to_s }.join language="el" lastmodified=created begin lastmodified_txt=xmldoc.root.elements[ITEM_LASTMODIFIED].text if lastmodified_txt begin lastmodified=Date.strptime(lastmodified_txt,"%d.%m.%Y") rescue ArgumentError lastmodified=Date.new end end end if xmldoc.root.elements[ITEM_LASTMODIFIED] return Article.new(title,filename,text,created,lastmodified,language) #rescue # raise BadArticleException.new(filename,$!) end end end puts Article.generate("example.xml") --------------020808070807060205090301--