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
func combineDateWithTime(date: NSDate, time: NSDate) -> NSDate? { | |
let calendar = NSCalendar.currentCalendar() | |
let dateComponents = calendar.components([.Year, .Month, .Day], fromDate: date) | |
let timeComponents = calendar.components([.Hour, .Minute, .Second], fromDate: time) | |
let mergedComponments = NSDateComponents() | |
mergedComponments.year = dateComponents.year | |
mergedComponments.month = dateComponents.month | |
mergedComponments.day = dateComponents.day |
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
+ (NSDate *) roundDateTo5Minutes:(NSDate *) mydate { | |
NSDateComponents *time = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:mydate]; | |
NSInteger minutes = [time minute]; | |
int remain = minutes % 5; | |
if (remain < 3){ | |
mydate = [mydate dateByAddingTimeInterval:-60 * (remain)]; | |
}else{ | |
mydate = [mydate dateByAddingTimeInterval:60 * (5-remain)]; |