Skip to content

Commit 0d49d79

Browse files
committed
Added TimeFormatter and updated podspec to 1.1
1 parent 13a52a9 commit 0d49d79

File tree

12 files changed

+118
-2
lines changed

12 files changed

+118
-2
lines changed

PGLFormatter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "PGLFormatter"
4-
s.version = "0.0.3"
4+
s.version = "1.1"
55
s.summary = "Simple container of NSFormatter and useful functions to format numbers and dates."
66

77
s.description = <<-DESC

PGLFormatter.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@
210210
1277BEB81AB7419A002BBE75 /* Project object */ = {
211211
isa = PBXProject;
212212
attributes = {
213+
LastSwiftUpdateCheck = 0700;
213214
LastUpgradeCheck = 0620;
214215
ORGANIZATIONNAME = PGL;
215216
TargetAttributes = {
216217
1277BEC01AB7419A002BBE75 = {
217218
CreatedOnToolsVersion = 6.2;
219+
DevelopmentTeam = Y78FS8L855;
218220
};
219221
1277BECB1AB7419A002BBE75 = {
220222
CreatedOnToolsVersion = 6.2;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "0715DAFD05ED3E65A6B1BD9AF5B11D24A4215E61",
3+
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
4+
5+
},
6+
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
7+
"0715DAFD05ED3E65A6B1BD9AF5B11D24A4215E61" : 0,
8+
"A324B32EF1CE1721FF5AE80AAEDCAB397C0AE1AC" : 0
9+
},
10+
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "42974120-6A7C-4480-A0AB-1868DD62A591",
11+
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
12+
"0715DAFD05ED3E65A6B1BD9AF5B11D24A4215E61" : "PGLFormatter\/",
13+
"A324B32EF1CE1721FF5AE80AAEDCAB397C0AE1AC" : ""
14+
},
15+
"DVTSourceControlWorkspaceBlueprintNameKey" : "PGLFormatter",
16+
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
17+
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "PGLFormatter.xcodeproj",
18+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
19+
{
20+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/PGLongo\/PGLFormatter",
21+
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
22+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "0715DAFD05ED3E65A6B1BD9AF5B11D24A4215E61"
23+
},
24+
{
25+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "http:\/\/git.soullesspg.com\/scm\/keyn\/ios.git",
26+
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
27+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A324B32EF1CE1721FF5AE80AAEDCAB397C0AE1AC"
28+
}
29+
]
30+
}

PGLFormatter/Double.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,14 @@ public extension Double {
6767
func formatMass(unit: NSMassFormatterUnit)->String{
6868
return PGLFormatter.massFormatter.stringFromValue(self, unit:unit)
6969
}
70+
71+
72+
/**
73+
Returns a properly formatted time string for self
74+
:returns: A localized string that combines self.
75+
*/
76+
func formatTime()->String?{
77+
return PGLFormatter.timeFormatter.stringFromTimeInterval(self)
78+
}
7079

7180
}

PGLFormatter/Float.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public extension Float {
6868
func formatMass(unit: NSMassFormatterUnit)->String{
6969
return PGLFormatter.massFormatter.stringFromValue(Double(self), unit:unit)
7070
}
71+
72+
/**
73+
Returns a properly formatted time string for self
74+
:returns: A localized string that combines self.
75+
*/
76+
func formatTime()->String?{
77+
return PGLFormatter.timeFormatter.stringFromTimeInterval(Double(self))
78+
}
7179

7280
}
7381

PGLFormatter/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

PGLFormatter/Int.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public extension Int {
6767
return PGLFormatter.massFormatter.stringFromValue(Double(self), unit:unit)
6868
}
6969

70+
/**
71+
Returns a properly formatted time string for self
72+
:returns: A localized string that combines self.
73+
*/
74+
func formatTime()->String?{
75+
return PGLFormatter.timeFormatter.stringFromTimeInterval(Double(self))
76+
}
7077
}
7178

7279
public extension Int64 {
@@ -78,5 +85,7 @@ public extension Int64 {
7885
func formatToByte() -> String {
7986
return PGLFormatter.byteFormatter.stringFromByteCount(self)
8087
}
88+
89+
8190

8291
}

PGLFormatter/PGLFormatter.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ public class PGLFormatter: NSObject {
9090
}
9191

9292

93+
/**
94+
TimeFormatter
95+
*/
96+
public class var timeFormatter: NSDateComponentsFormatter {
97+
struct Static {
98+
static let instance : NSDateComponentsFormatter = {
99+
let formatter = NSDateComponentsFormatter()
100+
return formatter
101+
}()
102+
103+
}
104+
return Static.instance
105+
}
106+
93107

94108

95109

PGLFormatterTests/Extensions/DoubleTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,17 @@ class DoubleTests: XCTestCase {
7575
formatter.unitStyle = .Long
7676
XCTAssertEqual("42.42 kilograms", Double(42.42).formatMass(.Kilogram))
7777
}
78+
79+
func testFormatTime(){
80+
var formatter = PGLFormatter.timeFormatter
81+
XCTAssertNotNil(formatter, "Formatter should be not nil")
82+
formatter.unitsStyle = .Abbreviated
83+
XCTAssertEqual("-42s", (Double(-42)).formatTime()!)
84+
XCTAssertEqual("42s", (Double(42.42)).formatTime()!)
85+
XCTAssertEqual("42s", (Double(42)).formatTime()!)
86+
XCTAssertEqual("1h 10m", Double(4200).formatTime()!)
87+
88+
}
89+
7890

7991
}

PGLFormatterTests/Extensions/FloatTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ class FloatTests: XCTestCase {
7575
formatter.unitStyle = .Long
7676
XCTAssertEqual("42.42 kilograms", Float(42.42).formatMass(.Kilogram))
7777
}
78+
79+
func testFormatTime(){
80+
var formatter = PGLFormatter.timeFormatter
81+
XCTAssertNotNil(formatter, "Formatter should be not nil")
82+
formatter.unitsStyle = .Abbreviated
83+
XCTAssertEqual("-42s", (Float(-42)).formatTime()!)
84+
XCTAssertEqual("42s", (Float(42.42)).formatTime()!)
85+
XCTAssertEqual("42s", (Float(42)).formatTime()!)
86+
XCTAssertEqual("1h 10m", Float(4200).formatTime()!)
87+
88+
}
7889

7990

8091
}

0 commit comments

Comments
 (0)