5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/reportme/period.rb', line 5
def self.calc(today, wanted_periods=[:day])
today = today.to_date
r = []
wanted_periods.each do |period|
von, bis = case period
when :today
[today, today]
when :day
[today - 1.day, today - 1.day]
when :week
[today - 1.week, today - 1.day]
when :calendar_week
day_lastweek = today.to_date - 7.days
monday = day_lastweek - (day_lastweek.cwday - 1).days
[monday, monday + 6.days]
when :month
[today - 1.day - 30.days, today - 1.day]
when :calendar_month
n = today - 1.month
[n.beginning_of_month, n.end_of_month]
end
von = von.to_datetime
bis = bis.to_datetime + 23.hours + 59.minutes + 59.seconds
r << {:name => period, :von => von, :bis => bis}
end
r
end
|