It sounds like my dates aren’t in the same format, but I’m not sure what
the solution is. I’m using mySQL, and the field that I’m grabbing the
data from is of type “date”.
So ruby has several classes to do with dates and times.
Time which is implemented as a number of seconds since an epoch
(usually a 32bit which restricts the range of representable dates)
Date which is a number of days (with all the niceties to do with
Julian reform, Gregorian reform etc…)
DateTime which is sort of like Date but which also has time of day
info
date columns on the database comes back as instances of Date, but
0.days.ago etc… will be instances of Time.
You can convert these around with to_date/to_s.
I might write this as
delta = Date.today - document.expiration_on
case delta
when 720…360 then ‘doc_expired_360’
when 360…90 then ‘doc_expired_90’
delta = Date.today - document.expiration_on
result = case delta
when 720..360: "doc_expired_360"
when 360..90: "doc_expired_90"
when 90..60: "doc_expired_60"
when 60..30: "doc_expired_30"
when 30..1: "doc_expired"
else 'doc_current'
end
end
end
The problem, though, is that it’s returning all deltas as “doc_current”,
when I know they’re not. Any ideas?
Frederick C. wrote:
I might write this as
delta = Date.today - document.expiration_on
case delta
when 720…360 then ‘doc_expired_360’
when 360…90 then ‘doc_expired_90’