module TimeSheet::Time::Util

Public Class Methods

day_end() click to toggle source
# File lib/time_sheet/time/util.rb, line 33
def self.day_end
  day_start + 60 * 60 * 24 - 1
end
day_start() click to toggle source
# File lib/time_sheet/time/util.rb, line 29
def self.day_start
  now.to_date.to_time
end
hours(duration) click to toggle source
# File lib/time_sheet/time/util.rb, line 53
def self.hours(duration)
  (duration / 60.0).round(2)
end
minutes(duration) click to toggle source
# File lib/time_sheet/time/util.rb, line 49
def self.minutes(duration)
  duration.to_i
end
month_end(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 16
def self.month_end(factor = 0)
  tmp = (month_start(factor) + 45)
  Date.new(tmp.year, tmp.month) - 1
end
month_start(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 11
def self.month_start(factor = 0)
  tmp = Date.today.prev_month(factor * -1)
  Date.new tmp.year, tmp.month, 1
end
now() click to toggle source
# File lib/time_sheet/time/util.rb, line 37
def self.now
  Time.now
end
price(duration, rate) click to toggle source
# File lib/time_sheet/time/util.rb, line 57
def self.price(duration, rate)
  (self.hours(duration) * rate).round(2)
end
today() click to toggle source
# File lib/time_sheet/time/util.rb, line 41
def self.today
  now.to_date
end
week_end(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 25
def self.week_end(factor = 0)
  week_start(factor) + 6
end
week_start(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 21
def self.week_start(factor = 0)
  today - (today.wday - 1) % 7 + (factor * 7)
end
year_end(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 7
def self.year_end(factor = 0)
  Date.new(Date.today.year + factor, 12, 31)
end
year_start(factor = 0) click to toggle source
# File lib/time_sheet/time/util.rb, line 3
def self.year_start(factor = 0)
  Date.new(Date.today.year + factor, 1, 1)
end
yesterday() click to toggle source
# File lib/time_sheet/time/util.rb, line 45
def self.yesterday
  now.to_date - 1
end