HappyFriday 0.4.0 → 0.4.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: bae7fcd3f539194b5a234f341885ac99c674e742f74ffc1181127cc047f89b49
4
- data.tar.gz: '08da745d2b4cdc3b21f0e7fd7a94957c6e805bb7a8b6690825fd7ea9ff0bf5e7'
3
+ metadata.gz: c9357c7d344a25ec5773cfd40a97641602e5d5e33e10435b00b721ce6f2e777e
4
+ data.tar.gz: c0685d10bbfcfa912e6c5621d471060f7cae9efe7eb903943a3c38261c16d6ae
5
5
  SHA512:
6
- metadata.gz: 77ade964d2f191705d50f1f7028edabb951ff2486051beedcc71aa1f895927551722ce776f178d46d2c888ad4db895bb18f9bb83e1268ee87885115abfbf46f1
7
- data.tar.gz: 5b2c6b5dad43522d96a94936d4a0768389465385eef2de103ecc03f8a3b2c47cf96a1d42d6c42b6009b18762e56a29f161544b2d2c66128b44c915f590a18ac8
6
+ metadata.gz: 37eb44bf9423090e4399176da90c43be7341b4d5c719b789b316c1d0b3193c98fd8f1fdbc999507468453e4906021b048e053a21a04fa6d6e9534a7c48dfd5af
7
+ data.tar.gz: d4e2d3ef75a298d08e4d5e91ad8a99f542988e64095d7302471dc8c58c1b616238382254ba32ade1f85cd5fdf5dd853823c34c7788b45aaebe9619e37f81fcba
data/README.md CHANGED
@@ -17,24 +17,30 @@ If bundler is not being used to manage dependencies, install the gem by executin
17
17
  ### HappyFriday decision
18
18
  ```rb
19
19
  date = Date.new(2022, 5, 3)
20
- HappyFriday.happyfriday?(date)
20
+ HappyFriday.happy_friday?(date)
21
21
  => false
22
22
 
23
23
  date = Date.new(2022, 5, 27)
24
- HappyFriday.happyfriday?(date)
24
+ HappyFriday.happy_friday?(date)
25
25
  => true
26
26
  ```
27
27
 
28
- ### Getting HappyFriday
28
+ ### Get the next HappyFriday
29
29
  You can get a HappyFriday for that month.
30
30
  ```rb
31
- date = Date.new(2022, 5, 1)
32
- HappyFriday.get_happy_friday(date)
33
- => 2022-05-27 00:00:00 +0900
34
-
35
- date = Date.new(2022, 6, 1)
36
- HappyFriday.get_happy_friday(date)
37
- => 2022-06-24 00:00:00 +0900
31
+ date = Date.new(2022, 5)
32
+ HappyFriday.get_next_happy_friday(date)
33
+ => Fri, 27 May 2022
34
+
35
+ # If the last Friday of the month is a holiday, the day before becomes HappyFriday.
36
+ date = Date.new(2022, 4)
37
+ HappyFriday.get_next_happy_friday(date)
38
+ => Thu, 28 Apr 2022
39
+
40
+ # If HappyFriday of that month has passed, get next month.
41
+ date = Date.new(2022, 4, 30)
42
+ HappyFriday.get_next_happy_friday(date)
43
+ => Fri, 27 May 2022
38
44
  ```
39
45
 
40
46
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyFriday
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.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 self.happy_friday?(target_date)
11
+ target_date.strftime("%Y%m%d") == HappyFriday.get_next_happy_friday(target_date).strftime("%Y%m%d")
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 self.get_next_happy_friday(target_date)
15
+ last_of_month = Date.new(target_date.year, target_date.month, -1)
16
16
 
17
17
  case last_of_month.wday
18
18
  when 0..4
@@ -35,6 +35,15 @@ module HappyFriday
35
35
  end
36
36
  end
37
37
 
38
- last_friday
38
+ # If HappyFriday of that month has passed, get next month.
39
+ # TODO: refactoring
40
+ if target_date > last_friday
41
+ next_month = last_friday + 1.month
42
+ happy_friday = HappyFriday.get_next_happy_friday(Date.new(next_month.year, next_month.month))
43
+ else
44
+ happy_friday = last_friday
45
+ end
46
+
47
+ happy_friday
39
48
  end
40
49
  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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - holasoynaoki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-03 00:00:00.000000000 Z
11
+ date: 2022-06-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Determine if today is a HappyFriday.
14
14
  email: