Parcourir la source

完善基础版本

zzb il y a 4 ans
Parent
commit
ffa5d11eec
31 fichiers modifiés avec 2262 ajouts et 303 suppressions
  1. 322 280
      Example/Pods/Pods.xcodeproj/project.pbxproj
  2. 1 0
      Example/Pods/Target Support Files/ZZFoundation/ZZFoundation-umbrella.h
  3. 20 9
      Example/Tests/NSDate+ZZExTest.m
  4. 32 0
      ZZFoundation/Classes/Collection/NSArray+ZZEx.h
  5. 80 0
      ZZFoundation/Classes/Collection/NSArray+ZZEx.m
  6. 24 0
      ZZFoundation/Classes/Collection/NSMutableArray+ZZEx.h
  7. 36 0
      ZZFoundation/Classes/Collection/NSMutableArray+ZZEx.m
  8. 16 0
      ZZFoundation/Classes/Date/NSDate+ZZChineseCalendar.h
  9. 46 0
      ZZFoundation/Classes/Date/NSDate+ZZChineseCalendar.m
  10. 141 0
      ZZFoundation/Classes/Date/NSDate+ZZEx.h
  11. 509 0
      ZZFoundation/Classes/Date/NSDate+ZZEx.m
  12. 23 0
      ZZFoundation/Classes/Date/NSDate+ZZTimeStamp.h
  13. 25 0
      ZZFoundation/Classes/Date/NSDate+ZZTimeStamp.m
  14. 3 1
      ZZFoundation/Classes/Date/ZZFoundation_Date.h
  15. 128 0
      ZZFoundation/Classes/Date/date.md
  16. 74 0
      ZZFoundation/Classes/FileManager/NSFileManager+ZZEx.h
  17. 228 0
      ZZFoundation/Classes/FileManager/NSFileManager+ZZEx.m
  18. 17 0
      ZZFoundation/Classes/Format/NSDateFormatter+ZZEx.h
  19. 67 0
      ZZFoundation/Classes/Format/NSDateFormatter+ZZEx.m
  20. 18 0
      ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/NSObjec+PropertiesVarMethod.h
  21. 57 0
      ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/NSObjec+PropertiesVarMethod.m
  22. 16 0
      ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/ZZSwizzle.h
  23. 33 0
      ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/ZZSwizzle.m
  24. 29 4
      ZZFoundation/Classes/String/NSString+ZZEx.m
  25. 68 0
      ZZFoundation/Classes/String/Regex/NSString+ZZRegex.h
  26. 216 0
      ZZFoundation/Classes/String/Regex/NSString+ZZRegex.m
  27. 8 4
      ZZFoundation/Classes/String/Size/NSString+ZZRect.h
  28. 4 4
      ZZFoundation/Classes/String/Size/NSString+ZZRect.m
  29. 14 0
      ZZFoundation/Classes/String/StringRange/NSString+ZZRange.m
  30. 6 1
      ZZFoundation/Classes/String/ZZFoundation_String.h
  31. 1 0
      ZZFoundation/Classes/ZZFoundation.h

Fichier diff supprimé car celui-ci est trop grand
+ 322 - 280
Example/Pods/Pods.xcodeproj/project.pbxproj


+ 1 - 0
Example/Pods/Target Support Files/ZZFoundation/ZZFoundation-umbrella.h

@@ -14,6 +14,7 @@
 #import "NSMutableArray+ZZEx.h"
 #import "NSDate+ZZEx.h"
 #import "ZZFoundation_Date.h"
+#import "NSFileManager+ZZEx.h"
 #import "NSObjec+PropertiesVarMethod.h"
 #import "NSObject+ZZSwizzle.h"
 #import "NSString+ZZPath.h"

+ 20 - 9
Example/Tests/NSDate+ZZExTest.m

@@ -10,20 +10,31 @@
 #import <ZZFoundation.h>
 
 SPEC_BEGIN(DateEx)
-NSDate * today = [NSDate date];
-NSDate * timeZoneCurrent = [[NSDate date] addTimeZone];
+__block NSDate * yearlastWeek;
+__block NSDate * sometoday;
 
 describe(@"week", ^{
-    it(@"today should ", ^{
-        [[theValue([today weekOfMonth]) should] equal:theValue(5)];
+    beforeEach(^{
+        NSDateFormatter *format = [[NSDateFormatter alloc] init];
+        format.dateFormat = @"yyyy-MM-dd Z";
+        yearlastWeek = [format dateFromString:@"2020-12-22 +0800"];
+        sometoday = [format dateFromString:@"2020-12-30 +0800"];
+    });
+    
+    it(@"this week should be nth of this month", ^{
+        [[theValue([sometoday weekOfMonth]) should] equal:theValue(5)];
+    });
+    
+    it(@"this week should be nth of this year", ^{
+        //w: 1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of year starts from the last Sunday of last year)
+        NSLog(@"%zd",[yearlastWeek weekOfYear]);
+        [[theValue([yearlastWeek weekOfYear]) should] beGreaterThanOrEqualTo:theValue(51)];
     });
+    
     it(@"time should be correct", ^{
         NSDateFormatter *format = [[NSDateFormatter alloc] init];
-        [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
-        NSString * str = [today stringWithDateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterFullStyle];
-        NSString * str1 = [format stringFromDate:timeZoneCurrent];
-        NSLog(@"time now is:%@",str);
-        NSLog(@"timeZoneCurrent now is:%@",str1);
+        [format setDateFormat:@"yyyy-MM-dd HH时"];
+        [[[format stringFromDate:sometoday] should] equal:@"2020-12-30 11时"];
     });
 });
 

+ 32 - 0
ZZFoundation/Classes/Collection/NSArray+ZZEx.h

@@ -0,0 +1,32 @@
+//
+//  NSArray+ZZEx.h
+//  RuiBeiKang
+//
+//  Created by Apple on 3/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSArray (ZZEx)
+
+-(BOOL)ZZEmpty;
+
+//连接两个或更多的数组,并返回结果。
+-(NSArray *)ZZConact:(NSArray *)arr;
+
+//把数组的所有元素放入一个字符串。元素通过指定的分隔符进行分隔。
+-(NSString *)ZZJoin:(NSString *)separate;
+
+//倒序重拍列
+-(NSArray *)ZZReverse;
+
+-(NSArray *)ZZMap:(id(^)(id))x;
+
+
+-(NSArray*)ZZFilter:(BOOL(^)(id))Filter;
+@end
+
+NS_ASSUME_NONNULL_END

+ 80 - 0
ZZFoundation/Classes/Collection/NSArray+ZZEx.m

@@ -0,0 +1,80 @@
+//
+//  NSArray+ZZEx.m
+//  RuiBeiKang
+//
+//  Created by Apple on 3/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+#import "NSArray+ZZEx.h"
+
+@implementation NSArray (ZZEx)
+-(BOOL)ZZEmpty{
+    return self.count == 0;
+};
+
+//连接两个或更多的数组,并返回结果。
+-(NSArray *)ZZConact:(NSArray *)arr{
+    NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self];
+    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        [tempArr addObject:obj];
+    }];
+    return [tempArr copy];
+};
+
+
+
+-(NSString *)ZZJoin:(NSString *)separate{
+    NSMutableString *str = [@"" mutableCopy];
+    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        if ([obj isMemberOfClass:[NSString class]]) {
+            [str appendString:obj];
+            [str appendString:separate];
+        }
+        
+        if ([obj isMemberOfClass:[NSNumber class]]) {
+            [str appendString:[obj stringValue]];
+            [str appendString:separate];
+        }
+        
+        if ([obj isMemberOfClass:[NSObject class]]) {
+            [str appendString:[obj description]];
+            [str appendString:separate];
+        }
+        
+        if ([obj isMemberOfClass:[NSValue class]]){
+            NSAssert(false, @"no implement");
+        }
+    }];
+    return str;
+};
+
+-(NSArray *)ZZReverse{
+    NSMutableArray *arr = [NSMutableArray array];
+    [self enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        [arr addObject:obj];
+    }];
+    return arr;
+};
+
+
+
+-(NSArray *)ZZMap:(id(^)(id))map{
+    NSMutableArray *array = [[NSMutableArray alloc] init];
+    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        [array addObject:map(obj)];
+    }];
+    return array;
+};
+
+-(NSArray*)ZZFilter:(BOOL(^)(id))filter{
+    NSMutableArray *array = [[NSMutableArray alloc] init];
+    
+    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        if (filter(obj)) {
+            [array addObject:obj];
+        }
+    }];
+    return array;
+};
+@end

+ 24 - 0
ZZFoundation/Classes/Collection/NSMutableArray+ZZEx.h

@@ -0,0 +1,24 @@
+//
+//  NSMutableArray+ZZEx.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/28.
+//
+
+#import <Foundation/Foundation.h>
+#import "NSArray+ZZEx.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSMutableArray (ZZEx)
+//删除并返回数组的第一个元素
+-(id)ZZShift;
+
+//删除并返回数组的最后一个元素
+-(id)ZZPop;
+
+//向数组的末尾添加一个或更多元素,并返回新的长度。
+-(NSInteger)ZZPush:(id) obj;
+@end
+
+NS_ASSUME_NONNULL_END

+ 36 - 0
ZZFoundation/Classes/Collection/NSMutableArray+ZZEx.m

@@ -0,0 +1,36 @@
+//
+//  NSMutableArray+ZZEx.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/28.
+//
+
+#import "NSMutableArray+ZZEx.h"
+
+@implementation NSMutableArray (ZZEx)
+
+//删除并返回数组的第一个元素
+-(id)ZZShift{
+    if (self.count == 0) {
+        return nil;
+    }
+    id obj = self.firstObject;
+    [self removeObjectAtIndex:0];
+    return obj;
+};
+
+-(id)ZZPop{
+    if (self.count == 0) {
+        return nil;
+    }
+    id obj = self.lastObject;
+    [self removeLastObject];
+    return obj;
+};
+
+//向数组的末尾添加一个或更多元素,并返回新的长度。
+-(NSInteger)ZZPush:(id) obj{
+    [self addObject:obj];
+    return self.count;
+}
+@end

+ 16 - 0
ZZFoundation/Classes/Date/NSDate+ZZChineseCalendar.h

@@ -0,0 +1,16 @@
+//
+//  NSDate+ZZChineseCalendar.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/30.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSDate (ZZChineseCalendar)
++(NSString*)chineseCalendarWithDate:(NSDate *)date;
+@end
+
+NS_ASSUME_NONNULL_END

+ 46 - 0
ZZFoundation/Classes/Date/NSDate+ZZChineseCalendar.m

@@ -0,0 +1,46 @@
+//
+//  NSDate+ZZChineseCalendar.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/30.
+//
+
+#import "NSDate+ZZChineseCalendar.h"
+
+@implementation NSDate (ZZChineseCalendar)
++(NSString*)chineseCalendarWithDate:(NSDate *)date{
+   NSArray *chineseYears = [NSArray arrayWithObjects:
+                      @"甲子", @"乙丑", @"丙寅",    @"丁卯",    @"戊辰",    @"己巳",    @"庚午",    @"辛未",    @"壬申",    @"癸酉",
+                      @"甲戌",    @"乙亥",    @"丙子",    @"丁丑", @"戊寅",    @"己卯",    @"庚辰",    @"辛己",    @"壬午",    @"癸未",
+                      @"甲申",    @"乙酉",    @"丙戌",    @"丁亥",    @"戊子",    @"己丑",    @"庚寅",    @"辛卯",    @"壬辰",    @"癸巳",
+                      @"甲午",    @"乙未",    @"丙申",    @"丁酉",    @"戊戌",    @"己亥",    @"庚子",    @"辛丑",    @"壬寅",    @"癸丑",
+                      @"甲辰",    @"乙巳",    @"丙午",    @"丁未",    @"戊申",    @"己酉",    @"庚戌",    @"辛亥",    @"壬子",    @"癸丑",
+                      @"甲寅",    @"乙卯",    @"丙辰",    @"丁巳",    @"戊午",    @"己未",    @"庚申",    @"辛酉",    @"壬戌",    @"癸亥", nil];
+   
+   NSArray *chineseMonths=[NSArray arrayWithObjects:
+                       @"正月", @"二月", @"三月", @"四月", @"五月", @"六月", @"七月", @"八月",
+                       @"九月", @"十月", @"冬月", @"腊月", nil];
+   
+   
+   NSArray *chineseDays=[NSArray arrayWithObjects:
+                     @"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",
+                     @"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十",
+                     @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十",  nil];
+   
+   
+    NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
+   
+    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
+
+   NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:date];
+   
+    NSLog(@"%ld_%ld_%ld  %@",(long)localeComp.year,(long)localeComp.month,(long)localeComp.day, localeComp.date);
+   
+   NSString *y_str = [chineseYears objectAtIndex:localeComp.year-1];
+   NSString *m_str = [chineseMonths objectAtIndex:localeComp.month-1];
+   NSString *d_str = [chineseDays objectAtIndex:localeComp.day-1];
+
+   NSString *chineseCalStr =[NSString stringWithFormat: @"%@_%@_%@",y_str,m_str,d_str];
+   return chineseCalStr;
+}
+@end

+ 141 - 0
ZZFoundation/Classes/Date/NSDate+ZZEx.h

@@ -0,0 +1,141 @@
+//
+//  NSDate+ZZEx.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSDate (ZZEx)
+#define D_MINUTE    60
+#define D_HOUR        3600
+#define D_DAY        86400
+#define D_WEEK        604800
+#define D_YEAR        31556926
+
+
++ (NSCalendar *) currentCalendar; // avoid bottlenecks
+
+/// 明天
++ (NSDate *) dateTomorrow;
+
+/// 昨天
++ (NSDate *) dateYesterday;
+
+/// 从今天算起n天后
+/// @param days 往后推算的日期
++ (NSDate *) dateWithDaysFromNow: (NSInteger) days;
+
+/// 从今天算起n天之前
+/// @param days 往前推算的日期
++ (NSDate *) dateWithDaysBeforeNow: (NSInteger) days;
++ (NSDate *) dateWithHoursFromNow: (NSInteger) dHours;
++ (NSDate *) dateWithHoursBeforeNow: (NSInteger) dHours;
++ (NSDate *) dateWithMinutesFromNow: (NSInteger) dMinutes;
++ (NSDate *) dateWithMinutesBeforeNow: (NSInteger) dMinutes;
+
+// Short string utilities
+- (NSString *) stringWithDateStyle: (NSDateFormatterStyle) dateStyle timeStyle: (NSDateFormatterStyle) timeStyle;
+- (NSString *) stringWithFormat: (NSString *) format;
+@property (nonatomic, readonly) NSString *shortString;
+@property (nonatomic, readonly) NSString *shortDateString;
+@property (nonatomic, readonly) NSString *shortTimeString;
+@property (nonatomic, readonly) NSString *mediumString;
+@property (nonatomic, readonly) NSString *mediumDateString;
+@property (nonatomic, readonly) NSString *mediumTimeString;
+@property (nonatomic, readonly) NSString *longString;
+@property (nonatomic, readonly) NSString *longDateString;
+@property (nonatomic, readonly) NSString *longTimeString;
+
+// Comparing dates
+- (BOOL) isEqualToDateIgnoringTime: (NSDate *) aDate;
+
+/// 是不是今天
+- (BOOL) isToday;
+
+/// 是不是明天
+- (BOOL) isTomorrow;
+
+/// 是不是昨天
+- (BOOL) isYesterday;
+
+- (BOOL) isSameWeekAsDate: (NSDate *) aDate;
+- (BOOL) isThisWeek;
+- (BOOL) isNextWeek;
+- (BOOL) isLastWeek;
+
+- (BOOL) isSameMonthAsDate: (NSDate *) aDate;
+- (BOOL) isThisMonth;
+- (BOOL) isNextMonth;
+- (BOOL) isLastMonth;
+
+- (BOOL) isSameYearAsDate: (NSDate *) aDate;
+- (BOOL) isThisYear;
+- (BOOL) isNextYear;
+- (BOOL) isLastYear;
+
+- (BOOL) isEarlierThanDate: (NSDate *) aDate;
+- (BOOL) isLaterThanDate: (NSDate *) aDate;
+
+- (BOOL) isInFuture;
+- (BOOL) isInPast;
+
+// Date roles
+
+/// 工作日
+- (BOOL) isTypicallyWorkday;
+
+/// 休息日
+- (BOOL) isTypicallyWeekend;
+
+// Adjusting dates
+- (NSDate *) dateByAddingYears: (NSInteger) dYears;
+- (NSDate *) dateBySubtractingYears: (NSInteger) dYears;
+- (NSDate *) dateByAddingMonths: (NSInteger) dMonths;
+- (NSDate *) dateBySubtractingMonths: (NSInteger) dMonths;
+- (NSDate *) dateByAddingDays: (NSInteger) dDays;
+- (NSDate *) dateBySubtractingDays: (NSInteger) dDays;
+- (NSDate *) dateByAddingHours: (NSInteger) dHours;
+- (NSDate *) dateBySubtractingHours: (NSInteger) dHours;
+- (NSDate *) dateByAddingMinutes: (NSInteger) dMinutes;
+- (NSDate *) dateBySubtractingMinutes: (NSInteger) dMinutes;
+
+// Date extremes
+- (NSDate *) dateAtStartOfDay;
+- (NSDate *) dateAtEndOfDay;
+
+// Retrieving intervals
+- (NSInteger) minutesAfterDate: (NSDate *) aDate;
+- (NSInteger) minutesBeforeDate: (NSDate *) aDate;
+- (NSInteger) hoursAfterDate: (NSDate *) aDate;
+- (NSInteger) hoursBeforeDate: (NSDate *) aDate;
+- (NSInteger) daysAfterDate: (NSDate *) aDate;
+- (NSInteger) daysBeforeDate: (NSDate *) aDate;
+- (NSInteger)distanceInDaysToDate:(NSDate *)anotherDate;
+
+// Decomposing dates
+@property (readonly) NSInteger nearestHour;
+@property (readonly) NSInteger hour;
+@property (readonly) NSInteger minute;
+@property (readonly) NSInteger seconds;
+@property (readonly) NSInteger day;
+@property (readonly) NSInteger month;
+@property (readonly) NSInteger year;
+
+/// 今天属于本年的第几周
+@property (readonly) NSInteger weekOfYear;
+/// 今天属于本月的第几周
+@property (readonly) NSInteger weekOfMonth;
+/// 星期
+@property (readonly) NSInteger weekday;
+/// 星期日是第一天
+@property (readonly) NSInteger nthWeekday; // e.g. 2nd Tuesday of the month == 2
+
+
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 509 - 0
ZZFoundation/Classes/Date/NSDate+ZZEx.m

@@ -0,0 +1,509 @@
+//
+//  NSDate+ZZEx.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import "NSDate+ZZEx.h"
+
+
+
+static const unsigned componentFlags = (NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekOfMonth | NSCalendarUnitWeekOfYear |  NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday | NSCalendarUnitWeekdayOrdinal);
+
+@implementation NSDate (ZZEx)
+
+
+/// 经典错误!其实世界时间都是格林威治时间加时差
+//-(NSDate *)addTimeZone{
+//    NSTimeZone *timeZone = [NSTimeZone systemTimeZone]; // 获取的是系统的时区
+//    NSInteger interval = [timeZone secondsFromGMTForDate: [NSDate date]];// local时间距离GMT的秒数
+//    NSDate *tzDate = [self dateByAddingTimeInterval: interval];
+//    return tzDate;
+//}
+
+// Courtesy of Lukasz Margielewski
+// Updated via Holger Haenisch
++ (NSCalendar *) currentCalendar
+{
+    static NSCalendar *sharedCalendar = nil;
+    if (!sharedCalendar)
+        sharedCalendar = [NSCalendar autoupdatingCurrentCalendar];
+    return sharedCalendar;
+}
+
+#pragma mark - Relative Dates
+
++ (NSDate *) dateWithDaysFromNow: (NSInteger) days
+{
+    // Thanks, Jim Morrison
+    return [[NSDate date] dateByAddingDays:days];
+}
+
++ (NSDate *) dateWithDaysBeforeNow: (NSInteger) days
+{
+    // Thanks, Jim Morrison
+    return [[NSDate date] dateBySubtractingDays:days];
+}
+
++ (NSDate *) dateTomorrow
+{
+    return [NSDate dateWithDaysFromNow:1];
+}
+
++ (NSDate *) dateYesterday
+{
+    return [NSDate dateWithDaysBeforeNow:1];
+}
+
++ (NSDate *) dateWithHoursFromNow: (NSInteger) dHours
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] + D_HOUR * dHours;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
++ (NSDate *) dateWithHoursBeforeNow: (NSInteger) dHours
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] - D_HOUR * dHours;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
++ (NSDate *) dateWithMinutesFromNow: (NSInteger) dMinutes
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] + D_MINUTE * dMinutes;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
++ (NSDate *) dateWithMinutesBeforeNow: (NSInteger) dMinutes
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] - D_MINUTE * dMinutes;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
+#pragma mark - String Properties
+- (NSString *) stringWithFormat: (NSString *) format
+{
+    NSDateFormatter *formatter = [NSDateFormatter new];
+//    formatter.locale = [NSLocale currentLocale]; // Necessary?
+    formatter.dateFormat = format;
+    return [formatter stringFromDate:self];
+}
+
+- (NSString *) stringWithDateStyle: (NSDateFormatterStyle) dateStyle timeStyle: (NSDateFormatterStyle) timeStyle
+{
+    NSDateFormatter *formatter = [NSDateFormatter new];
+    formatter.dateStyle = dateStyle;
+    formatter.timeStyle = timeStyle;
+//    formatter.locale = [NSLocale currentLocale]; // Necessary?
+    return [formatter stringFromDate:self];
+}
+
+- (NSString *) shortString
+{
+    return [self stringWithDateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
+}
+
+- (NSString *) shortTimeString
+{
+    return [self stringWithDateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
+}
+
+- (NSString *) shortDateString
+{
+    return [self stringWithDateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterNoStyle];
+}
+
+- (NSString *) mediumString
+{
+    return [self stringWithDateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle ];
+}
+
+- (NSString *) mediumTimeString
+{
+    return [self stringWithDateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterMediumStyle ];
+}
+
+- (NSString *) mediumDateString
+{
+    return [self stringWithDateStyle:NSDateFormatterMediumStyle  timeStyle:NSDateFormatterNoStyle];
+}
+
+- (NSString *) longString
+{
+    return [self stringWithDateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterLongStyle ];
+}
+
+- (NSString *) longTimeString
+{
+    return [self stringWithDateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterLongStyle ];
+}
+
+- (NSString *) longDateString
+{
+    return [self stringWithDateStyle:NSDateFormatterLongStyle  timeStyle:NSDateFormatterNoStyle];
+}
+
+#pragma mark - Comparing Dates
+
+- (BOOL) isEqualToDateIgnoringTime: (NSDate *) aDate
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:componentFlags fromDate:aDate];
+    return ((components1.year == components2.year) &&
+            (components1.month == components2.month) &&
+            (components1.day == components2.day));
+}
+
+- (BOOL) isToday
+{
+    return [self isEqualToDateIgnoringTime:[NSDate date]];
+}
+
+- (BOOL) isTomorrow
+{
+    return [self isEqualToDateIgnoringTime:[NSDate dateTomorrow]];
+}
+
+- (BOOL) isYesterday
+{
+    return [self isEqualToDateIgnoringTime:[NSDate dateYesterday]];
+}
+
+// This hard codes the assumption that a week is 7 days
+- (BOOL) isSameWeekAsDate: (NSDate *) aDate
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:componentFlags fromDate:aDate];
+    
+    // Must be same week. 12/31 and 1/1 will both be week "1" if they are in the same week
+    if (components1.weekOfYear != components2.weekOfYear) return NO;
+    
+    // Must have a time interval under 1 week. Thanks @aclark
+    return (fabs([self timeIntervalSinceDate:aDate]) < D_WEEK);
+}
+
+- (BOOL) isThisWeek
+{
+    return [self isSameWeekAsDate:[NSDate date]];
+}
+
+- (BOOL) isNextWeek
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] + D_WEEK;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return [self isSameWeekAsDate:newDate];
+}
+
+- (BOOL) isLastWeek
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] - D_WEEK;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return [self isSameWeekAsDate:newDate];
+}
+
+// Thanks, mspasov
+- (BOOL) isSameMonthAsDate: (NSDate *) aDate
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth fromDate:aDate];
+    return ((components1.month == components2.month) &&
+            (components1.year == components2.year));
+}
+
+- (BOOL) isThisMonth
+{
+    return [self isSameMonthAsDate:[NSDate date]];
+}
+
+// Thanks Marcin Krzyzanowski, also for adding/subtracting years and months
+- (BOOL) isLastMonth
+{
+    return [self isSameMonthAsDate:[[NSDate date] dateBySubtractingMonths:1]];
+}
+
+- (BOOL) isNextMonth
+{
+    return [self isSameMonthAsDate:[[NSDate date] dateByAddingMonths:1]];
+}
+
+- (BOOL) isSameYearAsDate: (NSDate *) aDate
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:aDate];
+    return (components1.year == components2.year);
+}
+
+- (BOOL) isThisYear
+{
+    // Thanks, baspellis
+    return [self isSameYearAsDate:[NSDate date]];
+}
+
+- (BOOL) isNextYear
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:[NSDate date]];
+    
+    return (components1.year == (components2.year + 1));
+}
+
+- (BOOL) isLastYear
+{
+    NSDateComponents *components1 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:self];
+    NSDateComponents *components2 = [[NSDate currentCalendar] components:NSCalendarUnitYear fromDate:[NSDate date]];
+    
+    return (components1.year == (components2.year - 1));
+}
+
+- (BOOL) isEarlierThanDate: (NSDate *) aDate
+{
+    return ([self compare:aDate] == NSOrderedAscending);
+}
+
+- (BOOL) isLaterThanDate: (NSDate *) aDate
+{
+    return ([self compare:aDate] == NSOrderedDescending);
+}
+
+// Thanks, markrickert
+- (BOOL) isInFuture
+{
+    return ([self isLaterThanDate:[NSDate date]]);
+}
+
+// Thanks, markrickert
+- (BOOL) isInPast
+{
+    return ([self isEarlierThanDate:[NSDate date]]);
+}
+
+
+#pragma mark - Roles
+- (BOOL) isTypicallyWeekend
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:NSCalendarUnitWeekday fromDate:self];
+    if ((components.weekday == 1) ||
+        (components.weekday == 7))
+        return YES;
+    return NO;
+}
+
+- (BOOL) isTypicallyWorkday
+{
+    return ![self isTypicallyWeekend];
+}
+
+#pragma mark - Adjusting Dates
+
+// Thaks, rsjohnson
+- (NSDate *) dateByAddingYears: (NSInteger) dYears
+{
+    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
+    [dateComponents setYear:dYears];
+    NSDate *newDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:self options:0];
+    return newDate;
+}
+
+- (NSDate *) dateBySubtractingYears: (NSInteger) dYears
+{
+    return [self dateByAddingYears:-dYears];
+}
+
+- (NSDate *) dateByAddingMonths: (NSInteger) dMonths
+{
+    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
+    [dateComponents setMonth:dMonths];
+    NSDate *newDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:self options:0];
+    return newDate;
+}
+
+- (NSDate *) dateBySubtractingMonths: (NSInteger) dMonths
+{
+    return [self dateByAddingMonths:-dMonths];
+}
+
+// Courtesy of dedan who mentions issues with Daylight Savings
+- (NSDate *) dateByAddingDays: (NSInteger) dDays
+{
+    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
+    [dateComponents setDay:dDays];
+    NSDate *newDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:self options:0];
+    return newDate;
+}
+
+- (NSDate *) dateBySubtractingDays: (NSInteger) dDays
+{
+    return [self dateByAddingDays: (dDays * -1)];
+}
+
+- (NSDate *) dateByAddingHours: (NSInteger) dHours
+{
+    NSTimeInterval aTimeInterval = [self timeIntervalSinceReferenceDate] + D_HOUR * dHours;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
+- (NSDate *) dateBySubtractingHours: (NSInteger) dHours
+{
+    return [self dateByAddingHours: (dHours * -1)];
+}
+
+- (NSDate *) dateByAddingMinutes: (NSInteger) dMinutes
+{
+    NSTimeInterval aTimeInterval = [self timeIntervalSinceReferenceDate] + D_MINUTE * dMinutes;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    return newDate;
+}
+
+- (NSDate *) dateBySubtractingMinutes: (NSInteger) dMinutes
+{
+    return [self dateByAddingMinutes: (dMinutes * -1)];
+}
+
+- (NSDateComponents *) componentsWithOffsetFromDate: (NSDate *) aDate
+{
+    NSDateComponents *dTime = [[NSDate currentCalendar] components:componentFlags fromDate:aDate toDate:self options:0];
+    return dTime;
+}
+
+#pragma mark - Extremes
+
+- (NSDate *) dateAtStartOfDay
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    components.hour = 0;
+    components.minute = 0;
+    components.second = 0;
+    return [[NSDate currentCalendar] dateFromComponents:components];
+}
+
+// Thanks gsempe & mteece
+- (NSDate *) dateAtEndOfDay
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    components.hour = 23; // Thanks Aleksey Kononov
+    components.minute = 59;
+    components.second = 59;
+    return [[NSDate currentCalendar] dateFromComponents:components];
+}
+
+#pragma mark - Retrieving Intervals
+
+- (NSInteger) minutesAfterDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [self timeIntervalSinceDate:aDate];
+    return (NSInteger) (ti / D_MINUTE);
+}
+
+- (NSInteger) minutesBeforeDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [aDate timeIntervalSinceDate:self];
+    return (NSInteger) (ti / D_MINUTE);
+}
+
+- (NSInteger) hoursAfterDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [self timeIntervalSinceDate:aDate];
+    return (NSInteger) (ti / D_HOUR);
+}
+
+- (NSInteger) hoursBeforeDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [aDate timeIntervalSinceDate:self];
+    return (NSInteger) (ti / D_HOUR);
+}
+
+- (NSInteger) daysAfterDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [self timeIntervalSinceDate:aDate];
+    return (NSInteger) (ti / D_DAY);
+}
+
+- (NSInteger) daysBeforeDate: (NSDate *) aDate
+{
+    NSTimeInterval ti = [aDate timeIntervalSinceDate:self];
+    return (NSInteger) (ti / D_DAY);
+}
+
+// Thanks, dmitrydims
+// I have not yet thoroughly tested this
+- (NSInteger)distanceInDaysToDate:(NSDate *)anotherDate
+{
+    NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
+    NSDateComponents *components = [gregorianCalendar components:NSCalendarUnitDay fromDate:self toDate:anotherDate options:0];
+    return components.day;
+}
+
+#pragma mark - Decomposing Dates
+
+- (NSInteger) nearestHour
+{
+    NSTimeInterval aTimeInterval = [[NSDate date] timeIntervalSinceReferenceDate] + D_MINUTE * 30;
+    NSDate *newDate = [NSDate dateWithTimeIntervalSinceReferenceDate:aTimeInterval];
+    NSDateComponents *components = [[NSDate currentCalendar] components:NSCalendarUnitHour fromDate:newDate];
+    return components.hour;
+}
+
+- (NSInteger) hour
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.hour;
+}
+
+- (NSInteger) minute
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.minute;
+}
+
+- (NSInteger) seconds
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.second;
+}
+
+- (NSInteger) day
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.day;
+}
+
+- (NSInteger) month
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.month;
+}
+
+- (NSInteger) weekOfYear
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.weekOfYear;
+}
+
+-(NSInteger) weekOfMonth{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.weekOfMonth;
+}
+
+- (NSInteger)zz_weekday
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.weekday;
+}
+
+- (NSInteger) nthWeekday // e.g. 2nd Tuesday of the month is 2
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.weekdayOrdinal;
+}
+
+- (NSInteger) year
+{
+    NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
+    return components.year;
+}
+@end

+ 23 - 0
ZZFoundation/Classes/Date/NSDate+ZZTimeStamp.h

@@ -0,0 +1,23 @@
+//
+//  NSDate+ZZTimeStamp.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/30.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSDate (ZZTimeStamp)
+
+/// 获取当前时间戳
+-(NSTimeInterval)ZZTimeStamp;
+
+
+/// 时间戳转当前时间
+/// @param stamp 时间戳
+-(NSDate *)ZZDateFromStamp:(NSTimeInterval)stamp;
+@end
+
+NS_ASSUME_NONNULL_END

+ 25 - 0
ZZFoundation/Classes/Date/NSDate+ZZTimeStamp.m

@@ -0,0 +1,25 @@
+//
+//  NSDate+ZZTimeStamp.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/30.
+//
+
+#import "NSDate+ZZTimeStamp.h"
+
+@implementation NSDate (ZZTimeStamp)
+
+/// 获取当前时间戳
+-(NSTimeInterval)ZZTimeStamp{
+    NSDate *date = [NSDate date];
+    NSTimeInterval stamp = [date timeIntervalSince1970];
+    return stamp;
+};
+
+
+/// 时间戳转当前时间
+/// @param stamp 时间戳
+-(NSDate *)ZZDateFromStamp:(NSTimeInterval)stamp{
+    return [NSDate dateWithTimeIntervalSince1970:stamp];
+};
+@end

+ 3 - 1
ZZFoundation/Classes/Date/ZZFoundation_Date.h

@@ -8,5 +8,7 @@
 #ifndef ZZFoundation_Date_h
 #define ZZFoundation_Date_h
 
-
+#import "NSDate+ZZEx.h"
+#import "NSDate+ZZTimeStamp.h"
+#import "NSDate+ZZChineseCalendar.h"
 #endif /* ZZFoundation_Date_h */

+ 128 - 0
ZZFoundation/Classes/Date/date.md

@@ -0,0 +1,128 @@
+# Date总结
+
+## NSDate转字符串时间
+
+初始化一个NSDate时间`[NSDate date]`,获取的是零时区的时间(格林尼治的时间: 年-月-日 时:分:秒: +时区),而==北京时间是东八区==时间,因为时区不同,所以打印的时间相差了8小时。此刻表示的时间是一样的。
+
+```swift
+
+NSDate *date = [NSDate date];
+
+NSLog(@"date时间 = %@", date);
+
+    
+
+NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+
+[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
+
+NSString *dateStr = [formatter stringFromDate:date];
+
+NSLog(@"字符串时间 = %@", dateStr);
+
+打印结果:
+        2016-12-07 10:44:24.470 timeTest[32743:2995134] date时间 = 2016-12-07 02:44:24 +0000
+       
+ 
+        2016-12-07 10:44:24.471 timeTest[32743:2995134] 字符串时间 = 2016-12-07 10:44:24 +0800
+```
+
+打印结果前面的时间是北京时间:2016-12-07 10:44:24.470。而date打印出来的时间显示少了8小时,因为它表示的是零时区(+0000)时间02:44:24。此刻对应东八区的北京时间就是10:44:24。只是时区不同,表示的时间点是一样的。好比1公斤和2斤,重量是一样的。[NSDate date]获取的时间单位是零时区(+0000),我们所要的北京时间的单位是东八区(+0800)。
+
+系统会默认[NSDate date]获取的时间为零时区时间,而经过NSDateFormatter转化为字符串时间就是当前所在时区的准确时间,并没有8小时误差。
+
+转字符串时间的时区设定
+
+上文中NSDate时间转为字符串时间并没有设置NSDateFormatter的timeZone。不设置会默认使用当前所在的时区,与设置系统时区formatter.timeZone = [NSTimeZone systemTimeZone]的效果是一样的。
+
+也可以设置时区,获取指定时区的字符串时间
+
+```swift
+NSDate *date = [NSDate date]; 
+NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
+//东八区时间
+formatter.timeZone = [NSTimeZone timeZoneWithName:@"AsiShanghai"];
+NSString *dateStr = [formatter stringFromDate:date];
+NSLog(@"字符串时间 = %@", dateStr);
+```
+
+这时获取的时间就是东八区时间,哪怕手机拿到零时区的格林尼治,获取的也是东八区的时间,因为这里指定时区了。也有如下时区指定:
+
+```swift
+//东九区时间
+formatter.timeZone = [NSTimeZone timeZoneWithName:@"AsiTokyo"];
+//零区时间
+formatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
+       
+```
+
+通过下面方法可得到系统支持的时区对应的字符串常量:
+
+```swift
+NSArray *zones = [NSTimeZone knownTimeZoneNames];      
+for (NSString *zone in zones) {    
+   NSLog(@"时区名 = %@", zone); 
+}
+```
+
+- 字符串时间转NSDate
+字符串时间转为NSDate时间也会有时区问题。也会遇到有所谓的8小时误差,其实就是时区不同。比如下面的例子:
+
+```swift
+NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
+NSDate *newDate = [formatter dateFromString:@"2016-12-014:06:24 +0800"];
+NSLog(@"newDate = %@", newDate);
+
+打印结果:
+        2016-12-07 14:12:17.468 timeTest[34279:3155380] newDate = 2016-12-07 06:06:24 +0000
+```
+
+NSDateFormatter的指定格式是:@"yyyy-MM-dd HH:mm:ss Z"。这里面的Z指的是时区。要转化的字符串时间格式必须和这个格式匹配,上面给定的字符串时间是:@"2016-12-07 14:06:24 +0800",是一个东八区时间,转化为NSDate后是零区时间2016-12-07 06:06:24 +0000,字面显示上少了8小时,其实时间一样。
+
+其实如果上面给定的字符串时间为@"2016-12-07 14:06:24 +0000",转化出来的NSDate时间会完全一样,因为字符串时间为零时区时间,不存在时区误差。大家可以试一下。
+
+当不指定字符串时间的时区时,即没有后面的+0800,同时要把NSDateFormatter时间格式里的Z去掉,保证格式匹配。系统会认为字符串时间是系统所在时区的时间,转化为NSDate时间是零时区时间。
+
+同样,也可以使用formatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];这种方式指定字符串时间的时区,和用Z对应+0000是一样的。
+
+- NSDate转当前时区的NSDate时间
+
+因为[NSDate date]得出的时间是零时区时间,当我们要获取当前所在时区的NSDate时间时,通常会用以下方法:
+
+```swift
+NSDate *date = [NSDate date]; 
+NSTimeZone *zone = [NSTimeZone systemTimeZone];
+NSInteger interval = [zone secondsFromGMTForDate:date];
+NSDate *localDate = [datedateByAddingTimeInterval:interval];
+NSLog(@"localDate = %@",localDate);
+
+打印结果:
+
+2016-12-07 14:49:03.777 timeTest[34519:3183548] localDate = 2016-12-07 14:49:03 +0000
+       
+```
+
+上面代码中zone是当前时区,interval是当前时区和零时区时间的差值,最后结果localDate是零时区时间date加上这个差值interval,得到当前时区的NSDate时间。更有甚者,在开发中直接加8*60*60或28800这样的值,因为相差8小时嘛。这样在东八区没问题,在其他时区时间就错了。
+
+其实这种做法是不科学的,因为得到的最终时间还是零时区时间,时间后面明显是+0000,在使用中一般不显示时区,所以认为当做当前时区的时间使用也未尝不可。此为大坑!
+
+坑1:这时如果转为字符串时间,又会增加8小时。因为做时间转换的时候,系统会认为这个NSDate是零时区,得到的字符串时间是东八区的。
+
+解决办法是:将错就错,字符串时间也设置为零时区的字符串时间。从深坑跌入更深的坑!
+
+```swift
+
+NSDate *date = [NSDate date];
+NSTimeZone *zone = [NSTimeZone systemTimeZone];
+NSInteger interval = [zone secondsFromGMTForDate:date];
+NSDate *localDate = [datdateByAddingTimeInterval:interval];
+NSDateFormatter *formatter = [[NSDateFormatter alloc] ini;
+[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
+formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
+NSString *dateStr = [formatter stringFromDate:localDate];
+NSLog(@"字符串时间 = %@", dateStr);
+```
+
+这里的@"UTC"是指世界标准时间,也是现在用的时间标准,东八区比这个时间也是快8小时,这里填@"GMT"也是可以的。

+ 74 - 0
ZZFoundation/Classes/FileManager/NSFileManager+ZZEx.h

@@ -0,0 +1,74 @@
+//
+//  NSFileManager+ZZEx.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSFileManager (ZZEx)
+/// 创建文件夹
+/// @param path 完整的文件夹路径
+/// @return 返回创建结果
++(BOOL)ZZCreatDir:(NSString *)path;
+
+/// 创建文件
+/// @param filePath 完整的文件路径
+/// @return 返回创建结果
++(BOOL)ZZCreatFile:(NSString*)filePath;
+
+/// 写入文件,并且返回写入结果
+/// @param filePath 完整的文件路径
+/// @param data 数据
+/// @return 返回写入结果
+/// @discussion 如果filePath里的文件不存在,会去主动创建
++(BOOL)ZZWriteToFile:(NSString*)filePath contents:(NSData *)data;
+
+/// 往文件后追加数据
+/// @param data 数据
+/// @param filePath 完整的文件路径
+/// @return 返回写入结果
+/// @discussion: 如果filePath里的文件不存在,会去主动创建
++(BOOL)ZZAppendData:(NSData*)data withPath:(NSString *)filePath;
+
+/// 读取文件数据
+/// @param path 完整的文件路径
+/// @return 返回读取的结果
++(NSData*)ZZReadFileData:(NSString *)path;
+
+/// 获取文件列表
+/// @param path 完整的文件路径
+/// @return 返回读取文件列表数组
++(NSArray*)ZZFileList:(NSString*)path;
+
+/// 获取文件夹下所有文件(深度遍历)
+/// @param path 完整的文件路径
+/// @return 返回读取文件列表数组
++(NSArray*)ZZAllFileList:(NSString*)path;
+
++(BOOL)ZZMoveFile:(NSString *)fromPath toPath:(NSString *)toPath toPathIsDir:(BOOL)dir;
+
++(BOOL)ZZMoveItemAtPath:(NSString*)fromPath toPath:(NSString*)toPath;
+
++(BOOL)ZZRemoveFile:(NSString*)filePath;
+
+/// 删除某些后缀的文件
+/// @param suffixList 后缀名集合
+/// @param path 搜索路径
+/// @param deep 是否是深度遍历
++(void)ZZRemoveFileSuffixList:(NSArray<NSString*>*)suffixList filePath:(NSString*)path deep:(BOOL)deep;
+
+
+/// 获取文件大小
+/// @param path 文件路径
++(long long)ZZFileSiZZze:(NSString*)path;
+
+/// 获取文件信息
+/// @param path 文件路径
++(NSDictionary*)ZZFileInfo:(NSString*)path;
+@end
+
+NS_ASSUME_NONNULL_END

+ 228 - 0
ZZFoundation/Classes/FileManager/NSFileManager+ZZEx.m

@@ -0,0 +1,228 @@
+//
+//  NSFileManager+ZZEx.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import "NSFileManager+ZZEx.h"
+
+@implementation NSFileManager (ZZEx)
+#pragma mark -- 创建
++(BOOL)ZZCreatDir:(NSString *)path{
+    if (path.length==0) {
+        return NO;
+    }
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    BOOL isSuccess = YES;
+    BOOL isExist = [fileManager fileExistsAtPath:path];
+    if (isExist==NO) {
+        NSError *error;
+        if (![fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
+            isSuccess = NO;
+            NSLog(@"creat Directory Failed:%@",[error localizedDescription]);
+        }
+    }
+    return isSuccess;
+}
+
++(BOOL)ZZCreatFile:(NSString*)filePath{
+    if (filePath.length==0) {
+        return NO;
+    }
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    if ([fileManager fileExistsAtPath:filePath]) {
+        return YES;
+    }
+    NSError *error;
+    NSString *dirPath = [filePath stringByDeletingLastPathComponent];
+    BOOL isSuccess = [fileManager createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error];
+    if (error) {
+        NSLog(@"creat File Failed:%@",[error localizedDescription]);
+    }
+    if (!isSuccess) {
+        return isSuccess;
+    }
+    isSuccess = [fileManager createFileAtPath:filePath contents:nil attributes:nil];
+    return isSuccess;
+}
+#pragma mark -- 改
++(BOOL)ZZWriteToFile:(NSString*)filePath contents:(NSData *)data{
+    if (filePath.length==0) {
+        return NO;
+    }
+    BOOL result = [self ZZCreatFile:filePath];
+    if (result) {
+        if ([data writeToFile:filePath atomically:YES]) {
+            NSLog(@"write Success");
+        }else{
+            NSLog(@"write Failed");
+        }
+    }
+    else{
+        NSLog(@"write Failed");
+    }
+    return result;
+}
+
++(BOOL)ZZAppendData:(NSData*)data withPath:(NSString *)filePath{
+    if (filePath.length==0) {
+        return NO;
+    }
+    BOOL result = [self ZZCreatFile:filePath];
+    if (result) {
+        NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
+        [handle seekToEndOfFile];
+        [handle writeData:data];
+        [handle synchronizeFile];
+        [handle closeFile];
+    }
+    else{
+        NSLog(@"appendData Failed");
+    }
+    return result;
+}
+
+#pragma mark -- 读
++(NSData*)ZZReadFileData:(NSString *)path{
+    NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:path];
+    NSData *fileData = [handle readDataToEndOfFile];
+    [handle closeFile];
+    return fileData;
+}
+
++(NSArray*)ZZFileList:(NSString*)path{
+    if (path.length==0) {
+        return nil;
+    }
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    NSError *error;
+    NSArray *fileList = [fileManager contentsOfDirectoryAtPath:path error:&error];
+    if (error) {
+        NSLog(@"getFileList Failed:%@",[error localizedDescription]);
+    }
+    return fileList;
+}
+
++(NSArray*)ZZAllFileList:(NSString*)path{
+    if (path.length==0) {
+        return nil;
+    }
+    NSArray *fileArray = [self ZZFileList:path];
+    NSMutableArray *fileArrayNew = [NSMutableArray array];
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    for (NSString *aPath in fileArray) {
+        NSString * fullPath = [path stringByAppendingPathComponent:aPath];
+        BOOL isDir = NO;
+        if ([fileManager fileExistsAtPath:fullPath isDirectory:&isDir]) {
+            if (isDir) {
+                [fileArrayNew addObjectsFromArray:[self ZZAllFileList:fullPath]];
+            }else{
+                [fileArrayNew addObject:fullPath];
+            }
+        }
+    }
+    return fileArrayNew;
+}
+#pragma mark -- 移动
++(BOOL)ZZMoveFile:(NSString *)fromPath toPath:(NSString *)toPath toPathIsDir:(BOOL)dir{
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    if (![fileManager fileExistsAtPath:fromPath]) {
+        NSLog(@"Error: fromPath Not Exist");
+        return NO;
+    }
+    BOOL isDir = NO;
+    BOOL isExist = [fileManager fileExistsAtPath:toPath isDirectory:&isDir];
+    if (isExist) {
+        if (isDir) {
+            if ([self ZZCreatDir:toPath]) {
+                NSString *fileName = fromPath.lastPathComponent;
+                toPath = [toPath stringByAppendingPathComponent:fileName];
+                return [self ZZMoveItemAtPath:fromPath toPath:toPath];
+            }
+        }else{
+            [self ZZRemoveFile:toPath];
+            return [self ZZMoveItemAtPath:fromPath toPath:toPath];
+        }
+    }
+    else{
+        if (dir) {
+            if ([self ZZCreatDir:toPath]) {
+                NSString *fileName = fromPath.lastPathComponent;
+                toPath = [toPath stringByAppendingPathComponent:fileName];
+                return [self ZZMoveItemAtPath:fromPath toPath:toPath];
+            }
+        }else{
+            return [self ZZMoveItemAtPath:fromPath toPath:toPath];
+        }
+    }
+    return NO;
+}
+
++(BOOL)ZZMoveItemAtPath:(NSString*)fromPath toPath:(NSString*)toPath{
+    BOOL result = NO;
+    NSError * error = nil;
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+        result = [fileManager moveItemAtPath:fromPath toPath:toPath error:&error];
+    if (error){
+        NSLog(@"moveFile Fileid:%@",[error localizedDescription]);
+    }
+    return result;
+}
+#pragma mark -- 删除
++(BOOL)ZZRemoveFile:(NSString*)filePath{
+    BOOL isSuccess = NO;
+    NSError *error;
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    isSuccess = [fileManager removeItemAtPath:filePath error:&error];
+    if (error) {
+        NSLog(@"removeFile Field:%@",[error localizedDescription]);
+    }else{
+        NSLog(@"removeFile Success");
+    }
+    return isSuccess;
+}
+
++(void)ZZRemoveFileSuffixList:(NSArray<NSString*>*)suffixList filePath:(NSString*)path deep:(BOOL)deep{
+    NSArray *fileArray = nil;
+    if (deep) {  // 是否深度遍历
+        fileArray = [self ZZAllFileList:path];
+    }else{
+        fileArray = [self ZZFileList:path];
+        NSMutableArray *fileArrayTmp = [NSMutableArray array];
+        for (NSString *fileName in fileArray) {
+            NSString* allPath = [path stringByAppendingPathComponent:fileName];
+            [fileArrayTmp addObject:allPath];
+        }
+        fileArray = fileArrayTmp;
+    }
+    for (NSString *aPath in fileArray) {
+        for (NSString* suffix in suffixList) {
+            if ([aPath hasSuffix:suffix]) {
+                [self ZZRemoveFile:aPath];
+            }
+        }
+    }
+}
+
+
++(long long)ZZFileSiZZze:(NSString*)path{
+    unsigned long long fileLength = 0;
+    NSNumber *fileSize;
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:nil];
+    if ((fileSize = [fileAttributes objectForKey:NSFileSize])) {
+        fileLength = [fileSize unsignedLongLongValue]; //单位是 B
+    }
+    return fileLength;
+}
+
++(NSDictionary*)ZZFileInfo:(NSString*)path{
+    NSError *error;
+    NSDictionary *reslut =  [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
+    if (error) {
+        NSLog(@"getFileInfo Failed:%@",[error localizedDescription]);
+    }
+    return reslut;
+}
+@end

+ 17 - 0
ZZFoundation/Classes/Format/NSDateFormatter+ZZEx.h

@@ -0,0 +1,17 @@
+//
+//  NSDateFormatter+ZZEx.h
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSDateFormatter (ZZEx)
++(instancetype)format1;
++(instancetype)format2;
+@end
+
+NS_ASSUME_NONNULL_END

+ 67 - 0
ZZFoundation/Classes/Format/NSDateFormatter+ZZEx.m

@@ -0,0 +1,67 @@
+//
+//  NSDateFormatter+ZZEx.m
+//  Kiwi
+//
+//  Created by Max on 2020/12/29.
+//
+
+#import "NSDateFormatter+ZZEx.h"
+
+@implementation NSDateFormatter (ZZEx)
++(instancetype)format1{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
+    return format;
+};
+
++(instancetype)format2{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
+    return format;
+};
+
++(instancetype)format3{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy.MM.dd HH:mm:ss"];
+    return format;
+};
+
++(instancetype)format2_1{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy年MM月dd日 HH:mm:ss"];
+    return format;
+};
+
++(instancetype)format4_0{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy-MM-dd"];
+    return format;
+};
++(instancetype)format4_1{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy年MM月dd日"];
+    return format;
+};
++(instancetype)format5{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy/MM/dd"];
+    return format;
+};
++(instancetype)format6{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"yyyy.MM.dd"];
+    return format;
+};
+
++(instancetype)format7{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"HH:mm:ss"];
+    return format;
+};
+
++(instancetype)format8{
+    NSDateFormatter *format = [NSDateFormatter new];
+    [format setDateFormat:@"HH:mm"];
+    return format;
+};
+@end

+ 18 - 0
ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/NSObjec+PropertiesVarMethod.h

@@ -0,0 +1,18 @@
+//
+//  NSObjec+PropertiesVarMethod.h
+//  RuiBeiKang
+//
+//  Created by Apple on 2/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+
+#import <Foundation/Foundation.h>
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSObject (PropertiesVarMethod)
+- (NSArray *)getProperties;
+- (instancetype)getAllMethod;
+@end
+
+NS_ASSUME_NONNULL_END

+ 57 - 0
ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/NSObjec+PropertiesVarMethod.m

@@ -0,0 +1,57 @@
+//
+//  NSObjec+PropertiesVarMethod.m
+//  RuiBeiKang
+//
+//  Created by Apple on 2/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+#import "NSObjec+PropertiesVarMethod.h"
+#import "objc/runtime.h"
+
+@implementation NSObject (PropertiesVarMethod)
+//返回当前类的所有属性
+- (NSArray *)getProperties{
+    
+    // 获取当前类的所有属性
+    unsigned int count;// 记录属性个数
+    objc_property_t *properties = class_copyPropertyList([self class], &count);
+    // 遍历
+    NSMutableArray *mArray = [NSMutableArray array];
+    for (int i = 0; i < count; i++) {
+        
+        // An opaque type that represents an Objective-C declared property.
+        // objc_property_t 属性类型
+        objc_property_t property = properties[i];
+        // 获取属性的名称 C语言字符串
+        const char *cName = property_getName(property);
+        // 转换为Objective C 字符串
+        NSString *name = [NSString stringWithCString:cName encoding:NSUTF8StringEncoding];
+        [mArray addObject:name];
+    }
+    
+    return mArray.copy;
+}
+
+- (instancetype)getAllMethod{
+    unsigned int methodCount =0;
+    Method* methodList = class_copyMethodList([self class],&methodCount);
+    NSMutableArray *methodsArray = [NSMutableArray arrayWithCapacity:methodCount];
+    
+    for(int i=0;i<methodCount;i++)
+    {
+        Method temp = methodList[i];
+        IMP imp = method_getImplementation(temp);
+        SEL name_f = method_getName(temp);
+        const char* name_s =sel_getName(method_getName(temp));
+        int arguments = method_getNumberOfArguments(temp);
+        const char* encoding =method_getTypeEncoding(temp);
+        NSLog(@"方法名:%@,参数个数:%d,编码方式:%@",[NSString stringWithUTF8String:name_s],
+              arguments,
+              [NSString stringWithUTF8String:encoding]);
+        [methodsArray addObject:[NSString stringWithUTF8String:name_s]];
+    }
+    free(methodList);
+    return methodsArray;
+}
+@end

+ 16 - 0
ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/ZZSwizzle.h

@@ -0,0 +1,16 @@
+//
+//  NSObject+ZZSwizzle.h
+//  RuiBeiKang
+//
+//  Created by Apple on 8/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+BOOL ZZ_simple_Swizzle(Class aClass, SEL originalSel,SEL swizzleSel);
+BOOL ZZ_best_Swizzle(Class aClass, SEL originalSel,SEL swizzleSel);
+
+NS_ASSUME_NONNULL_END

+ 33 - 0
ZZFoundation/Classes/NSObject/NSObject+ZZRuntime/ZZSwizzle.m

@@ -0,0 +1,33 @@
+//
+//  NSObject+ZZSwizzle.m
+//  RuiBeiKang
+//
+//  Created by Apple on 8/7/19.
+//  Copyright © 2019年 JW. All rights reserved.
+//
+
+#import "ZZSwizzle.h"
+#import "objc/runtime.h"
+
+BOOL ZZ_simple_Swizzle(Class aClass, SEL originalSel,SEL swizzleSel){
+    
+    Method originalMethod = class_getInstanceMethod(aClass, originalSel);
+    Method swizzleMethod = class_getInstanceMethod(aClass, swizzleSel);
+    method_exchangeImplementations(originalMethod, swizzleMethod);
+    
+    return YES;
+}
+
+BOOL ZZ_best_Swizzle(Class aClass, SEL originalSel,SEL swizzleSel){
+    
+    Method originalMethod = class_getInstanceMethod(aClass, originalSel);
+    Method swizzleMethod = class_getInstanceMethod(aClass, swizzleSel);
+    BOOL didAddMethod = class_addMethod(aClass, originalSel, method_getImplementation(swizzleMethod), method_getTypeEncoding(swizzleMethod));
+    if (didAddMethod) {
+        class_replaceMethod(aClass, swizzleSel, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
+    }else{
+        method_exchangeImplementations(originalMethod, swizzleMethod);
+    }
+
+    return YES;
+}

+ 29 - 4
ZZFoundation/Classes/String/NSString+ZZEx.m

@@ -1,14 +1,29 @@
 //
-//  NSString+Ex.m
+//  NSString+ZZEx.m
 //  Kiwi
 //
 //  Created by Max on 2020/12/28.
 //
 
-#import "NSString+Ex.h"
+#import "NSString+ZZEx.h"
 
 @implementation NSString (Ex)
 
+
+/// 格式化字符串创建
+/// @param format 格式化
+NSString * ZZString(NSString *format, ...)
+{
+    va_list ap;
+    va_start (ap, format);
+
+    NSString *body = [[NSString alloc] initWithFormat:format arguments:ap];
+
+    va_end (ap);
+
+    return body;
+}
+
 -(NSString *)ZZSlice:(NSInteger)star{
     return [self substringFromIndex:star];
 };
@@ -22,7 +37,17 @@
     return [self ZZSlice:star end:star + length];
 }
 
--(NSString *)ZZReplace:(NSString *)replaceStr{
-    [self stringByReplacingCharactersInRange:<#(NSRange)#> withString:<#(nonnull NSString *)#>]
+-(NSArray *)ZZSplit:(NSString *)separator{
+    return [self componentsSeparatedByString:separator];
+};
+
+-(NSString *)ZZReplace:(NSString *)aStr with:(NSString *)bStr{
+    NSMutableString *muStr = [self mutableCopy];
+    NSArray *ranges = [muStr ZZRangeOfSubString:aStr];
+    for (NSValue *value  in ranges) {
+        NSRange range = [value rangeValue];
+        muStr = [[muStr stringByReplacingCharactersInRange:range withString:bStr] mutableCopy];
+    }
+    return muStr;
 }
 @end

+ 68 - 0
ZZFoundation/Classes/String/Regex/NSString+ZZRegex.h

@@ -0,0 +1,68 @@
+//
+//  NSString+ZZRegex.h
+//  InternetHospital
+//
+//  Created by Max on 2020/12/14.
+//  Copyright © 2020 GaoLian. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSString (ZZRegex)
+
+
+/// 是不是阿拉伯数字或小数点
+-(BOOL)ZZCheckAllNumber;
+
+/// 是否是中文
+- (BOOL)ZZCheckAllChinese;
+
+/// 是否全英文
+- (BOOL)ZZCheckAllEnglish;
+
+/// 是否包含英文
+- (BOOL)ZZCheckContainEnglish;
+
+
+/// 是否英文大写
+- (BOOL)ZZCheckCapitalLetter;
+
+/// 是否英文小写
+- (BOOL)ZZCheckSmallLetter;
+
+/// 有效的密码
+- (BOOL)ZZCheckValidPassword;
+
+/// 是不是全为空格
+- (BOOL)ZZCheckAllSpace;
+/// 包含一个以上空格
+- (BOOL)ZZCheckContainSpace;
+/// 是不是url
+-(BOOL)ZZCheckUrl;
+
+/// 有效的人名 姓名校验规则(最多5个汉字)
+- (BOOL)ZZCheckPersonName;
+
+/// 昵称 长度2-10
+- (BOOL)ZZCheckNickName;
+/// 是不是电话号码
+- (BOOL)ZZCheckPhoneNumber;
+
+
+///  单位名称校验规则(20个汉字)
+- (BOOL)ZZCheckCompanyName;
+/// 验证码
+- (BOOL)ZZCheckVerifyCode:(int)length;
+
+/// 身份证
+-(BOOL)ZZCheckIDCardNumber:(NSString *)value;
+
+/// 邮政编码
+- (BOOL)ZZCheckZipcode;
+
+
+@end
+
+NS_ASSUME_NONNULL_END

Fichier diff supprimé car celui-ci est trop grand
+ 216 - 0
ZZFoundation/Classes/String/Regex/NSString+ZZRegex.m


+ 8 - 4
ZZFoundation/Classes/String/Size/NSString+ZZRect.h

@@ -1,5 +1,5 @@
 //
-//  NSString+ZZSize.h
+//  NSString+ZZRect.h
 //  ruibeikang
 //
 //  Created by Apple on 23/7/19.
@@ -10,9 +10,13 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface NSString (ZZSize)
--(CGFloat (^)(CGFloat width,UIFont *font))ZZHeigh;
--(CGFloat (^)(CGFloat heigh,UIFont *font))ZZWidth;
+@interface NSString (ZZRect)
+
+/// 返回block,block的参数是width和font,block的返回值是计算出来的高度
+-(CGFloat (^)(CGFloat width,UIFont *font))ZZRectHeigh;
+
+/// 返回block,block的参数是height和font,block的返回值是计算出来的宽度
+-(CGFloat (^)(CGFloat heigh,UIFont *font))ZZRectWidth;
 @end
 
 NS_ASSUME_NONNULL_END

+ 4 - 4
ZZFoundation/Classes/String/Size/NSString+ZZRect.m

@@ -6,11 +6,11 @@
 //  Copyright © 2019年 Qzz. All rights reserved.
 //
 
-#import "NSString+ZZSize.h"
+#import "NSString+ZZRect.h"
 
-@implementation NSString (ZZSize)
+@implementation NSString (ZZRect)
 
--(CGFloat (^)(CGFloat width,UIFont *font))ZZHeigh{
+-(CGFloat (^)(CGFloat width,UIFont *font))ZZRectHeigh{
     return ^(CGFloat width,UIFont *font){
         NSDictionary *attribute = @{NSFontAttributeName: font};
         CGSize  size = [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT)  options:NSStringDrawingUsesLineFragmentOrigin  |NSStringDrawingUsesFontLeading |NSStringDrawingTruncatesLastVisibleLine attributes:attribute context:nil].size;
@@ -18,7 +18,7 @@
     };
 }
 
--(CGFloat (^)(CGFloat heigh,UIFont *font))ZZWidth{
+-(CGFloat (^)(CGFloat heigh,UIFont *font))ZZRectWidth{
     return ^(CGFloat heigh,UIFont *font){
         NSDictionary *attribute = @{NSFontAttributeName: font};
         CGSize  size = [self boundingRectWithSize:CGSizeMake(heigh,MAXFLOAT)  options:NSStringDrawingUsesLineFragmentOrigin  |NSStringDrawingUsesFontLeading |NSStringDrawingTruncatesLastVisibleLine attributes:attribute context:nil].size;

+ 14 - 0
ZZFoundation/Classes/String/StringRange/NSString+ZZRange.m

@@ -9,4 +9,18 @@
 
 @implementation NSString (ZZRange)
 
+- (NSArray*)ZZRangeOfSubString:(NSString*)subStr{
+    NSMutableArray *rangeArray = [NSMutableArray array];
+    NSString*string1 = [self stringByAppendingString:subStr];
+    NSString *temp;
+    for(int i =0; i < self.length; i ++) {
+        temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)];
+        if ([temp isEqualToString:subStr]) {
+            NSRange range = {i,subStr.length};
+            [rangeArray addObject: [NSValue valueWithRange:range]];
+        }
+    }
+    return rangeArray;
+}
+
 @end

+ 6 - 1
ZZFoundation/Classes/String/ZZFoundation_String.h

@@ -8,5 +8,10 @@
 #ifndef ZZFoundation_String_h
 #define ZZFoundation_String_h
 
-#import "NSString+ZZPath.h"
+#import <NSString+ZZEx.h>
+#import <NSString+ZZPath.h>
+#import <NSString+ZZRegex.h>
+#import <NSString+ZZRect.h>
+#import <NSString+ZZRange.h>
+
 #endif /* ZZFoundation_String_h */

+ 1 - 0
ZZFoundation/Classes/ZZFoundation.h

@@ -9,4 +9,5 @@
 #define ZZFoundation_h
 
 #import "ZZFoundation_String.h"
+#import "ZZFoundation_Date.h"
 #endif /* ZZFoundation_h */