Skip to content

Commit c36311e

Browse files
committed
- Moved files in preparation for parallel release of obj-c and swift pods
1 parent b763d05 commit c36311e

File tree

221 files changed

+11043
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+11043
-61
lines changed

DateTools.podspec

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = 'DateTools'
3-
s.version = '2.0.0-beta.3'
4-
s.summary = 'Dates and time made easy in Swift'
3+
s.version = '2.0.0'
4+
s.summary = 'Dates and time made easy in Objective-c'
55
s.homepage = 'https://github.com/MatthewYork/DateTools'
66

77
s.description = 'DateTools was written to streamline date and time handling in Swift.'
@@ -10,12 +10,12 @@ Pod::Spec.new do |s|
1010
s.author = { "Matthew York" => "[email protected]" }
1111

1212
s.source = { :git => "https://github.com/MatthewYork/DateTools.git",
13-
:tag => "#{s.version.to_s}" }
13+
:tag => "v#{s.version.to_s}" }
1414

1515
s.ios.deployment_target = '8.0'
1616
s.osx.deployment_target = '10.9'
1717
s.requires_arc = true
1818

19-
s.source_files = 'DateTools'
20-
s.resources = 'DateTools/DateTools.bundle'
19+
s.source_files = 'DateTools/DateTools'
20+
s.resources = 'DateTools/DateTools/DateTools.bundle'
2121
end

DateTools/DateTools/DTConstants.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2014 by Matthew York
2+
//
3+
// Permission is hereby granted, free of charge, to any
4+
// person obtaining a copy of this software and
5+
// associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge,
8+
// publish, distribute, sublicense, and/or sell copies of the
9+
// Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall
13+
// be included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
#import <Foundation/Foundation.h>
24+
25+
FOUNDATION_EXPORT const long long SECONDS_IN_YEAR;
26+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_28;
27+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_29;
28+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_30;
29+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_31;
30+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_WEEK;
31+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_DAY;
32+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_HOUR;
33+
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MINUTE;
34+
FOUNDATION_EXPORT const NSInteger MILLISECONDS_IN_DAY;
35+
#import "DTError.h"

DateTools/DateTools/DTConstants.m

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2014 by Matthew York
2+
//
3+
// Permission is hereby granted, free of charge, to any
4+
// person obtaining a copy of this software and
5+
// associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge,
8+
// publish, distribute, sublicense, and/or sell copies of the
9+
// Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall
13+
// be included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
#import "DTConstants.h"
24+
const long long SECONDS_IN_YEAR = 31556900;
25+
const NSInteger SECONDS_IN_MONTH_28 = 2419200;
26+
const NSInteger SECONDS_IN_MONTH_29 = 2505600;
27+
const NSInteger SECONDS_IN_MONTH_30 = 2592000;
28+
const NSInteger SECONDS_IN_MONTH_31 = 2678400;
29+
const NSInteger SECONDS_IN_WEEK = 604800;
30+
const NSInteger SECONDS_IN_DAY = 86400;
31+
const NSInteger SECONDS_IN_HOUR = 3600;
32+
const NSInteger SECONDS_IN_MINUTE = 60;
33+
const NSInteger MILLISECONDS_IN_DAY = 86400000;

DateTools/DateTools/DTError.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2014 by Matthew York
2+
//
3+
// Permission is hereby granted, free of charge, to any
4+
// person obtaining a copy of this software and
5+
// associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge,
8+
// publish, distribute, sublicense, and/or sell copies of the
9+
// Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall
13+
// be included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
#import <Foundation/Foundation.h>
24+
25+
#pragma mark - Domain
26+
extern NSString *const DTErrorDomain;
27+
28+
#pragma mark - Status Codes
29+
static const NSUInteger DTInsertOutOfBoundsException = 0;
30+
static const NSUInteger DTRemoveOutOfBoundsException = 1;
31+
static const NSUInteger DTBadTypeException = 2;
32+
33+
@interface DTError : NSObject
34+
35+
+(void)throwInsertOutOfBoundsException:(NSInteger)index array:(NSArray *)array;
36+
+(void)throwRemoveOutOfBoundsException:(NSInteger)index array:(NSArray *)array;
37+
+(void)throwBadTypeException:(id)obj expectedClass:(Class)classType;
38+
@end

DateTools/DateTools/DTError.m

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (C) 2014 by Matthew York
2+
//
3+
// Permission is hereby granted, free of charge, to any
4+
// person obtaining a copy of this software and
5+
// associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge,
8+
// publish, distribute, sublicense, and/or sell copies of the
9+
// Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall
13+
// be included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
#import "DTError.h"
24+
25+
#pragma mark - Domain
26+
NSString *const DTErrorDomain = @"com.mattyork.dateTools";
27+
28+
@implementation DTError
29+
30+
+(void)throwInsertOutOfBoundsException:(NSInteger)index array:(NSArray *)array{
31+
//Handle possible zero bounds
32+
NSInteger arrayUpperBound = (array.count == 0)? 0:array.count;
33+
34+
//Create info for error
35+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Operation was unsuccessful.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Attempted to insert DTTimePeriod at index %ld but the group is of size [0...%ld].", (long)index, (long)arrayUpperBound],NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Please try an index within the bounds or the group.", nil)};
36+
37+
//Handle Error
38+
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTInsertOutOfBoundsException userInfo:userInfo];
39+
[self printErrorWithCallStack:error];
40+
}
41+
42+
+(void)throwRemoveOutOfBoundsException:(NSInteger)index array:(NSArray *)array{
43+
//Handle possible zero bounds
44+
NSInteger arrayUpperBound = (array.count == 0)? 0:array.count;
45+
46+
//Create info for error
47+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Operation was unsuccessful.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Attempted to remove DTTimePeriod at index %ld but the group is of size [0...%ld].", (long)index, (long)arrayUpperBound],NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Please try an index within the bounds of the group.", nil)};
48+
49+
//Handle Error
50+
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTRemoveOutOfBoundsException userInfo:userInfo];
51+
[self printErrorWithCallStack:error];
52+
}
53+
54+
+(void)throwBadTypeException:(id)obj expectedClass:(Class)classType{
55+
//Create info for error
56+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Operation was unsuccessful.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Attempted to insert object of class %@ when expecting object of class %@.", NSStringFromClass([obj class]), NSStringFromClass(classType)],NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Please try again by inserting a DTTimePeriod object.", nil)};
57+
58+
//Handle Error
59+
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTBadTypeException userInfo:userInfo];
60+
[self printErrorWithCallStack:error];
61+
}
62+
63+
+(void)printErrorWithCallStack:(NSError *)error{
64+
//Print error
65+
NSLog(@"%@", error);
66+
67+
//Print call stack
68+
for (NSString *symbol in [NSThread callStackSymbols]) {
69+
NSLog(@"\n\n %@", symbol);
70+
}
71+
}
72+
@end

DateTools/DateTools/DTTimePeriod.h

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (C) 2014 by Matthew York
2+
//
3+
// Permission is hereby granted, free of charge, to any
4+
// person obtaining a copy of this software and
5+
// associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge,
8+
// publish, distribute, sublicense, and/or sell copies of the
9+
// Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall
13+
// be included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
#import <Foundation/Foundation.h>
24+
25+
26+
typedef NS_ENUM(NSUInteger, DTTimePeriodRelation){
27+
DTTimePeriodRelationAfter,
28+
DTTimePeriodRelationStartTouching,
29+
DTTimePeriodRelationStartInside,
30+
DTTimePeriodRelationInsideStartTouching,
31+
DTTimePeriodRelationEnclosingStartTouching,
32+
DTTimePeriodRelationEnclosing,
33+
DTTimePeriodRelationEnclosingEndTouching,
34+
DTTimePeriodRelationExactMatch,
35+
DTTimePeriodRelationInside,
36+
DTTimePeriodRelationInsideEndTouching,
37+
DTTimePeriodRelationEndInside,
38+
DTTimePeriodRelationEndTouching,
39+
DTTimePeriodRelationBefore,
40+
DTTimePeriodRelationNone //One or more of the dates does not exist
41+
};
42+
43+
typedef NS_ENUM(NSUInteger, DTTimePeriodSize) {
44+
DTTimePeriodSizeSecond,
45+
DTTimePeriodSizeMinute,
46+
DTTimePeriodSizeHour,
47+
DTTimePeriodSizeDay,
48+
DTTimePeriodSizeWeek,
49+
DTTimePeriodSizeMonth,
50+
DTTimePeriodSizeYear
51+
};
52+
53+
typedef NS_ENUM(NSUInteger, DTTimePeriodInterval) {
54+
DTTimePeriodIntervalOpen,
55+
DTTimePeriodIntervalClosed
56+
};
57+
58+
typedef NS_ENUM(NSUInteger, DTTimePeriodAnchor) {
59+
DTTimePeriodAnchorStart,
60+
DTTimePeriodAnchorCenter,
61+
DTTimePeriodAnchorEnd
62+
};
63+
64+
@interface DTTimePeriod : NSObject
65+
66+
/**
67+
* The start date for a DTTimePeriod representing the starting boundary of the time period
68+
*/
69+
@property (nonatomic,strong) NSDate *StartDate;
70+
71+
/**
72+
* The end date for a DTTimePeriod representing the ending boundary of the time period
73+
*/
74+
@property (nonatomic,strong) NSDate *EndDate;
75+
76+
#pragma mark - Custom Init / Factory Methods
77+
-(instancetype)initWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate;
78+
+(instancetype)timePeriodWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate;
79+
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size startingAt:(NSDate *)date;
80+
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount startingAt:(NSDate *)date;
81+
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size endingAt:(NSDate *)date;
82+
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount endingAt:(NSDate *)date;
83+
+(instancetype)timePeriodWithAllTime;
84+
85+
#pragma mark - Time Period Information
86+
-(BOOL)hasStartDate;
87+
-(BOOL)hasEndDate;
88+
-(BOOL)isMoment;
89+
-(double)durationInYears;
90+
-(double)durationInWeeks;
91+
-(double)durationInDays;
92+
-(double)durationInHours;
93+
-(double)durationInMinutes;
94+
-(double)durationInSeconds;
95+
96+
#pragma mark - Time Period Relationship
97+
-(BOOL)isEqualToPeriod:(DTTimePeriod *)period;
98+
-(BOOL)isInside:(DTTimePeriod *)period;
99+
-(BOOL)contains:(DTTimePeriod *)period;
100+
-(BOOL)overlapsWith:(DTTimePeriod *)period;
101+
-(BOOL)intersects:(DTTimePeriod *)period;
102+
-(DTTimePeriodRelation)relationToPeriod:(DTTimePeriod *)period;
103+
-(NSTimeInterval)gapBetween:(DTTimePeriod *)period;
104+
105+
#pragma mark - Date Relationships
106+
-(BOOL)containsDate:(NSDate *)date interval:(DTTimePeriodInterval)interval;
107+
108+
#pragma mark - Period Manipulation
109+
#pragma mark Shifts
110+
-(void)shiftEarlierWithSize:(DTTimePeriodSize)size;
111+
-(void)shiftEarlierWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount;
112+
-(void)shiftLaterWithSize:(DTTimePeriodSize)size;
113+
-(void)shiftLaterWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount;
114+
115+
#pragma mark Lengthen / Shorten
116+
-(void)lengthenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size;
117+
-(void)lengthenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size amount:(NSInteger)amount;
118+
-(void)shortenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size;
119+
-(void)shortenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size amount:(NSInteger)amount;
120+
121+
#pragma mark - Helper Methods
122+
-(DTTimePeriod *)copy;
123+
@end

0 commit comments

Comments
 (0)