Skip to content

Commit

Permalink
Merge pull request #41 from fumiyasac/feature/2024-update-library
Browse files Browse the repository at this point in the history
2024年のライブラリ保守対応
  • Loading branch information
fumiyasac authored Apr 29, 2024
2 parents 8ac9f68 + 18fdd42 commit 74a1733
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]

env:
DEVELOPER_DIR: /Applications/Xcode_14.1.app
DEVELOPER_DIR: /Applications/Xcode_15.3.app

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions CalculateCalendarLogic.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "CalculateCalendarLogic"
s.swift_versions = '5.0'
s.version = "0.6.1"
s.swift_versions = '5.7'
s.version = "0.7.0"
s.summary = "This library CalculateCalendarLogic (sample project name is handMadeCalendarAdvance) can judge a holiday in Japan."
s.description = <<-DESC
This library 'CalculateCalendarLogic' can judge a holiday in Japan.
Expand Down
16 changes: 10 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.5)
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (4.2.11.3)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.3)
base64 (0.2.0)
claide (1.1.0)
cocoapods (1.7.2)
activesupport (>= 4.0.2, < 5)
Expand Down Expand Up @@ -44,24 +47,25 @@ GEM
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.3)
escape (0.0.4)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
minitest (5.16.3)
minitest (5.22.3)
molinillo (0.6.6)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
rexml (3.2.5)
nkf (0.2.0)
rexml (3.2.6)
ruby-macho (1.4.0)
thread_safe (0.3.6)
tzinfo (1.2.10)
tzinfo (1.2.11)
thread_safe (~> 0.1)
xcodeproj (1.22.0)
xcodeproj (1.24.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,70 @@ class CalculateCalendarLogicTests: XCTestCase {

// 勤労感謝の日: 2023年11月23日(木曜日)
(2023, 11, 23, true),

// 2024年
// 元日: 2024年1月1日(月曜日)
(2024, 1, 1, true),

// 成人の日: 2024年1月8日(月曜日)
(2024, 1, 8, true),

// 建国記念の日: 2024年2月11日(日曜日)
(2024, 2, 11, true),

// 振替休日: 2024年2月12日(月曜日)
(2024, 2, 12, true),

// 天皇誕生日: 2024年2月23日(金曜日)
(2024, 2, 23, true),

// 春分の日: 2024年3月20日(水曜日)
(2024, 3, 20, true),

// 昭和の日: 2024年4月29日(月曜日)
(2024, 4, 29, true),

// 憲法記念日: 2024年5月3日(金曜日)
(2024, 5, 3, true),

// みどりの日: 2024年5月4日(土曜日)
(2024, 5, 4, true),

// こどもの日: 2024年5月5日(日曜日)
(2024, 5, 5, true),

// こどもの日: 2024年5月6日(月曜日)
(2024, 5, 6, true),

// 海の日: 2024年7月15日(月曜日)
(2024, 7, 15, true),

// 山の日: 2024年8月11日(日曜日)
(2024, 8, 11, true),

// 振替休日: 2024年8月12日(月曜日)
(2024, 8, 12, true),

// 敬老の日: 2024年9月16日(月曜日)
(2024, 9, 16, true),

// 秋分の日: 2024年9月22日(日曜日)
(2024, 9, 22, true),

// 振替休日: 2024年9月23日(月曜日)
(2024, 9, 23, true),

// スポーツの日: 2023年10月14日(月曜日)
(2024, 10, 14, true),

// 文化の日: 2024年11月3日(日曜日)
(2024, 11, 3, true),

// 振替休日: 2024年11月4日(月曜日)
(2024, 11, 4, true),

// 勤労感謝の日: 2023年11月23日(土曜日)
(2024, 11, 23, true),
]
testCases.forEach { (arg) in

Expand Down
10 changes: 6 additions & 4 deletions handMadeCalendarAdvance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSX";
PRODUCT_NAME = CalculateCalendarLogic;
SDKROOT = macosx;
Expand Down Expand Up @@ -751,7 +751,7 @@
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSX";
PRODUCT_NAME = CalculateCalendarLogic;
SDKROOT = macosx;
Expand Down Expand Up @@ -918,6 +918,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = S5BF5553KY;
INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -932,6 +933,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = S5BF5553KY;
INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1003,7 +1005,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1028,7 +1030,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = CalculateCalendarLogic/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
74 changes: 69 additions & 5 deletions handMadeCalendarAdvance/NewCalendarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ class NewCalendarViewController: UIViewController {
// 日本の祝祭日判定用のインスタンス
private let holidayObject: CalculateCalendarLogic = CalculateCalendarLogic()

private var stringDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ja_JP")
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy/MM/dd"
return dateFormatter
}()

private var currentCalendar: Calendar = {
var calendar = Calendar.current
calendar.locale = Locale(identifier: "ja_JP")
calendar.timeZone = TimeZone.current
return calendar
}()

override func viewDidLoad() {
super.viewDidLoad()
setupCalendarView()
Expand All @@ -25,9 +40,13 @@ class NewCalendarViewController: UIViewController {
if #available(iOS 16.0, *) {
let calendarView = UICalendarView()
calendarView.calendar = Calendar(identifier: .gregorian)
calendarView.locale = Locale(identifier: "ja")
calendarView.locale = Locale(identifier: "ja_JP")
calendarView.delegate = self

// 例. 任意の日付を1つ選択可能にする
// 補足: 複数日付を選択する場合はこちらをする
// https://developer.apple.com/documentation/uikit/uicalendarselectionmultidate
let dateSelection = UICalendarSelectionSingleDate(delegate: self)
calendarView.selectionBehavior = dateSelection
view.addSubview(calendarView)
calendarView.translatesAutoresizingMaskIntoConstraints = false
calendarView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
Expand Down Expand Up @@ -64,14 +83,59 @@ extension NewCalendarViewController: UICalendarViewDelegate {
@available(iOS 16.0, *)
func calendarView(_ calendarView: UICalendarView, decorationFor dateComponents: DateComponents) -> UICalendarView.Decoration? {
guard let targetYear = dateComponents.year,
let targetMonth = dateComponents.month,
let targetDay = dateComponents.day else {
let targetMonth = dateComponents.month,
let targetDay = dateComponents.day else {
return nil
}
if holidayObject.judgeJapaneseHoliday(year: targetYear, month: targetMonth, day: targetDay) {

// 注意: weekdayプロパティはUICalendarViewDelegateまで常にnilになる...
// print("dateComponents.weekday", dateComponents.weekday)

let weekday = getWeekDay(year: targetYear, month: targetMonth, day: targetDay)
let isHoliday = holidayObject.judgeJapaneseHoliday(year: targetYear, month: targetMonth, day: targetDay)

if isHoliday {
return .image(UIImage(systemName: "flag.2.crossed.fill"), color: .orange, size: .medium)
} else if weekday == 1 {
return .default(color: .red, size: .small)
} else if weekday == 7 {
return .default(color: .blue, size: .small)
} else {
return nil
}
}

// 年・月・日から曜日(日曜日:1 ~ 土曜日:7)を取得する
private func getWeekDay(year: Int, month: Int, day: Int) -> Int {
let formatString = "%04d/%02d/%02d"
guard let date: Date = stringDateFormatter.date(from: String(format: formatString, year, month, day)) else {
return 0
}
return currentCalendar.component(.weekday, from: date)
}
}

// MARK: - UICalendarSelectionSingleDateDelegate

extension NewCalendarViewController: UICalendarSelectionSingleDateDelegate {

// 日付を選択したタイミングで選択した日付情報を返す
@available(iOS 16.0, *)
func dateSelection(_ selection: UICalendarSelectionSingleDate, didSelectDate dateComponents: DateComponents?) {
guard let targetDateComponents = dateComponents else {
return
}
guard let targetYear = targetDateComponents.year,
let targetMonth = targetDateComponents.month,
let targetDay = targetDateComponents.day else {
return
}
print("あなたが選択した日付:", "\(targetYear)\(targetMonth)\(targetDay)")
}

// 日付を選択可能な状態とするかを設定する
@available(iOS 16.0, *)
func dateSelection(_ selection: UICalendarSelectionSingleDate, canSelectDate dateComponents: DateComponents?) -> Bool {
return true
}
}

0 comments on commit 74a1733

Please sign in to comment.