├── DateSuger.podspec ├── DateSuger.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcshareddata │ └── xcschemes │ │ └── DateSuger.xcscheme └── xcuserdata │ └── danis.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── DateSuger ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── LICENSE ├── README.md ├── Source ├── DateSuger.swift └── Operators.swift └── images └── logo.png /DateSuger.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint DateSuger.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'DateSuger' 11 | s.version = '0.1.1' 12 | s.summary = 'Make NSDate much more easier to use' 13 | s.homepage = 'https://github.com/danisfabric/DateSuger' 14 | s.license = 'MIT' 15 | s.author = { 'DanisFabric' => 'danisfabric@gmail.com' } 16 | s.ios.deployment_target = '8.0' 17 | s.osx.deployment_target = '10.10' 18 | s.source = { :git => 'https://github.com/danisfabric/DateSuger.git', :tag => s.version.to_s} 19 | s.source_files = 'Source/*.swift' 20 | s.requires_arc = true 21 | 22 | end 23 | -------------------------------------------------------------------------------- /DateSuger.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 12AB8DB11C1E6FC6006C7A28 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12AB8DB01C1E6FC6006C7A28 /* Operators.swift */; }; 11 | 12FE177A1C1D6D69006DA324 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12FE17791C1D6D69006DA324 /* AppDelegate.swift */; }; 12 | 12FE177C1C1D6D69006DA324 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12FE177B1C1D6D69006DA324 /* ViewController.swift */; }; 13 | 12FE177F1C1D6D69006DA324 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 12FE177D1C1D6D69006DA324 /* Main.storyboard */; }; 14 | 12FE17811C1D6D69006DA324 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 12FE17801C1D6D69006DA324 /* Assets.xcassets */; }; 15 | 12FE17841C1D6D69006DA324 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 12FE17821C1D6D69006DA324 /* LaunchScreen.storyboard */; }; 16 | 12FE178D1C1D6D8D006DA324 /* DateSuger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12FE178C1C1D6D8D006DA324 /* DateSuger.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 12AB8DB01C1E6FC6006C7A28 /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; 21 | 12FE17761C1D6D69006DA324 /* DateSuger.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DateSuger.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 12FE17791C1D6D69006DA324 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 12FE177B1C1D6D69006DA324 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 12FE177E1C1D6D69006DA324 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 12FE17801C1D6D69006DA324 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 12FE17831C1D6D69006DA324 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 12FE17851C1D6D69006DA324 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 12FE178C1C1D6D8D006DA324 /* DateSuger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateSuger.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 12FE17731C1D6D69006DA324 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 12FE176D1C1D6D69006DA324 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 12FE17781C1D6D69006DA324 /* DateSuger */, 46 | 12FE17771C1D6D69006DA324 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 12FE17771C1D6D69006DA324 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 12FE17761C1D6D69006DA324 /* DateSuger.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 12FE17781C1D6D69006DA324 /* DateSuger */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 12FE17791C1D6D69006DA324 /* AppDelegate.swift */, 62 | 12FE177B1C1D6D69006DA324 /* ViewController.swift */, 63 | 12FE178B1C1D6D8D006DA324 /* Source */, 64 | 12FE177D1C1D6D69006DA324 /* Main.storyboard */, 65 | 12FE17801C1D6D69006DA324 /* Assets.xcassets */, 66 | 12FE17821C1D6D69006DA324 /* LaunchScreen.storyboard */, 67 | 12FE17851C1D6D69006DA324 /* Info.plist */, 68 | ); 69 | path = DateSuger; 70 | sourceTree = ""; 71 | }; 72 | 12FE178B1C1D6D8D006DA324 /* Source */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 12FE178C1C1D6D8D006DA324 /* DateSuger.swift */, 76 | 12AB8DB01C1E6FC6006C7A28 /* Operators.swift */, 77 | ); 78 | path = Source; 79 | sourceTree = SOURCE_ROOT; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 12FE17751C1D6D69006DA324 /* DateSuger */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 12FE17881C1D6D69006DA324 /* Build configuration list for PBXNativeTarget "DateSuger" */; 87 | buildPhases = ( 88 | 12FE17721C1D6D69006DA324 /* Sources */, 89 | 12FE17731C1D6D69006DA324 /* Frameworks */, 90 | 12FE17741C1D6D69006DA324 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = DateSuger; 97 | productName = DateSuger; 98 | productReference = 12FE17761C1D6D69006DA324 /* DateSuger.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 12FE176E1C1D6D69006DA324 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 0720; 108 | LastUpgradeCheck = 0720; 109 | ORGANIZATIONNAME = danis; 110 | TargetAttributes = { 111 | 12FE17751C1D6D69006DA324 = { 112 | CreatedOnToolsVersion = 7.2; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 12FE17711C1D6D69006DA324 /* Build configuration list for PBXProject "DateSuger" */; 117 | compatibilityVersion = "Xcode 3.2"; 118 | developmentRegion = English; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 12FE176D1C1D6D69006DA324; 125 | productRefGroup = 12FE17771C1D6D69006DA324 /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 12FE17751C1D6D69006DA324 /* DateSuger */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | 12FE17741C1D6D69006DA324 /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 12FE17841C1D6D69006DA324 /* LaunchScreen.storyboard in Resources */, 140 | 12FE17811C1D6D69006DA324 /* Assets.xcassets in Resources */, 141 | 12FE177F1C1D6D69006DA324 /* Main.storyboard in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 12FE17721C1D6D69006DA324 /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 12FE177C1C1D6D69006DA324 /* ViewController.swift in Sources */, 153 | 12AB8DB11C1E6FC6006C7A28 /* Operators.swift in Sources */, 154 | 12FE178D1C1D6D8D006DA324 /* DateSuger.swift in Sources */, 155 | 12FE177A1C1D6D69006DA324 /* AppDelegate.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 12FE177D1C1D6D69006DA324 /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 12FE177E1C1D6D69006DA324 /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | 12FE17821C1D6D69006DA324 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 12FE17831C1D6D69006DA324 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 12FE17861C1D6D69006DA324 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 186 | CLANG_CXX_LIBRARY = "libc++"; 187 | CLANG_ENABLE_MODULES = YES; 188 | CLANG_ENABLE_OBJC_ARC = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_CONSTANT_CONVERSION = YES; 191 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 192 | CLANG_WARN_EMPTY_BODY = YES; 193 | CLANG_WARN_ENUM_CONVERSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 196 | CLANG_WARN_UNREACHABLE_CODE = YES; 197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 198 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 199 | COPY_PHASE_STRIP = NO; 200 | DEBUG_INFORMATION_FORMAT = dwarf; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | ENABLE_TESTABILITY = YES; 203 | GCC_C_LANGUAGE_STANDARD = gnu99; 204 | GCC_DYNAMIC_NO_PIC = NO; 205 | GCC_NO_COMMON_BLOCKS = YES; 206 | GCC_OPTIMIZATION_LEVEL = 0; 207 | GCC_PREPROCESSOR_DEFINITIONS = ( 208 | "DEBUG=1", 209 | "$(inherited)", 210 | ); 211 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 212 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 213 | GCC_WARN_UNDECLARED_SELECTOR = YES; 214 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 215 | GCC_WARN_UNUSED_FUNCTION = YES; 216 | GCC_WARN_UNUSED_VARIABLE = YES; 217 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 218 | MTL_ENABLE_DEBUG_INFO = YES; 219 | ONLY_ACTIVE_ARCH = YES; 220 | SDKROOT = iphoneos; 221 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 222 | }; 223 | name = Debug; 224 | }; 225 | 12FE17871C1D6D69006DA324 /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_WARN_BOOL_CONVERSION = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_EMPTY_BODY = YES; 237 | CLANG_WARN_ENUM_CONVERSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_UNREACHABLE_CODE = YES; 241 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 242 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 243 | COPY_PHASE_STRIP = NO; 244 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 245 | ENABLE_NS_ASSERTIONS = NO; 246 | ENABLE_STRICT_OBJC_MSGSEND = YES; 247 | GCC_C_LANGUAGE_STANDARD = gnu99; 248 | GCC_NO_COMMON_BLOCKS = YES; 249 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 250 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 251 | GCC_WARN_UNDECLARED_SELECTOR = YES; 252 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 253 | GCC_WARN_UNUSED_FUNCTION = YES; 254 | GCC_WARN_UNUSED_VARIABLE = YES; 255 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 256 | MTL_ENABLE_DEBUG_INFO = NO; 257 | SDKROOT = iphoneos; 258 | VALIDATE_PRODUCT = YES; 259 | }; 260 | name = Release; 261 | }; 262 | 12FE17891C1D6D69006DA324 /* Debug */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 266 | INFOPLIST_FILE = DateSuger/Info.plist; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 268 | PRODUCT_BUNDLE_IDENTIFIER = com.danis.DateSuger; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | }; 271 | name = Debug; 272 | }; 273 | 12FE178A1C1D6D69006DA324 /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | INFOPLIST_FILE = DateSuger/Info.plist; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = com.danis.DateSuger; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | }; 282 | name = Release; 283 | }; 284 | /* End XCBuildConfiguration section */ 285 | 286 | /* Begin XCConfigurationList section */ 287 | 12FE17711C1D6D69006DA324 /* Build configuration list for PBXProject "DateSuger" */ = { 288 | isa = XCConfigurationList; 289 | buildConfigurations = ( 290 | 12FE17861C1D6D69006DA324 /* Debug */, 291 | 12FE17871C1D6D69006DA324 /* Release */, 292 | ); 293 | defaultConfigurationIsVisible = 0; 294 | defaultConfigurationName = Release; 295 | }; 296 | 12FE17881C1D6D69006DA324 /* Build configuration list for PBXNativeTarget "DateSuger" */ = { 297 | isa = XCConfigurationList; 298 | buildConfigurations = ( 299 | 12FE17891C1D6D69006DA324 /* Debug */, 300 | 12FE178A1C1D6D69006DA324 /* Release */, 301 | ); 302 | defaultConfigurationIsVisible = 0; 303 | defaultConfigurationName = Release; 304 | }; 305 | /* End XCConfigurationList section */ 306 | }; 307 | rootObject = 12FE176E1C1D6D69006DA324 /* Project object */; 308 | } 309 | -------------------------------------------------------------------------------- /DateSuger.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DateSuger.xcodeproj/xcshareddata/xcschemes/DateSuger.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DateSuger.xcodeproj/xcuserdata/danis.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DateSuger.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 12FE17751C1D6D69006DA324 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DateSuger/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DateSuger 4 | // 5 | // Created by Danis on 15/12/13. 6 | // Copyright © 2015年 danis. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /DateSuger/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /DateSuger/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DateSuger/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /DateSuger/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /DateSuger/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DateSuger 4 | // 5 | // Created by Danis on 15/12/13. 6 | // Copyright © 2015年 danis. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | let date1 = NSDate.dateWithYear(2018, month: 3, day: 28)! 17 | let date2 = date1.dateByAddingDays(23) 18 | let date3 = date2 + .Year(1) + .Month(4) 19 | 20 | if date1 < date2 { 21 | print("2333") 22 | } 23 | if date3 == NSDate() { 24 | print("What ~") 25 | } 26 | } 27 | 28 | override func didReceiveMemoryWarning() { 29 | super.didReceiveMemoryWarning() 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 DanisFabric 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://github.com/DanisFabric/DateSuger/blob/master/images/logo.png) 2 | 3 | # DateSuger 4 | 5 | DateSuger 是一个优化Cocoa时间、日期使用方式的组件。Cocoa的 NSDate、NSDateComponent,NSCalendar等类提供了极其强大的日期处理的功能,但是使用起来却十分繁琐。DateSuger就是基于Swift2.0语言的对日期处理逻辑的一系列的语法糖。 6 | 7 | ## 要求 8 | 9 | * iOS8 + 10 | * Swift 2.0 + 11 | 12 | ## 安装 13 | 14 | ### Cocoapods 15 | 16 | `pod 'DateSuger' ` 17 | 18 | ### 手动 19 | 20 | 直接将Source目录下的swift文件导入到工程。 21 | 22 | ## 使用 23 | 24 | ### 日期编辑 25 | 26 | 我们想获得当前时间十天后的NSDate对象,在Cocoa中是这么做的: 27 | 28 | ``` 29 | let date1 = NSDate() 30 | let components = NSDateComponents() 31 | components.day = 10 32 | let calenar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) 33 | let date2 = calenar?.dateByAddingComponents(components, toDate: date1, options: []) 34 | ``` 35 | 36 | 在DateSuger里面一句话就可以代替: 37 | 38 | ``` 39 | let date3 = NSDate().dateByAddingDays(10) 40 | ``` 41 | 42 | 还想更简单吗?还能这样: 43 | 44 | ``` 45 | let date4 = NSDate() + .Day(10) 46 | ``` 47 | 48 | 这样相比于传统的Cocoa的接口,更加易用和容易理解。计算1年零3个月之后: 49 | 50 | ``` 51 | let date5 = NSDate() + .Year(1) + .Month(3) 52 | ``` 53 | 就是这么简单~ 54 | 55 | ### 日期信息 56 | 57 | 如果我们要知道今天是几月,或是星期几,传统代码如下: 58 | 59 | ``` 60 | let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) 61 | let components = calendar?.components([.Weekday,.Month], fromDate: NSDate()) 62 | let weekday = components?.weekday 63 | let month = components?.month 64 | ``` 65 | 通过DateSuger可以直接从NSDate实例中获取: 66 | 67 | ``` 68 | let weekday = NSDate().weekday 69 | ``` 70 | 71 | 支持的日期信息有: 72 | 73 | |Component| 74 | |---| 75 | |Era| 76 | |Year| 77 | |Day| 78 | |Hour| 79 | |Minute| 80 | |Second| 81 | |Quarter| 82 | |Weekday| 83 | |WeekdayOrdinal| 84 | |WeekOfMonth| 85 | |WeekOfYear| 86 | |DayOfYear| 87 | 88 | 89 | ### 其他信息判断 90 | 91 | DateSuger支持对一些常用信息的判断,通过实例代码展示: 92 | 93 | ``` 94 | let v1 = NSDate().isInLeapYear // 判断是否是闰年 95 | let v2 = NSDate().isToday // 判断是否是今天 96 | let v3 = NSDate().isTomorrow // 判断是否是明天 97 | let v4 = NSDate().isYesterday // 判断是否是昨天 98 | let v5 = NSDate().isSameDay(someDate) // 判断是否和某日期在同一天 99 | ``` 100 | ### 快速创建NSDate 101 | 102 | 能够通过指定年月日、小时、分钟、秒来创建NSDate 103 | 104 | ``` 105 | let date1 = NSDate.dateWithYear(2015, month: 3, day: 106 | let date2 = NSDate.dateWithYear(2015, month: 3, day: 28, hour: 3, minute: 12, second: 12) 107 | ``` 108 | 109 | ### 日期比较 110 | 111 | DateSuger 实现了`Comparable`协议,能够通过`==`,`>`,`<`,`>=`,`<=`来对日期进行比较。 112 | 113 | ``` 114 | if date1 > date2 { 115 | //... 116 | } 117 | if date1 >= date2 { 118 | //... 119 | } 120 | if date1 == date2 { 121 | //... 122 | } 123 | ``` 124 | 125 | ### 获得日期的时间差 126 | 127 | Date Suger 能够快速的获取两个日期间隔的年数,天数等信息。 128 | 129 | ``` 130 | let years1 = NSDate.yearsFrom(date1, toDate: NSDate()) 131 | let years2 = NSDate().yearsFrom(date1) 132 | ``` 133 | 134 | ### License 135 | 136 | The MIT License (MIT) 137 | 138 | Copyright (c) 2015 DanisFabric 139 | 140 | Permission is hereby granted, free of charge, to any person obtaining a copy 141 | of this software and associated documentation files (the "Software"), to deal 142 | in the Software without restriction, including without limitation the rights 143 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 144 | copies of the Software, and to permit persons to whom the Software is 145 | furnished to do so, subject to the following conditions: 146 | 147 | The above copyright notice and this permission notice shall be included in all 148 | copies or substantial portions of the Software. 149 | 150 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 152 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 153 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 154 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 155 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 156 | SOFTWARE. -------------------------------------------------------------------------------- /Source/DateSuger.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateEasy.swift 3 | // DateEasy 4 | // 5 | // Created by Danis on 15/12/13. 6 | // Copyright © 2015年 danis. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum DSDateComponentType { 12 | case Era 13 | case Year 14 | case Month 15 | case Day 16 | case Hour 17 | case Minute 18 | case Second 19 | case Quarter 20 | case Weekday 21 | case WeekdayOrdinal 22 | case WeekOfMonth 23 | case WeekOfYear 24 | case DayOfYear 25 | } 26 | 27 | //MARK: - Default Values 28 | 29 | let DefaultCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! 30 | let AllCalendarUnits: NSCalendarUnit = [ 31 | .Era, 32 | .Year, 33 | .Quarter, 34 | .Month, 35 | .Day, 36 | .Hour, 37 | .Minute, 38 | .Second, 39 | .WeekOfYear, 40 | .WeekOfMonth, 41 | .Weekday, 42 | .WeekdayOrdinal, 43 | ] 44 | 45 | // MARK: - Date Components 46 | extension NSDate { 47 | public var era: Int { 48 | return componentForType(.Era, calendar: nil) 49 | } 50 | public var year: Int { 51 | return componentForType(.Year, calendar: nil) 52 | } 53 | public var month: Int { 54 | return componentForType(.Month, calendar: nil) 55 | } 56 | public var day: Int { 57 | return componentForType(.Day, calendar: nil) 58 | } 59 | public var hour: Int { 60 | return componentForType(.Hour, calendar: nil) 61 | } 62 | public var minute: Int { 63 | return componentForType(.Minute, calendar: nil) 64 | } 65 | public var second: Int { 66 | return componentForType(.Second, calendar: nil) 67 | } 68 | public var quarter: Int { 69 | return componentForType(.Quarter, calendar: nil) 70 | } 71 | public var weekday: Int { 72 | return componentForType(.Weekday, calendar: nil) 73 | } 74 | public var weekdayOrdinal: Int { 75 | return componentForType(.WeekdayOrdinal, calendar: nil) 76 | } 77 | public var weekOfMonth: Int { 78 | return componentForType(.WeekOfMonth, calendar: nil) 79 | } 80 | public var weekOfYear: Int { 81 | return componentForType(.WeekOfYear, calendar: nil) 82 | } 83 | public var dayOfYear: Int { 84 | return componentForType(.DayOfYear, calendar: nil) 85 | } 86 | public func era(withCalendar calendar: NSCalendar) -> Int { 87 | return componentForType(.Era, calendar: calendar) 88 | } 89 | public func year(withCalendar calendar: NSCalendar) -> Int { 90 | return componentForType(.Year, calendar: calendar) 91 | } 92 | public func month(withCalendar calendar: NSCalendar) -> Int { 93 | return componentForType(.Month, calendar: calendar) 94 | } 95 | public func day(withCalendar calendar: NSCalendar) -> Int { 96 | return componentForType(.Day, calendar: calendar) 97 | } 98 | public func hour(withCalendar calendar: NSCalendar) -> Int { 99 | return componentForType(.Hour, calendar: calendar) 100 | } 101 | public func minute(withCalendar calendar: NSCalendar) -> Int { 102 | return componentForType(.Minute, calendar: calendar) 103 | } 104 | public func second(withCalendar calendar: NSCalendar) -> Int { 105 | return componentForType(.Second, calendar: calendar) 106 | } 107 | public func quarter(withCalendar calendar: NSCalendar) -> Int { 108 | return componentForType(.Quarter, calendar: calendar) 109 | } 110 | public func weekday(withCalendar calendar: NSCalendar) -> Int { 111 | return componentForType(.Weekday, calendar: calendar) 112 | } 113 | public func weekdayOrdinal(withCalendar calendar: NSCalendar) -> Int { 114 | return componentForType(.WeekdayOrdinal, calendar: calendar) 115 | } 116 | public func weekOfMonth(withCalendar calendar: NSCalendar) -> Int { 117 | return componentForType(.WeekOfMonth, calendar: calendar) 118 | } 119 | public func weekOfYear(withCalendar calendar: NSCalendar) -> Int { 120 | return componentForType(.WeekOfYear, calendar: calendar) 121 | } 122 | public func dayOfYear(withCalendar calendar: NSCalendar) -> Int { 123 | return componentForType(.DayOfYear, calendar: calendar) 124 | } 125 | func componentForType(type: DSDateComponentType, var calendar: NSCalendar?) -> Int { 126 | if calendar == nil { 127 | calendar = DefaultCalendar 128 | } 129 | let dateComponents = calendar!.components(AllCalendarUnits, fromDate: self) 130 | 131 | switch type { 132 | case .Era: 133 | return dateComponents.era 134 | case .Year: 135 | return dateComponents.year 136 | case .Month: 137 | return dateComponents.month 138 | case .Day: 139 | return dateComponents.day 140 | case .Hour: 141 | return dateComponents.hour 142 | case .Minute: 143 | return dateComponents.minute 144 | case .Second: 145 | return dateComponents.second 146 | case .Quarter: 147 | return dateComponents.quarter 148 | case .Weekday: 149 | return dateComponents.weekday 150 | case .WeekdayOrdinal: 151 | return dateComponents.weekdayOrdinal 152 | case .WeekOfMonth: 153 | return dateComponents.weekOfMonth 154 | case .WeekOfYear: 155 | return dateComponents.weekOfYear 156 | case .DayOfYear: 157 | return calendar!.ordinalityOfUnit(.Day, inUnit: .Year, forDate: self) 158 | } 159 | } 160 | } 161 | 162 | // MARK: - Other Infomation 163 | extension NSDate { 164 | public var daysInMonth: Int { 165 | let calendar = DefaultCalendar 166 | let days = calendar.rangeOfUnit(.Day, inUnit: .Month, forDate: self) 167 | return days.length 168 | } 169 | public var daysInYear: Int { 170 | if self.isInLeapYear { 171 | return 366 172 | } 173 | return 365 174 | } 175 | public var isInLeapYear: Bool { 176 | let dateComponents = DefaultCalendar.components(.Year, fromDate: self) 177 | if dateComponents.year % 400 == 0 { 178 | return true 179 | } 180 | else if dateComponents.year % 100 == 0 { 181 | return false 182 | } 183 | else if dateComponents.year % 4 == 0 { 184 | return true 185 | } 186 | return false 187 | } 188 | public var isToday: Bool { 189 | return self.isSameDay(NSDate()) 190 | } 191 | public var isTomorrow: Bool { 192 | let tomorrow = NSDate() + .Day(1) 193 | return self.isSameDay(tomorrow) 194 | } 195 | public var isYesterday: Bool { 196 | let yesterday = NSDate() - .Day(1) 197 | return self.isSameDay(yesterday) 198 | } 199 | public func isSameDay(date: NSDate) -> Bool { 200 | return NSDate.isSameDay(self, asDate: date) 201 | } 202 | public static func isSameDay(date: NSDate, asDate otherDate: NSDate) -> Bool { 203 | let firstComp = DefaultCalendar.components([.Era,.Year,.Month,.Day], fromDate: date) 204 | let secondComp = DefaultCalendar.components([.Era,.Year,.Month,.Day], fromDate: otherDate) 205 | 206 | let firstDate = DefaultCalendar.dateFromComponents(firstComp)! 207 | let secondDate = DefaultCalendar.dateFromComponents(secondComp)! 208 | 209 | return firstDate.isEqualToDate(secondDate) 210 | } 211 | } 212 | // MARK: - Date Creating 213 | extension NSDate { 214 | public static func dateWithYear(year: Int, month: Int, day: Int) -> NSDate? { 215 | return dateWithYear(year, month: month, day: day, hour: 0, minute: 0, second: 0) 216 | } 217 | public static func dateWithYear(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int) -> NSDate? { 218 | let components = NSDateComponents() 219 | components.year = year 220 | components.month = month 221 | components.day = day 222 | components.hour = hour 223 | components.minute = minute 224 | components.second = second 225 | 226 | return DefaultCalendar.dateFromComponents(components) 227 | } 228 | } 229 | // MARK: - Date Editing 230 | extension NSDate { 231 | public func dateByAddingYears(years: Int) -> NSDate { 232 | let components = NSDateComponents() 233 | components.year = years 234 | 235 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 236 | } 237 | public func dateByAddingMonths(months: Int) -> NSDate { 238 | let components = NSDateComponents() 239 | components.month = months 240 | 241 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 242 | } 243 | public func dateByAddingWeeks(weeks: Int) -> NSDate { 244 | let components = NSDateComponents() 245 | components.weekOfYear = weeks 246 | 247 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 248 | } 249 | public func dateByAddingDays(days: Int) -> NSDate { 250 | let components = NSDateComponents() 251 | components.day = days 252 | 253 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 254 | } 255 | public func dateByAddingHours(hours: Int) -> NSDate { 256 | let components = NSDateComponents() 257 | components.hour = hours 258 | 259 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 260 | } 261 | public func dateByAddingMinutes(minutes: Int) -> NSDate { 262 | let components = NSDateComponents() 263 | components.minute = minutes 264 | 265 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 266 | } 267 | public func dateByAddingSeconds(seconds: Int) -> NSDate { 268 | let components = NSDateComponents() 269 | components.second = seconds 270 | 271 | return DefaultCalendar.dateByAddingComponents(components, toDate: self, options: [])! 272 | } 273 | public func dateBySubtractingYears(years: Int) -> NSDate { 274 | return dateByAddingYears(-years) 275 | } 276 | public func dateBySubtractingMonths(months: Int) -> NSDate { 277 | return dateByAddingMonths(-months) 278 | } 279 | public func dateBySubtractingWeeks(weeks: Int) -> NSDate { 280 | return dateByAddingWeeks(-weeks) 281 | } 282 | public func dateBySubtractingDays(days: Int) -> NSDate { 283 | return dateByAddingDays(-days) 284 | } 285 | public func dateBySubtractingHours(hours: Int) -> NSDate { 286 | return dateByAddingHours(-hours) 287 | } 288 | public func dateBySubtractingMinutes(minutes: Int) -> NSDate { 289 | return dateByAddingMinutes(-minutes) 290 | } 291 | public func dateBySubtractingSeconds(seconds: Int) -> NSDate { 292 | return dateByAddingSeconds(-seconds) 293 | } 294 | } 295 | 296 | // MARK: - Interval 297 | extension NSDate { 298 | public static func yearsFrom(date: NSDate, toDate: NSDate) -> Int { 299 | let components = DefaultCalendar.components(.Year, fromDate: date, toDate: toDate, options: []) 300 | return components.year 301 | } 302 | public static func monthsFrom(date: NSDate, toDate: NSDate) -> Int { 303 | let components = DefaultCalendar.components(.Month, fromDate: date, toDate: toDate, options: []) 304 | return components.month 305 | } 306 | public static func weeksFrom(date: NSDate, toDate: NSDate) -> Int { 307 | let components = DefaultCalendar.components(.WeekOfYear, fromDate: date, toDate: toDate, options: []) 308 | return components.weekOfYear 309 | } 310 | public static func daysFrom(date: NSDate, toDate: NSDate) -> Int { 311 | let components = DefaultCalendar.components(.Day, fromDate: date, toDate: toDate, options: []) 312 | return components.day 313 | } 314 | public static func hoursFrom(date: NSDate, toDate: NSDate) -> Int { 315 | let components = DefaultCalendar.components(.Hour, fromDate: date, toDate: toDate, options: []) 316 | return components.hour 317 | } 318 | public static func minutesFrom(date: NSDate, toDate: NSDate) -> Int { 319 | let components = DefaultCalendar.components(.Minute, fromDate: date, toDate: toDate, options: []) 320 | return components.minute 321 | } 322 | public static func secondsFrom(date: NSDate, toDate: NSDate) -> Int { 323 | let components = DefaultCalendar.components(.Second, fromDate: date, toDate: toDate, options: []) 324 | return components.second 325 | } 326 | 327 | public func yearsFrom(date: NSDate) -> Int{ 328 | return NSDate.yearsFrom(date, toDate: self) 329 | } 330 | public func monthsFrom(date: NSDate) -> Int { 331 | return NSDate.monthsFrom(date, toDate: self) 332 | } 333 | public func weeksFrom(date: NSDate) -> Int { 334 | return NSDate.weeksFrom(date, toDate: self) 335 | } 336 | public func daysFrom(date: NSDate) -> Int { 337 | return NSDate.daysFrom(date, toDate: self) 338 | } 339 | public func hoursFrom(date: NSDate) -> Int { 340 | return NSDate.hoursFrom(date, toDate: self) 341 | } 342 | public func minutesFrom(date: NSDate) -> Int { 343 | return NSDate.minutesFrom(date, toDate: self) 344 | } 345 | public func secondsFrom(date: NSDate) -> Int { 346 | return NSDate.secondsFrom(date, toDate: self) 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /Source/Operators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Operators.swift 3 | // DateSuger 4 | // 5 | // Created by Danis on 15/12/14. 6 | // Copyright © 2015年 danis. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | //MARK: - Comparision 12 | extension NSDate : Comparable {} 13 | 14 | public func > (left: NSDate, right: NSDate) -> Bool { 15 | if left.timeIntervalSince1970 > right.timeIntervalSince1970 { 16 | return true 17 | } 18 | return false 19 | } 20 | public func < (left:NSDate, right: NSDate) -> Bool { 21 | if left.timeIntervalSince1970 < right.timeIntervalSince1970 { 22 | return true 23 | } 24 | return false 25 | } 26 | 27 | // MARK: - Calculation 28 | public func + (left: NSDate, right: NSTimeInterval) -> NSDate { 29 | return NSDate(timeInterval: right, sinceDate: left) 30 | } 31 | public func - (left: NSDate, right: NSTimeInterval) -> NSDate { 32 | return NSDate(timeInterval: -right, sinceDate: left) 33 | } 34 | 35 | public enum DateCane { 36 | case Year(Int) 37 | case Month(Int) 38 | case Week(Int) 39 | case Day(Int) 40 | case Hour(Int) 41 | case Minute(Int) 42 | case Second(Int) 43 | } 44 | 45 | public func + (left: NSDate, right: DateCane) -> NSDate { 46 | switch right { 47 | case .Year(let years): 48 | return left.dateByAddingYears(years) 49 | case .Month(let months): 50 | return left.dateByAddingMonths(months) 51 | case .Week(let weeks): 52 | return left.dateByAddingWeeks(weeks) 53 | case .Day(let days): 54 | return left.dateByAddingDays(days) 55 | case .Hour(let hours): 56 | return left.dateByAddingHours(hours) 57 | case .Minute(let minutes): 58 | return left.dateByAddingMinutes(minutes) 59 | case .Second(let seconds): 60 | return left.dateByAddingSeconds(seconds) 61 | } 62 | } 63 | public func - (left: NSDate, right: DateCane) -> NSDate { 64 | switch right { 65 | case .Year(let years): 66 | return left.dateBySubtractingYears(years) 67 | case .Month(let months): 68 | return left.dateBySubtractingMonths(months) 69 | case .Week(let weeks): 70 | return left.dateBySubtractingWeeks(weeks) 71 | case .Day(let days): 72 | return left.dateBySubtractingDays(days) 73 | case .Hour(let hours): 74 | return left.dateBySubtractingHours(hours) 75 | case .Minute(let minutes): 76 | return left.dateBySubtractingMinutes(minutes) 77 | case .Second(let seconds): 78 | return left.dateBySubtractingSeconds(seconds) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanisFabric/DateSuger/9adea1db493435049e22c51ec33bbc281d5536a3/images/logo.png --------------------------------------------------------------------------------