Skip to content

Commit

Permalink
Updated to Swift 2.2. Added more date extension enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
basememara committed Mar 22, 2016
1 parent 7160c59 commit bec0b39
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 252 deletions.
43 changes: 36 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## OS X Finder
.DS_Store
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData
DerivedData/

## Various settings
*.pbxuser
Expand All @@ -14,21 +15,49 @@ DerivedData
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
xcuserdata/

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build
pod_deploy

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 Basem Emara <basememara@gmail.com>
Copyright (c) 2016 Zamzam Inc. <contact@zamzam.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 23 additions & 0 deletions Sources/CLKComplicationServer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CLKComplicationServer.swift
// ZamzamKit
//
// Created by Basem Emara on 3/22/16.
// Copyright © 2016 Zamzam. All rights reserved.
//

import Foundation
import ClockKit

public extension CLKComplicationServer {

public func reloadTimelineForComplications() {
if let complications = self.activeComplications
where complications.any() {
for complication in complications {
self.reloadTimelineForComplication(complication)
}
}
}

}
6 changes: 4 additions & 2 deletions Sources/Extensions/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public extension Array {
var to: [Element] = []
var i = 0
while i < self.count && i < count {
to.append(self[i++])
i += 1
to.append(self[i])
}
return to
}
Expand All @@ -27,7 +28,8 @@ public extension Array {
var to: [Element] = []
var i = count
while i < self.count {
to.append(self[i++])
i += 1
to.append(self[i])
}
return to
}
Expand Down
42 changes: 2 additions & 40 deletions Sources/Extensions/NSDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,8 @@ public extension NSDate {
return (timeSpan, timeLeft, percentComplete)
}

public func yearsFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Year, fromDate: date, toDate: self, options: [])
.year
}

public func monthsFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Month, fromDate: date, toDate: self, options: [])
.month
}

public func weeksFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.WeekOfYear, fromDate: date, toDate: self, options: [])
.weekOfYear
}

public func daysFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Day, fromDate: date, toDate: self, options: [])
.day
}

public func hoursFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Hour, fromDate: date, toDate: self, options: [])
.hour
}

public func minutesFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Minute, fromDate: date, toDate: self, options: [])
.minute
}

public func secondsFrom(date: NSDate) -> Int {
return NSCalendar.currentCalendar()
.components(.Second, fromDate: date, toDate: self, options: [])
.second
public func hasElapsed(seconds: Int, fromDate: NSDate = NSDate()) -> Bool {
return fromDate.timeIntervalSinceDate(self).seconds > seconds
}

}
33 changes: 33 additions & 0 deletions Sources/Extensions/NSTimeInterval.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// NSTimeInterval.swift
// ZamzamKit
//
// Created by Basem Emara on 3/22/16.
// Copyright © 2016 Zamzam. All rights reserved.
//

import Foundation

public extension NSTimeInterval {

public var seconds: Int {
return Int(self)
}

public var minutes: Double {
return self / 60.0
}

public var hours: Double {
return self / 3600.0
}

public var days: Double {
return self / 86400.0
}

public var weeks: Double {
return self / 604800.0
}

}
12 changes: 3 additions & 9 deletions Sources/Protocols/Complicationable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ public extension Complicationable {
}

func reloadComplications() {
if let server = CLKComplicationServer.sharedInstance()
where lastComplicationReload == nil
|| NSDate().timeIntervalSinceDate(lastComplicationReload!)
> NSTimeInterval(complicationExpiryInterval) {
for complication in server.activeComplications {
server.reloadTimelineForComplication(complication)
}

lastComplicationReload = NSDate()
if lastComplicationReload?.hasElapsed(complicationExpiryInterval) ?? true {
CLKComplicationServer.sharedInstance().reloadTimelineForComplications()
lastComplicationReload = NSDate()
}
}

Expand Down
7 changes: 7 additions & 0 deletions ZamzamKit iOSTests/DateTimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ class DateTimeTests: XCTestCase {
"Incremented date by minute should be \(expectedDate)")
}

func testHasElapsed() {
let date = NSDate(fromString: "2016/03/22 09:30")!

XCTAssert(date.hasElapsed(300, fromDate: NSDate(fromString: "2016/03/22 09:40")!),
"Date has elapsed.")
}

}
88 changes: 0 additions & 88 deletions ZamzamKit iOSTests/StorageTests.swift

This file was deleted.

8 changes: 0 additions & 8 deletions ZamzamKit iOSTests/ZamzamKit.playground/Contents.swift

This file was deleted.

6 changes: 0 additions & 6 deletions ZamzamKit iOSTests/ZamzamKit.playground/timeline.xctimeline

This file was deleted.

7 changes: 7 additions & 0 deletions ZamzamKit.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//: Playground - noun: a place where people can play

import UIKit

let date1 = NSDate(timeIntervalSinceNow: -60)
let seconds = NSDate().timeIntervalSinceDate(date1)
print(seconds)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='osx'>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
2 changes: 1 addition & 1 deletion ZamzamKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ZamzamKit"
s.version = "0.8.2"
s.version = "0.8.3"
s.summary = "A Swift framework for rapidly developing Apple mobile apps."
s.description = <<-DESC
ZamzamKit is a Swift framework for Apple devices to allow
Expand Down
Loading

0 comments on commit bec0b39

Please sign in to comment.