diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 482d4e0..bb3290e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: CI on: [push, pull_request] env: - DEVELOPER_DIR: /Applications/Xcode_12.4.app + DEVELOPER_DIR: /Applications/Xcode_14.1.app jobs: build: diff --git a/CalculateCalendarLogic.podspec b/CalculateCalendarLogic.podspec index d5604b7..33b69e0 100644 --- a/CalculateCalendarLogic.podspec +++ b/CalculateCalendarLogic.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "CalculateCalendarLogic" s.swift_versions = '5.0' - s.version = "0.5.0" + s.version = "0.6.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. @@ -11,12 +11,12 @@ Pod::Spec.new do |s| s.homepage = "http://qiita.com/fumiyasac@github/items/33bfc07ad36dfffcdf8f" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Fumiya Sakai" => "fumiya.def.mathmatica@gmail.com" } - s.platform = :ios, '9.0' + s.platform = :ios, '13.0' s.source = { :git => "https://github.com/fumiyasac/handMadeCalendarAdvance.git", :tag => "#{s.version}" } s.social_media_url = "https://twitter.com/fumiyasac" s.source_files = "CalculateCalendarLogic/*.swift" s.exclude_files = "CalculateCalendarLogic/*.plist" s.requires_arc = true - s.ios.deployment_target = '9.0' - s.osx.deployment_target = '10.10' + s.ios.deployment_target = '13.0' + s.osx.deployment_target = '11.0' end diff --git a/Gemfile.lock b/Gemfile.lock index bbe324b..b0c0f53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,19 +1,20 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.0) - activesupport (4.2.11) + CFPropertyList (3.0.5) + 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) - claide (1.0.2) - cocoapods (1.6.0.beta.2) + claide (1.1.0) + cocoapods (1.7.2) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.6.0.beta.2) - cocoapods-deintegrate (>= 1.0.2, < 2.0) + cocoapods-core (= 1.7.2) + cocoapods-deintegrate (>= 1.0.3, < 2.0) cocoapods-downloader (>= 1.2.2, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) @@ -22,55 +23,57 @@ GEM cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 2.0.1) + fourflusher (>= 2.3.0, < 3.0) gh_inspector (~> 1.0) molinillo (~> 0.6.6) nap (~> 1.0) - ruby-macho (~> 1.3, >= 1.3.1) - xcodeproj (>= 1.7.0, < 2.0) - cocoapods-core (1.6.0.beta.2) + ruby-macho (~> 1.4) + xcodeproj (>= 1.10.0, < 2.0) + cocoapods-core (1.7.2) activesupport (>= 4.0.2, < 6) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.2) - cocoapods-downloader (1.2.2) + cocoapods-deintegrate (1.0.5) + cocoapods-downloader (1.6.3) cocoapods-plugins (1.0.0) nap - cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.3.1) + cocoapods-search (1.0.1) + cocoapods-stats (1.1.0) + cocoapods-trunk (1.6.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) - cocoapods-try (1.1.0) + cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.4) + concurrent-ruby (1.1.10) escape (0.0.4) - fourflusher (2.0.1) + fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) i18n (0.9.5) concurrent-ruby (~> 1.0) - minitest (5.11.3) + minitest (5.16.3) molinillo (0.6.6) - nanaimo (0.2.6) + nanaimo (0.3.0) nap (1.1.0) netrc (0.11.0) - ruby-macho (1.3.1) + rexml (3.2.5) + ruby-macho (1.4.0) thread_safe (0.3.6) - tzinfo (1.2.5) + tzinfo (1.2.10) thread_safe (~> 0.1) - xcodeproj (1.7.0) + xcodeproj (1.22.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.6) + nanaimo (~> 0.3.0) + rexml (~> 3.2.4) PLATFORMS ruby DEPENDENCIES - cocoapods (= 1.6.0.beta.2) + cocoapods (= 1.7.2) BUNDLED WITH - 1.13.7 + 1.17.2 diff --git a/README.md b/README.md index 44d20f1..52941ec 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool { ### Requirements & Support -+ iOS 9 or later -+ macOS 10.10 or later ++ iOS 13.0 or later ++ macOS 11.0 or later ### Installation @@ -43,7 +43,7 @@ Create Podfile and specify it in your Podfile: ★ Example of Podfile ``` -platform :ios, '9.0' +platform :ios, '13.0' use_frameworks! target [YOUR PROJECT NAME]' do pod 'CalculateCalendarLogic' @@ -156,8 +156,8 @@ public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool { ### 対応バージョンとサポート -+ iOS 9 or later -+ macOS 10.10 or later ++ iOS 13.0 or later ++ macOS 11.0 or later ### 導入方法 @@ -247,6 +247,7 @@ print("2016年1月1日:\(result)") まだまだ甘い部分があるかもしれませんが、その際はPullRequest等を送っていただければ幸いです。アプリ開発の中でこのサンプルが少しでもお役にたつ事ができれば嬉しい限りです。 ++ 2023.01.01: 保守対応&iOS16で利用可能なUICalendarViewのサンプル追加を行いました。 + 2021.06.05: Gihub Actions追加([uhooi](https://github.com/uhooi)様) + 2020.12.02: Xcode12.2への対応/2021年の祝日に関する追加対応/サンプルコード修正等を行いました。 + 2019.06.26: Swift5.0及びXcode10.2.1への対応を行いました。 diff --git a/Tests/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift b/Tests/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift index 7cdc068..681cde8 100644 --- a/Tests/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift +++ b/Tests/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift @@ -427,6 +427,58 @@ class CalculateCalendarLogicTests: XCTestCase { // 勤労感謝の日: 2022年11月23日(水曜日) (2022, 11, 23, true), + + // 2023年 + // 元日: 2023年1月1日(日曜日) + (2023, 1, 1, true), + + // 振替休日: 2023年1月2日(月曜日) + (2023, 1, 2, true), + + // 成人の日: 2023年1月9日(月曜日) + (2023, 1, 9, true), + + // 建国記念の日: 2023年2月11日(土曜日) + (2023, 2, 11, true), + + // 天皇誕生日: 2023年2月23日(木曜日) + (2023, 2, 23, true), + + // 春分の日: 2023年3月21日(火曜日) + (2023, 3, 21, true), + + // 昭和の日: 2023年4月29日(土曜日) + (2023, 4, 29, true), + + // 憲法記念日: 2023年5月3日(水曜日) + (2023, 5, 3, true), + + // みどりの日: 2023年5月4日(木曜日) + (2023, 5, 4, true), + + // こどもの日: 2023年5月5日(金曜日) + (2023, 5, 5, true), + + // 海の日: 2023年7月17日(月曜日) + (2023, 7, 17, true), + + // 山の日: 2023年8月11日(金曜日) + (2023, 8, 11, true), + + // 敬老の日: 2023年9月18日(月曜日) + (2023, 9, 18, true), + + // 秋分の日: 2023年9月23日(土曜日) + (2023, 9, 23, true), + + // スポーツの日: 2023年10月9日(月曜日) + (2023, 10, 9, true), + + // 文化の日: 2023年11月3日(金曜日) + (2023, 11, 3, true), + + // 勤労感謝の日: 2023年11月23日(木曜日) + (2023, 11, 23, true), ] testCases.forEach { (arg) in diff --git a/handMadeCalendarAdvance.xcodeproj/project.pbxproj b/handMadeCalendarAdvance.xcodeproj/project.pbxproj index 9b75c28..165d0d2 100644 --- a/handMadeCalendarAdvance.xcodeproj/project.pbxproj +++ b/handMadeCalendarAdvance.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 31889D151E29F3B600DFD4CB /* CalculateCalendarLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = E517AF681CE0F669006847A0 /* CalculateCalendarLogic.swift */; }; 31889D161E29F3BC00DFD4CB /* CalculateCalendarLogicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */; }; DE0166BC1CDE5892002BB133 /* CalendarCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0166BB1CDE5892002BB133 /* CalendarCell.swift */; }; + DE03CFF329608C650054BCF1 /* NewCalendarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE03CFF229608C650054BCF1 /* NewCalendarViewController.swift */; }; DE7396FA1CCB4EC100A9A222 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE7396F91CCB4EC100A9A222 /* AppDelegate.swift */; }; DE7396FC1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE7396FB1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift */; }; DE7396FF1CCB4EC100A9A222 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DE7396FD1CCB4EC100A9A222 /* Main.storyboard */; }; @@ -92,6 +93,7 @@ 31889CFE1E29F37F00DFD4CB /* CalculateCalendarLogic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CalculateCalendarLogic.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 31889D061E29F37F00DFD4CB /* CalculateCalendarLogic OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "CalculateCalendarLogic OSXTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; DE0166BB1CDE5892002BB133 /* CalendarCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarCell.swift; sourceTree = ""; }; + DE03CFF229608C650054BCF1 /* NewCalendarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewCalendarViewController.swift; sourceTree = ""; }; DE7396F61CCB4EC100A9A222 /* handMadeCalendarAdvance.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = handMadeCalendarAdvance.app; sourceTree = BUILT_PRODUCTS_DIR; }; DE7396F91CCB4EC100A9A222 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DE7396FB1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthlyCalendarViewController.swift; sourceTree = ""; }; @@ -246,6 +248,7 @@ DEE369B3257C8A1600A22800 /* MainViewController.swift */, DE7396FB1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift */, DEE369C2257C8E5A00A22800 /* DatePickerCalendarViewController.swift */, + DE03CFF229608C650054BCF1 /* NewCalendarViewController.swift */, ); name = ViewController; sourceTree = ""; @@ -266,7 +269,8 @@ E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */, E517AF5C1CE0F63C006847A0 /* Info.plist */, ); - path = CalculateCalendarLogicTests; + name = CalculateCalendarLogicTests; + path = Tests/CalculateCalendarLogicTests; sourceTree = ""; }; /* End PBXGroup section */ @@ -606,6 +610,7 @@ files = ( DEE369D1257CCD3400A22800 /* DisplayDateTextField.swift in Sources */, DEE369C3257C8E5A00A22800 /* DatePickerCalendarViewController.swift in Sources */, + DE03CFF329608C650054BCF1 /* NewCalendarViewController.swift in Sources */, DE7396FC1CCB4EC100A9A222 /* MonthlyCalendarViewController.swift in Sources */, DE7396FA1CCB4EC100A9A222 /* AppDelegate.swift in Sources */, DE0166BC1CDE5892002BB133 /* CalendarCell.swift in Sources */, @@ -767,9 +772,9 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + INFOPLIST_FILE = Tests/CalculateCalendarLogicTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSXTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -787,9 +792,9 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + INFOPLIST_FILE = Tests/CalculateCalendarLogicTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "net.just1factory.CalculateCalendarLogic-OSXTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -939,6 +944,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; INFOPLIST_FILE = handMadeCalendarAdvanceTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvanceTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -952,6 +958,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; INFOPLIST_FILE = handMadeCalendarAdvanceTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvanceTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1036,7 +1043,8 @@ E517AF631CE0F63D006847A0 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + INFOPLIST_FILE = Tests/CalculateCalendarLogicTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogicTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1048,7 +1056,8 @@ E517AF641CE0F63D006847A0 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + INFOPLIST_FILE = Tests/CalculateCalendarLogicTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogicTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/handMadeCalendarAdvance.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/handMadeCalendarAdvance.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 020c963..e83e691 100644 --- a/handMadeCalendarAdvance.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/handMadeCalendarAdvance.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:../Tests/CalculateCalendarLogicTests"> diff --git a/handMadeCalendarAdvance/Base.lproj/Main.storyboard b/handMadeCalendarAdvance/Base.lproj/Main.storyboard index 9fd98d9..30e7850 100644 --- a/handMadeCalendarAdvance/Base.lproj/Main.storyboard +++ b/handMadeCalendarAdvance/Base.lproj/Main.storyboard @@ -1,13 +1,32 @@ - + - + + + + + + + + + + + + + + + + + + + + @@ -155,7 +174,7 @@ + - + + + + diff --git a/handMadeCalendarAdvance/NewCalendarViewController.swift b/handMadeCalendarAdvance/NewCalendarViewController.swift new file mode 100644 index 0000000..461da11 --- /dev/null +++ b/handMadeCalendarAdvance/NewCalendarViewController.swift @@ -0,0 +1,77 @@ +// +// NewCalendarViewController.swift +// handMadeCalendarAdvance +// +// Created by 酒井文也 on 2023/01/01. +// Copyright © 2023 just1factory. All rights reserved. +// + +import UIKit +import CalculateCalendarLogic + +class NewCalendarViewController: UIViewController { + + // 日本の祝祭日判定用のインスタンス + private let holidayObject: CalculateCalendarLogic = CalculateCalendarLogic() + + override func viewDidLoad() { + super.viewDidLoad() + setupCalendarView() + } + + // CalendarViewのセットアップ + // ※現時点(Xcode14.1)ではまだStoryboardから追加できない... + private func setupCalendarView() { + if #available(iOS 16.0, *) { + let calendarView = UICalendarView() + calendarView.calendar = Calendar(identifier: .gregorian) + calendarView.locale = Locale(identifier: "ja") + calendarView.delegate = self + + view.addSubview(calendarView) + calendarView.translatesAutoresizingMaskIntoConstraints = false + calendarView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true + calendarView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true + calendarView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true + calendarView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true + } else { + let title = "バージョンがiOS15以下です" + let message = "iOS16以前ではCalendarViewを表示することができません。" + let completionHandler: (() -> ())? = { + self.navigationController?.popViewController(animated: true) + } + showCloseAlertWith(title: title, message: message, completionHandler: completionHandler) + } + } + + private func showCloseAlertWith(title: String, message: String, completionHandler: (() -> ())? = nil) { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + let okAction = UIAlertAction(title: "前の画面へ戻る", style: .default, handler: { _ in + completionHandler?() + }) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } +} + +// MARK: - UICalendarViewDelegate + +extension NewCalendarViewController: UICalendarViewDelegate { + + // CalendarViewに適用する装飾を決定する + // 👉 このコードでは祝祭日の部分にオレンジの🗓マークを付与する + // 参考: https://www.fuwamaki.com/article/353 + @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 { + return nil + } + if holidayObject.judgeJapaneseHoliday(year: targetYear, month: targetMonth, day: targetDay) { + return .image(UIImage(systemName: "calendar"), color: .orange, size: .medium) + } else { + return nil + } + } +}