Skip to content

Commit 74a1733

Browse files
authored
Merge pull request #41 from fumiyasac/feature/2024-update-library
2024年のライブラリ保守対応
2 parents 8ac9f68 + 18fdd42 commit 74a1733

File tree

6 files changed

+152
-18
lines changed

6 files changed

+152
-18
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on: [push, pull_request]
44

55
env:
6-
DEVELOPER_DIR: /Applications/Xcode_14.1.app
6+
DEVELOPER_DIR: /Applications/Xcode_15.3.app
77

88
jobs:
99
build:

CalculateCalendarLogic.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "CalculateCalendarLogic"
3-
s.swift_versions = '5.0'
4-
s.version = "0.6.1"
3+
s.swift_versions = '5.7'
4+
s.version = "0.7.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.

Gemfile.lock

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
CFPropertyList (3.0.5)
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
57
rexml
68
activesupport (4.2.11.3)
79
i18n (~> 0.7)
810
minitest (~> 5.1)
911
thread_safe (~> 0.3, >= 0.3.4)
1012
tzinfo (~> 1.1)
1113
atomos (0.1.3)
14+
base64 (0.2.0)
1215
claide (1.1.0)
1316
cocoapods (1.7.2)
1417
activesupport (>= 4.0.2, < 5)
@@ -44,24 +47,25 @@ GEM
4447
netrc (~> 0.11)
4548
cocoapods-try (1.2.0)
4649
colored2 (3.1.2)
47-
concurrent-ruby (1.1.10)
50+
concurrent-ruby (1.2.3)
4851
escape (0.0.4)
4952
fourflusher (2.3.1)
5053
fuzzy_match (2.0.4)
5154
gh_inspector (1.1.3)
5255
i18n (0.9.5)
5356
concurrent-ruby (~> 1.0)
54-
minitest (5.16.3)
57+
minitest (5.22.3)
5558
molinillo (0.6.6)
5659
nanaimo (0.3.0)
5760
nap (1.1.0)
5861
netrc (0.11.0)
59-
rexml (3.2.5)
62+
nkf (0.2.0)
63+
rexml (3.2.6)
6064
ruby-macho (1.4.0)
6165
thread_safe (0.3.6)
62-
tzinfo (1.2.10)
66+
tzinfo (1.2.11)
6367
thread_safe (~> 0.1)
64-
xcodeproj (1.22.0)
68+
xcodeproj (1.24.0)
6569
CFPropertyList (>= 2.3.3, < 4.0)
6670
atomos (~> 0.1.3)
6771
claide (>= 1.0.2, < 2.0)

Tests/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift

+64
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,70 @@ class CalculateCalendarLogicTests: XCTestCase {
479479

480480
// 勤労感謝の日: 2023年11月23日(木曜日)
481481
(2023, 11, 23, true),
482+
483+
// 2024年
484+
// 元日: 2024年1月1日(月曜日)
485+
(2024, 1, 1, true),
486+
487+
// 成人の日: 2024年1月8日(月曜日)
488+
(2024, 1, 8, true),
489+
490+
// 建国記念の日: 2024年2月11日(日曜日)
491+
(2024, 2, 11, true),
492+
493+
// 振替休日: 2024年2月12日(月曜日)
494+
(2024, 2, 12, true),
495+
496+
// 天皇誕生日: 2024年2月23日(金曜日)
497+
(2024, 2, 23, true),
498+
499+
// 春分の日: 2024年3月20日(水曜日)
500+
(2024, 3, 20, true),
501+
502+
// 昭和の日: 2024年4月29日(月曜日)
503+
(2024, 4, 29, true),
504+
505+
// 憲法記念日: 2024年5月3日(金曜日)
506+
(2024, 5, 3, true),
507+
508+
// みどりの日: 2024年5月4日(土曜日)
509+
(2024, 5, 4, true),
510+
511+
// こどもの日: 2024年5月5日(日曜日)
512+
(2024, 5, 5, true),
513+
514+
// こどもの日: 2024年5月6日(月曜日)
515+
(2024, 5, 6, true),
516+
517+
// 海の日: 2024年7月15日(月曜日)
518+
(2024, 7, 15, true),
519+
520+
// 山の日: 2024年8月11日(日曜日)
521+
(2024, 8, 11, true),
522+
523+
// 振替休日: 2024年8月12日(月曜日)
524+
(2024, 8, 12, true),
525+
526+
// 敬老の日: 2024年9月16日(月曜日)
527+
(2024, 9, 16, true),
528+
529+
// 秋分の日: 2024年9月22日(日曜日)
530+
(2024, 9, 22, true),
531+
532+
// 振替休日: 2024年9月23日(月曜日)
533+
(2024, 9, 23, true),
534+
535+
// スポーツの日: 2023年10月14日(月曜日)
536+
(2024, 10, 14, true),
537+
538+
// 文化の日: 2024年11月3日(日曜日)
539+
(2024, 11, 3, true),
540+
541+
// 振替休日: 2024年11月4日(月曜日)
542+
(2024, 11, 4, true),
543+
544+
// 勤労感謝の日: 2023年11月23日(土曜日)
545+
(2024, 11, 23, true),
482546
]
483547
testCases.forEach { (arg) in
484548

handMadeCalendarAdvance.xcodeproj/project.pbxproj

+6-4
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@
722722
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
723723
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
724724
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
725-
MACOSX_DEPLOYMENT_TARGET = 10.10;
725+
MACOSX_DEPLOYMENT_TARGET = 10.15;
726726
PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSX";
727727
PRODUCT_NAME = CalculateCalendarLogic;
728728
SDKROOT = macosx;
@@ -751,7 +751,7 @@
751751
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
752752
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
753753
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
754-
MACOSX_DEPLOYMENT_TARGET = 10.10;
754+
MACOSX_DEPLOYMENT_TARGET = 10.15;
755755
PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSX";
756756
PRODUCT_NAME = CalculateCalendarLogic;
757757
SDKROOT = macosx;
@@ -918,6 +918,7 @@
918918
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
919919
DEVELOPMENT_TEAM = S5BF5553KY;
920920
INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist;
921+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
921922
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
922923
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance;
923924
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -932,6 +933,7 @@
932933
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
933934
DEVELOPMENT_TEAM = S5BF5553KY;
934935
INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist;
936+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
935937
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
936938
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance;
937939
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1003,7 +1005,7 @@
10031005
DYLIB_INSTALL_NAME_BASE = "@rpath";
10041006
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
10051007
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1006-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1008+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
10071009
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10081010
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic;
10091011
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1028,7 +1030,7 @@
10281030
DYLIB_INSTALL_NAME_BASE = "@rpath";
10291031
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
10301032
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1031-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1033+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
10321034
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10331035
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic;
10341036
PRODUCT_NAME = "$(TARGET_NAME)";

handMadeCalendarAdvance/NewCalendarViewController.swift

+69-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ class NewCalendarViewController: UIViewController {
1414
// 日本の祝祭日判定用のインスタンス
1515
private let holidayObject: CalculateCalendarLogic = CalculateCalendarLogic()
1616

17+
private var stringDateFormatter: DateFormatter = {
18+
let dateFormatter = DateFormatter()
19+
dateFormatter.locale = Locale(identifier: "ja_JP")
20+
dateFormatter.timeZone = TimeZone.current
21+
dateFormatter.dateFormat = "yyyy/MM/dd"
22+
return dateFormatter
23+
}()
24+
25+
private var currentCalendar: Calendar = {
26+
var calendar = Calendar.current
27+
calendar.locale = Locale(identifier: "ja_JP")
28+
calendar.timeZone = TimeZone.current
29+
return calendar
30+
}()
31+
1732
override func viewDidLoad() {
1833
super.viewDidLoad()
1934
setupCalendarView()
@@ -25,9 +40,13 @@ class NewCalendarViewController: UIViewController {
2540
if #available(iOS 16.0, *) {
2641
let calendarView = UICalendarView()
2742
calendarView.calendar = Calendar(identifier: .gregorian)
28-
calendarView.locale = Locale(identifier: "ja")
43+
calendarView.locale = Locale(identifier: "ja_JP")
2944
calendarView.delegate = self
30-
45+
// 例. 任意の日付を1つ選択可能にする
46+
// 補足: 複数日付を選択する場合はこちらをする
47+
// https://developer.apple.com/documentation/uikit/uicalendarselectionmultidate
48+
let dateSelection = UICalendarSelectionSingleDate(delegate: self)
49+
calendarView.selectionBehavior = dateSelection
3150
view.addSubview(calendarView)
3251
calendarView.translatesAutoresizingMaskIntoConstraints = false
3352
calendarView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
@@ -64,14 +83,59 @@ extension NewCalendarViewController: UICalendarViewDelegate {
6483
@available(iOS 16.0, *)
6584
func calendarView(_ calendarView: UICalendarView, decorationFor dateComponents: DateComponents) -> UICalendarView.Decoration? {
6685
guard let targetYear = dateComponents.year,
67-
let targetMonth = dateComponents.month,
68-
let targetDay = dateComponents.day else {
86+
let targetMonth = dateComponents.month,
87+
let targetDay = dateComponents.day else {
6988
return nil
7089
}
71-
if holidayObject.judgeJapaneseHoliday(year: targetYear, month: targetMonth, day: targetDay) {
90+
91+
// 注意: weekdayプロパティはUICalendarViewDelegateまで常にnilになる...
92+
// print("dateComponents.weekday", dateComponents.weekday)
93+
94+
let weekday = getWeekDay(year: targetYear, month: targetMonth, day: targetDay)
95+
let isHoliday = holidayObject.judgeJapaneseHoliday(year: targetYear, month: targetMonth, day: targetDay)
96+
97+
if isHoliday {
7298
return .image(UIImage(systemName: "flag.2.crossed.fill"), color: .orange, size: .medium)
99+
} else if weekday == 1 {
100+
return .default(color: .red, size: .small)
101+
} else if weekday == 7 {
102+
return .default(color: .blue, size: .small)
73103
} else {
74104
return nil
75105
}
76106
}
107+
108+
// 年・月・日から曜日(日曜日:1 ~ 土曜日:7)を取得する
109+
private func getWeekDay(year: Int, month: Int, day: Int) -> Int {
110+
let formatString = "%04d/%02d/%02d"
111+
guard let date: Date = stringDateFormatter.date(from: String(format: formatString, year, month, day)) else {
112+
return 0
113+
}
114+
return currentCalendar.component(.weekday, from: date)
115+
}
116+
}
117+
118+
// MARK: - UICalendarSelectionSingleDateDelegate
119+
120+
extension NewCalendarViewController: UICalendarSelectionSingleDateDelegate {
121+
122+
// 日付を選択したタイミングで選択した日付情報を返す
123+
@available(iOS 16.0, *)
124+
func dateSelection(_ selection: UICalendarSelectionSingleDate, didSelectDate dateComponents: DateComponents?) {
125+
guard let targetDateComponents = dateComponents else {
126+
return
127+
}
128+
guard let targetYear = targetDateComponents.year,
129+
let targetMonth = targetDateComponents.month,
130+
let targetDay = targetDateComponents.day else {
131+
return
132+
}
133+
print("あなたが選択した日付:", "\(targetYear)\(targetMonth)\(targetDay)")
134+
}
135+
136+
// 日付を選択可能な状態とするかを設定する
137+
@available(iOS 16.0, *)
138+
func dateSelection(_ selection: UICalendarSelectionSingleDate, canSelectDate dateComponents: DateComponents?) -> Bool {
139+
return true
140+
}
77141
}

0 commit comments

Comments
 (0)