HappyFriday 0.3.1 → 0.5.1

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
  SHA256:
3
- metadata.gz: dc61748501928c69e0c18053c2ec7bba02c344bf19a545f91e56f701877b4202
4
- data.tar.gz: ec5251820ad1d7c24dfae6fab231e0e0ab9ba1bcb760b697eb0aab75c8530ed4
3
+ metadata.gz: e7e2a2da8392cf104f420a5761b804499f3fa5bb531e044f5a3d0cfa3fb9fb28
4
+ data.tar.gz: 19caecefaba952ec58b0955606668de9d6edafd60080792e0e76244808b39a41
5
5
  SHA512:
6
- metadata.gz: aca0d24fc307b04be91c461f46a99cc5dfbb05edaac1074adeb05eecdbdf4c837fff6491c30fc28490bf06a0790cccc3d1e54f6af8ad9f03286fe5f3e44de5fe
7
- data.tar.gz: a1041d067961bbccda61f0669b824959a2291449e1828f46202a0a254b1483c3466d4dee61f0a3199ea58109686e9f1ff295efa0895e0ff316b5503c2ff1f3ca
6
+ metadata.gz: 6fd4e5698a27346df8827ec58993d0759396b4fa7e1ec3d33a6b2e0d6ceac141c579b3cc068d6394e38deac90e28f33f5611c1b5e521fc53df326f4f90152139
7
+ data.tar.gz: 22452139f2a94c58a69ba6c9a7c45165e2879a80c518dcc13d94adbf791ae7ccb6fe329dbff1f224c1381c8841049913722717908869c238f4526ba2f2b87633
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # HappyFriday
2
2
 
3
- Gem that can determine HappyFriday.
3
+ This gem is capable of obtaining and determining HappyFriday.
4
+ Extend to Date class.
4
5
 
5
6
  ## Installation
6
7
 
@@ -15,20 +16,27 @@ If bundler is not being used to manage dependencies, install the gem by executin
15
16
  ## Usage
16
17
 
17
18
  ### HappyFriday decision
18
- true or false returns.
19
19
  ```rb
20
- date = Date.new(2022, 5, 3)
21
- HappyFriday.happyfriday?(date) # false
20
+ Date.new(2022, 5, 3).happy_friday?
21
+ => false
22
22
 
23
- date = Date.new(2022, 5, 27)
24
- HappyFriday.happyfriday?(date) # true
23
+ Date.new(2022, 5, 27).happy_friday?
24
+ => true
25
25
  ```
26
26
 
27
- ### Getting HappyFriday
27
+ ### Get the next HappyFriday
28
28
  You can get a HappyFriday for that month.
29
29
  ```rb
30
- date = Date.new(2022, 5, 1)
31
- HappyFriday.get_happy_friday(date) # 2022-05-27 00:00:00 +0900
30
+ Date.new(2022, 5).get_next_happy_friday
31
+ => Fri, 27 May 2022
32
+
33
+ # If the last Friday of the month is a holiday, the day before becomes HappyFriday.
34
+ Date.new(2022, 4).get_next_happy_friday
35
+ => Thu, 28 Apr 2022
36
+
37
+ # If HappyFriday of that month has passed, get next month.
38
+ Date.new(2022, 4, 30).get_next_happy_friday
39
+ => Fri, 27 May 2022
32
40
  ```
33
41
 
34
42
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyFriday
4
- VERSION = "0.3.1"
4
+ VERSION = "0.5.1"
5
5
  end
data/lib/HappyFriday.rb CHANGED
@@ -7,12 +7,12 @@ require 'holiday_jp'
7
7
  module HappyFriday
8
8
  class Error < StandardError; end
9
9
 
10
- def self.happyfriday?(target_date)
11
- target_date.strftime("%Y%m%d") == HappyFriday.get_happy_friday(target_date).strftime("%Y%m%d")
10
+ def happy_friday?
11
+ self == self.get_next_happy_friday
12
12
  end
13
13
 
14
- def self.get_happy_friday(date)
15
- last_of_month = Date.new(date.year, date.month, -1)
14
+ def get_next_happy_friday
15
+ last_of_month = self.end_of_month
16
16
 
17
17
  case last_of_month.wday
18
18
  when 0..4
@@ -23,16 +23,29 @@ module HappyFriday
23
23
  raise 'Unpredictable day of the week.'
24
24
  end
25
25
 
26
- last_friday = last_of_month.ago(before_friday_days.days)
26
+ last_friday = last_of_month - before_friday_days.days
27
27
 
28
28
  raise 'err' unless last_friday.wday == 5
29
29
 
30
- # Doesn't work
31
- # while HolidayJp.holiday?(last_friday)
32
- # last_friday = last_friday.ago(1.week)
33
- # end
34
- # return false if last_friday.month != last_of_month.month
30
+ 100.times do
31
+ if HolidayJp.holiday?(last_friday)
32
+ last_friday -= 1
33
+ else
34
+ break
35
+ end
36
+ end
37
+
38
+ # If HappyFriday of that month has passed, get next month.
39
+ if self > last_friday
40
+ happy_friday = self.next_month.beginning_of_month.get_next_happy_friday
41
+ else
42
+ happy_friday = last_friday
43
+ end
35
44
 
36
- last_friday
45
+ happy_friday
37
46
  end
38
47
  end
48
+
49
+ class Date
50
+ include HappyFriday
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HappyFriday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - holasoynaoki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Determine if today is a HappyFriday.
14
14
  email:
@@ -33,7 +33,7 @@ licenses:
33
33
  metadata:
34
34
  homepage_uri: https://github.com/holasoynaoki/HappyFriday
35
35
  source_code_uri: https://github.com/holasoynaoki/HappyFriday
36
- post_install_message:
36
+ post_install_message:
37
37
  rdoc_options: []
38
38
  require_paths:
39
39
  - lib
@@ -48,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.15
52
- signing_key:
51
+ rubygems_version: 3.1.6
52
+ signing_key:
53
53
  specification_version: 4
54
54
  summary: Determine if today is a HappyFriday.
55
55
  test_files: []