Skip to content

Instantly share code, notes, and snippets.

@fumiyasac
Last active September 17, 2016 18:19
Show Gist options
  • Save fumiyasac/4e73fcfbd6753d86ca6229fe8f09c3fd to your computer and use it in GitHub Desktop.
Save fumiyasac/4e73fcfbd6753d86ca6229fe8f09c3fd to your computer and use it in GitHub Desktop.
日本の祝祭日を計算してカレンダ-に表示するアプリサンプル ref: http://qiita.com/fumiyasac@github/items/33bfc07ad36dfffcdf8f
Pod::Spec.new do |s|
s.name = "CalculateCalendarLogic"
s.version = "0.0.2"
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.
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.
DESC
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, "8.0"
s.source = { :git => "https://github.com/fumiyasac/handMadeCalendarAdvance.git", :tag => "#{s.version}" }
s.social_media_url = "https://twitter.com/fumisac"
s.ios.deployment_target = '8.0'
s.source_files = "CalculateCalendarLogic/*"
s.requires_arc = true
end
/**
*
* ゴールデンウィークの振替休日を判定する
* 2007年以降で5/6が月・火・水(5/3 or 5/4 or 5/5が日曜日)なら5/6を祝日とする
* See also: https://www.bengo4.com/other/1146/1288/n_1412/
*
*/
private func getGoldenWeekAlterHoliday(year: Int, weekday: Weekday) -> Bool {
switch weekday {
case .Mon, .Tue, .Wed where 2007 <= year:
return true
default:
return false
}
}
/**
*
* シルバーウィークの振替休日を判定する
* 敬老の日の2日後が秋分の日ならば間に挟まれた期間は国民の休日とする
*
*/
private func getAlterHolidaySliverWeek(year year: Int) -> Bool {
return oldPeopleDay(year: year) + 2 == SpringAutumn.Autumn.calcDay(year: year)
}
/**
* 指定した年の敬老の日を調べる
*/
internal func oldPeopleDay(year year: Int) -> Int {
let cal = NSCalendar.currentCalendar()
func dateFromDay(day day: Int) -> NSDate? {
return cal.dateWithEra(AD, year: year, month: 9, day: day, hour: 0, minute: 0, second: 0, nanosecond: 0)
}
func weekdayAndDayFromDate(date date: NSDate) -> (weekday: Int, day: Int) {
return (
weekday: cal.component(.Weekday, fromDate: date),
day: cal.component(.Day, fromDate: date)
)
}
let monday = 2
return (15...21)
.map(dateFromDay)
.flatMap{ $0 }
.map(weekdayAndDayFromDate)
.filter{ $0.weekday == monday }
.first!
.day
}
class CalculateCalendarLogicTests: XCTestCase {
・・・
/**
*
* 春分の日・秋分の日の組み合わせが正しいかのテスト
* 計算式算出の参考:http://koyomi8.com/reki_doc/doc_0330.htm
* テストケース参考:http://www.nao.ac.jp/faq/a0301.html
*
*/
func testShunbunAndShubun() {
let test = CalculateCalendarLogic()
let testCases: [(Int,Int,Int,Bool)] =
[
// ↓↓↓↓↓ テストケースここから ↓↓↓↓↓
// 2000年: 春分の日[3月20日]・秋分の日[9月23日]
(2000, 3, 20, true),
(2000, 9, 23, true),
// 2001年: 春分の日[3月20日]・秋分の日[9月23日]
(2001, 3, 20, true),
(2001, 9, 23, true),
// 2002年: 春分の日[3月21日]・秋分の日[9月23日]
(2002, 3, 21, true),
(2002, 9, 23, true),
// 2003年: 春分の日[3月21日]・秋分の日[9月23日]
(2003, 3, 21, true),
(2003, 9, 23, true),
・・・(途中は省略します)・・・
// 2027年: 春分の日[3月21日]・秋分の日[9月23日]
(2027, 3, 21, true),
(2027, 9, 23, true),
// 2028年: 春分の日[3月20日]・秋分の日[9月22日]
(2028, 3, 20, true),
(2028, 9, 22, true),
// 2029年: 春分の日[3月20日]・秋分の日[9月23日]
(2029, 3, 20, true),
(2029, 9, 23, true),
// 2030年: 春分の日[3月20日]・秋分の日[9月23日]
(2030, 3, 20, true),
(2030, 9, 23, true)
// ↑↑↑↑↑ テストケースここまで ↑↑↑↑↑
]
// タプルを格納した配列をループさせて、判定結果が正しいかを検証する
testCases.forEach { year, month, day, expected in
let result = test.judgeJapaneseHoliday(year, month: month, day: day)
guard let weekday = Weekday(year: year, month: month, day: day) else { XCTFail() ; return }
let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)"
if expected {
XCTAssertTrue (result, message)
}else{
XCTAssertFalse(result, message)
}
}
}
・・・
}
//追加時
$ git tag 0.0.2 (タグを作成)
$ git push origin 0.0.2 (タグをリモートへプッシュ)
//削除時
$ git tag -d 0.0.2 (ローカルのタグを削除)
$ git push origin :0.0.2 (リモートのタグを削除)
$ pod trunk register [Eメール] '[登録名]'
$ pod trunk push [ライブラリ名].podspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment