Date formatting--Error with Gantt chart and calendar when using redmine

28 views
Skip to first unread message

Eric Hayes

unread,
Aug 12, 2009, 2:53:43 PM8/12/09
to Rails SQLServer Adapter
I have setup a sample redmine environment with this adapter and it
works great for the most part.

However, date handling still seems to be buggy. I'm not sure if
there's a patch out there that will address this issue, but trying to
display the gantt chart causes an error. I have attached my error
below:


When I go to this page:
http://127.0.0.1:3000/projects/sampleproject/issues/gantt

----------------------
TypeError in Issues#gantt

Showing issues/gantt.rhtml where line #192 raised:

can't convert Date into Float

Extracted source (around line #192):

189:
190: i_late_date = [i_end_date, Date.today].min if i_start_date <
Date.today
191:
192: i_left = ((i_start_date - @gantt.date_from)*zoom).floor
193: i_width = ((i_end_date - i_start_date + 1)*zoom).floor -
2 # total width of the issue (- 2 for left and right
borders)
194: d_width = ((i_done_date - i_start_date)*zoom).floor -
2 # done width
195: l_width = i_late_date ? ((i_late_date - i_start_date+1)
*zoom).floor - 2 : 0 # delay width

RAILS_ROOT: C:/Ruby-Apps/Redmine/0.8-stable
Application Trace | Framework Trace | Full Trace

C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/
core_ext/time/calculations.rb:249:in `minus_without_duration'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/
core_ext/time/calculations.rb:249:in `minus_without_coercion'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/
core_ext/time/calculations.rb:258:in `-'
app/views/issues/gantt.rhtml:192:in
`_run_erb_47app47views47issues47gantt46rhtml'
app/views/issues/gantt.rhtml:181:in `each'
app/views/issues/gantt.rhtml:181:in
`_run_erb_47app47views47issues47gantt46rhtml'
app/controllers/issues_controller.rb:349:in `gantt'
app/controllers/issues_controller.rb:348:in `gantt'
C:/Ruby/bin/mongrel_rails:19:in `load'
C:/Ruby/bin/mongrel_rails:19

----------------------

I'm not very ruby savvy, but if we are trying to display a datetime as
just a date in sql server, we can use convert:

CONVERT(varchar, COLUMN_NAME, 101)

If anybody has any ideas for how to resolve this issue or if you have
a link to a solution it would be greatly appreciated. Thanks!

Ken Collins

unread,
Aug 12, 2009, 2:57:23 PM8/12/09
to rails-sqlse...@googlegroups.com

This just looks raw ruby related to what you are trying to objects. I
may need more to go on... but.

1) What version of SQL Server?
2) What are the underlying types of some of your local variables and
the sqltypes in the DB.

I have mode advice based on that.

- Ken

Eric Hayes

unread,
Aug 12, 2009, 3:15:20 PM8/12/09
to Rails SQLServer Adapter
1.) SQL Server 2005
2.) datatypes are datetime (in addition i created 2 udts called "date"
and "time" which are set to "datetime")

Ken Collins

unread,
Aug 12, 2009, 3:25:41 PM8/12/09
to rails-sqlse...@googlegroups.com

Thanks, although I am not sure what a UDTS is.

That said, this just looks like a simple ruby issue and familiarity
with Date/Time objects.

>> Date.today
=> Wed, 12 Aug 2009
>> Date.today + 1
=> Thu, 13 Aug 2009
>> Time.now
=> Wed Aug 12 15:21:42 -0400 2009
>> Time.now - (Date.today + 1)
TypeError: can't convert Date into Float

A bit of background on the adapter. Since SQL Server does not have
native date/time types, we have placed methods in the adapter for
coercing model attributes into strict date or time objects. See the
docs on that. The native rails adapter which this adapter supers to
will take SQL Server native date/time columns from say 2005/2008 and
create the proper ruby objects without coercion. Long story short...
just looks like you are trying to add apples and oranges. Can you
confirm?

- Ken

Eric Hayes

unread,
Aug 12, 2009, 4:25:22 PM8/12/09
to Rails SQLServer Adapter
Yes, in ruby when I type Date.today I get this:

#<Date: 4910111/2,0,2299161>

Here's the code that attempts to retrieve the gantt information (from
issues_controller.rb in redmine):

def gantt
@gantt = Redmine::Helpers::Gantt.new(params)
retrieve_query
if @query.valid?
events = []
# Issues that have start and due dates
events += Issue.find(:all,
:order => "start_date, due_date",
:include =>
[:tracker, :status, :assigned_to, :priority, :project],
:conditions => ["(#{@query.statement}) AND
(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)
or (start_date<? and due_date>?)) and start_date is not null and
due_date is not null)", @gantt.date_from, @gantt.date_to,
@gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
)
# Issues that don't have a due date but that are assigned to a
version with a date
events += Issue.find(:all,
:order => "start_date, effective_date",
:include =>
[:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
:conditions => ["(#{@query.statement}) AND
(((start_date>=? and start_date<=?) or (effective_date>=? and
effective_date<=?) or (start_date<? and effective_date>?)) and
start_date is not null and due_date is null and effective_date is not
null)", @gantt.date_from, @gantt.date_to, @gantt.date_from,
@gantt.date_to, @gantt.date_from, @gantt.date_to]
)
# Versions
events += Version.find(:all, :include => :project,
:conditions => ["(#
{@query.project_statement}) AND effective_date BETWEEN ? AND ?",
@gantt.date_from, @gantt.date_to])

@gantt.events = events
end



When looking at your adapter I see that there is this code to coerce
datetime to date or time:

def simplified_datetime
if table_klass &&
table_klass.coerced_sqlserver_date_columns.include?(name)
:date
elsif table_klass &&
table_klass.coerced_sqlserver_time_columns.include?(name)
:time
else
:datetime
end
end



Also UDT means user defined type(s)--not sure if this is the proper
acronym, but it seems to make sense :P

Eric Hayes

unread,
Aug 13, 2009, 12:00:47 PM8/13/09
to Rails SQLServer Adapter
Ok resolved the issue. For anyone who is curious, here is my patch
(against Redmine rev2836)

http://pastie.org/582814

On Aug 12, 1:25 pm, Eric Hayes <ejha...@ucdavis.edu> wrote:
> Yes, in ruby when I type Date.today I get this:
>
> #<Date: 4910111/2,0,2299161>
>
> Here's the code that attempts to retrieve the gantt information (from
> issues_controller.rb in redmine):
>
>   def gantt
>     @gantt = Redmine::Helpers::Gantt.new(params)
>     retrieve_query
>     if @query.valid?
>       events = []
>       # Issues that have start and due dates
>       events += Issue.find(:all,
>                            :order => "start_date, due_date",
>                            :include =>
> [:tracker, :status, :assigned_to, :priority, :project],
>                            :conditions => ["(#...@query.statement}) AND
> (((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)
> or (start_date<? and due_date>?)) and start_date is not null and
> due_date is not null)", @gantt.date_from, @gantt.date_to,
> @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
>                            )
>       # Issues that don't have a due date but that are assigned to a
> version with a date
>       events += Issue.find(:all,
>                            :order => "start_date, effective_date",
>                            :include =>
> [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
>                            :conditions => ["(#...@query.statement}) AND
> (((start_date>=? and start_date<=?) or (effective_date>=? and
> effective_date<=?) or (start_date<? and effective_date>?)) and
> start_date is not null and due_date is null and effective_date is not
> null)", @gantt.date_from, @gantt.date_to, @gantt.date_from,
> @gantt.date_to, @gantt.date_from, @gantt.date_to]
>                            )
>       # Versions
>       events += Version.find(:all, :include => :project,
>                                    :conditions => ["(#
> {...@query.project_statement}) AND effective_date BETWEEN ? AND ?",
Reply all
Reply to author
Forward
0 new messages