Skip to content

Commit

Permalink
Added a method to set the hour, minute, second of a date
Browse files Browse the repository at this point in the history
  • Loading branch information
melvitax committed Apr 1, 2016
1 parent 16a27e6 commit 1d87788
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 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 = "3.1.2"
s.version = "3.2.0"
s.summary = "NSDate Extension for Swift 2.0"
s.description = <<-DESC
Extension for NSDate in Swift for creating, modifying or comparing dates.
Expand Down
15 changes: 14 additions & 1 deletion AFDateHelper/AFDateExtension.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AFDateExtension.swift
//
// Version 3.1.1
// Version 3.2.0
//
// Created by Melvin Rivera on 7/15/14.
// Copyright (c) 2014. All rights reserved.
Expand Down Expand Up @@ -545,6 +545,19 @@ public extension NSDate {
return NSDate().dateBySubtractingDays(1).dateAtStartOfDay()
}

/**
Return a new NSDate object with the new hour, minute and seconds values
:returns: NSDate
*/
func setTimeOfDate(hour hour: Int, minute: Int, second: Int) -> NSDate {
let components = self.components()
components.hour = hour
components.minute = minute
components.second = second
return NSCalendar.currentCalendar().dateFromComponents(components)!
}


// MARK: Retrieving Intervals

Expand Down
4 changes: 4 additions & 0 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class ViewController: UITableViewController {
date = now.dateAtTheEndOfMonth()
sectionItems.append(TableItem(title: "End of Month", description: "\(date.toString())"))

// MARK: setTimeOfDate
date = now.setTimeOfDate(hour: 6, minute: 30, second: 15)
sectionItems.append(TableItem(title: "Set Time of Date", description: "\(date.toString())"))

items.append(sectionItems)


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ date.dateAtStartOfWeek() -> NSDate
date.dateAtEndOfWeek() -> NSDate
date.dateAtTheStartOfMonth() -> NSDate
date.dateAtTheEndOfMonth() -> NSDate
date.setTimeOfDate(hour: 6, minute: 30, second: 15) -> NSDate
```

### Time Interval Between Dates
Expand Down

0 comments on commit 1d87788

Please sign in to comment.