Skip to content

Instantly share code, notes, and snippets.

@revans
Created September 3, 2010 21:27
Show Gist options
  • Save revans/564599 to your computer and use it in GitHub Desktop.
Save revans/564599 to your computer and use it in GitHub Desktop.
# Ruby 1.9.2
class Numeric
def second
self * 1
end
alias_method :seconds, :second
def minute
self * 60
end
alias_method :minutes, :minute
def hour
self * 3600
end
alias_method :hours, :hour
def day
self * (24 * 3600)
end
alias_method :days, :day
alias_method :nights, :day
alias_method :night, :day
def week
self * (7 * 24 * 3600)
end
alias_method :weeks, :week
end
class Time
def next_business_day
n = self
# Specific to an app I'm working on
n = n + 1.day if n.hour > 13 && !n.friday?
n = (n.hour > 13 && n.friday?) ? n + 5.days : n + 4.days
# Check for Weekend or Holiday
n = n + 3.days if n.saturday?
n = n + 2.days if n.sunday?
n = n + 1.day if n.monday? # Could be a holiday. Is there a better way to do this?
n
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment