merch_calendar 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03d1ef8749bf05803819f78ae5b53330c5556401
4
- data.tar.gz: 229bd27912548d1064dfcc67eac8a45050411af4
3
+ metadata.gz: 753130ad5089afe3bbf400936388243467903ece
4
+ data.tar.gz: c070388ae4bc90740a312caa54af3c973f38c5d7
5
5
  SHA512:
6
- metadata.gz: 69a83b60890605d93cc33896bbb927313975396d833cc7377de66e52061fcda98ea20884c4ce19b3f6a50b0befd506b8a018c15c176dbb4be7a35d66f4f62216
7
- data.tar.gz: ab095357f4b3ef7fbb07733d374ed387b39a399c4680916b5238c0dcc870732d6a6bfddd71b0e6afc10e95252d2e4e2b465b522e7f8db443086e6c27be93a83e
6
+ metadata.gz: 2309d87f9066582a29f97c1c5bcff1c87ae6beaabc74586ad221f889c7092b5f3787d6948942364bab59441d625a869c60a1cce5c865286072875edc8530837b
7
+ data.tar.gz: 07d1d3dff25f45f0a7ca81e308c8e1cf27ec455088238e130f9b2131745628c43175bf50e5937f0d41f885d008ba456a17f08c9f963341463ad387a33d9bf6ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merch_calendar (0.0.3)
4
+ merch_calendar (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://www.rubygems.org/
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Merch Calendar
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/merch_calendar.svg)](http://badge.fury.io/rb/merch_calendar)
4
- [![Build Status](https://travis-ci.org/stitchfix/merch_calendar.svg)](https://travis-ci.org/stitchfix/merch_calendar)
4
+ [![Build Status](https://travis-ci.org/stitchfix/merch_calendar.svg?branch=master)](https://travis-ci.org/stitchfix/merch_calendar)
5
5
  [![Code Climate](https://codeclimate.com/github/stitchfix/merch_calendar/badges/gpa.svg)](https://codeclimate.com/github/stitchfix/merch_calendar)
6
6
  [![Coverage Status](https://coveralls.io/repos/stitchfix/merch_calendar/badge.svg)](https://coveralls.io/r/stitchfix/merch_calendar)
7
7
 
@@ -73,6 +73,44 @@ MerchCalendar.start_of_month(2014, julian_month: 5)
73
73
  MerchCalendar.start_of_month(2014, merch_month: 4)
74
74
  ```
75
75
 
76
+ #### Confusing things to look out for:
77
+
78
+ Merch calendars have the first month in February, and the last (12th) month is in January of the following year. In the code block above, each method is *asking* a very different question. This will definitely cause confusion, so here are some explanations.
79
+
80
+ ```ruby
81
+ # This is asking "In the Merch year of 2014, where is the month of January?"
82
+ # January is the last (12th) month of a merch year, so this date will be in the NEXT
83
+ # julian calendar year
84
+ MerchCalendar.start_of_month(2014, 1)
85
+ MerchCalendar.start_of_month(2014, month: 1)
86
+ MerchCalendar.start_of_month(2014, julian_month: 1)
87
+ # => 2015-01-04
88
+ # ^^^^ - NEXT year
89
+
90
+ # This is asking "When is the start of the FIRST month of the merch year 2014"
91
+ MerchCalendar.start_of_month(2014, merch_month: 1)
92
+ # => 2014-02-02
93
+
94
+ ```
95
+
96
+ This table should describe the progression of dates:
97
+
98
+ | N | `start_of_month(2014, N)` | `start_of_month(2014, merch_month: N)` |
99
+ | ------------- | ------------- | ------------- |
100
+ | 1 | **2015-01-04** | 2014-02-02 |
101
+ | 2 | 2014-02-02 | 2014-03-02 |
102
+ | 3 | 2014-03-02 | 2014-04-06 |
103
+ | 4 | 2014-04-06 | 2014-05-04 |
104
+ | 5 | 2014-05-04 | 2014-06-01 |
105
+ | 6 | 2014-06-01 | 2014-07-06 |
106
+ | 7 | 2014-07-06 | 2014-08-03 |
107
+ | 8 | 2014-08-03 | 2014-08-31 |
108
+ | 9 | 2014-08-31 | 2014-10-05 |
109
+ | 10 | 2014-10-05 | 2014-11-02 |
110
+ | 11 | 2014-11-02 | 2014-11-30 |
111
+ | 12 | 2014-11-30 | **2015-01-04** |
112
+
113
+
76
114
  Other useful methods:
77
115
 
78
116
  ```ruby
@@ -98,6 +98,18 @@ module MerchCalendar
98
98
  end
99
99
  end
100
100
 
101
-
101
+ def merch_months_in(start_date, end_date)
102
+ merch_months = []
103
+ prev_date = start_date - 2
104
+ date = start_date
105
+ while date <= end_date do
106
+ date = MerchCalendar.start_of_month(date.year, merch_month: date.month)
107
+ next if prev_date == date
108
+ merch_months.push(date)
109
+ prev_date = date
110
+ date += 14
111
+ end
112
+ merch_months
113
+ end
102
114
  end
103
- end
115
+ end
@@ -87,6 +87,16 @@ module MerchCalendar
87
87
  end
88
88
 
89
89
 
90
+ # An array of merch dates in start_date to end_date
91
+ #
92
+ # @param start_date [Date] the start date
93
+ # @param end_date [Date] the end date
94
+ #
95
+ # @return [Array<Date>] array of merch months
96
+ def merch_months_in(start_date, end_date)
97
+ date_calc.merch_months_in(start_date, end_date)
98
+ end
99
+
90
100
 
91
101
  # Converts a merch month to the correct julian month
92
102
  #
@@ -1,3 +1,3 @@
1
1
  module MerchCalendar
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -48,5 +48,43 @@ describe MerchCalendar::DateCalculator do
48
48
 
49
49
  it "#end_of_quarter"
50
50
 
51
+ describe "#merch_months_in" do
52
+ it "returns merch date for start_date if start_date is the same as end_date" do
53
+ start_date = Date.new(2014,8,1)
54
+ end_date = start_date
55
+ start_merch_date = MerchCalendar.start_of_month(start_date.year, merch_month: start_date.month)
56
+
57
+ merch_months = subject.merch_months_in(start_date, end_date)
58
+ expect(merch_months.count).to be(1)
59
+ expect(merch_months.first.year).to eq start_merch_date.year
60
+ expect(merch_months.first.month).to eq start_merch_date.month
61
+ expect(merch_months.first.day).to eq start_merch_date.day
62
+ end
63
+
64
+ it "returns valid merch dates for 2014" do
65
+ start_date = Date.new(2014, 1, 1)
66
+ end_date = Date.new(2014, 12, 1)
67
+
68
+ merch_months = subject.merch_months_in(start_date, end_date)
69
+ expect(merch_months.count).to be 11
70
+
71
+ merch_months.each do |merch_month|
72
+ expect(merch_month.year).to be 2014
73
+ end
74
+
75
+ expect(merch_months[0].strftime('%Y-%m-%d')).to eq '2014-02-02'
76
+ expect(merch_months[1].strftime('%Y-%m-%d')).to eq '2014-03-02'
77
+ expect(merch_months[2].strftime('%Y-%m-%d')).to eq '2014-04-06'
78
+ expect(merch_months[3].strftime('%Y-%m-%d')).to eq '2014-05-04'
79
+ expect(merch_months[4].strftime('%Y-%m-%d')).to eq '2014-06-01'
80
+ expect(merch_months[5].strftime('%Y-%m-%d')).to eq '2014-07-06'
81
+ expect(merch_months[6].strftime('%Y-%m-%d')).to eq '2014-08-03'
82
+ expect(merch_months[7].strftime('%Y-%m-%d')).to eq '2014-08-31'
83
+ expect(merch_months[8].strftime('%Y-%m-%d')).to eq '2014-10-05'
84
+ expect(merch_months[9].strftime('%Y-%m-%d')).to eq '2014-11-02'
85
+ expect(merch_months[10].strftime('%Y-%m-%d')).to eq '2014-11-30'
86
+ end
87
+ end
88
+
51
89
  end
52
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merch_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch Dempsey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.1
135
+ rubygems_version: 2.2.0
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Utility for manipulating dates within a 4-5-4 retail calendar