GithubHelp home page GithubHelp logo

myammm / handmadecalendaradvance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fumiyasac/handmadecalendaradvance

0.0 1.0 0.0 574 KB

[ING]Swift版の日本の祝祭日判定コードとカレンダーサンプル(iOS Sample Study: Swift)

License: MIT License

Ruby 1.84% Objective-C 0.83% Swift 97.34%

handmadecalendaradvance's Introduction

handMadeCalendarAdvance(CalculateCalendarLogic)

This library CalculateCalendarLogic (sample project name is handMadeCalendarAdvance) can judge a holiday in Japan.

Description

This library 'CalculateCalendarLogic' can judge a holiday in Japan. When you use this library, you can judge can judge a holiday in Japan very easily. A method which named 'judgeJapaneseHoliday' method stores variables year, month, and day in an argument, it returns true or false.

About CalculateCalendarLogic.swift

/* CalculateCalendarLogic.swift */

public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool {

    /**
     *
     * - Description judge japanese holiday
     * - parameter year: year value (Int)
     * - parameter month: month value (Int)
     * - parameter day: day value (Int)
     * - returns: result (Bool)
     */

     // judge holiday logic...
}

Requirements & Support

  • iOS8~10 or later
  • macOS 10.10 or later

Installation

We can use this library with CocoaPods, Carthage, Manually.

Use CocoaPods

Create Podfile and specify it in your Podfile:

★ Example of Podfile

platform :ios, '8.0'
use_frameworks!
target [YOUR PROJECT NAME]' do
  pod 'CalculateCalendarLogic'
end
Use Carthage

Create Carthage and specify it in your Cartfile:

★ Cartfile

github "fumiyasac/handMadeCalendarAdvance"
Manually

Copy all the files in CalculateCalendarLogic/CalculateCalendarLogic.swift file into your project.

Author

fumiyasac(Fumiya Sakai)

Example

It's as below.

/* ViewController.swift */

// Step1: import CalculateCalendarLogic (If you install manually, you don't need import statement.)
import CalculateCalendarLogic

// Step2: create instance of CalculateCalendarLogic
let holiday = CalculateCalendarLogic()
...

// Step3: input year, month and day values into judgeJapaneseHoliday method.
let result: Bool = holiday.judgeJapaneseHoliday(year: 2016, month: 1, day: 1)

// Result:
print("2016 January 1:\(result)")

//You will display「2016 January 1:true」in your Xcode console.

License

MIT

Contributor

Special Thanks to

and more iOS developers.

handMadeCalendarAdvance(CalculateCalendarLogic)

Swift版の日本の祝祭日判定コードとカレンダーライブラリとサンプル

サンプル表示例

日本の祝祭日の判定ロジックとそのロジックを活用したカレンダーサンプルの例になります。 (※ 計算ロジックの実態部分はCalculateCalendarLogic.swiftを参照)

概要

日本の祝祭日(振替休日)を判定する構造体を作成しました。 使い方に関してはCalculateCalendarLogic.swiftをお使いのプロジェクトにコピーし、下記の「使い方」を参考に記述をして頂くとご利用になれます。 その他のカレンダーアプリを作成する際やお使いのアプリでご活用して頂ければ幸いです。

このライブラリの内部仕様について

下記のようにjudgeJapaneseHolidayメソッドに年・月・日を引数として渡すことでその日が祝祭日(振替休日)であるかを判定します。 戻り値はBool型で返却して判定できるようにしています。

/* CalculateCalendarLogic.swift */

public func judgeJapaneseHoliday(year: Int, month: Int, day: Int) -> Bool {

    /**
     *
     * 祝日になる日を判定する
     * (引数) year: Int, month: Int, day: Int
     * weekdayIndexはWeekdayのenumに該当する値(0...6)が入る
     * 参考資料1. カレンダーロジックの参考                      :http://p-ho.net/index.php?page=22
     * 参考資料2. 書き方(タプル)の参考                        :http://blog.kitoko552.com/entry/2015/06/17/213553
     * 参考資料3. [Swift] 関数における引数/戻り値とタプルの関係 :http://dev.classmethod.jp/smartphone/swift-function-tupsle/
     *
     */

     // 実装は実際のクラスを参照して頂ければ幸いです。
}

対応バージョンとサポート

  • iOS 8~10 or later
  • macOS 10.10 or later

導入方法

このライブラリはCocoaPods・Carthage及び手動での追加に対応しています。

CocoaPodsでの追加

プロジェクト内にPodfileを作成し下記のように記述をして下さい。

★ Podfileの記述例

target '[自分のプロジェクト名]' do
  use_frameworks!
  pod 'CalculateCalendarLogic'
end
Carthageでの追加

プロジェクト内にCartfileを作成し下記のように記述をして下さい。

★ Cartfileの記述

github "fumiyasac/handMadeCalendarAdvance"

参考:Carthageを使った外部ライブラリ導入方法

手動での追加

また手動でライブラリファイルを追加する場合には、CalculateCalendarLogic.swiftファイルをご自身のプロジェクトに追加して下さい。

導入例:ライブラリを使わないカレンダーサンプル

Author

fumiyasac(Fumiya Sakai)

プロジェクトでの実装例

下記のように判定したい年・月・日を引数にセットするだけでOKです。

/* ViewController.swift */

// Step1: ライブラリのインポート(手動で導入した場合は不要)
import CalculateCalendarLogic

// Step2: CalculateCalendarLogicのインスタンスを作成
let holiday = CalculateCalendarLogic()
...

// Step3: 使用する際は引数を入れての判定を行う
let result: Bool = holiday.judgeJapaneseHoliday(year: 2016, month: 1, day: 1)

// 実行結果
print("2016年1月1日:\(result)")

//コンソールでは「2016年1月1日:true」と表示されます

本実装ではBool型での判定ではありますが、このメソッドをカスタマイズして戻り値を変更して「祝祭日の判定&祝祭日名を返す」ようにする等の用途に応じてのカスタマイズも可能です。

テストケース等その他

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

  • 今年(2016年)の祝祭日の判定が正しく行えていること
  • ゴールデンウィークの判定が正しく行えていること(※サンプル:2017年/2019年/2021年)
  • シルバーウィークの判定が正しく行えていること(※サンプル:2015年/2026年/2032年)
  • 春分の日・秋分の日の判定が正しく行えていること(※サンプル:2000年〜2030年)

テストケースに関しては今後追加予定です。

ライセンス

MIT

更新履歴

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

  • 2017.10.10: Swift4及びXCode9への対応を行いました。
  • 2017.01.14: macOS10.10と以降バージョンへのサポートが可能になりました。
  • 2016.12.31: 最新版をCocoaPods & Carthageへの対応を行いました。
  • 2016.12.29: Swift3系への対応を行いました。
  • 2016.10.13: Swift2.3及びSwift3.0ブランチ作成
  • 2016.09.03: CocoaPodsへの対応をしました(ドキュメント修正や追記含む)
  • 2016.05.28: READMEに追記をしました(Carthageで導入する際の手順や文章の修正等)
  • 2016.05.09: カレンダーに実装した例を掲載しました(UICollectionViewを使用)
  • 2016.05.01: CalculateCalendarLogic.swiftの実装と祝祭日判定テストケースを追加

謝辞

このライブラリの作成にあたりakio0911さん、akuraruさん、keygxさん、+ econa77さんに多くのお力添えを頂きまして誠にありがとうございました。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.