month_date 0.0.2.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9f25631633895fc8311027eebbea530498e41e7
4
- data.tar.gz: 1957a9bf38a9c5b1f0d2eee8497e1bc5f221e8f7
3
+ metadata.gz: d8208efe08a9be50450569631009260655535286
4
+ data.tar.gz: 8b950e49651159d12345c24eb19b2a3e7540e714
5
5
  SHA512:
6
- metadata.gz: c4ac34acf487552a5f358053e818073018a75a817139182ff05bdef8a1ed41dc26c454cfcab061ba3b5ac21e0e3fe6f70833fcfa8285446c144286e8b9335435
7
- data.tar.gz: 4a9b9cc6d0f3d4a117292653341bdd5ba0c4ba5c938f3ee5e69898ab7806e66d5ff5b3f3aa259bd469201d1e7d6d5f0214a8159c3502c2b1764f5991da70f9fd
6
+ metadata.gz: 2dc36062a8768577f426b92c546a426da2df70d28e394b2dff07eddfbc68d742fd69451927d0d47eea288dbdae4c3f26c40ff840667153b5917e2dd3dbc0a2d0
7
+ data.tar.gz: c655f6e505c397f17c50d23ced9354497616cc9cd700ec164c8b1ccf7ba11d7ace3c2cea9781dc898ee40d41931c68b56ebb5bce64763e4847f0c3a98b1da010
@@ -1,3 +1,3 @@
1
1
  module MonthDate
2
- VERSION = "0.0.2.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/month_date.rb CHANGED
@@ -19,6 +19,47 @@ module MonthDate
19
19
  Date.new(year, month, -1).day
20
20
  end
21
21
 
22
+ def MonthDate.days_in_range(start_date, end_date)
23
+ start_date = Time.parse(start_date.to_s)
24
+ end_date = Time.parse(end_date.to_s)
25
+ result = []
26
+ if start_date.mon == end_date.mon && start_date.year == end_date.year
27
+ (start_date.day..end_date.day).to_a.each do |day|
28
+ date = Date.new(start_date.year, start_date.mon, day)
29
+ result << date.strftime("%Y%m%d")
30
+ end
31
+ elsif start_date.year == end_date.year
32
+ # first count the start date month date.
33
+ (start_date.day..self.days_in_month(start_date.year, start_date.mon)).to_a.each do |day|
34
+ date = Date.new(start_date.year, start_date.mon, day)
35
+ result << date.strftime("%Y%m%d")
36
+ end
37
+ (start_date.mon+1..end_date.mon-1).to_a.each do |month|
38
+ result += self.date_in_month(start_date.year, month)
39
+ end
40
+ (1..end_date.day).each do |day|
41
+ date = Date.new(end_date.year, end_date.mon, day)
42
+ result << date.strftime("%Y%m%d")
43
+ end
44
+ else
45
+ (start_date.day..self.days_in_month(start_date.year, start_date.mon)).to_a.each do |day|
46
+ date = Date.new(start_date.year, start_date.mon, day)
47
+ result << date.strftime("%Y%m%d")
48
+ end
49
+ (start_date.mon+1..12).to_a.each do |month|
50
+ result += self.date_in_month(start_date.year, month)
51
+ end
52
+ (1..end_date.mon-1).to_a.each do |month|
53
+ result += self.date_in_month(end_date.year, month)
54
+ end
55
+ (1..end_date.day).each do |day|
56
+ date = Date.new(end_date.year, end_date.mon, day)
57
+ result << date.strftime("%Y%m%d")
58
+ end
59
+ end
60
+ return result
61
+ end
62
+
22
63
  def MonthDate.date_in_month(year, month)
23
64
  days = self.days_in_month(year, month)
24
65
  ary = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: month_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ctxhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler