Module: BankingDateTools
- Defined in:
- lib/banking_date_tools.rb,
lib/banking_date_tools/version.rb,
lib/banking_date_tools/banking_date_tools.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
- #banking_day?(date = Date.today, options = {}) ⇒ Boolean
- #get_banking_day(date, options = {}) ⇒ Object
- #get_next_banking_day(date, options = {}) ⇒ Object
- #get_previous_banking_day(date, options = {}) ⇒ Object
- #safe_date(date) ⇒ Object
-
#tick(date = nil) ⇒ Object
creates a date integer formated like a MS.Net date tick.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/banking_date_tools.rb', line 9 def self.included(base) base.extend(BankingDateTools) end |
.root ⇒ Object
5 6 7 |
# File 'lib/banking_date_tools.rb', line 5 def self.root File.(File.dirname(File.dirname(__FILE__))) end |
Instance Method Details
#banking_day?(date = Date.today, options = {}) ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 4 def banking_day?(date=Date.today, ={}) date = Date.today if date.nil? # Set defaults = { :holidays => [], :force_allow_days => [] }.merge!() unless [:force_allow_days].include?(date) return false if [:no_holidays] && [:holidays].include?(date) if [:no_weekends] return false if (date.saturday? || date.sunday?) else return false if [:no_saturdays] && date.saturday? return false if [:no_sundays] && date.sunday? end end true end |
#get_banking_day(date, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 24 def get_banking_day(date, ={}) = ({:padding => 0, :previous => false}.merge()) adjusted_padding = ([:padding].abs + 1) increment = ([:previous] ? -1 : 1) adjusted_padding.times do |p| date = (date + increment ) if p != 0 while !banking_day?(date, ) date = (date + increment ) end end date end |
#get_next_banking_day(date, options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 37 def get_next_banking_day(date, ={}) = ({:padding => 1, :previous => false}.merge()) get_banking_day(date, ) end |
#get_previous_banking_day(date, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 42 def get_previous_banking_day(date, ={}) = ({:padding => 1, :previous => true}.merge()) get_banking_day(date, ) end |
#safe_date(date) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 47 def safe_date(date) if date.blank? return Date.today end # if date.class == String # if date.include?("/") || date.include?("-") # split = date.split("/") if date.include?("/") # split = date.split("-") if date.include?("-") # time = "" # if split[2] && split[2].include?(":") # year_time = split[2].split(" ") # split[2] = year_time[0] # time = year_time[1] # end # safe = "#{split[2]}-#{split[0]}-#{split[1]}" # safe << " #{time}" unless time.blank? # return safe if split.length == 3 && split[2].length == 4 # end # end date.to_date end |
#tick(date = nil) ⇒ Object
creates a date integer formated like a MS.Net date tick
70 71 72 73 74 75 76 77 |
# File 'lib/banking_date_tools/banking_date_tools.rb', line 70 def tick(date=nil) if date.blank? date = Time.now else date = date.to_time end date.tick end |