what_date 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/what_date/client.rb +16 -0
- data/lib/what_date/date_of_month.rb +33 -0
- data/lib/what_date/version.rb +1 -1
- data/what_date.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d947d42c8a1beb11fcbc8327ac2933f7c0cd4a19dfb4cb07adaf48ce6402e7
|
4
|
+
data.tar.gz: eab41983ec577e1aabb9d3abace7a74197c0d56409bb51427ff2d77c0cba98cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a8e5c833ba814f98a8ca0c08e8768f7b2edd3caed7ce311d2ae04b78664b96ac962394138eb672f419c3f29dfa0fd18cce5f63d7a7e9d8e13419e0487d1dc5
|
7
|
+
data.tar.gz: 4c83b1bede76efe2eafe93c58094a86f86a1af451a1c9a16a5ea26c4044f85551792677ed019383c39cd5f38c93af266a6c33a7808c2f0845871407db6ba0e61
|
data/README.md
CHANGED
@@ -17,11 +17,26 @@ Or install it yourself as:
|
|
17
17
|
$ gem install what_date
|
18
18
|
|
19
19
|
## Usage
|
20
|
-
|
20
|
+
You can query the date of any day in the current week, the previous week or the following week. You can supply a date so the query is relative to the week of the given date
|
21
21
|
```
|
22
|
+
## initialize client
|
22
23
|
$client = WhatDate.client
|
24
|
+
|
25
|
+
## get dates
|
23
26
|
$client.friday
|
24
27
|
$client.tuesday(Date.new(2018,2,3)) ##date of tuesday in the week of the given date
|
28
|
+
$client.prev_tuesday
|
29
|
+
$client.next_tuesday
|
30
|
+
|
31
|
+
```
|
32
|
+
You can also ask for the date of a particular day of a given month. Use ordinals such as first, second and up to fifth. But'last' does not work yet.
|
33
|
+
|
34
|
+
```
|
35
|
+
$client.first_monday_of_june_2018
|
36
|
+
$##4 June 2018
|
37
|
+
$client.third_tuesday_of_may_2018
|
38
|
+
$##19 June 2018
|
39
|
+
|
25
40
|
```
|
26
41
|
|
27
42
|
## Development
|
data/lib/what_date/client.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext/date/calculations'
|
3
|
+
require 'what_date/date_of_month'
|
4
|
+
|
3
5
|
module WhatDate
|
4
6
|
class Client
|
7
|
+
include WhatDate::DateOfMonth
|
5
8
|
|
6
9
|
Date::DAYS_INTO_WEEK.each do |day, inc|
|
7
10
|
define_method(day) do |ref_date=nil|
|
@@ -9,5 +12,18 @@ module WhatDate
|
|
9
12
|
ref_date.monday.days_since(inc)
|
10
13
|
end
|
11
14
|
end
|
15
|
+
|
16
|
+
Date::DAYS_INTO_WEEK.each do |day, inc|
|
17
|
+
define_method("prev_#{day.to_s}".to_sym) do |ref_date = nil|
|
18
|
+
send(day, ref_date).days_ago(7)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Date::DAYS_INTO_WEEK.each do |day, inc|
|
23
|
+
define_method("next_#{day.to_s}".to_sym) do |ref_date = nil|
|
24
|
+
send(day, ref_date).days_since(7)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
12
28
|
end
|
13
29
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module WhatDate
|
2
|
+
module DateOfMonth
|
3
|
+
|
4
|
+
def date_of_month(order:1, day:, month:, year: Date.today.year)
|
5
|
+
month_int = Date::MONTHNAMES.index(month)
|
6
|
+
first_date = Date.new(year, month_int, 1)
|
7
|
+
first_day = first_date.wday
|
8
|
+
lookup = Date::DAYNAMES.index(day.titleize)
|
9
|
+
if lookup < first_day
|
10
|
+
inc = (order - 1) * 7 + (lookup - first_day + 8)
|
11
|
+
else
|
12
|
+
inc = (order - 1) * 7 + (lookup - first_day + 1)
|
13
|
+
end
|
14
|
+
Date.new(year, month_int, inc)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def method_missing(meth, *args)
|
19
|
+
if meth.to_s =~ /^(first||second||third||fourth||fifth)_(monday||tuesday||wednesday||thursday||friday||saturday||sunday)_of_[A-Za-z]+_\d+$/
|
20
|
+
methods = meth.to_s.split("_")
|
21
|
+
order = { "first" => 1, "second" => 2, "third" => 3, "fourth" => 4, "fifth" => 5 }[methods[0]]
|
22
|
+
day = methods[1].titleize
|
23
|
+
month = methods[3].titleize
|
24
|
+
year = methods[4].to_i
|
25
|
+
date_of_month(order: order, day: day, month: month, year: year)
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/what_date/version.rb
CHANGED
data/what_date.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["zorro.ej@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A simple tool to return the dates given a day}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{You may ask for the date of next Tuesday, this Monday, last Saturyda, or the first Saturyda of Nov 2011}
|
14
14
|
spec.homepage = "https://github.com/ej2015/what_date.git"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.11'
|
83
|
-
description:
|
83
|
+
description: You may ask for the date of next Tuesday, this Monday, last Saturyda,
|
84
|
+
or the first Saturyda of Nov 2011
|
84
85
|
email:
|
85
86
|
- zorro.ej@gmail.com
|
86
87
|
executables: []
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- bin/setup
|
99
100
|
- lib/what_date.rb
|
100
101
|
- lib/what_date/client.rb
|
102
|
+
- lib/what_date/date_of_month.rb
|
101
103
|
- lib/what_date/version.rb
|
102
104
|
- what_date.gemspec
|
103
105
|
homepage: https://github.com/ej2015/what_date.git
|