Update 1.7.1.beta

1. Supports font customisation
2. Supports titleVerticalOffset and subtitleVerticalOffset
3. Remove SSLunarDate dependency, use NSCalendar and
NSCalendarIdentifierChinese instead
This commit is contained in:
dingwenchao 2015-11-29 19:00:56 +08:00
parent 7eeef02f48
commit fb8a05f02e
45 changed files with 332 additions and 3235 deletions

View File

@ -41,20 +41,6 @@
30FCB3971BAAD112002B87AD /* FSCalendarStickyHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 30FCB3951BAAD112002B87AD /* FSCalendarStickyHeader.m */; };
30FCB3981BAAD112002B87AD /* FSCalendarStickyHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 30FCB3951BAAD112002B87AD /* FSCalendarStickyHeader.m */; };
EE52AE181B91E68A00016662 /* FSCalendarScopeExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE52AE171B91E68A00016662 /* FSCalendarScopeExampleViewController.m */; };
EE638CB21B89DB450006DD1A /* LunarDateFormatter.strings in Resources */ = {isa = PBXBuildFile; fileRef = EE638C911B89DB450006DD1A /* LunarDateFormatter.strings */; };
EE638CB31B89DB450006DD1A /* libLunar.c in Sources */ = {isa = PBXBuildFile; fileRef = EE638C941B89DB450006DD1A /* libLunar.c */; };
EE638CB41B89DB450006DD1A /* SSHolidayCA.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638C971B89DB450006DD1A /* SSHolidayCA.m */; };
EE638CB51B89DB450006DD1A /* SSHolidayChina.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638C991B89DB450006DD1A /* SSHolidayChina.m */; };
EE638CB61B89DB450006DD1A /* SSHolidayCountry.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638C9B1B89DB450006DD1A /* SSHolidayCountry.m */; };
EE638CB71B89DB450006DD1A /* SSHolidayHK.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638C9D1B89DB450006DD1A /* SSHolidayHK.m */; };
EE638CB81B89DB450006DD1A /* SSHolidayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638C9F1B89DB450006DD1A /* SSHolidayManager.m */; };
EE638CB91B89DB450006DD1A /* SSHolidayTW.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CA11B89DB450006DD1A /* SSHolidayTW.m */; };
EE638CBA1B89DB450006DD1A /* SSHolidayUK.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CA31B89DB450006DD1A /* SSHolidayUK.m */; };
EE638CBB1B89DB450006DD1A /* SSHolidayUS.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CA51B89DB450006DD1A /* SSHolidayUS.m */; };
EE638CBC1B89DB450006DD1A /* SSHolidayWest.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CA71B89DB450006DD1A /* SSHolidayWest.m */; };
EE638CBD1B89DB450006DD1A /* SSLunarDate.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CAA1B89DB450006DD1A /* SSLunarDate.m */; };
EE638CBE1B89DB450006DD1A /* SSLunarDateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CAC1B89DB450006DD1A /* SSLunarDateFormatter.m */; };
EE638CBF1B89DB450006DD1A /* SSLunarDateHoliday.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CAE1B89DB450006DD1A /* SSLunarDateHoliday.m */; };
EE638CC31B89DB6E0006DD1A /* LoadViewExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CC21B89DB6E0006DD1A /* LoadViewExampleViewController.m */; };
EE638CC61B89DB7D0006DD1A /* ViewDidLoadExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CC51B89DB7D0006DD1A /* ViewDidLoadExampleViewController.m */; };
EE638CC91B89DB940006DD1A /* CalendarConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE638CC81B89DB940006DD1A /* CalendarConfigViewController.m */; };
@ -132,38 +118,6 @@
EE0D7FCB1B89C5D3003C287B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EE52AE161B91E68A00016662 /* FSCalendarScopeExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarScopeExampleViewController.h; sourceTree = SOURCE_ROOT; };
EE52AE171B91E68A00016662 /* FSCalendarScopeExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarScopeExampleViewController.m; sourceTree = SOURCE_ROOT; };
EE638C921B89DB450006DD1A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LunarDateFormatter.strings; sourceTree = "<group>"; };
EE638C931B89DB450006DD1A /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/LunarDateFormatter.strings; sourceTree = "<group>"; };
EE638C941B89DB450006DD1A /* libLunar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libLunar.c; sourceTree = "<group>"; };
EE638C951B89DB450006DD1A /* libLunar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libLunar.h; sourceTree = "<group>"; };
EE638C961B89DB450006DD1A /* SSHolidayCA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayCA.h; sourceTree = "<group>"; };
EE638C971B89DB450006DD1A /* SSHolidayCA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayCA.m; sourceTree = "<group>"; };
EE638C981B89DB450006DD1A /* SSHolidayChina.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayChina.h; sourceTree = "<group>"; };
EE638C991B89DB450006DD1A /* SSHolidayChina.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayChina.m; sourceTree = "<group>"; };
EE638C9A1B89DB450006DD1A /* SSHolidayCountry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayCountry.h; sourceTree = "<group>"; };
EE638C9B1B89DB450006DD1A /* SSHolidayCountry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayCountry.m; sourceTree = "<group>"; };
EE638C9C1B89DB450006DD1A /* SSHolidayHK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayHK.h; sourceTree = "<group>"; };
EE638C9D1B89DB450006DD1A /* SSHolidayHK.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayHK.m; sourceTree = "<group>"; };
EE638C9E1B89DB450006DD1A /* SSHolidayManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayManager.h; sourceTree = "<group>"; };
EE638C9F1B89DB450006DD1A /* SSHolidayManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayManager.m; sourceTree = "<group>"; };
EE638CA01B89DB450006DD1A /* SSHolidayTW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayTW.h; sourceTree = "<group>"; };
EE638CA11B89DB450006DD1A /* SSHolidayTW.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayTW.m; sourceTree = "<group>"; };
EE638CA21B89DB450006DD1A /* SSHolidayUK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayUK.h; sourceTree = "<group>"; };
EE638CA31B89DB450006DD1A /* SSHolidayUK.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayUK.m; sourceTree = "<group>"; };
EE638CA41B89DB450006DD1A /* SSHolidayUS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayUS.h; sourceTree = "<group>"; };
EE638CA51B89DB450006DD1A /* SSHolidayUS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayUS.m; sourceTree = "<group>"; };
EE638CA61B89DB450006DD1A /* SSHolidayWest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSHolidayWest.h; sourceTree = "<group>"; };
EE638CA71B89DB450006DD1A /* SSHolidayWest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSHolidayWest.m; sourceTree = "<group>"; };
EE638CA81B89DB450006DD1A /* SSLunarDate-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SSLunarDate-Prefix.pch"; sourceTree = "<group>"; };
EE638CA91B89DB450006DD1A /* SSLunarDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSLunarDate.h; sourceTree = "<group>"; };
EE638CAA1B89DB450006DD1A /* SSLunarDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSLunarDate.m; sourceTree = "<group>"; };
EE638CAB1B89DB450006DD1A /* SSLunarDateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSLunarDateFormatter.h; sourceTree = "<group>"; };
EE638CAC1B89DB450006DD1A /* SSLunarDateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSLunarDateFormatter.m; sourceTree = "<group>"; };
EE638CAD1B89DB450006DD1A /* SSLunarDateHoliday.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSLunarDateHoliday.h; sourceTree = "<group>"; };
EE638CAE1B89DB450006DD1A /* SSLunarDateHoliday.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSLunarDateHoliday.m; sourceTree = "<group>"; };
EE638CAF1B89DB450006DD1A /* SSLunarDateType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSLunarDateType.h; sourceTree = "<group>"; };
EE638CB01B89DB450006DD1A /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LunarDateFormatter.strings"; sourceTree = "<group>"; };
EE638CB11B89DB450006DD1A /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/LunarDateFormatter.strings"; sourceTree = "<group>"; };
EE638CC11B89DB6E0006DD1A /* LoadViewExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadViewExampleViewController.h; sourceTree = SOURCE_ROOT; };
EE638CC21B89DB6E0006DD1A /* LoadViewExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadViewExampleViewController.m; sourceTree = SOURCE_ROOT; };
EE638CC41B89DB7D0006DD1A /* ViewDidLoadExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewDidLoadExampleViewController.h; sourceTree = SOURCE_ROOT; };
@ -316,7 +270,6 @@
EE0D80241B89C868003C287B /* Storyboard Example */,
EE0D80231B89C853003C287B /* LoadView Example */,
EE0D80251B89C874003C287B /* ViewDidLoad Example */,
EE638C901B89DB450006DD1A /* SSLunarDate */,
EE638CDB1B89DC230006DD1A /* Images.xcassets */,
EE0D7FCA1B89C5D3003C287B /* Supporting Files */,
);
@ -370,42 +323,6 @@
name = "FSCalendarScope Example";
sourceTree = "<group>";
};
EE638C901B89DB450006DD1A /* SSLunarDate */ = {
isa = PBXGroup;
children = (
EE638C911B89DB450006DD1A /* LunarDateFormatter.strings */,
EE638C941B89DB450006DD1A /* libLunar.c */,
EE638C951B89DB450006DD1A /* libLunar.h */,
EE638C961B89DB450006DD1A /* SSHolidayCA.h */,
EE638C971B89DB450006DD1A /* SSHolidayCA.m */,
EE638C981B89DB450006DD1A /* SSHolidayChina.h */,
EE638C991B89DB450006DD1A /* SSHolidayChina.m */,
EE638C9A1B89DB450006DD1A /* SSHolidayCountry.h */,
EE638C9B1B89DB450006DD1A /* SSHolidayCountry.m */,
EE638C9C1B89DB450006DD1A /* SSHolidayHK.h */,
EE638C9D1B89DB450006DD1A /* SSHolidayHK.m */,
EE638C9E1B89DB450006DD1A /* SSHolidayManager.h */,
EE638C9F1B89DB450006DD1A /* SSHolidayManager.m */,
EE638CA01B89DB450006DD1A /* SSHolidayTW.h */,
EE638CA11B89DB450006DD1A /* SSHolidayTW.m */,
EE638CA21B89DB450006DD1A /* SSHolidayUK.h */,
EE638CA31B89DB450006DD1A /* SSHolidayUK.m */,
EE638CA41B89DB450006DD1A /* SSHolidayUS.h */,
EE638CA51B89DB450006DD1A /* SSHolidayUS.m */,
EE638CA61B89DB450006DD1A /* SSHolidayWest.h */,
EE638CA71B89DB450006DD1A /* SSHolidayWest.m */,
EE638CA81B89DB450006DD1A /* SSLunarDate-Prefix.pch */,
EE638CA91B89DB450006DD1A /* SSLunarDate.h */,
EE638CAA1B89DB450006DD1A /* SSLunarDate.m */,
EE638CAB1B89DB450006DD1A /* SSLunarDateFormatter.h */,
EE638CAC1B89DB450006DD1A /* SSLunarDateFormatter.m */,
EE638CAD1B89DB450006DD1A /* SSLunarDateHoliday.h */,
EE638CAE1B89DB450006DD1A /* SSLunarDateHoliday.m */,
EE638CAF1B89DB450006DD1A /* SSLunarDateType.h */,
);
path = SSLunarDate;
sourceTree = SOURCE_ROOT;
};
EE638CF21B8A1F550006DD1A /* FSCalendarTests */ = {
isa = PBXGroup;
children = (
@ -543,7 +460,6 @@
EE638CDC1B89DC230006DD1A /* Images.xcassets in Resources */,
EE638CD91B89DC0A0006DD1A /* Main_iPad.storyboard in Resources */,
30B0BAD51B8D8E23004B9476 /* Info.plist in Resources */,
EE638CB21B89DB450006DD1A /* LunarDateFormatter.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -570,34 +486,21 @@
3092253B1B905C4300123031 /* FSCalendarConstance.m in Sources */,
30F5D85A1B9FC4BB00C1C201 /* MultipleSelectionViewController.m in Sources */,
30FCB3971BAAD112002B87AD /* FSCalendarStickyHeader.m in Sources */,
EE638CBC1B89DB450006DD1A /* SSHolidayWest.m in Sources */,
EE638CBB1B89DB450006DD1A /* SSHolidayUS.m in Sources */,
30B0BAD21B8D8E23004B9476 /* FSCalendarCell.m in Sources */,
30B0BAD71B8D8E23004B9476 /* UIView+FSExtension.m in Sources */,
EE638CD41B89DBE90006DD1A /* FSTableViewController.m in Sources */,
3084BD191BF9AB8100C956F7 /* CalendarIdentifierViewController.m in Sources */,
EE638CCB1B89DBAC0006DD1A /* main.m in Sources */,
EE638CB51B89DB450006DD1A /* SSHolidayChina.m in Sources */,
30B0BAD11B8D8E23004B9476 /* FSCalendarAppearance.m in Sources */,
EEC9C0351BDC8F7000383A07 /* FSCalendarFlowLayout.m in Sources */,
EE638CB31B89DB450006DD1A /* libLunar.c in Sources */,
EE638CBA1B89DB450006DD1A /* SSHolidayUK.m in Sources */,
EE638CC61B89DB7D0006DD1A /* ViewDidLoadExampleViewController.m in Sources */,
EE638CB91B89DB450006DD1A /* SSHolidayTW.m in Sources */,
30B0BACF1B8D8E23004B9476 /* FSCalendar+IBExtension.m in Sources */,
EE638CBE1B89DB450006DD1A /* SSLunarDateFormatter.m in Sources */,
EE638CB71B89DB450006DD1A /* SSHolidayHK.m in Sources */,
EEC9C03A1BDC9E7000383A07 /* FSCalendarCollectionView.m in Sources */,
EE89AF9F1B9162B90001B657 /* NSString+FSExtension.m in Sources */,
EE638CB81B89DB450006DD1A /* SSHolidayManager.m in Sources */,
EE52AE181B91E68A00016662 /* FSCalendarScopeExampleViewController.m in Sources */,
EE638CBF1B89DB450006DD1A /* SSLunarDateHoliday.m in Sources */,
EE638CB41B89DB450006DD1A /* SSHolidayCA.m in Sources */,
30024F951BD1015300B1C04C /* DelegateAppearanceViewController.m in Sources */,
EE638CC31B89DB6E0006DD1A /* LoadViewExampleViewController.m in Sources */,
30B0BAD31B8D8E23004B9476 /* FSCalendarHeader.m in Sources */,
EE638CBD1B89DB450006DD1A /* SSLunarDate.m in Sources */,
EE638CB61B89DB450006DD1A /* SSHolidayCountry.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -631,17 +534,6 @@
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
EE638C911B89DB450006DD1A /* LunarDateFormatter.strings */ = {
isa = PBXVariantGroup;
children = (
EE638C921B89DB450006DD1A /* en */,
EE638C931B89DB450006DD1A /* ja */,
EE638CB01B89DB450006DD1A /* zh-Hans */,
EE638CB11B89DB450006DD1A /* zh-Hant */,
);
name = LunarDateFormatter.strings;
sourceTree = "<group>";
};
EE638CD51B89DC090006DD1A /* Main_iPad.storyboard */ = {
isa = PBXVariantGroup;
children = (
@ -786,7 +678,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.wenchao.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.wenchao.FSCalendar;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
@ -807,7 +699,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.wenchao.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.wenchao.FSCalendar;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";

View File

@ -1,15 +0,0 @@
//
// SSHolidayCA.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayCA : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,93 +0,0 @@
//
// SSHolidayCA.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCA.h"
#import "SSLunarDateHoliday.h"
#import "SSHolidayWest.h"
@interface SSHolidayCA()
{
NSDictionary *_solarHolidayCA;
NSDictionary *_variableHoliday;
int _cachedYear;
}
@property (readonly) NSDictionary *solarHolidayCA;
@property (readonly) NSDictionary *variableHoliday;
@end
@implementation SSHolidayCA
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
// 1. add table holiday
// 2. add selected wester holiday
NSMutableArray *result = [[NSMutableArray alloc] init];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:[self solarHolidayCA]]];
NSDateComponents *c = [self.calendar components:NSYearCalendarUnit fromDate:date];
if (_cachedYear != c.year) {
_cachedYear = (int)c.year;
_variableHoliday = nil;
}
[result addObjectsFromArray:[SSHolidayCountry getHolidayListFromTable:date calendar:self.calendar dict:[self variableHoliday]]];
return result;
}
-(NSDictionary *) variableHoliday {
if (_variableHoliday == nil) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSDate *d;
d = [self.west getGoodFriday:_cachedYear];
[dict setObject:HOLIDAY_GOOD_FRIDAY forKey:[self convertDateIndex:d]];
d = [self.west getEasterMonday:_cachedYear];
[dict setObject:HOLIDAY_EASTER_MONDAY
forKey:[self convertDateIndex:d]];
d = [self.west getLaborDay:_cachedYear];
[dict setObject:HOLIDAY_LABOR_DAY forKey:[self convertDateIndex:d]];
d = [self.west getThanksGivingDay:_cachedYear];
[dict setObject:HOLIDAY_THANKS_DAY forKey:[self convertDateIndex:d]];
d = [self.west getVictoriaDay:_cachedYear];
[dict setObject:HOLIDAY_VICTORIA_DAY forKey:[self convertDateIndex:d]];
_variableHoliday = dict;
}
return _variableHoliday;
}
// 1. Good Friday
// 2. Labor 's day
- (NSDictionary *) solarHolidayCA
{
if (!_solarHolidayCA)
_solarHolidayCA = @{@"0101":NSLocalizedString(@"New Year's Day",""),
@"0214":NSLocalizedString(@"Valentine",""),
@"0701":NSLocalizedString(@"Canada Day",""),
@"1111":NSLocalizedString(@"Remembrance Day",""),
@"1225":NSLocalizedString(@"Christmas Day",""),
@"1226":NSLocalizedString(@"Boxing Day","")
};
return _solarHolidayCA;
}
@end

View File

@ -1,16 +0,0 @@
//
// SSHolidayChina.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayChina : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,55 +0,0 @@
//
// SSHolidayChina.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayChina.h"
#import "SSLunarDate.h"
@interface SSHolidayChina()
{
NSDictionary *_solarHolidayCN;
}
@property (readonly) NSDictionary *solarHolidayCN;
@end
@implementation SSHolidayChina
- (NSDictionary *) solarHolidayCN
{
if (!_solarHolidayCN)
_solarHolidayCN = @{
@"0101":NSLocalizedString(@"元旦",""),
@"0214":NSLocalizedString(@"情人节",""),
@"0308":NSLocalizedString(@"妇女节",""),
@"0501":NSLocalizedString(@"劳动节",""),
@"0601":NSLocalizedString(@"儿童节",""),
@"0801":NSLocalizedString(@"建军节", ""),
@"0910":NSLocalizedString(@"教师节",""),
@"1001":NSLocalizedString(@"国庆节",""),
@"1225":NSLocalizedString(@"圣诞节","")
};
return _solarHolidayCN;
}
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
NSMutableArray *result = [[NSMutableArray alloc] init];
SSLunarDate *lunarDate = [[SSLunarDate alloc] initWithDate:date
calendar:self.calendar];
NSString *lunar = [lunarDate getLunarHolidayNameWithRegion:self.region];
if (lunar != nil)
[result addObject:lunar];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:self.solarHolidayCN]];
return result;
}
@end

View File

@ -1,26 +0,0 @@
//
// SSHolidayCountry.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SSHolidayManager.h"
#import "SSHolidayWest.h"
@interface SSHolidayCountry : NSObject
- (id) initWithRegion:(SSHolidayRegion) region;
- (NSArray *) getHolidayListForDate:(NSDate *)date;
+ (NSArray *) getHolidayListFromTable:(NSDate *)date
calendar:(NSCalendar *)cal
dict:(NSDictionary *) dict;
@property (strong, nonatomic) NSCalendar *calendar;
@property (strong, nonatomic) SSHolidayWest *west;
@property SSHolidayRegion region;
- (NSString*)convertDateIndex: (NSDate*)date;
@end

View File

@ -1,77 +0,0 @@
//
// SSHolidayCountry.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
#import "SSLunarDate.h"
#import "SSLunarDateHoliday.h"
@interface SSHolidayCountry ()
{
SSHolidayRegion _region;
NSCalendar *_calendar;
SSHolidayWest *_west;
}
@end
@implementation SSHolidayCountry
@synthesize calendar, region;
- (id) initWithRegion:(SSHolidayRegion) reg
{
self = [super init];
if (self) {
_region = reg;
_calendar = [NSCalendar currentCalendar];
}
return self;
}
- (NSCalendar *) calendar {
if (_calendar == nil)
_calendar = [NSCalendar currentCalendar];
return _calendar;
}
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
NSAssert(false, @"NSHolidayCountry dummy function called");
return [NSArray array];
}
+ (NSArray *) getHolidayListFromTable:(NSDate *)date
calendar:(NSCalendar *)cal
dict:(NSDictionary *) dict
{
NSString *index;
NSMutableArray *result = [[NSMutableArray alloc] init];
unsigned int flags = NSYearCalendarUnit
| NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *parts = [cal components:flags fromDate:date];
index = [SSLunarDateHoliday convertIndexFrom:(int)parts.month day:(int)parts.day];
NSString *holiday = [dict objectForKey:index];
if (holiday)
[result addObject:holiday];
return result;
}
-(NSString *) convertDateIndex:(NSDate *)date
{
NSDateComponents *c = [self.calendar components: NSDayCalendarUnit | NSMonthCalendarUnit fromDate:date];
return [SSLunarDateHoliday convertIndexFrom:(int)c.month day:(int)c.day];
}
- (SSHolidayWest *) west
{
if (_west == nil)
_west = [[SSHolidayWest alloc] initWithCalendar:self.calendar];
return _west;
}
@end

View File

@ -1,13 +0,0 @@
//
// SSHolidayHK.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayHK : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,92 +0,0 @@
//
// SSHolidayHK.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayHK.h"
#import "SSLunarDate.h"
@interface SSHolidayHK()
{
NSDictionary *_solarHolidayHK;
NSDictionary *_variableHoliday;
int _cachedYear;
}
@property (readonly) NSDictionary *solarHolidayTW;
@property (readonly) NSDictionary *variableHoliday;
@end
@implementation SSHolidayHK
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
NSMutableArray *result = [[NSMutableArray alloc] init];
SSLunarDate *lunarDate = [[SSLunarDate alloc] initWithDate:date
calendar:self.calendar];
NSDateComponents *c = [self.calendar components:NSYearCalendarUnit fromDate:date];
NSAssert(c.year != 0, @"should not zero");
if (_cachedYear != c.year) {
_cachedYear = (int)c.year;
_variableHoliday = nil;
}
NSString *lunar = [lunarDate getLunarHolidayNameWithRegion:self.region];
if (lunar != nil)
[result addObject:lunar];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:self.solarHolidayHK]];
[result addObjectsFromArray:[SSHolidayCountry getHolidayListFromTable:date calendar:self.calendar dict:[self variableHoliday]]];
return result;
}
-(NSDictionary *) variableHoliday {
if (_variableHoliday == nil) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSDate *d;
d = [self.west getGoodFriday:_cachedYear];
[dict setObject:HOLIDAY_GOOD_FRIDAY forKey:[self convertDateIndex:d]];
d = [self.west getGoodFridayNextDay:_cachedYear];
[dict setObject:HOLIDAY_GOOD_FRIDAY_NEXT forKey:[self convertDateIndex:d]];
d = [self.west getEasterMonday:_cachedYear];
[dict setObject:HOLIDAY_EASTER_MONDAY
forKey:[self convertDateIndex:d]];
_variableHoliday = dict;
}
return _variableHoliday;
}
// 1. Good Firday,
// 2. Good Firday + 1
// 3. Easter + 1
- (NSDictionary *) solarHolidayHK
{
if (!_solarHolidayHK)
_solarHolidayHK = @{@"0101":NSLocalizedString(@"元旦",""),
@"0214":NSLocalizedString(@"情人节",""),
@"0308":NSLocalizedString(@"妇女节",""),
@"0501":NSLocalizedString(@"劳动节",""),
@"0601":NSLocalizedString(@"儿童节",""),
@"0701":NSLocalizedString(@"特区紀念日", ""),
@"1001":NSLocalizedString(@"国庆节",""),
@"1225":NSLocalizedString(@"圣诞节","")
};
return _solarHolidayHK;
}
@end

View File

@ -1,48 +0,0 @@
//
// SSHolidayManager.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-20.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import <Foundation/Foundation.h>
typedef enum {
SSHolidayRegionChina = 0,
SSHolidayRegionHongkong,
SSHolidayRegionTaiwan,
SSHolidayRegionUS,
SSHolidayRegionCanadia,
SSHolidayRegionUK,
} SSHolidayRegion;
#define HOLIDAY_REGION_CHANGED_NOTICE @"SSHolidayRegionChanged"
// This class manage the solar holiday of selected region.
// Majoy of the holiday day is calc by some rules in WiKi,
// But for some unknow holiday, such as China off day, which will
// update every year, so this should be fetch from network.
@interface SSHolidayManager : NSObject
- initWithRegion:(SSHolidayRegion) region;
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,79 +0,0 @@
//
// SSHolidayManager.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-20.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import "SSHolidayManager.h"
#import "SSLunarDate.h"
#import "SSHolidayCountry.h"
#import "SSHolidayUK.h"
#import "SSHolidayTW.h"
#import "SSHolidayUS.h"
#import "SSHolidayChina.h"
#import "SSHolidayHK.h"
#import "SSHolidayCA.h"
@interface SSHolidayManager ()
{
SSHolidayRegion _region;
SSHolidayCountry *_country;
}
@property (readonly) SSHolidayCountry *country;
@end
@implementation SSHolidayManager
- (id) initWithRegion:(SSHolidayRegion)region
{
self = [super init];
if (self) {
_region = region;
_country = [self allocateHolidayAlgoByRegion:region];
}
return self;
}
- (SSHolidayCountry *) allocateHolidayAlgoByRegion:(SSHolidayRegion)r {
switch (r) {
case SSHolidayRegionChina:
return [[SSHolidayChina alloc] init];
case SSHolidayRegionHongkong:
return [[SSHolidayHK alloc] init];
case SSHolidayRegionTaiwan:
return [[SSHolidayTW alloc] init];
case SSHolidayRegionUS:
return [[SSHolidayUS alloc] init];
case SSHolidayRegionCanadia:
return [[SSHolidayCA alloc] init];
case SSHolidayRegionUK:
return [[SSHolidayUK alloc] init];
default:
NSAssert(false, @"should not be here");
return [[SSHolidayChina alloc] init];
}
}
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
return [_country getHolidayListForDate:date];
}
@end

View File

@ -1,16 +0,0 @@
//
// SSHolidayTW.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayTW : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,53 +0,0 @@
//
// SSHolidayTW.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayTW.h"
#import "SSLunarDate.h"
@interface SSHolidayTW()
{
NSDictionary *_solarHolidayTW;
}
@property (readonly) NSDictionary *solarHolidayTW;
@end
@implementation SSHolidayTW
- (NSDictionary *) solarHolidayTW
{ if (!_solarHolidayTW)
_solarHolidayTW = @{@"0101":NSLocalizedString(@"开国纪念日",""),
@"0214":NSLocalizedString(@"情人节",""),
@"0228":NSLocalizedString(@"和平纪念日",""),
@"0308":NSLocalizedString(@"妇女节",""),
@"0501":NSLocalizedString(@"劳动节",""),
@"0601":NSLocalizedString(@"儿童节",""),
@"0903":NSLocalizedString(@"军人节", ""),
@"1010":NSLocalizedString(@"中华民国国庆日",""),
@"1225":NSLocalizedString(@"圣诞节","")
};
return _solarHolidayTW;
}
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
NSMutableArray *result = [[NSMutableArray alloc] init];
SSLunarDate *lunarDate = [[SSLunarDate alloc] initWithDate:date
calendar:self.calendar];
NSString *lunar;
lunar = [lunarDate getLunarHolidayNameWithRegion:self.region];
if (lunar != nil)
[result addObject:lunar];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:self.solarHolidayTW]];
return result;
}
@end

View File

@ -1,14 +0,0 @@
//
// SSHolidayUK.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayUK : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,97 +0,0 @@
//
// SSHolidayUK.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayUK.h"
@interface SSHolidayUK()
{
NSDictionary *_fixedHoliday;
NSDictionary *_variableHoliday;
int _cachedYear;
}
@property (readonly) NSDictionary *fixedHoliday;
@property (readonly) NSDictionary *variableHoliday;
@end
@implementation SSHolidayUK
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
// 1. add table holiday
// 2. add selected wester holiday
NSMutableArray *result = [[NSMutableArray alloc] init];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:[self fixedHoliday]]];
NSDateComponents *c = [self.calendar components:NSYearCalendarUnit fromDate:date];
NSAssert(c.year != 0, @"should not zero");
if (_cachedYear != c.year) {
_cachedYear = (int)c.year;
_variableHoliday = nil;
}
[result addObjectsFromArray:[SSHolidayCountry getHolidayListFromTable:date calendar:self.calendar dict:[self variableHoliday]]];
return result;
}
- (NSDictionary *) fixedHoliday
{
if (!_fixedHoliday)
_fixedHoliday = @{@"0101":NSLocalizedString(@"New Year's Day",""),
@"0317":NSLocalizedString(@"St. Patrick's Day",""),
@"0712":NSLocalizedString(@"Orangeman's Day", ""),
@"1225":NSLocalizedString(@"Christmas Day","")};
return _fixedHoliday;
}
// 1. good Friday
// 2. easter Monday
// 3. may day bank holiday
// 4. spring bank holiday
// 5. last summary bank holiday
// 6. boxing day
- (NSDictionary *) variableHoliday
{
if (_variableHoliday == nil) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSDate *d;
d = [self.west getGoodFriday:_cachedYear];
[dict setObject:HOLIDAY_GOOD_FRIDAY forKey:[self convertDateIndex:d]];
d = [self.west getEaster:_cachedYear];
[dict setObject:HOLIDAY_EASTER_DAY forKey:[self convertDateIndex:d]];
d = [self.west getEasterMonday:_cachedYear];
[dict setObject:HOLIDAY_EASTER_MONDAY
forKey:[self convertDateIndex:d]];
d = [self.west getMayBankDay: _cachedYear];
[dict setObject:HOLIDAY_MAY_BANK_DAY forKey:[self convertDateIndex:d]];
d = [self.west getSpringBankDay: _cachedYear];
[dict setObject:HOLIDAY_SPRING_BANK_DAY forKey:[self convertDateIndex:d]];
d = [self.west getLateSummaryBankHoliday:_cachedYear];
[dict setObject:HOLIDAY_LATE_SUMMERY_BANK_DAY forKey:[self convertDateIndex:d]];
d = [self.west getBoxingDay:_cachedYear];
[dict setObject:HOLIDAY_BOXING_DAY forKey:[self convertDateIndex:d]];
_variableHoliday = dict;
}
return _variableHoliday;
}
@end

View File

@ -1,16 +0,0 @@
//
// SSHolidayUS.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013年 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayCountry.h"
@interface SSHolidayUS : SSHolidayCountry
- (NSArray *) getHolidayListForDate:(NSDate *)date;
@end

View File

@ -1,102 +0,0 @@
//
// SSHolidayUS.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-8-25.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
//
#import "SSHolidayUS.h"
#import "SSLunarDateHoliday.h"
#import "SSHolidayWest.h"
@interface SSHolidayUS()
{
NSDictionary *_solarHolidayUS;
NSDictionary *_variableHoliday;
int _cachedYear;
}
@property (readonly) NSDictionary *solarHolidayUS;
@property (readonly) NSDictionary *variableHoliday;
@end
@implementation SSHolidayUS
- (NSArray *) getHolidayListForDate:(NSDate *)date
{
// 1. add table holiday
// 2. add selected wester holiday
NSMutableArray *result = [[NSMutableArray alloc] init];
[result addObjectsFromArray: [SSHolidayCountry getHolidayListFromTable:date
calendar:self.calendar
dict:[self solarHolidayUS]]];
NSDateComponents *c = [self.calendar components:NSYearCalendarUnit fromDate:date];
if (_cachedYear != c.year) {
_cachedYear = (int)c.year;
_variableHoliday = nil;
}
[result addObjectsFromArray:[SSHolidayCountry getHolidayListFromTable:date calendar:self.calendar dict:[self variableHoliday]]];
return result;
}
-(NSDictionary *) variableHoliday {
if (_variableHoliday == nil) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSDate *d;
// FIXME: I really don't happy with these code, should be more table
// way, but I don't want setup a function pointer in Obj-c.
d = [self.west getGoodFriday:_cachedYear];
[dict setObject:HOLIDAY_GOOD_FRIDAY forKey:[self convertDateIndex:d]];
d = [self.west getEaster:_cachedYear];
[dict setObject:HOLIDAY_EASTER_DAY forKey:[self convertDateIndex:d]];
d = [self.west getMartinLutherKingBirthday:_cachedYear];
[dict setObject:HOLIDAY_MLK_BIRTHDAY forKey:[self convertDateIndex:d]];
d = [self.west getMemorialDay:_cachedYear];
[dict setObject:HOLIDAY_MEM_DAY forKey:[self convertDateIndex:d]];
d = [self.west getLaborDay:_cachedYear];
[dict setObject:HOLIDAY_LABOR_DAY forKey:[self convertDateIndex:d]];
d = [self.west getColumbusDay:_cachedYear];
[dict setObject:HOLIDAY_COLUMBUS_DAY forKey:[self convertDateIndex:d]];
d = [self.west getThanksGivingDay:_cachedYear];
[dict setObject:HOLIDAY_THANKS_DAY forKey:[self convertDateIndex:d]];
_variableHoliday = dict;
}
return _variableHoliday;
}
// 1. Third Monday in January, Birthday of Dr. Martin Luther King, Jr.
// 2. 2, Washington's Birthday/Presidents' Day
// 3. Last Monday in May Memorial Day
// 4. First Monday in September Labor Day
// 5. Second Monday in October Columbus Day
// 6. 11 Thanksgiving Day
- (NSDictionary *) solarHolidayUS
{ if (!_solarHolidayUS)
_solarHolidayUS = @{@"0101":NSLocalizedString(@"New Year's Day",""),
@"0214":NSLocalizedString(@"Valentine",""),
@"0704":NSLocalizedString(@"Independence Day",""),
@"1111":NSLocalizedString(@"Veterans Day", ""),
@"1225":NSLocalizedString(@"Christmas Day","")
};
return _solarHolidayUS;
}
@end

View File

@ -1,69 +0,0 @@
//
// SSHolidayWest.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-21.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import <Foundation/Foundation.h>
// United Kingdom holiday
#define HOLIDAY_GOOD_FRIDAY NSLocalizedString(@"Good Friday","")
#define HOLIDAY_GOOD_FRIDAY_NEXT NSLocalizedString(@"The day following Good Friday","")
#define HOLIDAY_EASTER_DAY NSLocalizedString(@"Easter Day","")
#define HOLIDAY_EASTER_MONDAY NSLocalizedString(@"Easter Monday","")
#define HOLIDAY_MAY_BANK_DAY NSLocalizedString(@"May Day Bank Holiday", "")
#define HOLIDAY_SPRING_BANK_DAY NSLocalizedString(@"Spring Bank Holiday", "")
#define HOLIDAY_LATE_SUMMERY_BANK_DAY NSLocalizedString(@"Summer Bank Holiday","")
#define HOLIDAY_BOXING_DAY NSLocalizedString(@"Boxing Day","")
// US Holiday
#define HOLIDAY_MLK_BIRTHDAY NSLocalizedString(@"Birthday of MLK", "")
#define HOLIDAY_MEM_DAY NSLocalizedString(@"Memorial Day", "")
#define HOLIDAY_LABOR_DAY NSLocalizedString(@"Labor Day", "")
#define HOLIDAY_COLUMBUS_DAY NSLocalizedString(@"Columbus Day", "")
#define HOLIDAY_THANKS_DAY NSLocalizedString(@"Thanksgiving Day", "")
// CA Holiday
#define HOLIDAY_VICTORIA_DAY NSLocalizedString(@"Victoria Day", "")
@interface SSHolidayWest : NSObject
{
NSCalendar *currentCalendar;
}
- (id) initWithCalendar:(NSCalendar *) calendar;
- (NSDate *) getEaster: (int) year;
- (NSDate *) getEasterMonday: (int) year;
- (NSDate *) getGoodFriday: (int) year;
- (NSDate *) getGoodFridayNextDay: (int) year;
- (NSDate *) getMartinLutherKingBirthday: (int) year;
- (NSDate *) getPresidentsDay: (int) year;
- (NSDate *) getMemorialDay: (int) year;
- (NSDate *) getLaborDay: (int) year;
- (NSDate *) getColumbusDay: (int) year;
- (NSDate *) getThanksGivingDay: (int) year;
- (NSDate *) getMayBankDay: (int) year;
- (NSDate *) getSpringBankDay: (int) year;
- (NSDate *) getLateSummaryBankHoliday: (int) year;
- (NSDate *) getBoxingDay: (int) year;
- (NSDate *) getVictoriaDay: (int) year;
@end

View File

@ -1,298 +0,0 @@
//
// SSHolidayWest.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-21.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// The Easter algorithm is from
// HTTP://www.codeproject.com/Articles/1595/Calculating-Easter-Sunday
#import "SSHolidayWest.h"
@implementation SSHolidayWest
// TODO: need implement a cache with current year.
- (id) initWithCalendar:(NSCalendar *)calendar
{
self = [super init];
if (self) {
currentCalendar = calendar;
}
return self;
}
- (NSDate *) getDateFromYear:(int) year month: (int) month day: (int) day
{
unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar *cal = currentCalendar;
NSDateComponents *parts = [cal components:flags
fromDate:[NSDate date]];
[parts setYear:year];
[parts setMonth:month];
[parts setDay:day];
return [cal dateFromComponents:parts];
}
- (NSDate *) getEasterMonday: (int) year
{
// good Friday is two day before easter day
NSDate *easterDay = [self getEaster:year];
NSDateComponents *c = [[NSDateComponents alloc] init];
c.day = 1;
return [currentCalendar
dateByAddingComponents:c toDate:easterDay options:0];
}
// calculate easter sunday
- (NSDate *) getEaster: (int) year
{
int correction = 0;
int day, month;
if (year < 1700) correction = 4;
else if (year < 1800) correction = 5;
else if (year < 1900) correction = 6;
else if (year < 2100) correction = 0;
else if (year < 2200) correction = 1;
else if (year < 2300) correction = 2;
else if (year < 2500) correction = 3;
day = (19 * (year % 19) + 24) % 30;
day = 22 + day + ((2 * (year % 4) + 4 * (year % 7) + 6 * day + 5 + correction) % 7);
// jump to next month
if (day > 31) {
month = 4;
day -= 31;
} else {
month = 3;
}
// compose to a NSDate...
return [self getDateFromYear:year month:month day:day];
}
- (NSDate *) getGoodFriday: (int) year
{
// good Friday is two day before easter day
NSDate *easterDay = [self getEaster:year];
NSDateComponents *c = [[NSDateComponents alloc] init];
c.day = -2;
return [currentCalendar
dateByAddingComponents:c toDate:easterDay options:0];
}
- (NSDate *) getGoodFridayNextDay: (int) year
{
// one day after good Friday
NSDate *easterDay = [self getEaster:year];
NSDateComponents *c = [[NSDateComponents alloc] init];
c.day = -1;
return [currentCalendar
dateByAddingComponents:c toDate:easterDay options:0];
}
// Third Monday in January, Birthday of Dr. Martin Luther King, Jr.
- (NSDate *) getMartinLutherKingBirthday: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 1;
c.weekdayOrdinal = 3; // third week
c.weekday = 2; // Monday
c.year = year;
return [calendar dateFromComponents:c];
}
// Third Monday in Feb
- (NSDate *) getPresidentsDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 2;
c.weekdayOrdinal = 3; // third week
c.weekday = 2; // Monday
c.year = year;
return [calendar dateFromComponents:c];
}
// Last Monday in May Memorial Day
- (NSDate *) getMemorialDay: (int) year
{
NSCalendar* calendar = currentCalendar;
NSDateComponents* firstMondayInJuneComponents = [NSDateComponents new] ;
firstMondayInJuneComponents.month = 6 ;
firstMondayInJuneComponents.weekdayOrdinal = 1 ;
firstMondayInJuneComponents.weekday = 2 ; //Monday
firstMondayInJuneComponents.year = year;
NSDate* firstMondayInJune = [calendar
dateFromComponents:firstMondayInJuneComponents] ;
// --> 2012-06-04
NSDateComponents* subtractAWeekComponents = [NSDateComponents new] ;
subtractAWeekComponents.weekOfYear = -1 ;
NSDate* memorialDay = [calendar dateByAddingComponents:subtractAWeekComponents
toDate:firstMondayInJune options:0] ;
// --> 2012-05-28
return memorialDay;
}
// First Monday in Septembe Labor Day
- (NSDate *) getLaborDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 9;
c.weekdayOrdinal = 1;
c.weekday = 2; // Monday
c.year = year;
return [calendar dateFromComponents:c];
}
// Second Monday in October Columbus Day
- (NSDate *) getColumbusDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 10;
c.weekdayOrdinal = 2;
c.weekday = 2; // Monday
c.year = year;
return [calendar dateFromComponents:c];
}
// Fourth Thursday in November
- (NSDate *) getThanksGivingDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 11;
c.weekdayOrdinal = 4;
c.weekday = 5;
c.year = year;
return [calendar dateFromComponents:c];
}
// 1st Monday in May
- (NSDate *) getMayBankDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 5;
c.weekdayOrdinal = 1; // 1st
c.weekday = 2; // Monday
c.year = year;
return [calendar dateFromComponents:c];
}
// last Monday in may
- (NSDate *) getSpringBankDay: (int) year
{
return [self getMemorialDay:year];
}
// last Monday in August
- (NSDate *) getLateSummaryBankHoliday: (int) year
{
NSCalendar* calendar = currentCalendar;
NSDateComponents* firstMondayNextMonthComponents = [NSDateComponents new] ;
firstMondayNextMonthComponents.month = 9 ;
firstMondayNextMonthComponents.weekdayOrdinal = 1 ;
firstMondayNextMonthComponents.weekday = 2 ; //Monday
firstMondayNextMonthComponents.year = year;
NSDate* firstMondayNextMonth = [calendar
dateFromComponents:firstMondayNextMonthComponents] ;
//
NSDateComponents* subtractAWeekComponents = [NSDateComponents new] ;
subtractAWeekComponents.weekOfYear = -1 ;
NSDate* day = [calendar dateByAddingComponents:subtractAWeekComponents
toDate:firstMondayNextMonth options:0] ;
return day;
}
- (NSDate *) getBoxingDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 12;
c.day = 26;
c.year = year;
NSDate *d = [calendar dateFromComponents:c];
NSDateComponents *cc = [calendar components:NSCalendarUnitWeekday fromDate:d];
if (cc.weekday == 1) {// if sunday, move to next monday
c.day = 27;
return [calendar dateFromComponents:c];
} else
return d;
}
// Last Monday before 5/25
- (NSDate *) getVictoriaDay: (int) year
{
NSCalendar *calendar = currentCalendar;
NSDateComponents *c = [[NSDateComponents alloc] init];
c.month = 5;
c.day = 24;
c.year = year;
NSDate *may24 = [calendar dateFromComponents:c];
NSDateComponents *cc = [calendar components:NSCalendarUnitWeekday fromDate:may24];
// if that day was monday, it equal to zero.
// if that day was tue, it equal to 1, minor 1 =
NSDateComponents *ccc = [NSDateComponents new];
int reminder = (int)cc.weekday - 2;
if (reminder >= 0)
ccc.day = - (cc.weekday - 2);
else
ccc.day = -6; // only happen when 24 is sunday.
return [calendar dateByAddingComponents:ccc toDate:may24 options:0];
}
@end

View File

@ -1,7 +0,0 @@
//
// Prefix header for all source files of the 'SSLunarDate' target in the 'SSLunarDate' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

View File

@ -1,65 +0,0 @@
//
// SSLunarDate.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-6.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import <Foundation/Foundation.h>
#import "SSLunarDateFormatter.h"
#import "SSLunarDateType.h"
#import "SSHolidayManager.h"
@interface SSLunarDate : NSObject
// init the solar date by [NSDate date];
- (id) init;
// init with solarDate
- (id) initWithDate:(NSDate *) solarDate;
// This with date and calendar.
// The calendar is because the calendar generate function is very heavy,
// so better can use a parameter to have the calendar.
- (id) initWithDate:(NSDate *)solarDate calendar:(NSCalendar *)calendar;
// Check whether the solar to lunar success or not, since the lunar convert
// have some range, the out ranged date will lead to empty string for the
// string functions.
- (BOOL) convertSuccess;
- (NSString *) monthString;
- (NSString *) dayString;
- (NSString *) zodiacString;
- (NSString *) string;
- (NSString *) yearGanzhiString;
- (BOOL) isLeapMonth; // return whether the date is a leap month.
- (NSString *) leapString;
- (BOOL) isLunarHolidayWithRegion:(SSHolidayRegion) region;
- (NSString *) getLunarHolidayNameWithRegion:(SSHolidayRegion) region;
// needs: 1. needs get the lunar date by a lunar date.
// 2. can get the string of date, to show on the calendar.
// 3. can show lunar holiday on the calendar.
// 4. the string must be i18n able, this is important for Hongko, Taiwan customer.
@end

View File

@ -1,180 +0,0 @@
//
// SSLunarDate.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-6.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import "SSLunarDate.h"
#import "libLunar.h"
#import "SSLunarDateHoliday.h"
@interface SSLunarDate()
{
BOOL dateOutOfRange;
NSCalendar *_calendar;
NSDate *_solarDate;
SSLunarDateFormatter *_formater;
LibLunarContext *_ctx;
SSLunarSimpleDate _simpleSolarDate;
}
@end
@implementation SSLunarDate
- (id) init
{
self = [super init];
if (self) {
[self setupAndDoConvert:[NSDate date]
calendar:[NSCalendar currentCalendar]];
}
return self;
}
- (void) dealloc
{
// not call [supoer dealloc] since ARC already provide this.
freeLunarContext(_ctx);
_ctx = NULL;
}
- (id) initWithDate:(NSDate *) solarDate
{
self = [super init];
if (self) {
[self setupAndDoConvert:solarDate
calendar:[NSCalendar currentCalendar]];
}
return self;
}
- (id) initWithDate:(NSDate *)solarDate calendar:(NSCalendar *)calendar
{
self = [super init];
if (self) {
[self setupAndDoConvert:solarDate calendar:calendar];
}
return self;
}
- (void) setupAndDoConvert:(NSDate *) solarDate calendar:(NSCalendar *) cal
{
_calendar = cal;
_formater = [SSLunarDateFormatter sharedLunarDateFormatter];
[self NSDataToLunarDate:solarDate withDate:&_simpleSolarDate];
// NSLog(@"solarDate:%d %d", _simpleSolarDate.month, _simpleSolarDate.day);
if (libLunarCheckYearRange(_simpleSolarDate.year) == false) {
dateOutOfRange = TRUE;
}
NSAssert(_ctx == NULL,
@"libLunar Context was not null when setup, leak...");
_ctx = createLunarContext();
NSAssert(_ctx != NULL, @"create context failed");
Solar2Lunar(_ctx, &_simpleSolarDate);
}
#define RETURN_EMPTY_IF_DATE_OUT_OF_RANGE do { if (dateOutOfRange) return @""; } while (0)
#define RETURN_NO_IF_DATE_OUT_OF_RANGE do { if (dateOutOfRange) return FALSE; } while (0)
- (BOOL) convertSuccess
{
return !dateOutOfRange;
}
- (NSString *) monthString
{
NSAssert(_formater, @"formatter is null!");
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getLunarMonthForDate:_ctx];
}
- (NSString *) dayString
{
NSAssert(_formater, @"formatter is null");
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getDayNameForDate:_ctx];
}
- (NSString *) zodiacString
{
NSAssert(_formater, @"formatter is null");
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getShengXiaoNameForDate:_ctx];
}
- (NSString *) leapString
{
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getLeapString];
}
- (NSString *) yearGanzhiString
{
NSAssert(_formater, @"formatter is null");
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getGanZhiYearNameForDate:_ctx];
}
- (NSString *) string
{
NSAssert(_formater, @"formatter is null");
RETURN_EMPTY_IF_DATE_OUT_OF_RANGE;
return [_formater getFullLunarStringForDate:_ctx];
}
- (BOOL) isLeapMonth
{
NSAssert(_formater, @"formatter is null");
RETURN_NO_IF_DATE_OUT_OF_RANGE;
return [_formater isLeapMonthForDate:_ctx];
}
- (void) NSDataToLunarDate:(NSDate *) date withDate:(SSLunarSimpleDate *) lunarDate
{
unsigned int flags = NSYearCalendarUnit \
| NSMonthCalendarUnit | NSDayCalendarUnit \
| NSHourCalendarUnit;
NSDateComponents *parts = [_calendar components:flags fromDate:date];
lunarDate->year = (int)parts.year;
lunarDate->month = (int)parts.month;
lunarDate->day = (int)parts.day;
lunarDate->hour = (int)parts.hour;
}
- (BOOL) isLunarHolidayWithRegion:(SSHolidayRegion) region
{
SSLunarDateHoliday *holiday = [SSLunarDateHoliday sharedSSLunarDateHoliday];
return [holiday isDateLunarHoliday:_ctx region:region];
}
- (NSString *) getLunarHolidayNameWithRegion:(SSHolidayRegion) region
{
SSLunarDateHoliday *holiday = [SSLunarDateHoliday sharedSSLunarDateHoliday];
return [holiday getLunarHolidayNameForDate:_ctx region:region];
}
@end

View File

@ -1,47 +0,0 @@
//
// SSLunarDateFormatter.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-7.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import <Foundation/Foundation.h>
#import "SSLunarDate.h"
#import "libLunar.h"
@interface SSLunarDateFormatter : NSObject
+ (SSLunarDateFormatter *)sharedLunarDateFormatter;
- (NSString *) getGanZhiNameForDate:(LibLunarContext *)lunar;
- (NSString *) getShengXiaoNameForDate:(LibLunarContext *)lunar;
- (NSString *) getGanZhiYearNameForDate:(LibLunarContext *)lunar;
- (NSString *) getLunarMonthForDate: (LibLunarContext *) lunar;
- (NSString *) getDayNameForDate: (LibLunarContext *) lunar;
- (NSString *) getFullLunarStringForDate: (LibLunarContext *) lunar;
- (BOOL) isLeapMonthForDate: (LibLunarContext *) lunar;
- (NSString *) getLeapString;
@end

View File

@ -1,277 +0,0 @@
//
// SSLunarDateFormatter.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-7.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import "SSLunarDateFormatter.h"
#define YEAR_STR NSLocalizedString(@"年", "year")
#define LEAP_STR NSLocalizedString(@"闰", "leap")
@interface SSLunarDateFormatter()
{
NSArray *_monthArray;
NSArray *_dayArray;
NSArray *_ganArray;
NSArray *_zhiArray;
NSArray *_zodiacArray;
NSArray *_solarTerm;
}
@end
static SSLunarDateFormatter *_sharedFormatter = NULL;
@implementation SSLunarDateFormatter
+ (SSLunarDateFormatter *)sharedLunarDateFormatter
{
@synchronized([SSLunarDateFormatter class]) {
if (!_sharedFormatter)
_sharedFormatter = [[self alloc] init];
return _sharedFormatter;
}
return nil;
}
+ (id) alloc
{
@synchronized([SSLunarDateFormatter class]) {
NSAssert(_sharedFormatter == NULL, @"attempt to alloc a second SharedLunarDateFormatter");
_sharedFormatter = [super alloc];
return _sharedFormatter;
}
return nil;
}
- (NSArray *) monthArray
{
if (!_monthArray)
_monthArray = @[
NSLocalizedString(@"正月",""),
NSLocalizedString(@"二月",""),
NSLocalizedString(@"三月",""),
NSLocalizedString(@"四月",""),
NSLocalizedString(@"五月",""),
NSLocalizedString(@"六月",""),
NSLocalizedString(@"七月",""),
NSLocalizedString(@"八月",""),
NSLocalizedString(@"九月",""),
NSLocalizedString(@"十月",""),
NSLocalizedString(@"十一月",""),
NSLocalizedString(@"腊月","")];
return _monthArray;
}
- (NSArray *) dayArray
{
if (!_dayArray)
_dayArray = @[
NSLocalizedString(@"初一",""),
NSLocalizedString(@"初二",""),
NSLocalizedString(@"初三",""),
NSLocalizedString(@"初四",""),
NSLocalizedString(@"初五",""),
NSLocalizedString(@"初六",""),
NSLocalizedString(@"初七",""),
NSLocalizedString(@"初八",""),
NSLocalizedString(@"初九",""),
NSLocalizedString(@"初十",""),
NSLocalizedString(@"十一",""),
NSLocalizedString(@"十二",""),
NSLocalizedString(@"十三",""),
NSLocalizedString(@"十四",""),
NSLocalizedString(@"十五",""),
NSLocalizedString(@"十六",""),
NSLocalizedString(@"十七",""),
NSLocalizedString(@"十八",""),
NSLocalizedString(@"十九",""),
NSLocalizedString(@"二十",""),
NSLocalizedString(@"廿一",""),
NSLocalizedString(@"廿二",""),
NSLocalizedString(@"廿三",""),
NSLocalizedString(@"廿四",""),
NSLocalizedString(@"廿五",""),
NSLocalizedString(@"廿六",""),
NSLocalizedString(@"廿七",""),
NSLocalizedString(@"廿八",""),
NSLocalizedString(@"廿九",""),
NSLocalizedString(@"三十","")];
return _dayArray;
}
- (NSArray *) ganArray
{
if (!_ganArray)
_ganArray = @[
NSLocalizedString(@"甲",""),
NSLocalizedString(@"乙",""),
NSLocalizedString(@"丙",""),
NSLocalizedString(@"丁",""),
NSLocalizedString(@"戊",""),
NSLocalizedString(@"己",""),
NSLocalizedString(@"庚",""),
NSLocalizedString(@"辛",""),
NSLocalizedString(@"壬",""),
NSLocalizedString(@"癸","")];
return _ganArray;
}
- (NSArray *) zhiArray
{
if (!_zhiArray)
_zhiArray = @[
NSLocalizedString(@"子",""),
NSLocalizedString(@"丑",""),
NSLocalizedString(@"寅",""),
NSLocalizedString(@"卯",""),
NSLocalizedString(@"辰",""),
NSLocalizedString(@"巳",""),
NSLocalizedString(@"午",""),
NSLocalizedString(@"未",""),
NSLocalizedString(@"申",""),
NSLocalizedString(@"酉",""),
NSLocalizedString(@"戌",""),
NSLocalizedString(@"亥","")];
return _zhiArray;
}
- (NSArray *) zodiacArray
{
if (!_zodiacArray)
_zodiacArray = @[
NSLocalizedString(@"鼠",""),
NSLocalizedString(@"牛",""),
NSLocalizedString(@"虎",""),
NSLocalizedString(@"兔",""),
NSLocalizedString(@"龙",""),
NSLocalizedString(@"蛇",""),
NSLocalizedString(@"马",""),
NSLocalizedString(@"羊",""),
NSLocalizedString(@"猴",""),
NSLocalizedString(@"鸡",""),
NSLocalizedString(@"狗",""),
NSLocalizedString(@"猪","")];
return _zodiacArray;
}
- (NSArray *) solarTerm
{
if (!_solarTerm)
_solarTerm = @[
NSLocalizedString(@"立春",""),
NSLocalizedString(@"雨水",""),
NSLocalizedString(@"清明",""),
NSLocalizedString(@"春分",""),
NSLocalizedString(@"惊蛰",""),
NSLocalizedString(@"谷雨",""),
NSLocalizedString(@"立夏",""),
NSLocalizedString(@"小满",""),
NSLocalizedString(@"芒种",""),
NSLocalizedString(@"夏至",""),
NSLocalizedString(@"小暑",""),
NSLocalizedString(@"大暑",""),
NSLocalizedString(@"立秋",""),
NSLocalizedString(@"处暑",""),
NSLocalizedString(@"白露",""),
NSLocalizedString(@"秋分",""),
NSLocalizedString(@"寒露",""),
NSLocalizedString(@"霜降",""),
NSLocalizedString(@"立冬",""),
NSLocalizedString(@"小雪",""),
NSLocalizedString(@"大雪",""),
NSLocalizedString(@"冬至",""),
NSLocalizedString(@"小寒",""),
NSLocalizedString(@"大寒","")];
return _solarTerm;
}
- (NSString *) getGanZhiNameForDate:(LibLunarContext *)lunar
{
NSAssert(lunar != NULL, @"lunar not be null");
return [NSString stringWithFormat:@"%@%@",
[self ganArray][lunar->_gan.year],
[self zhiArray][lunar->_zhi.year]];
}
- (NSString *) getGanZhiYearNameForDate:(LibLunarContext *)lunar
{
NSAssert(lunar != NULL, @"lunar not be null");
return [NSString stringWithFormat:@"%@%@%@",
[self ganArray][lunar->_gan.year],
[self zhiArray][lunar->_zhi.year],
YEAR_STR];
}
- (NSString *) getShengXiaoNameForDate:(LibLunarContext *)lunar
{
NSAssert(lunar != NULL, @"lunar should not null");
return [self zodiacArray][lunar->_zhi.year];
}
- (NSString *) getLunarMonthForDate: (LibLunarContext *) lunar
{
NSAssert(lunar != NULL, @"lunar should not null");
NSString *monthStr = [self monthArray][lunar->_lunar.month - 1];
if ([self isLeapMonthForDate:lunar]) {
return [NSString stringWithFormat:@"%@%@",
LEAP_STR,
monthStr];
} else
return monthStr;
}
- (NSString *) getDayNameForDate: (LibLunarContext *) lunar
{
NSAssert(lunar != NULL, @"lunar should not null");
return [self dayArray][lunar->_lunar.day - 1];
}
- (NSString *) getFullLunarStringForDate: (LibLunarContext *) lunar
{
NSAssert(lunar != NULL, @"lunar should not null");
return [NSString stringWithFormat:@"%@%@%@%@", [self getGanZhiNameForDate:lunar],
YEAR_STR, [self getLunarMonthForDate:lunar],
[self getDayNameForDate:lunar] ];
}
- (NSString *) getLeapString
{
return LEAP_STR;
}
- (BOOL) isLeapMonthForDate: (LibLunarContext *) lunar
{
NSAssert(lunar != NULL, @"lunar should not null");
return lunar->_lunar.leap == 1;
}
@end

View File

@ -1,45 +0,0 @@
//
// SSLunarDateHoliday.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-20.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import <Foundation/Foundation.h>
#import "SSLunarDate.h"
#import "SSHolidayManager.h"
#import "libLunar.h"
@interface SSLunarDateHoliday : NSObject
+(id) sharedSSLunarDateHoliday;
- (NSString *) getQingmingDate: (int) solarYear;
- (NSString *) getDongzhiDate: (int) solarYear;
- (BOOL) isDateLunarHoliday:(LibLunarContext *) lunar region:(SSHolidayRegion) region;
- (NSString *) getLunarHolidayNameForDate: (LibLunarContext *) lunar region:(SSHolidayRegion) region;
+ (NSString *) convertIndexFrom:(int) month day: (int) day;
@end

View File

@ -1,199 +0,0 @@
//
// SSLunarDateHoliday.m
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-20.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#import "SSLunarDateHoliday.h"
@interface SSLunarDateHoliday()
{
NSDictionary *_lunarHoliday;
}
@end
static SSLunarDateHoliday *_sslunarholiday = NULL;
@implementation SSLunarDateHoliday
+(id) sharedSSLunarDateHoliday
{
@synchronized([SSLunarDateHoliday class]) {
if (!_sslunarholiday)
_sslunarholiday = [[self alloc] init];
return _sslunarholiday;
}
return nil;
}
+ (id)alloc
{
@synchronized([SSLunarDateHoliday class]) {
NSAssert(_sslunarholiday == NULL, @"attempt second sslunarHoliday object");
if (!_sslunarholiday)
_sslunarholiday = [super alloc];
return _sslunarholiday;
}
return nil;
}
#define QINGMING_STR NSLocalizedString(@"清明节","")
- (NSDictionary *) lunarHolidayChina
{
if (!_lunarHoliday)
_lunarHoliday = @{
@"0101":NSLocalizedString(@"春节",""),
@"0115":NSLocalizedString(@"元宵节",""),
// Qing ming
@"0505":NSLocalizedString(@"端午节",""),
@"0707":NSLocalizedString(@"七夕",""),
@"0815":NSLocalizedString(@"中秋节",""),
@"0909":NSLocalizedString(@"重阳节",""),
// dong zhi
@"1208":NSLocalizedString(@"腊八",""),
@"1230":NSLocalizedString(@"除夕","")
// FIXME: 2013's Chu Xi is error!!!!
};
return _lunarHoliday;
}
+ (NSString *) getPaddingStringForInt:(int) n
{
return [NSString stringWithFormat:@"%@%d", (n < 10 ? @"0" : @""), n];
}
// Note about qingming:
// http://blog.csdn.net/soft_newcoder/article/details/6127261
- (NSString *) getQingmingDate: (int) solarYear
{
double c = 0.0f;
double d = 0.2422;
if (solarYear >= 1900 && solarYear <= 1999)
c = 5.59;
else if (solarYear >= 2000 && solarYear <= 2099)
c = 4.81;
else
return @"";
int date = ((solarYear % 100) * d + c ) - ((solarYear % 100) / 4);
return [NSString stringWithFormat:@"040%d", date];
}
// Note about Dongzhi & Xiazhi
// http://www.360doc.com/content/10/0424/23/963854_24736431.shtml
#define DONGZHI_STR NSLocalizedString(@"冬至","")
- (NSString *) getDongzhiDate: (int) solarYear
{
double c = 0.0f;
double d = 0.2422;
if (solarYear >= 1900 && solarYear <= 1999)
c = 22.60f;
else if (solarYear >= 2000 && solarYear <= 2099)
c = 21.94;
else
return @"";
int y = solarYear % 100;
int date = (y * d + c) - (y / 4);
if (solarYear == 1918 || solarYear == 2021)
date -= 1;
return [NSString stringWithFormat:@"12%d", date];
}
+ (NSString *) convertIndexFrom:(int) month day: (int) day
{
NSString *index;
index = [NSString stringWithFormat:@"%@%@",
[self.class getPaddingStringForInt:month],
[self.class getPaddingStringForInt:day]];
return index;
}
- (BOOL) isDateLunarHoliday:(LibLunarContext *) lunar region:(SSHolidayRegion) region
{
NSAssert(lunar != NULL, @"lunar should not null");
NSString *index;
// Leap month is not holiday...
if (lunar->_lunar.leap == 1)
return NO;
index = [self.class convertIndexFrom:lunar->_lunar.month
day:lunar->_lunar.day];
if (region == SSHolidayRegionChina)
return [self isDateLunarHolidayChina:lunar index:index];
return NO;
}
- (NSString *) getLunarHolidayNameForDate: (LibLunarContext *) lunar region:(SSHolidayRegion) region
{
NSAssert(lunar != NULL, @"lunar should not null");
if (![self isDateLunarHoliday:lunar region:region])
return nil;
NSString *index = [self.class convertIndexFrom:lunar->_lunar.month
day:lunar->_lunar.day];
if (region == SSHolidayRegionChina)
return [self getLunarHolidayNameForDateChina:lunar index:index];
return nil;
}
- (BOOL) isDateLunarHolidayChina:(LibLunarContext *) lunar index:(NSString *)index
{
if ([[self lunarHolidayChina] objectForKey:index] != nil)
return YES;
if ([index isEqualToString:[self getQingmingDate:lunar->_solar.year]])
return YES;
if ([index isEqualToString:[self getDongzhiDate:lunar->_solar.year]])
return YES;
return NO;
}
- (NSString *) getLunarHolidayNameForDateChina:(LibLunarContext *)lunar index:(NSString *)index
{
if ([index isEqualToString:[self getQingmingDate:lunar->_solar.year]])
return QINGMING_STR;
if ([index isEqualToString:[self getDongzhiDate:lunar->_solar.year]])
return DONGZHI_STR;
NSString *name = [[self lunarHolidayChina] objectForKey:index];
return name;
}
@end

View File

@ -1,49 +0,0 @@
//
// SSLunarDateType.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-7.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef SSLunarDate_SSLunarDateType_h
#define SSLunarDate_SSLunarDateType_h
typedef struct {
int year, month, day, hour, weekday;
int leap; /* the lunar month is a leap month */
} SSLunarSimpleDate;
#define Cyear 1900 /* Note that LC1900.1.1 is SC1900.1.31 */
#define Nyear 150 /* number of years covered by the table */
#define Nmonth 13 /* maximum number of months in a lunar year */
typedef struct LibLunarContext {
SSLunarSimpleDate _solar;
SSLunarSimpleDate _lunar;
SSLunarSimpleDate _gan;
SSLunarSimpleDate _zhi;
SSLunarSimpleDate _gan2;
SSLunarSimpleDate _zhi2;
SSLunarSimpleDate _lunar2;
int _ymonth[Nyear];
int _yday[Nyear];
int _mday[Nmonth + 1];
int _jieAlert;
} LibLunarContext;
#endif

View File

@ -1,880 +0,0 @@
//
// libLunar.c
// SSLunarDate
// Copyright (C) 2013 Zhang Jiejing
//
// This lib is modify from Lunar conversion program by Fung F.Lee and Ricky Yeung
// Because orignally work is not thread safe, I have modify the program to
// make it thread safe.
// Following is the copyright of orignial program.
//
/*
Lunar 2.2: A Calendar Conversion Program
for
Gregorian Solar Calendar and Chinese Lunar Calendar
---------------------------------------------------
# Copyright (C) 1988,1989,1991,1992,2001 Fung F. Lee and Ricky Yeung
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# Revision History:
# The last version of this program was released on July 23, 1992 as
# version 2.1a. This program was first released under the terms of
# GNU GPL on October 28, 2001 as version 2.2. Both versions are identical
# except for the license text.
#
#
# Please send your comments and suggestions to the authors:
# Fung F. Lee lee@umunhum.stanford.edu
# Ricky Yeung cryeung@hotmail.com
#
# The special "bitmap" file "lunar.bitmap" was contributed
# by Weimin Liu (weimin@alpha.ece.jhu.edu).
#
# Special thanks to Hwei Chen Ti (chetihc@nuscc.nus.sg or
# chetihc@nusvm.bitnet) who extended the tables from 2001 to 2049.
#
----------------------------------------------------------------------------*/
/*
This document contains Highest-bit-set GuoBiao (HGB) code, as adopted by
CCDOS on IBM PC compatibles, ChineseTalk 6.0 (GB version) on Macintosh,
and cxterm on UNIX and X window. Hence, one may need to transfer this
document as a **binary** file.
References:
1. "Zhong1guo2 yin1yang2 ri4yue4 dui4zhao4 wan4nian2li4" by Lin2 Qi3yuan2.
2. "Ming4li3 ge2xin1 zi3ping2 cui4yan2" by Xu2 Le4wu2.
3. Da1zhong4 wan4nian2li4.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "libLunar.h"
#define VALID_MIN_YEAR 1900
#define VALID_MAX_YEAR 2049
static SSLunarSimpleDate SolarFirstDate = {
/* Wednesday, 12 a.m., 31 January, 1900 */
1900, 1, 31, 0, 3, 0
};
static SSLunarSimpleDate LunarFirstDate = {
/* Wednesday, 12 a.m., First day, First month, 1900 */
1900, 1, 1, 0, 3, 0
};
static SSLunarSimpleDate GanFirstDate = {
/* geng1-nian2 wu4-yue4 jia3-ri4 jia3-shi2 */
6, 4, 0, 0, 3, 0
};
static SSLunarSimpleDate ZhiFirstDate = {
/* zi3-nian2 yin2-yue4 chen2-ri4 zi3-shi2 */
0, 2, 4, 0, 3, 0
};
static long yearInfo[Nyear] = {
/* encoding:
b bbbbbbbbbbbb bbbb
bit# 1 111111000000 0000
6 543210987654 3210
. ............ ....
month# 000000000111
M 123456789012 L
b_j = 1 for long month, b_j = 0 for short month
L is the leap month of the year if 1<=L<=12; NO leap month if L = 0.
The leap month (if exists) is long one iff M = 1.
*/
0x04bd8, /* 1900 */
0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, /* 1905 */
0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, /* 1910 */
0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, /* 1915 */
0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, /* 1920 */
0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, /* 1925 */
0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, /* 1930 */
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, /* 1935 */
0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, /* 1940 */
0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, /* 1945 */
0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, /* 1950 */
0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, /* 1955 */
0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, /* 1960 */
0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, /* 1965 */
0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, /* 1970 */
0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, /* 1975 */
0x0d558, 0x0b540, 0x0b5a0, 0x195a6, 0x095b0, /* 1980 */
0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, /* 1985 */
0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, /* 1990 */
0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, /* 1995 */
0x05ac0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, /* 2000 */
0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, /* 2005 */
0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, /* 2010 */
0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, /* 2015 */
0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, /* 2020 */
0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, /* 2025 */
0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, /* 2030 */
0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, /* 2035 */
0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, /* 2040 */
0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, /* 2045 */
0x0aa50, 0x1b255, 0x06d20, 0x0ada0 /* 2049 */
};
/*
In "4-column" calculation, a "mingli" (fortune-telling) calculation,
the beginning of a month is not the first day of the month as in
the Lunar Calendar; it is instead governed by "jie2" (festival).
Interestingly, in the Solar calendar, a jie always comes around certain
day. For example, the jie "li4chun1" (beginning of spring) always comes
near Feburary 4 of the Solar Calendar.
Meaning of array fest:
Each element, fest[i][j] stores the jie day (in term of the following Solar
month) of the lunar i-th year, j-th month.
For example, in 1992, fest[92][0] is 4, that means the jie "li4chun1"
(beginning of spring) is on Feb. 4, 1992; fest[92][11] is 5, that means
the jie of the 12th lunar month is on Jan. 5, 1993.
*/
typedef char byte;
static byte fest[Nyear][12] = {
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1900 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1901 */
{5, 6, 6, 6, 7, 8, 8, 8, 9, 8, 8, 6}, /* 1902 */
{5, 7, 6, 7, 7, 8, 9, 9, 9, 8, 8, 7}, /* 1903 */
{5, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1904 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1905 */
{5, 6, 6, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1906 */
{5, 7, 6, 7, 7, 8, 9, 9, 9, 8, 8, 7}, /* 1907 */
{5, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1908 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1909 */
{5, 6, 6, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1910 */
{5, 7, 6, 7, 7, 8, 9, 9, 9, 8, 8, 7}, /* 1911 */
{5, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1912 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1913 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1914 */
{5, 6, 6, 6, 7, 8, 8, 9, 9, 8, 8, 6}, /* 1915 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1916 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 7, 6}, /* 1917 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1918 */
{5, 6, 6, 6, 7, 8, 8, 9, 9, 8, 8, 6}, /* 1919 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1920 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 9, 7, 6}, /* 1921 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1922 */
{5, 6, 6, 6, 7, 8, 8, 9, 9, 8, 8, 6}, /* 1923 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1924 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 7, 6}, /* 1925 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1926 */
{5, 6, 6, 6, 7, 8, 8, 8, 9, 8, 8, 6}, /* 1927 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1928 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1929 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1930 */
{5, 6, 6, 6, 7, 8, 8, 8, 9, 8, 8, 6}, /* 1931 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1932 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1933 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1934 */
{5, 6, 6, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1935 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1936 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1937 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1938 */
{5, 6, 6, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1939 */
{5, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1940 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1941 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1942 */
{5, 6, 6, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1943 */
{5, 6, 5, 5, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1944 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1945 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1946 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1947 */
{5, 5, 5, 5, 6, 7, 7, 8, 8, 7, 7, 5}, /* 1948 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1949 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1950 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1951 */
{5, 5, 5, 5, 6, 7, 7, 8, 8, 7, 7, 5}, /* 1952 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1953 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 7, 6}, /* 1954 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1955 */
{5, 5, 5, 5, 6, 7, 7, 8, 8, 7, 7, 5}, /* 1956 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1957 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1958 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1959 */
{5, 5, 5, 5, 6, 7, 7, 7, 8, 7, 7, 5}, /* 1960 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1961 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1962 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1963 */
{5, 5, 5, 5, 6, 7, 7, 7, 8, 7, 7, 5}, /* 1964 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1965 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1966 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1967 */
{5, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1968 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1969 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1970 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1971 */
{5, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1972 */
{4, 6, 5, 5, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1973 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1974 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1975 */
{5, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1976 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 1977 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1978 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1979 */
{5, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1980 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 1981 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1982 */
{4, 6, 5, 6, 6, 8, 8, 8, 9, 8, 8, 6}, /* 1983 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1984 */
{5, 5, 5, 5, 5, 8, 7, 7, 8, 7, 7, 5}, /* 1985 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1986 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1987 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1988 */
{5, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1989 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 1990 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1991 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1992 */
{5, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1993 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1994 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1995 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1996 */
{5, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 1997 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 1998 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 1999 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2000 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2001 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 2002 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 2003 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2004 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2005 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2006 */
{4, 6, 5, 6, 6, 7, 8, 8, 9, 8, 7, 6}, /* 2007 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2008 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2009 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2010 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 2011 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2012 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2013 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2014 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 2015 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2016 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2017 */
{4, 5, 5, 5, 6, 7, 7, 8, 8, 7, 7, 5}, /* 2018 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 2019 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 7, 5}, /* 2020 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2021 */
{4, 5, 5, 5, 6, 7, 7, 7, 8, 7, 7, 5}, /* 2022 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 8, 7, 6}, /* 2023 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 6, 5}, /* 2024 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2025 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2026 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 2027 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 6, 5}, /* 2028 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2029 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2030 */
{4, 6, 5, 6, 6, 7, 8, 8, 8, 7, 7, 6}, /* 2031 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 6, 5}, /* 2032 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2033 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2034 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2035 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 6, 5}, /* 2036 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2037 */
{4, 5, 5, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2038 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2039 */
{4, 5, 4, 5, 5, 6, 7, 7, 8, 7, 6, 5}, /* 2040 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2041 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2042 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2043 */
{4, 5, 4, 5, 5, 6, 7, 7, 7, 7, 6, 5}, /* 2044 */
{3, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2045 */
{4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5}, /* 2046 */
{4, 6, 5, 5, 6, 7, 7, 8, 8, 7, 7, 6}, /* 2047 */
{4, 5, 4, 5, 5, 6, 7, 7, 7, 7, 6, 5}, /* 2048 */
{3, 5, 4, 5, 5, 6, 7, 7, 8, 7, 7, 5} /* 2049 */
};
static const int daysInSolarMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static int moon[2] = {29,30}; /* a short (long) lunar month has 29 (30) days */
#if 0
static char *Gan[] = {
"Jia3", "Yi3", "Bing3", "Ding1", "Wu4",
"Ji3", "Geng1", "Xin1", "Ren2", "Gui3"
};
static char *Zhi[] = {
"Zi3", "Chou3", "Yin2", "Mao3", "Chen2", "Si4",
"Wu3", "Wei4", "Shen1", "You3", "Xu1", "Hai4"
};
static char *ShengXiao[] = {
"Mouse", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"
};
static char *weekday[] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
static char *GanGB[] = {
"", "", "", "", "",
"", "", "", "", ""
};
static char *ZhiGB[] = {
"", "", "", "", "", "",
"", "", "", "", "", ""
};
static char *ShengXiaoGB[] = {
"", "", "", "", "", "",
"", "", "", "", "", ""
};
static char *weekdayGB[] = {
"", "", "", "",
"", "", ""
};
#endif
//Date _solar, _lunar, gan, zhi, gan2, zhi2, _lunar2;
//int ymonth[Nyear]; /* number of lunar months in the years */
//int yday[Nyear]; /* number of lunar days in the years */
//int mday[Nmonth+1]; /* number of days in the months of the lunar year */
int jieAlert; /* if there is uncertainty in JieQi calculation */
int showHZ = 0; /* output in hanzi */
char *progname;
long Solar2Day(SSLunarSimpleDate *d);
long Solar2Day1(SSLunarSimpleDate *d);
long Lunar2Day(LibLunarContext *ctx, SSLunarSimpleDate *d);
void Day2Lunar(LibLunarContext *ctx, long offset);
void Day2Solar(LibLunarContext *ctx, long offset);
int make_yday(LibLunarContext *ctx);
int make_mday(LibLunarContext *ctx, int year);
int GZcycle();
void CalGZ();
int JieDate(), JieDate();
void Report(SSLunarSimpleDate *, SSLunarSimpleDate *, SSLunarSimpleDate *), ReportE();
void ReportGB(SSLunarSimpleDate *solar, SSLunarSimpleDate *lunar, SSLunarSimpleDate *lunar2);
void usage(), Error();
int CmpDate(int month1, int day1, int month2, int day2);
struct LibLunarContext * createLunarContext()
{
struct LibLunarContext *ctx;
ctx = malloc(sizeof(struct LibLunarContext));
if (ctx == NULL)
return NULL;
memset(ctx, 0, sizeof(*ctx));
return ctx;
}
void freeLunarContext(struct LibLunarContext *context)
{
free(context);
}
SSLunarSimpleDate *getSolarDate(LibLunarContext *ctx)
{
if (ctx != NULL)
return &ctx->_solar;
return NULL;
}
SSLunarSimpleDate *getLunarDate(LibLunarContext *ctx)
{
if (ctx != NULL)
return &ctx->_lunar;
return NULL;
}
int libLunarCheckYearRange(int year)
{
if (year >= VALID_MIN_YEAR && year <= VALID_MAX_YEAR)
return 1;
else
return 0;
}
void Solar2Lunar(struct LibLunarContext *ctx,
SSLunarSimpleDate *solar)
{
long offset;
if (ctx == NULL) {
fprintf(stderr, "Soloar2Lunar: ctx pointer cannot be NULL");
return;
}
if (!libLunarCheckYearRange(solar->year)) {
fprintf(stderr, "Solar2Lunar: the year provide exceeds lib's ablility.");
return;
}
offset = Solar2Day(solar);
solar->weekday = (offset + SolarFirstDate.weekday) % 7;
/* A lunar day begins at 11 p.m. */
if (solar->hour == 23)
offset++;
Day2Lunar(ctx, offset);
ctx->_lunar.hour = solar->hour;
CalGZ(offset, &ctx->_lunar, &ctx->_gan, &ctx->_zhi);
jieAlert = JieDate(solar, &ctx->_lunar2);
ctx->_lunar2.day = ctx->_lunar.day;
ctx->_lunar2.hour = ctx->_lunar.hour;
CalGZ(offset, &ctx->_lunar2, &ctx->_gan2, &ctx->_zhi2);
}
void Lunar2Solar(struct LibLunarContext *ctx, SSLunarSimpleDate *lunar)
{
long offset;
int adj;
if (ctx == NULL) {
fprintf(stderr, "Lunar2Solar: ctx pointer cannot be NULL");
return;
}
/* A solar day begins at 12 a.m. */
adj = (ctx->_lunar.hour == 23)? -1 : 0;
offset = Lunar2Day(ctx, &ctx->_lunar);
ctx->_solar.weekday = (offset+ adj + SolarFirstDate.weekday) % 7;
Day2Solar(ctx, offset + adj);
ctx->_solar.hour = lunar->hour;
CalGZ(offset, lunar, &ctx->_gan, &ctx->_zhi);
jieAlert = JieDate(&ctx->_solar, &ctx->_lunar2);
ctx->_lunar2.day = lunar->day;
ctx->_lunar2.hour = lunar->hour;
CalGZ(offset, &ctx->_lunar2, &ctx->_gan2, &ctx->_zhi2);
}
#define LeapYear(y) (((y)%4==0) && ((y)%100!=0) || ((y)%400==0))
#define BYEAR 1201
/* BYEAR % 4 == 1 and BYEAR % 400 == 1 for easy calculation of leap years */
/* assert(BYEAR <= SolarFirstDate.year) */
long Solar2Day(SSLunarSimpleDate *d)
{
return (Solar2Day1(d) - Solar2Day1(&SolarFirstDate));
}
/* Compute the number of days from the Solar date BYEAR.1.1 */
long Solar2Day1(SSLunarSimpleDate *d)
{
long offset, delta;
int i;
delta = d->year - BYEAR;
if (delta<0) Error("Internal error: pick a larger constant for BYEAR.");
offset = delta * 365 + delta / 4 - delta / 100 + delta / 400;
for (i=1; i< d->month; i++)
offset += daysInSolarMonth[i];
if ((d->month > 2) && LeapYear(d->year))
offset++;
offset += d->day - 1;
if ((d->month == 2) && LeapYear(d->year))
{
if (d->day > 29) Error("Day out of range.");
}
else if (d->day > daysInSolarMonth[d->month]) Error("Day out of range.");
return offset;
}
/* Compute offset days of a lunar date from the beginning of the table */
long Lunar2Day(LibLunarContext *ctx, SSLunarSimpleDate *d)
{
long offset = 0;
int year, i, m, leapMonth;
year = d->year - LunarFirstDate.year;
for (i=0; i<year; i++)
offset += ctx->_yday[i];
leapMonth = make_mday(ctx, year);
if ((d->leap) && (leapMonth!=d->month))
{
printf("%d is not a leap month in year %d.\n", d->month, d->year);
exit(1);
}
for (m=1; m<d->month; m++)
offset += ctx->_mday[m];
if (leapMonth &&
((d->month>leapMonth) || (d->leap && (d->month==leapMonth))))
offset += ctx->_mday[m++];
offset += d->day - 1;
if (d->day > ctx->_mday[m]) Error("Day out of range.");
return offset;
}
void Day2Lunar(LibLunarContext *ctx,
long offset)
{
int i, m, nYear, leapMonth;
SSLunarSimpleDate *d = &ctx->_lunar;
nYear = make_yday(ctx);
for (i = 0; i < nYear && offset > 0; i++)
offset -= ctx->_yday[i];
// reduce each year day, try to get which year of current year is.
/* if the year less zero, means that year not really come year, */
if (offset<0)
offset += ctx->_yday[--i];
if (i >= Nyear) Error("Year out of range.");
/* so, the year is the current year + i */
d->year = i + LunarFirstDate.year;
leapMonth = make_mday(ctx, i);
for (m=1; m<=Nmonth && offset>0; m++)
offset -= ctx->_mday[m];
if (offset<0)
offset += ctx->_mday[--m];
d->leap = 0; /* don't know leap or not yet */
if (leapMonth>0) /* has leap month */
{
/* if preceeding month number is the leap month,
this month is the actual extra leap month */
d->leap = (leapMonth == (m - 1));
/* month > leapMonth is off by 1, so adjust it */
if (m > leapMonth) --m;
}
d->month = m;
d->day = (int)offset + 1;
}
void Day2Solar(LibLunarContext *ctx,
long offset)
{
int i, m, days;
SSLunarSimpleDate *d = &ctx->_solar;
/* offset is the number of days from SolarFirstDate */
offset -= Solar2Day(&LunarFirstDate); /* the argument is negative */
/* offset is now the number of days from SolarFirstDate.year.1.1 */
for (i=SolarFirstDate.year;
(i<SolarFirstDate.year+Nyear) && (offset > 0); i++)
offset -= 365 + LeapYear(i);
if (offset<0)
{
--i; /* LeapYear is a macro */
offset += 365 + LeapYear(i);
}
if (i==(SolarFirstDate.year + Nyear)) Error("Year out of range.");
d->year = i;
/* assert(offset<(365+LeapYear(i))); */
for (m=1; m<=12; m++)
{
days = daysInSolarMonth[m];
if ((m==2) && LeapYear(i)) /* leap February */
days++;
if (offset<days)
{
d->month = m;
d->day = (int)offset + 1;
return;
}
offset -= days;
}
}
int GZcycle(int g, int z)
{
int gz;
for (gz = z; gz % 10 != g && gz < 60; gz += 12) ;
if (gz >= 60) printf("internal error\n");
return gz+1;
}
void CalGZ(long offset, SSLunarSimpleDate *d, SSLunarSimpleDate *g, SSLunarSimpleDate *z)
{
int year, month;
year = d->year - LunarFirstDate.year;
month = year * 12 + d->month - 1; /* leap months do not count */
g->year = (GanFirstDate.year + year) % 10;
z->year = (ZhiFirstDate.year + year) % 12;
g->month = (GanFirstDate.month + month) % 10;
z->month = (ZhiFirstDate.month + month) % 12;
g->day = (GanFirstDate.day + offset) % 10;
z->day = (ZhiFirstDate.day + offset) % 12;
z->hour = ((d->hour + 1) / 2) % 12;
g->hour = (g->day * 12 + z->hour) % 10;
}
void Error(s)
char *s;
{
printf("libLunar:%s\n",s);
assert(-1);
// exit(1);
}
/* Compare two dates and return <,=,> 0 if the 1st is <,=,> the 2nd */
int CmpDate(int month1, int day1,int month2,int day2)
{
if (month1!=month2) return(month1-month2);
if (day1!=day2) return(day1-day2);
return(0);
}
/*
Given a solar date, find the "lunar" date for the purpose of
calculating the "4-columns" by taking jie into consideration.
*/
int JieDate(SSLunarSimpleDate *ds, SSLunarSimpleDate *dl)
{
int m, flag = 0;
if (ds->month==1)
{
flag = CmpDate(ds->month, ds->day,
1, fest[ds->year - SolarFirstDate.year - 1][11]);
if (flag<0) dl->month = 11;
else if (flag>0) dl->month = 12;
dl->year = ds->year - 1;
return(flag==0);
}
for (m=2; m<=12; m++)
{
flag = CmpDate(ds->month, ds->day,
m, fest[ds->year - SolarFirstDate.year][m-2]);
if (flag==0) m++;
if (flag<=0) break;
}
dl->month = (m-2) % 12;
dl->year = ds->year;
if ((dl->month)==0)
{
dl->year = ds->year - 1;
dl->month = 12;
}
return(flag==0);
}
/* Compute the number of days in each lunar year in the table */
int make_yday(LibLunarContext *ctx)
{
int year, i, leap;
long code;
for (year = 0; year < Nyear; year++)
{
code = yearInfo[year];
leap = code & 0xf;
ctx->_yday[year] = 0;
if (leap != 0)
{
i = (code >> 16) & 0x1;
ctx->_yday[year] += moon[i];
/* Big month or small month.... got it. Leap month only
* have two day, big month or small month. */
}
code >>= 4;
for (i = 0; i < Nmonth-1; i++)
{
/* 12 months. */
ctx->_yday[year] += moon[code&0x1];
code >>= 1;
}
ctx->_ymonth[year] = 12;
if (leap != 0) ctx->_ymonth[year]++;
}
return Nyear;
}
/* Compute the days of each month in the given lunar year */
int make_mday(LibLunarContext *ctx, int year)
{
int i, leapMonth;
long code;
code = yearInfo[year];
leapMonth = code & 0xf;
/* leapMonth == 0 means no leap month */
code >>= 4;
if (leapMonth == 0)
{
ctx->_mday[Nmonth] = 0;
for (i = Nmonth-1; i >= 1; i--)
{
ctx->_mday[i] = moon[code&0x1];
code >>= 1;
}
}
else
{
/*
There is a leap month (run4 yue4) L in this year.
mday[1] contains the number of days in the 1-st month;
mday[L] contains the number of days in the L-th month;
mday[L+1] contains the number of days in the L-th leap month;
mday[L+2] contains the number of days in the L+1 month, etc.
cf. yearInfo[]: info about the leap month is encoded differently.
*/
i = (yearInfo[year] >> 16) & 0x1;
ctx->_mday[leapMonth+1] = moon[i];
for (i = Nmonth; i >= 1; i--)
{
if (i == leapMonth+1)
i--;
ctx->_mday[i] = moon[code&0x1];
code >>= 1;
}
}
return leapMonth;
}
void Report(SSLunarSimpleDate *solar, SSLunarSimpleDate *lunar, SSLunarSimpleDate *lunar2)
{
if (showHZ)
ReportGB(solar, lunar, lunar2);
else
ReportE(solar, lunar, lunar2);
}
#if 0
void ReportGB(Date *solar, Date *lunar, Date *lunar2)
{
printf("%s%d%s%2d%s%2d%s%2d%s%s%s\n", "阳历: ",
solar->year, "", solar->month, "", solar->day,
"", solar->hour, "时 ",
"星期", weekdayGB[solar->weekday]);
printf("%s%d%s%s%2d%s%2d%s%s%s%s%s\n", "阴历: ",
lunar->year, "", (lunar->leap? "":""),
lunar->month, "", lunar->day, "",
ZhiGB[zhi.hour], "时 ",
"生肖属", ShengXiaoGB[zhi.year]);
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n", "干支: ",
GanGB[gan.year], ZhiGB[zhi.year], "年 ",
GanGB[gan.month], ZhiGB[zhi.month], "月 ",
GanGB[gan.day], ZhiGB[zhi.day], "日 ",
GanGB[gan.hour], ZhiGB[zhi.hour], "时 ");
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
"用四柱神算推算之时辰八字: ",
GanGB[gan2.year], ZhiGB[zhi2.year], "年 ",
GanGB[gan2.month], ZhiGB[zhi2.month], "月 ",
GanGB[gan2.day], ZhiGB[zhi2.day], "日 ",
GanGB[gan2.hour], ZhiGB[zhi2.hour], "时 ");
if (jieAlert)
{
printf("* %s, %s\n", "是日为节",
"月柱可能要修改");
if (lunar2->month==1)
printf("* %s\n", "年柱亦可能要修改");
printf("* %s\n", "请查有节气时间之万年历");
}
}
void ReportE(Date *solar, Date *lunar, Date *lunar2)
{
printf("Solar : %d.%d.%d.%d\t%s\n", solar->year, solar->month, solar->day,
solar->hour, weekday[solar->weekday]);
printf("Lunar : %d.%d%s.%d.%d\tShengXiao: %s\n",
lunar->year, lunar->month, (lunar->leap?"Leap":""), lunar->day,
lunar->hour, ShengXiao[zhi.year] );
printf("GanZhi: %s-%s.%s-%s.%s-%s.%s-%s\n",
Gan[gan.year], Zhi[zhi.year], Gan[gan.month], Zhi[zhi.month],
Gan[gan.day], Zhi[zhi.day], Gan[gan.hour], Zhi[zhi.hour]);
printf(" (GanZhi Order)\t%d-%d.%d-%d.%d-%d.%d-%d\n",
gan.year+1, zhi.year+1, gan.month+1, zhi.month+1,
gan.day+1, zhi.day+1, gan.hour+1, zhi.hour+1);
printf(" (JiaZi Cycle)\t%d.%d.%d.%d\n\n",
GZcycle(gan.year, zhi.year), GZcycle(gan.month, zhi.month),
GZcycle(gan.day, zhi.day), GZcycle(gan.hour, zhi.hour));
printf("BaZi (8-characters) according to 'Four Column Calculation':\n");
printf(" %s-%s.%s-%s.%s-%s.%s-%s\n",
Gan[gan2.year], Zhi[zhi2.year], Gan[gan2.month], Zhi[zhi2.month],
Gan[gan2.day], Zhi[zhi2.day], Gan[gan2.hour], Zhi[zhi2.hour]);
printf(" (GanZhi Order)\t%d-%d.%d-%d.%d-%d.%d-%d\n",
gan2.year+1, zhi2.year+1, gan2.month+1, zhi2.month+1,
gan2.day+1, zhi2.day+1, gan2.hour+1, zhi2.hour+1);
printf(" (JiaZi Cycle)\t%d.%d.%d.%d\n\n",
GZcycle(gan2.year, zhi2.year), GZcycle(gan2.month, zhi2.month),
GZcycle(gan2.day, zhi2.day), GZcycle(gan2.hour, zhi2.hour));
if (jieAlert)
{
printf("* The month column may need adjustment because the date falls on a jie.\n");
if (lunar2->month==1)
printf("* The day column may need adjustment, too.\n");
printf("* Please consult a detailed conversion table.\n");
}
}
#else
void ReportE(SSLunarSimpleDate *solar, SSLunarSimpleDate *lunar, SSLunarSimpleDate *lunar2) {}
void ReportGB(SSLunarSimpleDate *solar, SSLunarSimpleDate *lunar, SSLunarSimpleDate *lunar2) {}
#endif

View File

@ -1,38 +0,0 @@
//
// libLunar.h
// SSLunarDate
//
// Created by Jiejing Zhang on 13-2-6.
// Copyright (c) 2013 Jiejing Zhang. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef SSLunarDate_libLunar_h
#define SSLunarDate_libLunar_h
#include "SSLunarDateType.h"
int libLunarCheckYearRange(int year);
void Lunar2Solar(struct LibLunarContext *ctx, SSLunarSimpleDate *lunar);
void Solar2Lunar(struct LibLunarContext *ctx, SSLunarSimpleDate *solar);
SSLunarSimpleDate *getLunarDate(LibLunarContext *ctx);
SSLunarSimpleDate *getSolarDate(LibLunarContext *ctx);
LibLunarContext * createLunarContext();
void freeLunarContext(struct LibLunarContext *context);
#endif

View File

@ -7,13 +7,13 @@
//
#import "StoryboardExampleViewController.h"
#import "SSLunarDate.h"
#import "CalendarConfigViewController.h"
@interface StoryboardExampleViewController ()
@property (strong, nonatomic) NSCalendar *currentCalendar;
@property (strong, nonatomic) SSLunarDate *lunarDate;
@property (strong, nonatomic) NSCalendar *lunarCalendar;
@property (strong, nonatomic) NSArray *lunarChars;
@end
@ -27,7 +27,10 @@
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
_currentCalendar = [NSCalendar currentCalendar];
_lunarCalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierChinese];
_lunarCalendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
_lunarChars = @[@"初一",@"初二",@"初三",@"初四",@"初五",@"初六",@"初七",@"初八",@"初九",@"初十",@"十一",@"十二",@"十三",@"十四",@"十五",@"十六",@"十七",@"十八",@"十九",@"二十",@"二一",@"二二",@"二三",@"二四",@"二五",@"二六",@"二七",@"二八",@"二九",@"三十"];
_scrollDirection = _calendar.scrollDirection;
_calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase|FSCalendarCaseOptionsWeekdayUsesUpperCase;
@ -74,8 +77,8 @@
if (!_lunar) {
return nil;
}
_lunarDate = [[SSLunarDate alloc] initWithDate:date calendar:_currentCalendar];
return _lunarDate.dayString;
NSInteger day = [_lunarCalendar component:NSCalendarUnitDay fromDate:date];
return _lunarChars[day-1];
}
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date

View File

@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "FSCalendar"
s.version = "1.7.0"
s.version = "1.7.1.beta"
s.summary = "Designed to build the best iOS calendar control."
s.homepage = "https://github.com/WenchaoIOS/FSCalendar"

View File

@ -13,7 +13,7 @@
IB_DESIGNABLE
@interface FSCalendar (IBExtension)
@property (assign, nonatomic) IBInspectable BOOL autoAdjustTitleSize;
@property (assign, nonatomic) IBInspectable BOOL adjustsFontSizeToFitCellSize;
@property (assign, nonatomic) IBInspectable CGFloat titleTextSize;
@property (assign, nonatomic) IBInspectable CGFloat subtitleTextSize;
@property (assign, nonatomic) IBInspectable CGFloat weekdayTextSize;
@ -53,6 +53,7 @@ IB_DESIGNABLE
@property (assign, nonatomic) IBInspectable NSInteger fakedSelectedDay;
// Deprecated
@property (assign, nonatomic) IBInspectable FSCalendarCellStyle cellStyle FSCalendarDeprecated("use \'cellShape\' instead");
@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated("use \'cellShape\' instead");
@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated("use \'adjustsFontSizeToFitCellSize\' instead");
@end

View File

@ -10,65 +10,16 @@
@implementation FSCalendar (IBExtension)
#pragma mark - autoAdjustTitleSize
#pragma mark - adjustsFontSizeToFitCellSize
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
- (void)setAdjustsFontSizeToFitCellSize:(BOOL)adjustsFontSizeToFitCellSize
{
self.appearance.autoAdjustTitleSize = autoAdjustTitleSize;
self.appearance.adjustsFontSizeToFitCellSize = adjustsFontSizeToFitCellSize;
}
- (BOOL)autoAdjustTitleSize
- (BOOL)adjustsFontSizeToFitCellSize
{
return self.appearance.autoAdjustTitleSize;
}
#pragma mark - titleTextSize
- (void)setTitleTextSize:(CGFloat)titleTextSize
{
self.appearance.titleTextSize = titleTextSize;
}
- (CGFloat)titleTextSize
{
return self.appearance.titleTextSize;
}
#pragma mark - subtitleTextSize
- (void)setSubtitleTextSize:(CGFloat)subtitleTextSize
{
self.appearance.subtitleTextSize = subtitleTextSize;
}
- (CGFloat)subtitleTextSize
{
return self.appearance.subtitleTextSize;
}
#pragma mark - weekdayTextSize
- (void)setWeekdayTextSize:(CGFloat)weekdayTextSize
{
self.appearance.weekdayTextSize = weekdayTextSize;
}
- (CGFloat)weekdayTextSize
{
return self.appearance.weekdayTextSize;
}
#pragma mark - headerTitleTextSize
- (void)setHeaderTitleTextSize:(CGFloat)headerTitleTextSize
{
self.appearance.headerTitleTextSize = headerTitleTextSize;
}
- (CGFloat)headerTitleTextSize
{
return self.appearance.headerTitleTextSize;
return self.appearance.adjustsFontSizeToFitCellSize;
}
#pragma mark - eventColor
@ -377,6 +328,65 @@
return (FSCalendarCellStyle)self.appearance.cellShape;
}
#pragma mark - autoAdjustTitleSize
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
{
self.appearance.adjustsFontSizeToFitCellSize = autoAdjustTitleSize;
}
- (BOOL)autoAdjustTitleSize
{
return self.appearance.adjustsFontSizeToFitCellSize;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (void)setTitleTextSize:(CGFloat)titleTextSize
{
self.appearance.titleTextSize = titleTextSize;
}
- (CGFloat)titleTextSize
{
return self.appearance.titleTextSize;
}
- (void)setSubtitleTextSize:(CGFloat)subtitleTextSize
{
self.appearance.subtitleTextSize = subtitleTextSize;
}
- (CGFloat)subtitleTextSize
{
return self.appearance.subtitleTextSize;
}
- (void)setWeekdayTextSize:(CGFloat)weekdayTextSize
{
self.appearance.weekdayTextSize = weekdayTextSize;
}
- (CGFloat)weekdayTextSize
{
return self.appearance.weekdayTextSize;
}
- (void)setHeaderTitleTextSize:(CGFloat)headerTitleTextSize
{
self.appearance.headerTitleTextSize = headerTitleTextSize;
}
- (CGFloat)headerTitleTextSize
{
return self.appearance.headerTitleTextSize;
}
#pragma GCC diagnostic pop
@end

View File

@ -152,8 +152,8 @@
_calendar = [NSCalendar currentCalendar];
_components = [[NSDateComponents alloc] init];
_formatter = [[NSDateFormatter alloc] init];
_timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
_locale = [NSLocale currentLocale];
_timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
_firstWeekday = 1;
[self invalidateDateTools];
@ -828,7 +828,7 @@
if (self.hasValidateVisibleLayout) {
[self reloadData];
}
[self scrollToPageForDate:_today animated:YES];
[self scrollToPageForDate:_today animated:NO];
}
}
@ -999,7 +999,7 @@
[self reloadVisibleCells];
}
[_weekdays setValue:[UIFont systemFontOfSize:_appearance.weekdayTextSize] forKey:@"font"];
[_weekdays setValue:_appearance.preferredWeekdayFont forKey:@"font"];
[self invalidateHeaders];
[self invalidateWeekdaySymbols];
}
@ -1353,7 +1353,7 @@
{
if (!_collectionView.tracking) {
if (!self.floatingMode) {
if ([self isDateInDifferentPage:date]) {
if ([self isDateInDifferentPage:date] && [self isDateInRange:date]) {
[self willChangeValueForKey:@"currentPage"];
switch (_scope) {
case FSCalendarScopeMonth: {
@ -1538,7 +1538,7 @@
if (!_weekdays.count) {
NSArray *weekSymbols = self.calendar.shortStandaloneWeekdaySymbols;
_weekdays = [NSMutableArray arrayWithCapacity:weekSymbols.count];
UIFont *weekdayFont = [UIFont systemFontOfSize:_appearance.weekdayTextSize];
UIFont *weekdayFont = _appearance.preferredWeekdayFont;
for (int i = 0; i < weekSymbols.count; i++) {
UILabel *weekdayLabel = [[UILabel alloc] initWithFrame:CGRectZero];
weekdayLabel.text = weekSymbols[i];

View File

@ -36,10 +36,13 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
@interface FSCalendarAppearance : NSObject
@property (assign, nonatomic) CGFloat titleTextSize;
@property (assign, nonatomic) CGFloat subtitleTextSize;
@property (assign, nonatomic) CGFloat weekdayTextSize;
@property (assign, nonatomic) CGFloat headerTitleTextSize;
@property (strong, nonatomic) UIFont *titleFont;
@property (strong, nonatomic) UIFont *subtitleFont;
@property (strong, nonatomic) UIFont *weekdayFont;
@property (strong, nonatomic) UIFont *headerTitleFont;
@property (assign, nonatomic) CGFloat titleVerticalOffset;
@property (assign, nonatomic) CGFloat subtitleVerticalOffset;
@property (strong, nonatomic) UIColor *eventColor;
@property (strong, nonatomic) UIColor *weekdayTextColor;
@ -64,12 +67,12 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
@property (strong, nonatomic) UIColor *todayColor;
@property (strong, nonatomic) UIColor *todaySelectionColor;
@property (strong, nonatomic) UIColor *borderDefaultColor;
@property (strong, nonatomic) UIColor *borderSelectionColor;
@property (strong, nonatomic) UIColor *borderDefaultColor;
@property (strong, nonatomic) UIColor *borderSelectionColor;
@property (assign, nonatomic) FSCalendarCellShape cellShape;
@property (assign, nonatomic) FSCalendarCaseOptions caseOptions;
@property (assign, nonatomic) BOOL autoAdjustTitleSize;
@property (assign, nonatomic) BOOL adjustsFontSizeToFitCellSize;
// For preview only
@property (assign, nonatomic) BOOL fakeSubtitles;
@ -83,9 +86,14 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated("use \'cellShape\' instead");
@property (assign, nonatomic) BOOL useVeryShortWeekdaySymbols FSCalendarDeprecated("use \'caseOptions\' instead");
@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated("use \'adjustFontSizeToFitCellSize\' instead");
@property (assign, nonatomic) CGFloat titleTextSize FSCalendarDeprecated("use \'titleFont\' instead");
@property (assign, nonatomic) CGFloat subtitleTextSize FSCalendarDeprecated("use \'subtitleFont\' instead");
@property (assign, nonatomic) CGFloat weekdayTextSize FSCalendarDeprecated("use \'weekdayFont\' instead");
@property (assign, nonatomic) CGFloat headerTitleTextSize FSCalendarDeprecated("use \'headerTitleFont\' instead");
@end

View File

@ -19,6 +19,26 @@
@property (strong, nonatomic) NSMutableDictionary *subtitleColors;
@property (strong, nonatomic) NSMutableDictionary *borderColors;
@property (strong, nonatomic) NSString *titleFontName;
@property (strong, nonatomic) NSString *subtitleFontName;
@property (strong, nonatomic) NSString *weekdayFontName;
@property (strong, nonatomic) NSString *headerTitleFontName;
@property (assign, nonatomic) CGFloat titleFontSize;
@property (assign, nonatomic) CGFloat subtitleFontSize;
@property (assign, nonatomic) CGFloat weekdayFontSize;
@property (assign, nonatomic) CGFloat headerTitleFontSize;
@property (assign, nonatomic) CGFloat preferredTitleFontSize;
@property (assign, nonatomic) CGFloat preferredSubtitleFontSize;
@property (assign, nonatomic) CGFloat preferredWeekdayFontSize;
@property (assign, nonatomic) CGFloat preferredHeaderTitleFontSize;
@property (readonly, nonatomic) UIFont *preferredTitleFont;
@property (readonly, nonatomic) UIFont *preferredSubtitleFont;
@property (readonly, nonatomic) UIFont *preferredWeekdayFont;
@property (readonly, nonatomic) UIFont *preferredHeaderTitleFont;
- (void)adjustTitleIfNecessary;
@end
@ -30,12 +50,18 @@
self = [super init];
if (self) {
_autoAdjustTitleSize = YES;
_adjustsFontSizeToFitCellSize = YES;
_titleFontSize = _preferredTitleFontSize = FSCalendarStandardTitleTextSize;
_subtitleFontSize = _preferredSubtitleFontSize = FSCalendarStandardSubtitleTextSize;
_weekdayFontSize = _preferredWeekdayFontSize = FSCalendarStandardWeekdayTextSize;
_headerTitleFontSize = _preferredHeaderTitleFontSize = FSCalendarStandardHeaderTextSize;
_titleFontName = [UIFont systemFontOfSize:1].fontName;
_subtitleFontName = [UIFont systemFontOfSize:1].fontName;
_weekdayFontName = [UIFont systemFontOfSize:1].fontName;
_headerTitleFontName = [UIFont systemFontOfSize:1].fontName;
_titleTextSize = FSCalendarStandardTitleTextSize;
_subtitleTextSize = FSCalendarStandardSubtitleTextSize;
_weekdayTextSize = FSCalendarStandardWeekdayTextSize;
_headerTitleTextSize = FSCalendarStandardHeaderTextSize;
_headerTitleColor = FSCalendarStandardTitleTextColor;
_headerDateFormat = @"MMMM yyyy";
_headerMinimumDissolvedAlpha = 0.2;
@ -75,7 +101,105 @@
return self;
}
- (void)setTitleFont:(UIFont *)titleFont
{
BOOL needsLayout = NO;
if (![_titleFontName isEqualToString:titleFont.fontName]) {
_titleFontName = titleFont.fontName;
needsLayout = YES;
}
if (_titleFontSize != titleFont.pointSize) {
_titleFontSize = titleFont.pointSize;
needsLayout = YES;
}
if (needsLayout) {
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (UIFont *)titleFont
{
return [UIFont fontWithName:_titleFontName size:_titleFontSize];
}
- (void)setSubtitleFont:(UIFont *)subtitleFont
{
BOOL needsLayout = NO;
if (![_subtitleFontName isEqualToString:subtitleFont.fontName]) {
_subtitleFontName = subtitleFont.fontName;
needsLayout = YES;
}
if (_subtitleFontSize != subtitleFont.pointSize) {
_subtitleFontSize = subtitleFont.pointSize;
needsLayout = YES;
}
if (needsLayout) {
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (UIFont *)subtitleFont
{
return [UIFont fontWithName:_subtitleFontName size:_subtitleFontSize];
}
- (void)setWeekdayFont:(UIFont *)weekdayFont
{
BOOL needsLayout = NO;
if (![_weekdayFontName isEqualToString:weekdayFont.fontName]) {
_weekdayFontName = weekdayFont.fontName;
needsLayout = YES;
}
if (_weekdayFontSize != weekdayFont.pointSize) {
_weekdayFontSize = weekdayFont.pointSize;
needsLayout = YES;
}
if (needsLayout) {
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (UIFont *)weekdayFont
{
return [UIFont fontWithName:_weekdayFontName size:_weekdayFontSize];
}
- (void)setHeaderTitleFont:(UIFont *)headerTitleFont
{
BOOL needsLayout = NO;
if (![_headerTitleFontName isEqualToString:headerTitleFont.fontName]) {
_headerTitleFontName = headerTitleFont.fontName;
needsLayout = YES;
}
if (_headerTitleFontSize != headerTitleFont.pointSize) {
_headerTitleFontSize = headerTitleFont.pointSize;
needsLayout = YES;
}
if (needsLayout) {
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setTitleVerticalOffset:(CGFloat)titleVerticalOffset
{
if (_titleVerticalOffset != titleVerticalOffset) {
_titleVerticalOffset = titleVerticalOffset;
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setSubtitleVerticalOffset:(CGFloat)subtitleVerticalOffset
{
if (_subtitleVerticalOffset != subtitleVerticalOffset) {
_subtitleVerticalOffset = subtitleVerticalOffset;
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (UIFont *)headerTitleFont
{
return [UIFont fontWithName:_headerTitleFontName size:_headerTitleFontSize];
}
- (void)setTitleDefaultColor:(UIColor *)color
{
@ -84,7 +208,6 @@
} else {
[_titleColors removeObjectForKey:@(FSCalendarCellStateNormal)];
}
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
@ -311,28 +434,6 @@
return _borderColors[@(FSCalendarCellStateSelected)];
}
- (void)setTitleTextSize:(CGFloat)titleTextSize
{
if (_titleTextSize != titleTextSize) {
_titleTextSize = titleTextSize;
if (_autoAdjustTitleSize) {
return;
}
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setSubtitleTextSize:(CGFloat)subtitleTextSize
{
if (_subtitleTextSize != subtitleTextSize) {
_subtitleTextSize = subtitleTextSize;
if (_autoAdjustTitleSize) {
return;
}
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setCellShape:(FSCalendarCellShape)cellShape
{
if (_cellShape != cellShape) {
@ -341,16 +442,6 @@
}
}
- (void)setWeekdayTextSize:(CGFloat)weekdayTextSize
{
if (_weekdayTextSize != weekdayTextSize) {
_weekdayTextSize = weekdayTextSize;
UIFont *font = [UIFont systemFontOfSize:weekdayTextSize];
[_calendar.weekdays setValue:font forKey:@"font"];
}
}
- (void)setWeekdayTextColor:(UIColor *)weekdayTextColor
{
if (![_weekdayTextColor isEqual:weekdayTextColor]) {
@ -359,15 +450,6 @@
}
}
- (void)setHeaderTitleTextSize:(CGFloat)headerTitleTextSize
{
if (_headerTitleTextSize != headerTitleTextSize) {
_headerTitleTextSize = headerTitleTextSize;
[_calendar.header.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
[_calendar.visibleStickyHeaders makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setHeaderTitleColor:(UIColor *)color
{
if (![_headerTitleColor isEqual:color]) {
@ -376,13 +458,6 @@
[_calendar.visibleStickyHeaders makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
}
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
{
if (_autoAdjustTitleSize != autoAdjustTitleSize) {
_autoAdjustTitleSize = autoAdjustTitleSize;
[self adjustTitleIfNecessary];
}
}
- (void)setHeaderMinimumDissolvedAlpha:(CGFloat)headerMinimumDissolvedAlpha
{
@ -401,26 +476,46 @@
}
}
- (UIFont *)preferredTitleFont
{
return [UIFont fontWithName:_titleFontName size:_adjustsFontSizeToFitCellSize?_preferredTitleFontSize:_titleFontSize];
}
- (UIFont *)preferredSubtitleFont
{
return [UIFont fontWithName:_subtitleFontName size:_adjustsFontSizeToFitCellSize?_preferredSubtitleFontSize:_subtitleFontSize];
}
- (UIFont *)preferredWeekdayFont
{
return [UIFont fontWithName:_weekdayFontName size:_adjustsFontSizeToFitCellSize?_preferredWeekdayFontSize:_weekdayFontSize];
}
- (UIFont *)preferredHeaderTitleFont
{
return [UIFont fontWithName:_headerTitleFontName size:_adjustsFontSizeToFitCellSize?_preferredHeaderTitleFontSize:_headerTitleFontSize];
}
- (void)adjustTitleIfNecessary
{
if (!self.calendar.floatingMode) {
if (_autoAdjustTitleSize) {
if (_adjustsFontSizeToFitCellSize) {
CGFloat factor = (_calendar.scope==FSCalendarScopeMonth) ? 6 : 1.1;
_titleTextSize = _calendar.collectionView.fs_height/3/factor;
_titleTextSize -= (_titleTextSize-FSCalendarStandardTitleTextSize)*0.5;
_subtitleTextSize = _calendar.collectionView.fs_height/4.5/factor;
_subtitleTextSize -= (_subtitleTextSize-FSCalendarStandardSubtitleTextSize)*0.75;
_headerTitleTextSize = _titleTextSize * 1.25;
_weekdayTextSize = _titleTextSize;
_preferredTitleFontSize = _calendar.collectionView.fs_height/3/factor;
_preferredTitleFontSize -= (_preferredTitleFontSize-FSCalendarStandardTitleTextSize)*0.5;
_preferredSubtitleFontSize = _calendar.collectionView.fs_height/4.5/factor;
_preferredSubtitleFontSize -= (_preferredSubtitleFontSize-FSCalendarStandardSubtitleTextSize)*0.75;
_preferredHeaderTitleFontSize = _preferredTitleFontSize * 1.25;
_preferredWeekdayFontSize = _preferredTitleFontSize;
}
} else {
_headerTitleTextSize = 20;
_preferredHeaderTitleFontSize = 20;
if (FSCalendarDeviceIsIPad) {
_headerTitleTextSize = FSCalendarStandardHeaderTextSize * 1.5;
_titleTextSize = FSCalendarStandardTitleTextSize * 1.3;
_subtitleTextSize = FSCalendarStandardSubtitleTextSize * 1.15;
_weekdayTextSize = _titleTextSize;
_preferredHeaderTitleFontSize = FSCalendarStandardHeaderTextSize * 1.5;
_preferredTitleFontSize = FSCalendarStandardTitleTextSize * 1.3;
_preferredSubtitleFontSize = FSCalendarStandardSubtitleTextSize * 1.15;
_preferredWeekdayFontSize = _preferredTitleFontSize;
}
}
@ -428,7 +523,7 @@
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
[_calendar.header.collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
[_calendar.visibleStickyHeaders makeObjectsPerformSelector:@selector(setNeedsLayout)];
[_calendar.weekdays setValue:[UIFont systemFontOfSize:_weekdayTextSize] forKeyPath:@"font"];
[_calendar.weekdays setValue:self.preferredWeekdayFont forKeyPath:@"font"];
}
- (void)setCaseOptions:(FSCalendarCaseOptions)caseOptions
@ -475,6 +570,56 @@
return (_caseOptions & (15<<4) ) == FSCalendarCaseOptionsWeekdayUsesSingleUpperCase;
}
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
{
self.adjustsFontSizeToFitCellSize = autoAdjustTitleSize;
}
- (BOOL)autoAdjustTitleSize
{
return self.adjustsFontSizeToFitCellSize;
}
- (void)setTitleTextSize:(CGFloat)titleTextSize
{
self.titleFont = [UIFont fontWithName:_titleFontName size:titleTextSize];
}
- (CGFloat)titleTextSize
{
return _titleFontSize;
}
- (void)setSubtitleTextSize:(CGFloat)subtitleTextSize
{
self.subtitleFont = [UIFont fontWithName:_subtitleFontName size:subtitleTextSize];
}
- (CGFloat)subtitleTextSize
{
return _subtitleFontSize;
}
- (void)setWeekdayTextSize:(CGFloat)weekdayTextSize
{
self.weekdayFont = [UIFont fontWithName:_weekdayFontName size:weekdayTextSize];
}
- (CGFloat)weekdayTextSize
{
return _weekdayFontSize;
}
- (void)setHeaderTitleTextSize:(CGFloat)headerTitleTextSize
{
self.headerTitleFont = [UIFont fontWithName:_headerTitleFontName size:headerTitleTextSize];
}
- (CGFloat)headerTitleTextSize
{
return _headerTitleFontSize;
}
@end

View File

@ -33,14 +33,12 @@
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont systemFontOfSize:14];
titleLabel.textColor = [UIColor darkTextColor];
[self.contentView addSubview:titleLabel];
self.titleLabel = titleLabel;
UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
subtitleLabel.textAlignment = NSTextAlignmentCenter;
subtitleLabel.font = [UIFont systemFontOfSize:10];
subtitleLabel.textColor = [UIColor lightGrayColor];
[self.contentView addSubview:subtitleLabel];
self.subtitleLabel = subtitleLabel;
@ -133,14 +131,14 @@
- (void)configureCell
{
_titleLabel.font = [UIFont systemFontOfSize:_appearance.titleTextSize];
_titleLabel.font = _appearance.preferredTitleFont;
_titleLabel.text = [NSString stringWithFormat:@"%@",@([_calendar dayOfDate:_date])];
__block CGFloat titleHeight = 0;
__block CGFloat subtitleHeight = 0;
if (_subtitle) {
_subtitleLabel.font = [UIFont systemFontOfSize:_appearance.subtitleTextSize];
_subtitleLabel.font = _appearance.preferredSubtitleFont;
}
#define m_calculateTitleHeight \
@ -155,17 +153,17 @@
_subtitleLabel.text = _subtitle; \
CGFloat height = titleHeight + subtitleHeight; \
_titleLabel.frame = CGRectMake(0, \
(self.contentView.fs_height*5.0/6.0-height)*0.5, \
(self.contentView.fs_height*5.0/6.0-height)*0.5+_appearance.titleVerticalOffset, \
self.fs_width, \
titleHeight); \
\
_subtitleLabel.frame = CGRectMake(0, \
_titleLabel.fs_bottom - (_titleLabel.fs_height-_titleLabel.font.pointSize),\
_titleLabel.fs_bottom - (_titleLabel.fs_height-_titleLabel.font.pointSize)+_appearance.subtitleVerticalOffset,\
self.fs_width,\
subtitleHeight);\
_subtitleLabel.textColor = self.colorForSubtitleLabel; \
} else { \
_titleLabel.frame = CGRectMake(0, 0, self.fs_width, floor(self.contentView.fs_height*5.0/6.0)); \
_titleLabel.frame = CGRectMake(0, _appearance.titleVerticalOffset, self.fs_width, floor(self.contentView.fs_height*5.0/6.0)); \
_subtitleLabel.hidden = YES; \
}

View File

@ -48,6 +48,11 @@
@property (readonly, nonatomic) NSDictionary *subtitleColors;
@property (readonly, nonatomic) NSDictionary *borderColors;
@property (readonly, nonatomic) UIFont *preferredTitleFont;
@property (readonly, nonatomic) UIFont *preferredSubtitleFont;
@property (readonly, nonatomic) UIFont *preferredWeekdayFont;
@property (readonly, nonatomic) UIFont *preferredHeaderTitleFont;
- (void)adjustTitleIfNecessary;
@end

View File

@ -61,6 +61,8 @@
collectionView.backgroundColor = [UIColor clearColor];
collectionView.dataSource = self;
collectionView.delegate = self;
collectionView.showsHorizontalScrollIndicator = NO;
collectionView.showsVerticalScrollIndicator = NO;
[self addSubview:collectionView];
[collectionView registerClass:[FSCalendarHeaderCell class] forCellWithReuseIdentifier:@"cell"];
self.collectionView = collectionView;
@ -140,7 +142,7 @@
{
FSCalendarHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.header = self;
cell.titleLabel.font = [UIFont systemFontOfSize:_appearance.headerTitleTextSize];
cell.titleLabel.font = _appearance.preferredHeaderTitleFont;
cell.titleLabel.textColor = _appearance.headerTitleColor;
_calendar.formatter.dateFormat = _appearance.headerDateFormat;
BOOL usesUpperCase = (_appearance.caseOptions & 15) == FSCalendarCaseOptionsHeaderUsesUpperCase;
@ -181,7 +183,7 @@
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
[cell setNeedsLayout];
}
@ -189,7 +191,6 @@
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
#pragma mark - Properties

View File

@ -81,7 +81,7 @@
}];
#define m_calculate \
CGFloat titleHeight = [@"1" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_appearance.titleTextSize]}].height*1.5 + weekdayMargin*3;
CGFloat titleHeight = [@"1" sizeWithAttributes:@{NSFontAttributeName:_appearance.preferredHeaderTitleFont}].height*1.5 + weekdayMargin*3;
#define m_adjust \
_separator.frame = CGRectMake(0, _contentView.fs_height-weekdayHeight-weekdayMargin*2, _contentView.fs_width, 1.0); \
@ -141,11 +141,11 @@
- (void)reloadAppearance
{
_titleLabel.font = [UIFont systemFontOfSize:self.appearance.headerTitleTextSize];
_titleLabel.textColor = self.appearance.headerTitleColor;
_titleLabel.font = _appearance.preferredHeaderTitleFont;
_titleLabel.textColor = _appearance.headerTitleColor;
[_weekdayLabels enumerateObjectsUsingBlock:^(UILabel *label, NSUInteger index, BOOL *stop) {
label.font = [UIFont systemFontOfSize:self.appearance.weekdayTextSize];
label.textColor = self.appearance.weekdayTextColor;
label.font = _appearance.preferredWeekdayFont;
label.textColor = _appearance.weekdayTextColor;
}];
}

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.7.0</string>
<string>1.7.1.beta</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>