Skip to content

Commit

Permalink
Fixed daylight savings issues
Browse files Browse the repository at this point in the history
  • Loading branch information
melvitax committed Jul 7, 2015
1 parent 0315866 commit 15daf87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AFDateHelper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "AFDateHelper"
s.version = "2.0.0"
s.version = "2.0.1"
s.summary = "Extension for NSDate in Swift."
s.description = <<-DESC
Extension for NSDate in Swift for creating, modifying or comparing dates.
Expand Down
32 changes: 19 additions & 13 deletions AFDateHelper/AFDateExtension.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AFDateExtension.swift
//
// Version 2.0.0
// Version 2.0.1
//
// Created by Melvin Rivera on 7/15/14.
// Copyright (c) 2014. All rights reserved.
Expand Down Expand Up @@ -236,38 +236,44 @@ extension NSDate {

func dateByAddingDays(days: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate + NSDate.dayInSeconds() * Double(days)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.day = days
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateBySubtractingDays(days: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate - NSDate.dayInSeconds() * Double(days)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.day = (days * -1)
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateByAddingHours(hours: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate + NSDate.hourInSeconds() * Double(hours)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.hour = hours
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateBySubtractingHours(hours: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate - NSDate.hourInSeconds() * Double(hours)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.hour = (hours * -1)
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateByAddingMinutes(minutes: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate + NSDate.minuteInSeconds() * Double(minutes)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.minute = minutes
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateBySubtractingMinutes(minutes: Int) -> NSDate
{
let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate - NSDate.minuteInSeconds() * Double(minutes)
return NSDate(timeIntervalSinceReferenceDate: interval)
let dateComp = NSDateComponents()
dateComp.minute = (minutes * -1)
return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(0))!
}

func dateAtStartOfDay() -> NSDate
Expand Down

0 comments on commit 15daf87

Please sign in to comment.