-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSDate+addition.m
executable file
·43 lines (35 loc) · 1.15 KB
/
NSDate+addition.m
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
//
// NSDate+addition.m
// Closer
//
// Created by Max on 1/16/11.
// Copyright 2011 Lis@cintosh. All rights reserved.
//
#import "NSDate+addition.h"
@implementation NSDate(addition)
- (NSInteger)year
{
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy";
return [dateFormatter stringFromDate:self].integerValue;
}
- (NSString *)naturalTimeString
{
// Returns the more natural time format string. ex: 7h55
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale currentLocale];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
return [dateFormatter stringFromDate:self];
}
- (NSString *)description // ???: USED?
{
if (self.timeIntervalSinceNow < 0)
return nil;
// Returns the smallest format. ex: 22/07/11, 16h09
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale currentLocale];
dateFormatter.dateStyle = NSDateFormatterShortStyle; // e.g.: 22/07/11
NSString * dateString = [dateFormatter stringFromDate:self];
return [NSString stringWithFormat:@"%@, %@", dateString, [self naturalTimeString]];
}
@end