month_date 0.0.4.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -10
- data/lib/month_date/version.rb +1 -1
- data/lib/month_date.rb +10 -10
- data/month_date.gemspec +2 -2
- data/spec/month_date_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -0
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2a76e34d43f16f82237f77c4bfae70ee79026c
|
4
|
+
data.tar.gz: 229e8aeb4e30e631bf635c3f18bbc291739e837c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb74af0d088cd213346469271783b798161e5df44f33a1db804a88ffb49887e3a6932c6f7787ca873d7189ee6c2ff4a6f2f4f2207a381fd87a6dc8241528b51c
|
7
|
+
data.tar.gz: 0204125466500cf4a91d9b0aa84d6f10eceb60ed071ab8ec08a8823956155e74fb8c56689cdd1ef6679eb07f1d151a99ce6094f8815ec24f2b487f9230dffc68
|
data/README.md
CHANGED
@@ -4,24 +4,45 @@
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
+
require('month_date')
|
8
|
+
|
9
|
+
## Method
|
7
10
|
### get dates in specific week
|
8
11
|
|
9
12
|
MonthDate.week_date_in_month(year, month, week)
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
example:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
MonthDate.week_date_in_month(2014, 1, 1) # get all Monday dates in 2014/1
|
15
18
|
|
19
|
+
=> ["20140106", "20140113", "20140120", "20140127"]
|
20
|
+
```
|
16
21
|
### get dates in range
|
17
22
|
|
18
23
|
MonthDate.dates_in_range(start_date, end_date)
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
MonthDate.dates_in_range("20141230", "20150102")
|
29
|
+
|
30
|
+
=> ["20141230", "20141231", "20150101", "20150102"]
|
31
|
+
```
|
32
|
+
### get all dates in month
|
33
|
+
|
34
|
+
MonthDate.date_in_month(year, month)
|
35
|
+
|
36
|
+
example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
MonthDate.date_in_month(2014, 1)
|
40
|
+
|
41
|
+
=> ["20140101", "20140102", "20140103", "20140104", "20140105", "20140106", "20140107", "20140108", "20140109", "20140110", "20140111", "20140112", "20140113", "20140114", "20140115", "20140116", "20140117", "20140118", "20140119", "20140120", "20140121", "20140122", "20140123", "20140124", "20140125", "20140126", "20140127", "20140128", "20140129", "20140130", "20140131"]
|
42
|
+
```
|
43
|
+
|
22
44
|
#### parameter
|
23
45
|
##### week
|
24
|
-
|
25
46
|
| 0 | Sunday |
|
26
47
|
|---|-----------|
|
27
48
|
| 1 | Monday |
|
@@ -46,7 +67,6 @@ Or install it yourself as:
|
|
46
67
|
|
47
68
|
$ gem install month_date
|
48
69
|
|
49
|
-
## Parameter
|
50
70
|
|
51
|
-
|
52
|
-
|
71
|
+
## License
|
72
|
+
MIT
|
data/lib/month_date/version.rb
CHANGED
data/lib/month_date.rb
CHANGED
@@ -3,13 +3,13 @@ require "time"
|
|
3
3
|
require "date"
|
4
4
|
|
5
5
|
module MonthDate
|
6
|
-
def MonthDate.week_date_in_month(year, month, week)
|
6
|
+
def MonthDate.week_date_in_month(year, month, week, format="%Y%m%d")
|
7
7
|
days = self.days_in_month(year, month)
|
8
8
|
result = []
|
9
9
|
1.upto(days) do |day|
|
10
10
|
date = Date.new(year, month, day)
|
11
11
|
if date.wday == week
|
12
|
-
result << date.strftime(
|
12
|
+
result << date.strftime(format)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
return result
|
@@ -19,32 +19,32 @@ module MonthDate
|
|
19
19
|
Date.new(year, month, -1).day
|
20
20
|
end
|
21
21
|
|
22
|
-
def MonthDate.dates_in_range(start_date, end_date)
|
22
|
+
def MonthDate.dates_in_range(start_date, end_date, format="%Y%m%d")
|
23
23
|
start_date = Time.parse(start_date.to_s)
|
24
24
|
end_date = Time.parse(end_date.to_s)
|
25
25
|
result = []
|
26
26
|
if start_date.mon == end_date.mon && start_date.year == end_date.year
|
27
27
|
(start_date.day..end_date.day).to_a.each do |day|
|
28
28
|
date = Date.new(start_date.year, start_date.mon, day)
|
29
|
-
result << date.strftime(
|
29
|
+
result << date.strftime(format)
|
30
30
|
end
|
31
31
|
elsif start_date.year == end_date.year
|
32
32
|
# first count the start date month date.
|
33
33
|
(start_date.day..self.days_in_month(start_date.year, start_date.mon)).to_a.each do |day|
|
34
34
|
date = Date.new(start_date.year, start_date.mon, day)
|
35
|
-
result << date.strftime(
|
35
|
+
result << date.strftime(format)
|
36
36
|
end
|
37
37
|
(start_date.mon+1..end_date.mon-1).to_a.each do |month|
|
38
38
|
result += self.date_in_month(start_date.year, month)
|
39
39
|
end
|
40
40
|
(1..end_date.day).each do |day|
|
41
41
|
date = Date.new(end_date.year, end_date.mon, day)
|
42
|
-
result << date.strftime(
|
42
|
+
result << date.strftime(format)
|
43
43
|
end
|
44
44
|
else
|
45
45
|
(start_date.day..self.days_in_month(start_date.year, start_date.mon)).to_a.each do |day|
|
46
46
|
date = Date.new(start_date.year, start_date.mon, day)
|
47
|
-
result << date.strftime(
|
47
|
+
result << date.strftime(format)
|
48
48
|
end
|
49
49
|
(start_date.mon+1..12).to_a.each do |month|
|
50
50
|
result += self.date_in_month(start_date.year, month)
|
@@ -54,18 +54,18 @@ module MonthDate
|
|
54
54
|
end
|
55
55
|
(1..end_date.day).each do |day|
|
56
56
|
date = Date.new(end_date.year, end_date.mon, day)
|
57
|
-
result << date.strftime(
|
57
|
+
result << date.strftime(format)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
return result
|
61
61
|
end
|
62
62
|
|
63
|
-
def MonthDate.date_in_month(year, month)
|
63
|
+
def MonthDate.date_in_month(year, month, format="%Y%m%d")
|
64
64
|
days = self.days_in_month(year, month)
|
65
65
|
ary = []
|
66
66
|
1.upto(days) do |day|
|
67
67
|
date = Date.new(year, month, day)
|
68
|
-
ary << date.strftime(
|
68
|
+
ary << date.strftime(format)
|
69
69
|
end
|
70
70
|
return ary
|
71
71
|
end
|
data/month_date.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["ctxhou"]
|
10
10
|
spec.email = ["vjack070707@gmail.com"]
|
11
11
|
spec.summary = %q{Quickly get the specific date of month}
|
12
|
-
spec.description = %q{
|
13
|
-
spec.homepage = ""
|
12
|
+
spec.description = %q{More easy way to get some dates in ruby.}
|
13
|
+
spec.homepage = "https://github.com/ctxhou/month_date"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MonthDate do
|
4
|
+
it "Return correct date" do
|
5
|
+
expect(MonthDate.week_date_in_month(2014, 1, 1)).to eq ["20140106", "20140113", "20140120", "20140127"]
|
6
|
+
expect(MonthDate.week_date_in_month(2014, 1, 1, "%F")).to eq ["2014-01-06", "2014-01-13", "2014-01-20", "2014-01-27"]
|
7
|
+
end
|
8
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "month_date"
|
metadata
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: month_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ctxhou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
41
|
+
description: More easy way to get some dates in ruby.
|
42
42
|
email:
|
43
43
|
- vjack070707@gmail.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
@@ -53,7 +53,9 @@ files:
|
|
53
53
|
- lib/month_date.rb
|
54
54
|
- lib/month_date/version.rb
|
55
55
|
- month_date.gemspec
|
56
|
-
|
56
|
+
- spec/month_date_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: https://github.com/ctxhou/month_date
|
57
59
|
licenses:
|
58
60
|
- MIT
|
59
61
|
metadata: {}
|
@@ -63,18 +65,20 @@ require_paths:
|
|
63
65
|
- lib
|
64
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
|
-
- -
|
68
|
+
- - ">="
|
67
69
|
- !ruby/object:Gem::Version
|
68
70
|
version: '0'
|
69
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
72
|
requirements:
|
71
|
-
- -
|
73
|
+
- - ">="
|
72
74
|
- !ruby/object:Gem::Version
|
73
75
|
version: '0'
|
74
76
|
requirements: []
|
75
77
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.4.
|
78
|
+
rubygems_version: 2.4.5
|
77
79
|
signing_key:
|
78
80
|
specification_version: 4
|
79
81
|
summary: Quickly get the specific date of month
|
80
|
-
test_files:
|
82
|
+
test_files:
|
83
|
+
- spec/month_date_spec.rb
|
84
|
+
- spec/spec_helper.rb
|