could this be any more compact or ruby like that it is?
class Date
def *financial_year_end*
Date.civil(year, 6, 30) < self ? Date.civil(year, 6, 30) :
Date.civil(year - 1, 6, 30)
end
end
could this be any more compact or ruby like that it is?
class Date
def *financial_year_end*
Date.civil(year, 6, 30) < self ? Date.civil(year, 6, 30) :
Date.civil(year - 1, 6, 30)
end
end
could this be any more compact or ruby like that it is?
class Date
def *financial_year_end*
Date.civil(year, 6, 30) < self ? Date.civil(year, 6, 30) :
Date.civil(year - 1, 6, 30)
endend
Well, you could avoid the multiple date creations and step the date back 12 months when needed.
class Date
def financial_year_end
if (this_year = Date.civil(year, 6, 30)) < self
this_year
else
this_year << 12
end
end
end
jun15 = Date.civil(2008, 6, 15)
=> #<Date: 4909265/2,0,2299161>
jul15 = Date.civil(2008, 7, 15)
=> #<Date: 4909325/2,0,2299161>
puts jun15
2008-06-15
=> nil
puts jul15
2008-07-15
=> nil
puts jun15, jun15.financial_year_end
2008-06-15
2007-06-30
=> nil
puts jul15, jul15.financial_year_end
2008-07-15
2008-06-30
=> nil
The name seems odd to me as the expectation that *I* had was to ask a date when the financial year that it is part of will end. However, it's your method, so just document what you mean it to be.
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
On Dec 19, 2008, at 2:26 AM, Greg Hauptmann wrote:
thanks - I like the "this_year << 12" - didn't realize this was available
for dates
On Sat, Dec 20, 2008 at 2:22 AM, Rob Biedenharn <Rob@agileconsultingllc.com>wrote:
On Dec 19, 2008, at 2:26 AM, Greg Hauptmann wrote:
could this be any more compact or ruby like that it is?
class Date
def *financial_year_end*
Date.civil(year, 6, 30) < self ? Date.civil(year, 6, 30) :
Date.civil(year - 1, 6, 30)
endend
Well, you could avoid the multiple date creations and step the date back 12
months when needed.class Date
def financial_year_end
if (this_year = Date.civil(year, 6, 30)) < self
this_year
else
this_year << 12
end
end
end> jun15 = Date.civil(2008, 6, 15)
=> #<Date: 4909265/2,0,2299161>
> jul15 = Date.civil(2008, 7, 15)
=> #<Date: 4909325/2,0,2299161>
> puts jun15
2008-06-15
=> nil
> puts jul15
2008-07-15
=> nil
> puts jun15, jun15.financial_year_end
2008-06-15
2007-06-30
=> nil
> puts jul15, jul15.financial_year_end
2008-07-15
2008-06-30
=> nilThe name seems odd to me as the expectation that *I* had was to ask a date
when the financial year that it is part of will end. However, it's your
method, so just document what you mean it to be.-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com