Skip to content

Commit

Permalink
Merge 3f46c13 into 6f35274
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Worek committed May 31, 2017
2 parents 6f35274 + 3f46c13 commit 8a1b02a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
merch_calendar (0.0.4)
merch_calendar (0.0.5.rc1)

GEM
remote: https://www.rubygems.org/
Expand Down Expand Up @@ -58,4 +58,4 @@ DEPENDENCIES
simplecov

BUNDLED WITH
1.11.2
1.15.0
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -119,6 +119,14 @@ MerchCalendar.weeks_in_year(2015)

# returns an array of MerchWeek objects for each week within the provided month
MerchCalendar.weeks_for_month(2014, 1)

# get the start date of a given merch week
MerchCalendar.start_of_week(2017, 4, 1)
# => #<Date: 2017-04-02 ((2457846j,0s,0n),+0s,2299161j)>

# get the end date of a given merch week
MerchCalendar.end_of_week(2017, 4, 1)
# => #<Date: 2017-04-08 ((2457852j,0s,0n),+0s,2299161j)>
```

## Documentation
Expand Down
13 changes: 13 additions & 0 deletions lib/merch_calendar/date_calculator.rb
@@ -1,3 +1,5 @@
require "date"

module MerchCalendar

# @api private
Expand Down Expand Up @@ -49,6 +51,17 @@ def end_of_month(year, merch_month)
end
end

def start_of_week(year, month, merch_week)
weeks = MerchCalendar.weeks_for_month(year, month)

week = weeks.find { |week| week.week == merch_week }
week.start_of_week
end

def end_of_week(year, month, merch_week)
start_of_week(year, month, merch_week) + 6
end

# Return the starting date for a particular quarter
def start_of_quarter(year, quarter)
case quarter
Expand Down
22 changes: 22 additions & 0 deletions lib/merch_calendar/util.rb
Expand Up @@ -3,6 +3,28 @@ module MerchCalendar
# Utility methods for the merch calendar
module Util

# The start date of the week
#
# @param year [Fixnum] the merch year
# @param month [Fixnum] an integer specifying the julian month.
# @param month [Fixnum] an integer specifying the merch week.
#
# @return [Date] the starting date of the specified week
def start_of_week(year, month, week)
date_calc.start_of_week(year, month, week)
end

# The end date of the week
#
# @param year [Fixnum] the merch year
# @param month [Fixnum] an integer specifying the julian month.
# @param month [Fixnum] an integer specifying the merch week.
#
# @return [Date] the ending date of the specified week
def end_of_week(year, month, week)
date_calc.end_of_week(year, month, week)
end

# The start date of the month
#
# @example
Expand Down
2 changes: 1 addition & 1 deletion lib/merch_calendar/version.rb
@@ -1,3 +1,3 @@
module MerchCalendar
VERSION = '0.0.4'
VERSION = '0.0.5.rc1'
end
18 changes: 14 additions & 4 deletions spec/merch_calendar_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe MerchCalendar do
RSpec.describe MerchCalendar do
context "responds to util methods" do
[
:start_of_month, :end_of_month,
Expand All @@ -17,6 +17,17 @@
end
end

describe "#start_of_week" do
it "returns the correct date for a given merch week" do
expect(described_class.start_of_week(2017, 4, 1)).to eq Date.new(2017, 4, 2)
end
end

describe "#end_of_week" do
it "returns the correct date for a given merch week" do
expect(described_class.end_of_week(2017, 4, 1)).to eq Date.new(2017, 4, 8)
end
end

it "#start_of_month" do
expect(described_class.start_of_month(2014,1)).to be_a Date
Expand All @@ -34,7 +45,6 @@
expect(described_class.end_of_year(2014)).to be_a Date
end


it "#start_of_quarter" do
expect(described_class.start_of_quarter(2014,1)).to be_a Date
end
Expand All @@ -47,12 +57,12 @@
expect(described_class.weeks_in_year(2014)).to be_a Fixnum
end


it "#merch_to_julian" do
expect(described_class.merch_to_julian(1)).to be_a Fixnum
end

it "#julian_to_merch" do
expect(described_class.julian_to_merch(1)).to be_a Fixnum
end

end
end

0 comments on commit 8a1b02a

Please sign in to comment.