prekin 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: 8cb9bb6add4be7406125161040a45776c2cc4f034e558ab922a9928896608dd6
4
- data.tar.gz: 4d73b4c060d359e14df73c78a8e72ed99eb935419b2f9515582f93981b7dda79
3
+ metadata.gz: d6e6045e286aaf97a4de2d757e298d03f0d0d1b0788a1d8590d3cd5049a11bcf
4
+ data.tar.gz: 67747c5a5cb31926dc1f38dd8eb0c14747c57f1f7a1e3981319a06aa9adae6bd
5
5
  SHA512:
6
- metadata.gz: 786006fa3132ad7345a1ca93f3786df487a8de496d28d06d147a1e113c3584f251d3eca118cacdf5e09914859aff1112a7c0bd443ba857aa0bdcf596671b9847
7
- data.tar.gz: 0464c9fe76f546274ebe6846fbc26730b85ffdc08820b8494873f39acffb6292d11f7dc42aebd665ce45b98a684498d66501f4f171d4ec5f65e292eaa25f6b19
6
+ metadata.gz: e02b54a40bb89956b7142ced5a6e88bf97c1e85d6919c9808df54897e8944633ee83b3dae6041ca5f4907785b254389af2065578ac4a7c33b859ac7a07b9d51b
7
+ data.tar.gz: 10cb630127e358d6e3240e9c48d393fd8a3c044164676567047fbe48fd5046f3663d25f25a5c1d6494cd5f7d9e017b6f32092e53dbb25f719e10a824af77ccbf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prekin (0.1.0)
4
+ prekin (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Prekin
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/prekin.rb CHANGED
@@ -6,4 +6,80 @@ require 'prekin/extend_time_class'
6
6
 
7
7
  module Prekin
8
8
  class Error < StandardError; end
9
+
10
+ class << self
11
+ # TODO: 月および年をまたぐ場合の処理が都度都度になっており、複雑すぎる
12
+ def next(year_month_str = nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
13
+ base_month = if year_month_str.nil?
14
+ Date.today.month
15
+ else
16
+ Date.parse(year_month_str).month
17
+ end
18
+ end_day_of_this_month = if year_month_str.nil?
19
+ Date.new(Date.today.year, base_month, -1)
20
+ else
21
+ Date.new(
22
+ Date.parse(year_month_str).year,
23
+ base_month,
24
+ -1
25
+ )
26
+ end
27
+ days_in_month = end_day_of_this_month.day
28
+
29
+ # 現在の月を1日ずつ増やしながら、その日が金曜日かどうかをチェックする
30
+ dates = []
31
+ for i in 1..days_in_month # rubocop:disable Style/For
32
+ date = if year_month_str.nil?
33
+ Date.new(Date.today.year, base_month, i)
34
+ else
35
+ Date.new(Date.parse(year_month_str).year, base_month, i)
36
+ end
37
+
38
+ dates << date if date.wday == 5
39
+ end
40
+
41
+ # 金曜日である日付を配列で得て、最終金曜日を返す (String)
42
+ if dates.last < Date.parse(year_month_str || Date.today.to_s)
43
+ end_day_of_next_month = if year_month_str.nil?
44
+ if base_month == 12
45
+ Date.new(Date.today.year + 1, 1, -1)
46
+ else
47
+ Date.new(Date.today.year, base_month + 1, -1)
48
+ end
49
+ elsif base_month == 12
50
+ Date.new(
51
+ Date.parse(year_month_str).year + 1,
52
+ 1,
53
+ -1
54
+ )
55
+ else
56
+ Date.new(
57
+ Date.parse(year_month_str).year,
58
+ base_month + 1,
59
+ -1
60
+ )
61
+ end
62
+ days_in_month = end_day_of_next_month.day
63
+
64
+ dates = []
65
+ for i in 1..days_in_month # rubocop:disable Style/For
66
+ date = if year_month_str.nil?
67
+ if base_month == 12 # rubocop:disable Metrics/BlockNesting
68
+ Date.new(Date.today.year + 1, 1, i)
69
+ else
70
+ Date.new(Date.today.year, base_month + 1, i)
71
+ end
72
+ elsif base_month == 12
73
+ Date.new(Date.parse(year_month_str).year + 1, 1, i)
74
+ else
75
+ Date.new(Date.parse(year_month_str).year, base_month + 1, i)
76
+ end
77
+
78
+ dates << date if date.wday == 5
79
+ end
80
+ end
81
+
82
+ dates.last.to_s
83
+ end
84
+ end
9
85
  end
data/prekin.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['takiya@toran.sakura.ne.jp']
10
10
 
11
11
  spec.summary = "Judge whether the target day of month is 'PREMIUM FRIDAY' or not."
12
- spec.description = "Return true or false when you specify the day of month (by Time Class, Date Class or DateTime Class). The criteria is whether the day is 'PREMIUM FRIDAY' or not. 'PREMIUM FRIDAY' is the last friday in month in Japan."
12
+ spec.description = "Return true or false when you specify the day of month (by Time class, Date class, DateTime class or String class). The criteria is whether the day is 'PREMIUM FRIDAY' or not. 'PREMIUM FRIDAY' is the last friday in month in Japan."
13
13
  spec.homepage = 'https://github.com/nikukyugamer/prekin'
14
14
  spec.license = 'MIT'
15
15
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prekin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Osamu Takiya
@@ -94,9 +94,9 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Return true or false when you specify the day of month (by Time Class,
98
- Date Class or DateTime Class). The criteria is whether the day is 'PREMIUM FRIDAY'
99
- or not. 'PREMIUM FRIDAY' is the last friday in month in Japan.
97
+ description: Return true or false when you specify the day of month (by Time class,
98
+ Date class, DateTime class or String class). The criteria is whether the day is
99
+ 'PREMIUM FRIDAY' or not. 'PREMIUM FRIDAY' is the last friday in month in Japan.
100
100
  email:
101
101
  - takiya@toran.sakura.ne.jp
102
102
  executables: []