Different results between development and test

I have a method for returning the number of weeks based on a run_date
and end_date in my model:

def weeks
# logger.debug “** Start date: #{self.run_date} End date:
# logger.debug “** Difference: #{self.end_date - self.run_date}”
( ( self.end_date - self.run_date ) / 60 / 60 / 24 / 7 ).to_i

This was frustrating me for the last couple of hours because I couldn’t
figure out why I was getting wrong results or unit test failure whether
I added the division by 60/60/24/7 or not… Until I added the
logger.debug calls:

** Start date: Wed Sep 27 00:00:00 PDT 2006 End date: Wed Oct 25
00:00:00 PDT 2006
** Difference: 2419200.0

** Start date: 2006-09-27 End date: 2006-10-25
** Difference: 28

Both MySQL databases use the DATE type for these columns, not DATETIME.
I’m sure I can find a way around this by casting, but I’d sure like to
know if anyone has an answer for this? I’m just learning Rails and I’d
sure like to understand what could be happening here.


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