Skip to content

Commit ee6013d

Browse files
authored
Merge pull request #33 from fumiyasac/feature/fix_for_2021
2021年の祝祭日に関する変更対応&その他諸々の対応
2 parents 2ed6ade + 2098e76 commit ee6013d

File tree

15 files changed

+542
-92
lines changed

15 files changed

+542
-92
lines changed

CalculateCalendarLogic.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "CalculateCalendarLogic"
33
s.swift_versions = '5.0'
4-
s.version = "0.3.0"
4+
s.version = "0.4.0"
55
s.summary = "This library CalculateCalendarLogic (sample project name is handMadeCalendarAdvance) can judge a holiday in Japan."
66
s.description = <<-DESC
77
This library 'CalculateCalendarLogic' can judge a holiday in Japan.

CalculateCalendarLogic/CalculateCalendarLogic.swift

+27-9
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public struct CalculateCalendarLogic {
178178
minute: 0,
179179
second: 0,
180180
nanosecond: 0)) else {
181-
fatalError() // FIXME: throwにしたほうがよい?
181+
fatalError("date is invalid.")
182182
}
183183
let weekdayNum = cal.component(.weekday, from: date) // 1:日曜日 ~ 7:土曜日
184184

@@ -200,6 +200,12 @@ public struct CalculateCalendarLogic {
200200
/// See also: http://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html
201201
let SpecialProvisionYear = 2020
202202

203+
/// 「国民の祝日」の特例が2020年(平成32年12月2日)に公布・施行された。
204+
/// 令和3年(2021年)に限り「海の日」は7月22日、「スポーツの日」は7月23日、「山の日」は8月8日となる。
205+
/// ※ 国民の祝日に関する法律第3条第2項の規定に基づき、8月9日は休日となります。
206+
/// See also: http://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html
207+
let SpecialExtraProvisionYear = 2021
208+
203209
/// (注意)春分の日・秋分の日は1948年以前も祝祭日であったが、このカレンダーロジックの基準は1948年〜を基準とするので考慮しない
204210
/// See also: https://ja.wikipedia.org/wiki/%E7%9A%87%E9%9C%8A%E7%A5%AD
205211

@@ -306,29 +312,38 @@ public struct CalculateCalendarLogic {
306312
case (year, 5, 6, _) where year >= AlternateHolidaysLawYear && getGoldenWeekAlterHoliday(year: year, weekday: weekday):
307313
return true
308314

309-
//(1).7月20日(1996年から2002年まで)、(2).7月の第3月曜日(2003年から)、(3).7月23日(2020年のみ): 海の日
315+
//(1).7月20日(1996年から2002年まで)、(2).7月の第3月曜日(2003年から)、(3).7月23日(2020年のみ)、(4).7月22日(2021年のみ): 海の日
310316
case (1996...2002, 7, 20, _):
311317
return true
312318

313319
case (year, 7, 15...21, .mon)
314-
where 2003 <= year && year != SpecialProvisionYear:
320+
where 2003 <= year && year != SpecialProvisionYear && year != SpecialExtraProvisionYear:
315321
return true
316322

317323
case (SpecialProvisionYear, 7, 23, _):
318324
return true
319-
325+
326+
case (SpecialExtraProvisionYear, 7, 22, _):
327+
return true
328+
320329
//7月21日: 海の日の振替休日
321330
case (1996...2002, 7, 21, .mon):
322331
return true
323332

324-
//(1).8月11日(2016年から)、(2).8月10日(2020年のみ): 山の日
333+
//(1).8月11日(2016年から)、(2).8月10日(2020年のみ)、(3).8月8日(2021年のみ ※8月9日振替休日): 山の日
325334
case (year, 8, 11, _)
326-
where year > 2015 && year != SpecialProvisionYear:
335+
where year > 2015 && year != SpecialProvisionYear && year != SpecialExtraProvisionYear:
327336
return true
328337

329338
case (SpecialProvisionYear, 8, 10, _):
330339
return true
331340

341+
case (SpecialExtraProvisionYear, 8, 8, _):
342+
return true
343+
344+
case (SpecialExtraProvisionYear, 8, 9, .mon):
345+
return true
346+
332347
//8月12日: 山の日の振替休日
333348
case (year, 8, 12, .mon) where year > 2015:
334349
return true
@@ -364,17 +379,20 @@ public struct CalculateCalendarLogic {
364379
&& getAlterHolidaySliverWeek(year: year) && year > 2008:
365380
return true
366381

367-
//(1).10月10日(1966年から1999年まで)、(2).10月の第2月曜日(2000年から)、(3).7月24日(2020年のみ): 体育の日(スポーツの日)
382+
//(1).10月10日(1966年から1999年まで)、(2).10月の第2月曜日(2000年から)、(3).7月24日(2020年のみ)、(4).7月23日(2021年のみ): 体育の日(スポーツの日)
368383
case (1966...1999, 10, 10, _):
369384
return true
370385

371386
case (year, 10, 8...14, .mon)
372-
where year > 1999 && year != SpecialProvisionYear:
387+
where year > 1999 && year != SpecialProvisionYear && year != SpecialExtraProvisionYear:
373388
return true
374389

375390
case (SpecialProvisionYear, 7, 24, _):
376391
return true
377-
392+
393+
case (SpecialExtraProvisionYear, 7, 23, _):
394+
return true
395+
378396
//10月11日: 体育の日の振替休日
379397
case (1966...1999, 10, 11, .mon):
380398
return true

CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift

+55
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,61 @@ class CalculateCalendarLogicTests: XCTestCase {
324324
// 勤労感謝の日: 2020年11月23日(月曜日)
325325
(2020, 11, 23, true),
326326

327+
// 2021年
328+
// 元日: 2021年1月1日(金曜日)
329+
(2021, 1, 1, true),
330+
331+
// 成人の日: 2021年1月11日(月曜日)
332+
(2021, 1, 11, true),
333+
334+
// 建国記念の日: 2021年2月11日(木曜日)
335+
(2021, 2, 11, true),
336+
337+
// 天皇誕生日: 2021年2月23日(火曜日)
338+
(2021, 2, 23, true),
339+
340+
// 春分の日: 2021年3月20日(土曜日)
341+
(2021, 3, 20, true),
342+
343+
// 昭和の日: 2021年4月29日(木曜日)
344+
(2021, 4, 29, true),
345+
346+
// 憲法記念日: 2021年5月3日(月曜日)
347+
(2021, 5, 3, true),
348+
349+
// みどりの日: 2021年5月4日(火曜日)
350+
(2021, 5, 4, true),
351+
352+
// こどもの日: 2021年5月5日(水曜日)
353+
(2021, 5, 5, true),
354+
355+
// 海の日: 2021年7月22日(木曜日)
356+
(2021, 7, 19, false),
357+
(2021, 7, 22, true),
358+
359+
// スポーツの日: 2021年7月23日(金曜日)
360+
(2021, 7, 23, true),
361+
(2021, 10, 11, false),
362+
363+
// 山の日: 2021年8月8日(日曜日)
364+
(2021, 8, 8, true),
365+
366+
// 振替休日: 2021年8月9日(月曜日)
367+
(2021, 8, 9, true),
368+
(2021, 8, 11, false),
369+
370+
// 敬老の日: 2021年9月20日(月曜日)
371+
(2021, 9, 20, true),
372+
373+
// 秋分の日: 2021年9月23日(木曜日)
374+
(2021, 9, 23, true),
375+
376+
// 文化の日: 2021年11月3日(水曜日)
377+
(2021, 11, 3, true),
378+
379+
// 勤労感謝の日: 2020年11月23日(火曜日)
380+
(2021, 11, 23, true),
381+
327382
// 2022年
328383
// 元日: 2022年1月1日(土曜日)
329384
(2022, 1, 1, true),

Package.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "CalculateCalendarLogic",
8+
products: [
9+
.library(
10+
name: "CalculateCalendarLogic",
11+
targets: ["CalculateCalendarLogic"]
12+
)
13+
],
14+
targets: [
15+
.target(
16+
name: "CalculateCalendarLogic",
17+
path: "CalculateCalendarLogic"
18+
),
19+
.testTarget(
20+
name: "CalculateCalendarLogicTests",
21+
dependencies: ["CalculateCalendarLogic"]
22+
)
23+
],
24+
swiftLanguageVersions: [.v5]
25+
)

README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool {
3434

3535
### Installation
3636

37-
We can use this library with CocoaPods, Carthage, Manually.
37+
We can use this library with CocoaPods, Carthage, Swift Package Manager, Manually.
3838

3939
##### Use CocoaPods
4040

@@ -60,6 +60,11 @@ Create Carthage and specify it in your Cartfile:
6060
github "fumiyasac/handMadeCalendarAdvance"
6161
```
6262

63+
##### Use Swift Package Manager
64+
65+
Using Xcode, go to File -> Swift Packages -> Add Package Dependency and enter URL below:
66+
https://github.com/fumiyasac/handMadeCalendarAdvance
67+
6368
##### Manually
6469

6570
Copy all the files in CalculateCalendarLogic/CalculateCalendarLogic.swift file into your project.
@@ -105,6 +110,7 @@ Special Thanks to
105110
+ [econa77](https://twitter.com/econa77): Mac OS 10.10 Support
106111
+ [essochi](https://github.com/essochi): Ver0.1.7
107112
+ [myammm](https://github.com/myammm): Ver0.2.0
113+
+ [kazuomatz](https://github.com/kazuomatz): Refactoring & Bugfix
108114

109115
and more iOS developers.
110116

@@ -154,7 +160,7 @@ public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool {
154160

155161
### 導入方法
156162

157-
このライブラリはCocoaPods・Carthage及び手動での追加に対応しています
163+
このライブラリはCocoaPods・Carthage・Swift Package Manager及び手動での追加に対応しています
158164

159165
##### CocoaPodsでの追加
160166

@@ -181,6 +187,11 @@ github "fumiyasac/handMadeCalendarAdvance"
181187

182188
参考:[Carthageを使った外部ライブラリ導入方法](http://swift.swift-studying.com/entry/2015/09/23/215356)
183189

190+
##### Swift Package Managerでの追加
191+
192+
お使いのXcodeで「File -> Swift Packages -> Add Package Dependency」と進み、後述するURLを入力してEnterキーを押下して下さい。
193+
https://github.com/fumiyasac/handMadeCalendarAdvance
194+
184195
##### 手動での追加
185196

186197
また手動でライブラリファイルを追加する場合には、`CalculateCalendarLogic.swift`ファイルをご自身のプロジェクトに追加して下さい。
@@ -220,7 +231,7 @@ print("2016年1月1日:\(result)")
220231

221232
現行プログラムでCalculateCalendarLogic.swiftで考慮したテストケースは下記の通りです。
222233

223-
+ 今年(2016年)の祝祭日の判定が正しく行えていること
234+
+ 今年(2016年〜2022年)の祝祭日の判定が正しく行えていること
224235
+ ゴールデンウィークの判定が正しく行えていること(※サンプル:2017年/2019年/2021年)
225236
+ シルバーウィークの判定が正しく行えていること(※サンプル:2015年/2026年/2032年)
226237
+ 春分の日・秋分の日の判定が正しく行えていること(※サンプル:2000年〜2030年)
@@ -235,7 +246,9 @@ print("2016年1月1日:\(result)")
235246

236247
まだまだ甘い部分があるかもしれませんが、その際はPullRequest等を送っていただければ幸いです。アプリ開発の中でこのサンプルが少しでもお役にたつ事ができれば嬉しい限りです。
237248

249+
+ 2019.12.02: Xcode12.2への対応/2021年の祝日に関する追加対応/サンプルコード修正等を行いました。
238250
+ 2019.06.26: Swift5.0及びXcode10.2.1への対応を行いました。
251+
+ 2019.01.23: 2019年の祝日に関する追加対応を行いました([kazuomatz](https://github.com/kazuomatz)様)。
239252
+ 2018.12.02: Swift4.2及びXcode10への対応を行いました。
240253
+ 2018.08.08: 2020年のカレンダーへの対応を行いました([myammm](https://github.com/myammm)様)。
241254
+ 2018.07.04: Swift4.1及びXCode9.4への対応を行いました([essochi](https://github.com/essochi)様)。
@@ -251,5 +264,5 @@ print("2016年1月1日:\(result)")
251264

252265
### 謝辞
253266

254-
このライブラリの作成にあたり[akio0911](https://github.com/akio0911)さん、[akuraru](https://github.com/akuraru)さん、[keygx](https://github.com/keygx)さん、+ [econa77](https://twitter.com/econa77)さんに多くのお力添えを頂きまして誠にありがとうございました。
267+
このライブラリの作成にあたり[akio0911](https://github.com/akio0911)さん、[akuraru](https://github.com/akuraru)さん、[keygx](https://github.com/keygx)さん、[econa77](https://twitter.com/econa77)さん、[kazuomatz](https://github.com/kazuomatz)さんに多くのお力添えを頂きまして誠にありがとうございました。
255268
また、プルリクエスト等を定期的に頂けることで本当に助かっております。

handMadeCalendarAdvance.xcodeproj/project.pbxproj

+23-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
DE7397041CCB4EC100A9A222 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DE7397021CCB4EC100A9A222 /* LaunchScreen.storyboard */; };
1919
DE73970F1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE73970E1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests.swift */; };
2020
DE73971A1CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE7397191CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift */; };
21+
DEE369B4257C8A1600A22800 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEE369B3257C8A1600A22800 /* MainViewController.swift */; };
22+
DEE369C3257C8E5A00A22800 /* DatePickerCalendarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEE369C2257C8E5A00A22800 /* DatePickerCalendarViewController.swift */; };
23+
DEE369D1257CCD3400A22800 /* DisplayDateTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEE369D0257CCD3400A22800 /* DisplayDateTextField.swift */; };
2124
E517AF4D1CE0F63C006847A0 /* CalculateCalendarLogic.h in Headers */ = {isa = PBXBuildFile; fileRef = E517AF4C1CE0F63C006847A0 /* CalculateCalendarLogic.h */; settings = {ATTRIBUTES = (Public, ); }; };
2225
E517AF541CE0F63C006847A0 /* CalculateCalendarLogic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */; };
2326
E517AF5B1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */; };
@@ -102,6 +105,9 @@
102105
DE7397151CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = handMadeCalendarAdvanceUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
103106
DE7397191CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = handMadeCalendarAdvanceUITests.swift; sourceTree = "<group>"; };
104107
DE73971B1CCB4EC100A9A222 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
108+
DEE369B3257C8A1600A22800 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
109+
DEE369C2257C8E5A00A22800 /* DatePickerCalendarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerCalendarViewController.swift; sourceTree = "<group>"; };
110+
DEE369D0257CCD3400A22800 /* DisplayDateTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayDateTextField.swift; sourceTree = "<group>"; };
105111
E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CalculateCalendarLogic.framework; sourceTree = BUILT_PRODUCTS_DIR; };
106112
E517AF4C1CE0F63C006847A0 /* CalculateCalendarLogic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CalculateCalendarLogic.h; sourceTree = "<group>"; };
107113
E517AF4E1CE0F63C006847A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -171,6 +177,7 @@
171177
isa = PBXGroup;
172178
children = (
173179
DE0166BB1CDE5892002BB133 /* CalendarCell.swift */,
180+
DEE369D0257CCD3400A22800 /* DisplayDateTextField.swift */,
174181
);
175182
name = Component;
176183
sourceTree = "<group>";
@@ -205,8 +212,8 @@
205212
isa = PBXGroup;
206213
children = (
207214
DE0166BA1CDE40DC002BB133 /* Component */,
215+
DEE369BB257C8B5600A22800 /* ViewController */,
208216
DE7396F91CCB4EC100A9A222 /* AppDelegate.swift */,
209-
DE7396FB1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift */,
210217
DE7396FD1CCB4EC100A9A222 /* Main.storyboard */,
211218
DE7397001CCB4EC100A9A222 /* Assets.xcassets */,
212219
DE7397021CCB4EC100A9A222 /* LaunchScreen.storyboard */,
@@ -233,6 +240,16 @@
233240
path = handMadeCalendarAdvanceUITests;
234241
sourceTree = "<group>";
235242
};
243+
DEE369BB257C8B5600A22800 /* ViewController */ = {
244+
isa = PBXGroup;
245+
children = (
246+
DEE369B3257C8A1600A22800 /* MainViewController.swift */,
247+
DE7396FB1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift */,
248+
DEE369C2257C8E5A00A22800 /* DatePickerCalendarViewController.swift */,
249+
);
250+
name = ViewController;
251+
sourceTree = "<group>";
252+
};
236253
E517AF4B1CE0F63C006847A0 /* CalculateCalendarLogic */ = {
237254
isa = PBXGroup;
238255
children = (
@@ -587,9 +604,12 @@
587604
isa = PBXSourcesBuildPhase;
588605
buildActionMask = 2147483647;
589606
files = (
607+
DEE369D1257CCD3400A22800 /* DisplayDateTextField.swift in Sources */,
608+
DEE369C3257C8E5A00A22800 /* DatePickerCalendarViewController.swift in Sources */,
590609
DE7396FC1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift in Sources */,
591610
DE7396FA1CCB4EC100A9A222 /* AppDelegate.swift in Sources */,
592611
DE0166BC1CDE5892002BB133 /* CalendarCell.swift in Sources */,
612+
DEE369B4257C8A1600A22800 /* MainViewController.swift in Sources */,
593613
);
594614
runOnlyForDeploymentPostprocessing = 0;
595615
};
@@ -703,7 +723,7 @@
703723
SDKROOT = macosx;
704724
SKIP_INSTALL = YES;
705725
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
706-
SWIFT_VERSION = 4.2;
726+
SWIFT_VERSION = 5.0;
707727
VERSIONING_SYSTEM = "apple-generic";
708728
VERSION_INFO_PREFIX = "";
709729
};
@@ -732,7 +752,7 @@
732752
SDKROOT = macosx;
733753
SKIP_INSTALL = YES;
734754
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
735-
SWIFT_VERSION = 4.2;
755+
SWIFT_VERSION = 5.0;
736756
VERSIONING_SYSTEM = "apple-generic";
737757
VERSION_INFO_PREFIX = "";
738758
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Bucket
3+
uuid = "E9FE371E-F5FD-4AC0-947E-3E32C1A3FDD7"
34
type = "1"
45
version = "2.0">
56
</Bucket>

0 commit comments

Comments
 (0)