Skip to content

Commit

Permalink
Merge pull request #2 from moneytree/fix-week
Browse files Browse the repository at this point in the history
fixed the by_week using ruby commercial weeks
  • Loading branch information
rpranata committed Nov 21, 2012
2 parents a47f083 + 46fd998 commit 68c7467
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lib/by_star/by_week.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ def by_week_Time_or_Date(time, options={})
alias_method :by_week_Date, :by_week_Time_or_Date

def by_week_Fixnum(week, options={})
time = Time.new(options[:year], 1, 1).in_time_zone(Time.zone) if options[:year]
time ||= Time.current
year = options[:year] ? options[:year] : Time.current.year

# This is the nescessary decrement as the beginning_of_year should be
# the first-week (week-1). While the calculation of start_time will add
# x amount of weeks to the beginning_of_year. (0-based week)
week = week - 1
start_time = time.beginning_of_year + week.to_i.weeks
# get the time in the current zone from the fixnum week (commercial week)
start_time = DateTime.commercial year, week, 1, 0, 0, 0, Time.zone.formatted_offset

between(start_time, (start_time + 1.week).end_of_day, options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/by_star/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ByStar
VERSION = "2.0.0.1"
VERSION = "2.0.0.2"
end

0 comments on commit 68c7467

Please sign in to comment.