diff --git a/Clocker/Clocker.xcodeproj/project.pbxproj b/Clocker/Clocker.xcodeproj/project.pbxproj index c5f3d17..62049eb 100755 --- a/Clocker/Clocker.xcodeproj/project.pbxproj +++ b/Clocker/Clocker.xcodeproj/project.pbxproj @@ -51,6 +51,7 @@ 3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; }; 3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; }; 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; }; + 35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */; }; 357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; }; 357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; }; 3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; }; @@ -286,6 +287,7 @@ 3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = ""; }; 3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = ""; }; 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = ""; }; + 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatterManagerTests.swift; sourceTree = ""; }; 3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; 357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = ""; }; 357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = ""; }; @@ -881,6 +883,7 @@ C20839CB21515C1F00C86589 /* Info.plist */, 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */, 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */, + 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */, ); path = ClockerUnitTests; sourceTree = ""; @@ -1268,6 +1271,7 @@ files = ( 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */, 9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */, + 35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */, C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index 48e8b5d..994ff35 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -392,4 +392,15 @@ class ClockerUnitTests: XCTestCase { XCTAssertNotNil(convertedDate) } } + + func testStringFiltering() { + let stringWithComma = "Mumbai, Maharashtra" + let stringWithoutComma = "Mumbai" + let emptyString = "" + + XCTAssertEqual(stringWithComma.filteredName(), "Mumbai") + XCTAssertEqual(stringWithoutComma.filteredName(), "Mumbai") + XCTAssertEqual(emptyString.filteredName(), "") + + } } diff --git a/Clocker/ClockerUnitTests/DateFormatterManagerTests.swift b/Clocker/ClockerUnitTests/DateFormatterManagerTests.swift new file mode 100644 index 0000000..0ae9e05 --- /dev/null +++ b/Clocker/ClockerUnitTests/DateFormatterManagerTests.swift @@ -0,0 +1,36 @@ +// Copyright © 2015 Abhishek Banthia + +import XCTest + +@testable import Clocker; + +class DateFormatterManagerTests: XCTestCase { + + func testRegularDateFormatter() throws { + let subject = DateFormatterManager.dateFormatter(with: .medium, for: "UTC") + XCTAssertEqual(subject.dateStyle, .medium) + XCTAssertEqual(subject.timeStyle, .medium) + XCTAssertEqual(subject.locale.identifier, "en_US") + XCTAssertEqual(subject.timeZone.identifier, "GMT") + } + + func testDateFormatterWithFormat() throws { + let subject = DateFormatterManager.dateFormatterWithFormat(with: .none, format: "hh:mm a", timezoneIdentifier: "Asia/Calcutta") + XCTAssertEqual(subject.dateStyle, .none) + XCTAssertEqual(subject.timeStyle, .none) + XCTAssertEqual(subject.locale.identifier, "en_US") + XCTAssertEqual(subject.timeZone.identifier, "Asia/Calcutta") + XCTAssertEqual(subject.locale.identifier, "en_US") + XCTAssertEqual(subject.dateFormat, "hh:mm a") + } + + func testLocalizedDateFormatter() throws { + let subject = DateFormatterManager.localizedFormatter(with: "hh:mm:ss", for: "America/Los_Angeles") + XCTAssertEqual(subject.dateStyle, .none) + XCTAssertEqual(subject.timeStyle, .none) + XCTAssertEqual(subject.locale.identifier, Locale.autoupdatingCurrent.identifier) + XCTAssertEqual(subject.timeZone.identifier, "America/Los_Angeles") + XCTAssertEqual(subject.dateFormat, "hh:mm:ss") + } + +} diff --git a/Clocker/Overall App/DateFormatterManager.swift b/Clocker/Overall App/DateFormatterManager.swift index db70d94..2a11b0f 100644 --- a/Clocker/Overall App/DateFormatterManager.swift +++ b/Clocker/Overall App/DateFormatterManager.swift @@ -3,7 +3,6 @@ import Cocoa class DateFormatterManager: NSObject { - public static let sharedInstance = DateFormatterManager() private static var dateFormatter = DateFormatter() private static var calendarDateFormatter = DateFormatter() @@ -22,21 +21,6 @@ class DateFormatterManager: NSObject { return dateFormatter } - class func dateFormatterWithCalendar(with style: DateFormatter.Style) -> DateFormatter { - calendarDateFormatter.dateStyle = style - calendarDateFormatter.timeStyle = style - calendarDateFormatter.locale = USLocale - calendarDateFormatter.calendar = gregorianCalendar - return calendarDateFormatter - } - - class func simpleFormatter(with style: DateFormatter.Style) -> DateFormatter { - simpleFormatter.dateStyle = style - simpleFormatter.timeStyle = style - simpleFormatter.locale = USLocale - return simpleFormatter - } - class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter { specializedFormatter.dateStyle = style specializedFormatter.timeStyle = style @@ -55,15 +39,6 @@ class DateFormatterManager: NSObject { return dateFormatter } - class func localizedCalendaricalDateFormatter(with format: String) -> DateFormatter { - calendarDateFormatter.dateStyle = .none - calendarDateFormatter.timeStyle = .none - calendarDateFormatter.locale = Locale.autoupdatingCurrent - calendarDateFormatter.dateFormat = format - calendarDateFormatter.calendar = gregorianCalendar - return calendarDateFormatter - } - class func localizedSimpleFormatter(_ format: String) -> DateFormatter { localizedSimpleFormatter.dateStyle = .none localizedSimpleFormatter.timeStyle = .none