-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Moved files in preparation for parallel release of obj-c and swift …
…pods
- Loading branch information
1 parent
b763d05
commit c36311e
Showing
221 changed files
with
11,043 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'DateTools' | ||
s.version = '2.0.0-beta.3' | ||
s.summary = 'Dates and time made easy in Swift' | ||
s.version = '2.0.0' | ||
s.summary = 'Dates and time made easy in Objective-c' | ||
s.homepage = 'https://github.com/MatthewYork/DateTools' | ||
|
||
s.description = 'DateTools was written to streamline date and time handling in Swift.' | ||
|
@@ -10,12 +10,12 @@ Pod::Spec.new do |s| | |
s.author = { "Matthew York" => "[email protected]" } | ||
|
||
s.source = { :git => "https://github.com/MatthewYork/DateTools.git", | ||
:tag => "#{s.version.to_s}" } | ||
:tag => "v#{s.version.to_s}" } | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.osx.deployment_target = '10.9' | ||
s.requires_arc = true | ||
|
||
s.source_files = 'DateTools' | ||
s.resources = 'DateTools/DateTools.bundle' | ||
s.source_files = 'DateTools/DateTools' | ||
s.resources = 'DateTools/DateTools/DateTools.bundle' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2014 by Matthew York | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the | ||
// Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall | ||
// be included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
FOUNDATION_EXPORT const long long SECONDS_IN_YEAR; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_28; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_29; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_30; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MONTH_31; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_WEEK; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_DAY; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_HOUR; | ||
FOUNDATION_EXPORT const NSInteger SECONDS_IN_MINUTE; | ||
FOUNDATION_EXPORT const NSInteger MILLISECONDS_IN_DAY; | ||
#import "DTError.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2014 by Matthew York | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the | ||
// Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall | ||
// be included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import "DTConstants.h" | ||
const long long SECONDS_IN_YEAR = 31556900; | ||
const NSInteger SECONDS_IN_MONTH_28 = 2419200; | ||
const NSInteger SECONDS_IN_MONTH_29 = 2505600; | ||
const NSInteger SECONDS_IN_MONTH_30 = 2592000; | ||
const NSInteger SECONDS_IN_MONTH_31 = 2678400; | ||
const NSInteger SECONDS_IN_WEEK = 604800; | ||
const NSInteger SECONDS_IN_DAY = 86400; | ||
const NSInteger SECONDS_IN_HOUR = 3600; | ||
const NSInteger SECONDS_IN_MINUTE = 60; | ||
const NSInteger MILLISECONDS_IN_DAY = 86400000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2014 by Matthew York | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the | ||
// Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall | ||
// be included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#pragma mark - Domain | ||
extern NSString *const DTErrorDomain; | ||
|
||
#pragma mark - Status Codes | ||
static const NSUInteger DTInsertOutOfBoundsException = 0; | ||
static const NSUInteger DTRemoveOutOfBoundsException = 1; | ||
static const NSUInteger DTBadTypeException = 2; | ||
|
||
@interface DTError : NSObject | ||
|
||
+(void)throwInsertOutOfBoundsException:(NSInteger)index array:(NSArray *)array; | ||
+(void)throwRemoveOutOfBoundsException:(NSInteger)index array:(NSArray *)array; | ||
+(void)throwBadTypeException:(id)obj expectedClass:(Class)classType; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (C) 2014 by Matthew York | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the | ||
// Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall | ||
// be included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import "DTError.h" | ||
|
||
#pragma mark - Domain | ||
NSString *const DTErrorDomain = @"com.mattyork.dateTools"; | ||
|
||
@implementation DTError | ||
|
||
+(void)throwInsertOutOfBoundsException:(NSInteger)index array:(NSArray *)array{ | ||
//Handle possible zero bounds | ||
NSInteger arrayUpperBound = (array.count == 0)? 0:array.count; | ||
|
||
//Create info for error | ||
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)}; | ||
|
||
//Handle Error | ||
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTInsertOutOfBoundsException userInfo:userInfo]; | ||
[self printErrorWithCallStack:error]; | ||
} | ||
|
||
+(void)throwRemoveOutOfBoundsException:(NSInteger)index array:(NSArray *)array{ | ||
//Handle possible zero bounds | ||
NSInteger arrayUpperBound = (array.count == 0)? 0:array.count; | ||
|
||
//Create info for error | ||
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)}; | ||
|
||
//Handle Error | ||
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTRemoveOutOfBoundsException userInfo:userInfo]; | ||
[self printErrorWithCallStack:error]; | ||
} | ||
|
||
+(void)throwBadTypeException:(id)obj expectedClass:(Class)classType{ | ||
//Create info for error | ||
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)}; | ||
|
||
//Handle Error | ||
NSError *error = [NSError errorWithDomain:DTErrorDomain code:DTBadTypeException userInfo:userInfo]; | ||
[self printErrorWithCallStack:error]; | ||
} | ||
|
||
+(void)printErrorWithCallStack:(NSError *)error{ | ||
//Print error | ||
NSLog(@"%@", error); | ||
|
||
//Print call stack | ||
for (NSString *symbol in [NSThread callStackSymbols]) { | ||
NSLog(@"\n\n %@", symbol); | ||
} | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright (C) 2014 by Matthew York | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the | ||
// Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall | ||
// be included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
typedef NS_ENUM(NSUInteger, DTTimePeriodRelation){ | ||
DTTimePeriodRelationAfter, | ||
DTTimePeriodRelationStartTouching, | ||
DTTimePeriodRelationStartInside, | ||
DTTimePeriodRelationInsideStartTouching, | ||
DTTimePeriodRelationEnclosingStartTouching, | ||
DTTimePeriodRelationEnclosing, | ||
DTTimePeriodRelationEnclosingEndTouching, | ||
DTTimePeriodRelationExactMatch, | ||
DTTimePeriodRelationInside, | ||
DTTimePeriodRelationInsideEndTouching, | ||
DTTimePeriodRelationEndInside, | ||
DTTimePeriodRelationEndTouching, | ||
DTTimePeriodRelationBefore, | ||
DTTimePeriodRelationNone //One or more of the dates does not exist | ||
}; | ||
|
||
typedef NS_ENUM(NSUInteger, DTTimePeriodSize) { | ||
DTTimePeriodSizeSecond, | ||
DTTimePeriodSizeMinute, | ||
DTTimePeriodSizeHour, | ||
DTTimePeriodSizeDay, | ||
DTTimePeriodSizeWeek, | ||
DTTimePeriodSizeMonth, | ||
DTTimePeriodSizeYear | ||
}; | ||
|
||
typedef NS_ENUM(NSUInteger, DTTimePeriodInterval) { | ||
DTTimePeriodIntervalOpen, | ||
DTTimePeriodIntervalClosed | ||
}; | ||
|
||
typedef NS_ENUM(NSUInteger, DTTimePeriodAnchor) { | ||
DTTimePeriodAnchorStart, | ||
DTTimePeriodAnchorCenter, | ||
DTTimePeriodAnchorEnd | ||
}; | ||
|
||
@interface DTTimePeriod : NSObject | ||
|
||
/** | ||
* The start date for a DTTimePeriod representing the starting boundary of the time period | ||
*/ | ||
@property (nonatomic,strong) NSDate *StartDate; | ||
|
||
/** | ||
* The end date for a DTTimePeriod representing the ending boundary of the time period | ||
*/ | ||
@property (nonatomic,strong) NSDate *EndDate; | ||
|
||
#pragma mark - Custom Init / Factory Methods | ||
-(instancetype)initWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate; | ||
+(instancetype)timePeriodWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate; | ||
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size startingAt:(NSDate *)date; | ||
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount startingAt:(NSDate *)date; | ||
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size endingAt:(NSDate *)date; | ||
+(instancetype)timePeriodWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount endingAt:(NSDate *)date; | ||
+(instancetype)timePeriodWithAllTime; | ||
|
||
#pragma mark - Time Period Information | ||
-(BOOL)hasStartDate; | ||
-(BOOL)hasEndDate; | ||
-(BOOL)isMoment; | ||
-(double)durationInYears; | ||
-(double)durationInWeeks; | ||
-(double)durationInDays; | ||
-(double)durationInHours; | ||
-(double)durationInMinutes; | ||
-(double)durationInSeconds; | ||
|
||
#pragma mark - Time Period Relationship | ||
-(BOOL)isEqualToPeriod:(DTTimePeriod *)period; | ||
-(BOOL)isInside:(DTTimePeriod *)period; | ||
-(BOOL)contains:(DTTimePeriod *)period; | ||
-(BOOL)overlapsWith:(DTTimePeriod *)period; | ||
-(BOOL)intersects:(DTTimePeriod *)period; | ||
-(DTTimePeriodRelation)relationToPeriod:(DTTimePeriod *)period; | ||
-(NSTimeInterval)gapBetween:(DTTimePeriod *)period; | ||
|
||
#pragma mark - Date Relationships | ||
-(BOOL)containsDate:(NSDate *)date interval:(DTTimePeriodInterval)interval; | ||
|
||
#pragma mark - Period Manipulation | ||
#pragma mark Shifts | ||
-(void)shiftEarlierWithSize:(DTTimePeriodSize)size; | ||
-(void)shiftEarlierWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount; | ||
-(void)shiftLaterWithSize:(DTTimePeriodSize)size; | ||
-(void)shiftLaterWithSize:(DTTimePeriodSize)size amount:(NSInteger)amount; | ||
|
||
#pragma mark Lengthen / Shorten | ||
-(void)lengthenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size; | ||
-(void)lengthenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size amount:(NSInteger)amount; | ||
-(void)shortenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size; | ||
-(void)shortenWithAnchorDate:(DTTimePeriodAnchor)anchor size:(DTTimePeriodSize)size amount:(NSInteger)amount; | ||
|
||
#pragma mark - Helper Methods | ||
-(DTTimePeriod *)copy; | ||
@end |
Oops, something went wrong.