NSDate+FormatterAdditions.h 4.08 KB
Newer Older
Sandy's avatar
Sandy committed
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
//
//  NSDate+FormatterAdditions.h
//  JobTalk
//
//  Created by Xummer on 14-5-16.
//  Copyright (c) 2014年 BST. All rights reserved.
//

#import <Foundation/Foundation.h>

// https://github.com/samsoffes/sstoolkit/blob/master/SSToolkit/NSDate%2BSSToolkitAdditions.h

/**
 Provides extensions to `NSDate` for various common tasks.
 */

@interface NSDate (FormatterAdditions)

- (NSString *)year;
- (NSString *)month;
- (NSString *)day;
///---------------
/// @name ISO 8601
///---------------

/**
 Returns a new date represented by an ISO8601 string.
 
 @param iso8601String An ISO8601 string
 
 @return Date represented by the ISO8601 string
 */
+ (NSDate *)dateFromISO8601String:(NSString *)iso8601String;

/**
 Returns a string representation of the receiver in ISO8601 format.
 
 @return A string representation of the receiver in ISO8601 format.
 */
- (NSString *)ISO8601String;

/**
 @param dateFormatter a date formatter, like @"%Y-%m-%dT%H:%M:%SZ".
 
 @return A string representation of the receiver in dateFormatter.
*/
- (NSString *)stringWithFormatter:(NSString *)dateFormatter;

- (NSString *)chatAttachmentFormatterString;
- (NSString *)YMDHMSFormatterString;
- (NSString *)chatMsgFormatterString;
- (NSString *)localYMDString;
- (NSString *)briefTimeForTimeLine;

/** yyyy-MM-dd HH:mm:ss */
- (NSString *)httpParameterString;
/** yyyy-MM-dd */
- (NSString *)yearMonthDayString;
/** yyyy-MM */
- (NSString *)yearMonthString;
// yymmddhhmmssSSS
- (NSString *)mobileIDDateString;

- (NSDate *)endOfTheDay;
- (NSString *)yearString;
- (NSString *)monthString;
- (NSString *)dayString;
- (NSString *)yearWeekString;
///--------------------
/// @name Time In Words
///--------------------

/**
 Returns a string representing the time interval from now in words (including seconds).
 
 The strings produced by this method will be similar to produced by Twitter for iPhone or Tweetbot in the top right of
 the tweet cells.
 
 Internally, this does not use `timeInWordsFromTimeInterval:includingSeconds:`.
 
 @return A string representing the time interval from now in words
 */
- (NSString *)briefTimeInWords;

/**
 Returns a string representing the time interval from now in words (including seconds).
 
 The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
 
 @return A string representing the time interval from now in words
 
 @see timeInWordsIncludingSeconds:
 @see timeInWordsFromTimeInterval:includingSeconds:
 */
- (NSString *)timeInWords;

/**
 Returns a string representing the time interval from now in words.
 
 The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
 
 @param includeSeconds `YES` if seconds should be included. `NO` if they should not.
 
 @return A string representing the time interval from now in words
 
 @see timeInWordsIncludingSeconds:
 @see timeInWordsFromTimeInterval:includingSeconds:
 */
- (NSString *)timeInWordsIncludingSeconds:(BOOL)includeSeconds;

/**
 Returns a string representing a time interval in words.
 
 The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
 
 @param intervalInSeconds The time interval to convert to a string
 
 @param includeSeconds `YES` if seconds should be included. `NO` if they should not.
 
 @return A string representing the time interval in words
 
 @see timeInWords
 @see timeInWordsIncludingSeconds:
 */
+ (NSString *)timeInWordsFromTimeInterval:(NSTimeInterval)intervalInSeconds includingSeconds:(BOOL)includeSeconds;

/** 该日期是该年的第几周 */
- (NSInteger)getWeekOfYear;

+ (NSString *)weekFromeDateString:(NSString *)dateString;
@end

@interface NSDate (DateFormatterAdditions)

- (NSString *)timeStampStr;
+ (NSString *)curTimeStamp;

@end

@interface NSDate (DateCalculate)
- (NSDate *)dateAddHourse: (NSUInteger)hourse;
@end

@interface NSNumber (DateFormatterAdditions)

- (NSDate *)dateValue;

- (NSDate *)overZeroDateValue;

@end

@interface NSString (DateFormatterAdditions)

- (NSTimeInterval)timeStamp;

- (NSDate *)dateValue;

- (NSDate *)overZeroDateValue;

@end