module Runt::DPrecision
DPrecision¶ ↑
Module providing automatic precisioning of Date, DateTime, and PDate classes.
Inspired by a
pattern[http://martinfowler.com/ap2/timePoint.html]
by Martin
Fowler.
- Author
-
Matthew Lipper
Constants
- DAY
- DEFAULT
- HOUR
- MILLI
- MIN
- MONTH
- SEC
- WEEK
- YEAR
Pseudo Singletons:
Public Class Methods
explode(date,prec)
click to toggle source
# File lib/runt/dprecision.rb, line 35 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
to_p(date,prec=DEFAULT)
click to toggle source
# File lib/runt/dprecision.rb, line 18 def DPrecision.to_p(date,prec=DEFAULT) has_p = date.respond_to?(:date_precision) #puts "DPrecision.to_p(#{date.class}<#{has_p ? date.date_precision : nil}>,#{prec})" return date if PDate == date.class && (prec == date.date_precision) 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