Date format conversion problem

Hi,

I generate in RoR an XML file representing Oracle database data, which
is then sent to an Adobe Flex UI as an HTTP Web Service. In order to
format DATES in a way that Flex understands, I add the following code
to environment.rb :

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!
( :flex => ‘%a %b %d %H:%M:%S %Y’ )

Then, I temporarily modify the formatting of my datetime data, in this
function :

def list_timespan_flexdateformat_xml
old_proc = Hash::XML_FORMATTING[‘datetime’]
Hash::XML_FORMATTING[‘datetime’] = Proc.new { |datetime|
datetime.to_s(:flex2) }

@rv_wrk_calendar_events = RvWrkCalendarEvent.find(
                                  :all, :conditions =>

[ “start_date >= ? and start_date <= ?”,
# Une alternative, au cas
où… :
#:all, :conditions =>
[ “start_date >= to_date(?, ‘YYYY-MM-DD’) and start_date <= to_date(?,
‘YYYY-MM-DD’)”,

params[:min_start_date], params[:max_start_date]])
render :xml => @rv_wrk_calendar_events.to_xml

Hash::XML_FORMATTING['datetime'] = old_proc

end

This works well for all Oracle DATE fields that contain TIME
information. But for some mysterious reason, it doesn’t work when the
DATE field doesn’t contain TIME information. The only meager result is
that some formats (e.g., ‘%Y %m %d’, ‘%Y/%m/%d’ or ‘%Y-%m-%d’)
generate this :

<start_date type=“datetime”>2007-08-23</start_date>

instead of the default :

<start_date type=“datetime”>2007-08-23T00:00:00+02:00</start_date>

I tried replacing “datetime” with “time” in the code above, to no
avail…

I know I can eventually parse the date in Flex, but this problem is
driving me crazy!

Chris.

I quick google revieled a number of hits from various fields where the
date
was an issue in oracle.

I found this link

http://download-uk.oracle.com/docs/cd/B14117_01/server.101/b10749/ch4datetime.htm

from the section on DATE datatype:

A date can be specified as an ANSI date literal or as an Oracle date
value.

An ANSI date literal contains no time portion and must be specified in
exactly the following format:

DATE ‘YYYY-MM-DD’

The following is an example of an ANSI date literal:

DATE ‘1998-12-25’

Alternatively, you can specify an Oracle date value as shown in the
following example:
TO_DATE(‘1998-DEC-25 17:30’,‘YYYY-MON-DD
HH24:MI’,‘NLS_DATE_LANGUAGE=AMERICAN’)

Im probably way of the mark since I know nothing about oracle but that’s
my
2 cents worth.

Why dont you just .to_time your date before you send it over to flex?

Regards
Ivor

Yes, I’ll probably have to do that. I was hoping I could keep the
default Rails behavior and just be able to configure how it generates
the XML, without having to override the code…

Thanks,

Chris.

Hi Chris

Hi gers32,
you can take a look at strftime
example:
Date.now.strftime("%d/%m/%Y %H:%M:%S")
Time.now.stftime("%d/%m/%Y %H:%M:%S")

and if you large code base already written, then try overriding to_s
method of Date/DateTime/Time(which is relevent to you) in your
application.rb

I quick google revieled a number of hits from various fields where the
date
was an issue in oracle.

I found this link

http://download-uk.oracle.com/docs/cd/B14117_01/server.101/b10749/ch4datetime.htm

from the section on DATE datatype:

A date can be specified as an ANSI date literal or as an Oracle date
value.

An ANSI date literal contains no time portion and must be specified in
exactly the following format:

DATE ‘YYYY-MM-DD’

The following is an example of an ANSI date literal:

DATE ‘1998-12-25’

Alternatively, you can specify an Oracle date value as shown in the
following example:
TO_DATE(‘1998-DEC-25 17:30’,‘YYYY-MON-DD
HH24:MI’,‘NLS_DATE_LANGUAGE=AMERICAN’)

Im probably way of the mark since I know nothing about oracle but that’s
my
2 cents worth.

Why dont you just .to_time your date before you send it over to flex?

Regards
Ivor

Hi,

The reason I modify Hash::XML_FORMATTING[‘datetime’] locally is
because I might need to use another Date format in my XML somewhere
else in the application.

The issue, really, is that Rails somehow treats different Date fields
of my Oracle database differently…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs