Skip to content

Commit 048264d

Browse files
committed
fix minor things
1 parent 1e822f8 commit 048264d

File tree

13 files changed

+287
-140
lines changed

13 files changed

+287
-140
lines changed

EasyNSDateHandler.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Pod::Spec.new do |s|
1010
s.name = "EasyNSDateHandler"
1111
s.version = "0.1.0"
12-
s.summary = "This library is created for avoiding boilerplate code when generating NSDate from year month date and when getting string output from NSDate."
12+
s.summary = "This library is created for avoiding boilerplate code when dealing with NSDate creation and output."
1313

1414
# This description is used to generate tags and improve search results.
1515
# * Think: What does it do? Why did you write it? What is the focus?

Example/EasyNSDateHandler/KViewController.m

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "KViewController.h"
10+
#import "NSDate+EasyDatetimeHandler.h"
1011

1112
@interface KViewController ()
1213

@@ -18,6 +19,8 @@ - (void)viewDidLoad
1819
{
1920
[super viewDidLoad];
2021
// Do any additional setup after loading the view, typically from a nib.
22+
NSDate *date = [NSDate dateWithYear:2016 month:3 day:15];
23+
NSLog(@"%@", [date toStringWithDateFormat:NSDateToStringFormatOrderByYearDateMonth dateComponentSeparator:@"🍥"]);
2124
}
2225

2326
- (void)didReceiveMemoryWarning

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
EasyNSDateHandler: 67f6a0fd71a47942a77895949e57a62693d0ae57
12+
EasyNSDateHandler: 8448eb100134a160437f1c2c5b1e8eba6d0806dd
1313

1414
COCOAPODS: 0.39.0

Example/Pods/Headers/Private/EasyNSDateHandler/NSDate+EasyDatetimeHandler.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Local Podspecs/EasyNSDateHandler.podspec.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

+134-130
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/EasyNSDateHandler.xcscheme

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/EasyNSDateHandler/EasyNSDateHandler-umbrella.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// NSDate+EasyDatetimeHandler.h
3+
// TestDatetimeConverter
4+
//
5+
// Created by minhnh on 3/15/16.
6+
// Copyright © 2016 minhnh. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
typedef NS_ENUM(NSInteger, NSDateToStringFormatOrderByComponent) {
12+
NSDateToStringFormatOrderByYearMonthDate,
13+
NSDateToStringFormatOrderByYearDateMonth,
14+
NSDateToStringFormatOrderByMonthDateYear,
15+
NSDateToStringFormatOrderByDateMonthYear,
16+
NSDateToStringFormatOrderByYearMonth,
17+
NSDateToStringFormatOrderByMonthYear,
18+
NSDateToStringFormatOrderByDateMonth,
19+
NSDateToStringFormatOrderByMonthDate
20+
};
21+
22+
@interface NSDate (EasyDatetimeHandler)
23+
24+
/*!
25+
* @brief Create a NSDate from given year, month and day
26+
*/
27+
+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
28+
29+
/*!
30+
* @brief Generate a NSString output from NSDate object with given format and date/month/year separator symbol
31+
*/
32+
- (NSString *)toStringWithDateFormat:(NSDateToStringFormatOrderByComponent)format dateComponentSeparator:(NSString *)separator;
33+
34+
@end
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// NSDate+EasyDatetimeHandler.m
3+
// TestDatetimeConverter
4+
//
5+
// Created by minhnh on 3/15/16.
6+
// Copyright © 2016 minhnh. All rights reserved.
7+
//
8+
9+
#import "NSDate+EasyDatetimeHandler.h"
10+
11+
@implementation NSDate (EasyDatetimeHandler)
12+
13+
+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
14+
NSDate *date;
15+
16+
NSCalendar *calendar = [NSCalendar currentCalendar];
17+
NSDateComponents *components = [[NSDateComponents alloc] init];
18+
19+
components.year = year;
20+
components.month = month;
21+
components.day = day;
22+
23+
date = [calendar dateFromComponents:components];
24+
25+
return date;
26+
}
27+
28+
- (NSString *)toStringWithDateFormat:(NSDateToStringFormatOrderByComponent)format dateComponentSeparator:(NSString *)separator {
29+
NSString *returnedString;
30+
31+
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
32+
switch (format) {
33+
case NSDateToStringFormatOrderByYearMonthDate: {
34+
formatter.dateFormat = [NSString stringWithFormat:@"yyyy%@MM%@dd", separator, separator];
35+
break;
36+
}
37+
case NSDateToStringFormatOrderByYearDateMonth: {
38+
formatter.dateFormat = [NSString stringWithFormat:@"yyyy%@dd%@MM", separator, separator];
39+
break;
40+
}
41+
case NSDateToStringFormatOrderByMonthDateYear: {
42+
formatter.dateFormat = [NSString stringWithFormat:@"MM%@dd%@yyyy", separator, separator];
43+
break;
44+
}
45+
case NSDateToStringFormatOrderByDateMonthYear: {
46+
formatter.dateFormat = [NSString stringWithFormat:@"dd%@MM%@yyyy", separator, separator];
47+
break;
48+
}
49+
case NSDateToStringFormatOrderByYearMonth: {
50+
formatter.dateFormat = [NSString stringWithFormat:@"yyyy%@MM", separator];
51+
break;
52+
}
53+
case NSDateToStringFormatOrderByMonthYear: {
54+
formatter.dateFormat = [NSString stringWithFormat:@"MM%@yyyy", separator];
55+
break;
56+
}
57+
case NSDateToStringFormatOrderByDateMonth: {
58+
formatter.dateFormat = [NSString stringWithFormat:@"dd%@MM", separator];
59+
break;
60+
}
61+
case NSDateToStringFormatOrderByMonthDate: {
62+
formatter.dateFormat = [NSString stringWithFormat:@"MM%@dd", separator];
63+
break;
64+
}
65+
}
66+
67+
returnedString = [formatter stringFromDate:self];
68+
69+
return returnedString;
70+
}
71+
72+
@end

Pod/Classes/ReplaceMe.m

Whitespace-only changes.

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ To run the example project, clone the repo, and run `pod install` from the Examp
1111

1212
## Requirements
1313

14+
iOS ~> 6.0 or later
15+
1416
## Installation
1517

1618
EasyNSDateHandler is available through [CocoaPods](http://cocoapods.org). To install
@@ -20,9 +22,39 @@ it, simply add the following line to your Podfile:
2022
pod "EasyNSDateHandler"
2123
```
2224

25+
## Usage
26+
27+
* Include NSDate+EasyDatetimeHandler.h header
28+
29+
* Create a NSDate from given year, month, date
30+
31+
```objective-c
32+
+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
33+
```
34+
35+
* Get NSString output from NSDate object
36+
37+
```objective-c
38+
- (NSString *)toStringWithDateFormat:(NSDateToStringFormatOrderByComponent)format dateComponentSeparator:(NSString *)separator;
39+
```
40+
41+
The NSDateToStringFormatOrderByComponent enum as below
42+
```objective-c
43+
typedef NS_ENUM(NSInteger, NSDateToStringFormatOrderByComponent) {
44+
NSDateToStringFormatOrderByYearMonthDate,
45+
NSDateToStringFormatOrderByYearDateMonth,
46+
NSDateToStringFormatOrderByMonthDateYear,
47+
NSDateToStringFormatOrderByDateMonthYear,
48+
NSDateToStringFormatOrderByYearMonth,
49+
NSDateToStringFormatOrderByMonthYear,
50+
NSDateToStringFormatOrderByDateMonth,
51+
NSDateToStringFormatOrderByMonthDate
52+
};
53+
```
54+
2355
## Author
2456
25-
Minh Hoang, [email protected]
57+
Kaopiz Software Co., Ltd.
2658
2759
## License
2860

0 commit comments

Comments
 (0)