Module providing automatic precisioning of Date, DateTime, and PDate classes.
Inspired by a
pattern[http://martinfowler.com/ap2/timePoint.html]
by Martin
Fowler.
Matthew Lipper
Pseudo Singletons:
# File lib/runt/dprecision.rb, line 33 def DPrecision.explode(date,prec) result = [date.year,date.month,date.day] if(date.respond_to?("hour")) result << date.hour << date.min << date.sec else result << 0 << 0 << 0 end result end
# File lib/runt/dprecision.rb, line 18 def DPrecision.to_p(date,prec=DEFAULT) case prec when MIN then PDate.min(*DPrecision.explode(date,prec)) when DAY then PDate.day(*DPrecision.explode(date,prec)) when HOUR then PDate.hour(*DPrecision.explode(date,prec)) when WEEK then PDate.week(*DPrecision.explode(date,prec)) when MONTH then PDate.month(*DPrecision.explode(date,prec)) when YEAR then PDate.year(*DPrecision.explode(date,prec)) when SEC then PDate.sec(*DPrecision.explode(date,prec)) when MILLI then date #raise "Not implemented." else PDate.default(*DPrecision.explode(date,prec)) end end