class Nydp::Date
Constants
- MONTH_SIZES
Attributes
ruby_date[RW]
Public Class Methods
new(ruby_date ;)
click to toggle source
# File lib/nydp/date.rb, line 19 def initialize ruby_date ; @ruby_date = ruby_date ; end
Public Instance Methods
+(int ;)
click to toggle source
# File lib/nydp/date.rb, line 33 def + int ; int.is_a?(Integer) ? r2n(ruby_date + int) : r2n(change(*int.to_ruby)) ; end
-(other ;)
click to toggle source
# File lib/nydp/date.rb, line 32 def - other ; ruby_date - other ; end
<(other ;)
click to toggle source
# File lib/nydp/date.rb, line 26 def < other ; is_date?(other) && ruby_date < other ; end
<=>(other ;)
click to toggle source
# File lib/nydp/date.rb, line 28 def <=> other ; is_date?(other) && ruby_date <=> other ; end
==(other ;)
click to toggle source
# File lib/nydp/date.rb, line 27 def == other ; is_date?(other) && ruby_date == other ; end
>(other ;)
click to toggle source
# File lib/nydp/date.rb, line 25 def > other ; is_date?(other) && ruby_date > other ; end
_nydp_get(key ;)
click to toggle source
# File lib/nydp/date.rb, line 86 def _nydp_get key ; lookup key, ruby_date ; end
_nydp_keys()
click to toggle source
# File lib/nydp/date.rb, line 82 def _nydp_keys ; @@keys.to_a ; end
age(y,m,d,w)
click to toggle source
# File lib/nydp/date.rb, line 71 def age y,m,d,w # args not used interval = (::Date.today - ruby_date) / 365.0 age_in_years = interval.to_i extra_months = (12 * (interval - age_in_years)).to_i { years: age_in_years, months: extra_months } end
beginning_of_month(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 60 def beginning_of_month y, m, d, w ; build(y, m, 1) ; end
beginning_of_week(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 65 def beginning_of_week y, m, d, w ; ruby_date - ((w - 1) % 7) ; end
beginning_of_year(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 55 def beginning_of_year y, m, d, w ; build(y, 1, 1) ; end
build(y, m, d)
click to toggle source
# File lib/nydp/date.rb, line 10 def build y, m, d if m < 1 build( y - 1, m + 12, d ) else s = MONTH_SIZES[m] ::Date.new(y, m, (d > s ? s : d)) end end
change(amount, attr)
click to toggle source
# File lib/nydp/date.rb, line 87 def change amount, attr if attr == :day ; (ruby_date + amount) elsif attr == :week ; (ruby_date + (7 * amount)) elsif attr == :month ; (ruby_date >> amount) elsif attr == :year ; (ruby_date >> (12 * amount)) end end
day(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 47 def day y, m, d, w ; d ; end
dispatch(key, y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 83 def dispatch key, y, m, d, w ; self.send(key, y, m, d, w) if _nydp_keys.include?(key) ; end
end_of_month(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 61 def end_of_month y, m, d, w ; beginning_of_month(*splat(ruby_date.next_month)) - 1 ; end
end_of_week(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 66 def end_of_week y, m, d, w ; ruby_date + ((7 - w) % 7) ; end
end_of_year(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 56 def end_of_year y, m, d, w ; build(y, 12, 31) ; end
eql?(d ;)
click to toggle source
# File lib/nydp/date.rb, line 29 def eql? d ; self == d ; end
future?(*_ ;)
click to toggle source
# File lib/nydp/date.rb, line 50 def future? *_ ; ruby_date > ::Date.today ; end
hash()
click to toggle source
# File lib/nydp/date.rb, line 30 def hash ; ruby_date.hash ; end
inspect()
click to toggle source
# File lib/nydp/date.rb, line 24 def inspect ; ruby_date.inspect ; end
is_date?(other ;)
click to toggle source
# File lib/nydp/date.rb, line 31 def is_date? other ; other.is_a? ::Date ; end
last_month(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 58 def last_month y, m, d, w ; ruby_date.prev_month ; end
last_week(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 63 def last_week y, m, d, w ; ruby_date - 7 ; end
last_year(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 53 def last_year y, m, d, w ; ruby_date.prev_year ; end
lookup(key, date ;)
click to toggle source
# File lib/nydp/date.rb, line 85 def lookup key, date ; r2n(dispatch(key.to_s.gsub(/-/, '_').to_sym, *splat(date))) ; end
month(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 46 def month y, m, d, w ; m ; end
next_month(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 59 def next_month y, m, d, w ; ruby_date.next_month ; end
next_week(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 64 def next_week y, m, d, w ; ruby_date + 7 ; end
next_year(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 54 def next_year y, m, d, w ; ruby_date.next_year ; end
past?(*_ ;)
click to toggle source
# File lib/nydp/date.rb, line 51 def past? *_ ; ruby_date < ::Date.today ; end
splat(date ;)
click to toggle source
# File lib/nydp/date.rb, line 84 def splat date ; [date.year, date.month, date.day, date.wday] ; end
to_date()
click to toggle source
# File lib/nydp/date.rb, line 21 def to_date ; ruby_date ; end
to_ruby()
click to toggle source
# File lib/nydp/date.rb, line 23 def to_ruby ; ruby_date ; end
to_s()
click to toggle source
# File lib/nydp/date.rb, line 22 def to_s ; ruby_date.to_s ; end
tomorrow(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 69 def tomorrow y, m, d, w ; ruby_date + 1 ; end
week_day(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 48 def week_day y, m, d, w ; w ; end
year(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 45 def year y, m, d, w ; y ; end
yesterday(y, m, d, w ;)
click to toggle source
# File lib/nydp/date.rb, line 68 def yesterday y, m, d, w ; ruby_date - 1 ; end