Module: TimeSheet::Time::Util
- Defined in:
- lib/time_sheet/time/util.rb
Class Method Summary collapse
- .day_end ⇒ Object
- .day_start ⇒ Object
- .hours(duration) ⇒ Object
- .minutes(duration) ⇒ Object
- .month_end(factor = 0) ⇒ Object
- .month_start(factor = 0) ⇒ Object
- .now ⇒ Object
- .price(duration, rate) ⇒ Object
- .today ⇒ Object
- .week_end(factor = 0) ⇒ Object
- .week_start(factor = 0) ⇒ Object
- .year_end(factor = 0) ⇒ Object
- .year_start(factor = 0) ⇒ Object
- .yesterday ⇒ Object
Class Method Details
.day_end ⇒ Object
33 34 35 |
# File 'lib/time_sheet/time/util.rb', line 33 def self.day_end day_start + 60 * 60 * 24 - 1 end |
.day_start ⇒ Object
29 30 31 |
# File 'lib/time_sheet/time/util.rb', line 29 def self.day_start now.to_date.to_time end |
.hours(duration) ⇒ Object
53 54 55 |
# File 'lib/time_sheet/time/util.rb', line 53 def self.hours(duration) (duration / 60.0).round(2) end |
.minutes(duration) ⇒ Object
49 50 51 |
# File 'lib/time_sheet/time/util.rb', line 49 def self.minutes(duration) duration.to_i end |
.month_end(factor = 0) ⇒ Object
16 17 18 19 |
# 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) ⇒ Object
11 12 13 14 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/time_sheet/time/util.rb', line 37 def self.now Time.now end |
.price(duration, rate) ⇒ Object
57 58 59 |
# File 'lib/time_sheet/time/util.rb', line 57 def self.price(duration, rate) (self.hours(duration) * rate).round(2) end |
.today ⇒ Object
41 42 43 |
# File 'lib/time_sheet/time/util.rb', line 41 def self.today now.to_date end |
.week_end(factor = 0) ⇒ Object
25 26 27 |
# File 'lib/time_sheet/time/util.rb', line 25 def self.week_end(factor = 0) week_start(factor) + 6 end |
.week_start(factor = 0) ⇒ Object
21 22 23 |
# 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) ⇒ Object
7 8 9 |
# 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) ⇒ Object
3 4 5 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/time_sheet/time/util.rb', line 45 def self.yesterday now.to_date - 1 end |