class Date
Public Class Methods
create_from_string(p_date_str)
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 33 def self.create_from_string(p_date_str) #MAUNEWP Added 1/2011..creats a date from a string parts = p_date_str.split("/") return nil if parts.length != 3 return Date.new(parts[2].to_i,parts[0].to_i,parts[1].to_i) end
is_today_weekend?()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 43 def self.is_today_weekend? (Date.today.wday == 0) or (Date.today.wday == 6) end
next_week(date)
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 51 def self.next_week(date) date.start_of_week + 7.days end
start_of_week()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 15 def self.start_of_week Date.today.start_of_week end
Public Instance Methods
end_of_week()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 59 def end_of_week self.start_of_week + 4.days end
for_highcharts()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 6 def for_highcharts # MAU 05/2014 - I left the experiments commented out for reference # I cant say I understand exactly how this works, but using examples I came up with a method that HighCharts seems to work well with # "#{self.to_time.to_i}000".to_i # "#{self.strftime('%Y-%m-%d 14:00').to_time.utc.to_i}000".to_i # "Date.UTC(#{self.strftime('%Y,%m,%d')})" "#{(self-1.day).to_time.strftime("%Y-%m-%d 19:00").to_time.utc.to_i}000".to_i end
formatted()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 39 def formatted self.strftime("%m/%d/%Y") end
is_weekend?()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 47 def is_weekend? (self.wday == 0) or (self.wday == 6) end
next_week()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 55 def next_week self.start_of_week + 7.days end
start_of_month()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 28 def start_of_month self.strftime('%Y-%m-01').to_date end
start_of_next_month()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 2 def start_of_next_month (self + 1.month).start_of_month end
start_of_week()
click to toggle source
# File lib/marskal/core/extensions/date.rb, line 19 def start_of_week if self.wday == 0 #sundays count as end of week for vehicle app return self - 6 else (self - self.wday.days) + 1 #start on monfay end end