diff --git a/Analytics.xcodeproj/project.pbxproj b/Analytics.xcodeproj/project.pbxproj index a00b2fb09..d99ed7fe9 100644 --- a/Analytics.xcodeproj/project.pbxproj +++ b/Analytics.xcodeproj/project.pbxproj @@ -73,6 +73,7 @@ EADEB8F31DECD335005322DA /* AnalyticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADEB8E71DECD335005322DA /* AnalyticsTests.swift */; }; EADEB8F41DECD335005322DA /* ContextTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADEB8E81DECD335005322DA /* ContextTest.swift */; }; EADEB8F51DECD335005322DA /* CryptoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADEB8E91DECD335005322DA /* CryptoTest.swift */; }; + F61EB4AF1F996DEF0038C8C0 /* AnalyticsUtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61EB4AE1F996DEF0038C8C0 /* AnalyticsUtilTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -163,6 +164,7 @@ EADEB8FF1DED3711005322DA /* circle.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = circle.yml; sourceTree = ""; }; EADEB9001DED3711005322DA /* Analytics.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Analytics.podspec; sourceTree = ""; }; EADEB9011DED3711005322DA /* Podfile.lock */ = {isa = PBXFileReference; lastKnownFileType = text; path = Podfile.lock; sourceTree = ""; }; + F61EB4AE1F996DEF0038C8C0 /* AnalyticsUtilTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyticsUtilTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -255,6 +257,7 @@ EADEB8E61DECD335005322DA /* UserDefaultsStorageTest.swift */, EA8F09731E24C5C600B8B93F /* MiddlewareTests.swift */, EADEB8E71DECD335005322DA /* AnalyticsTests.swift */, + F61EB4AE1F996DEF0038C8C0 /* AnalyticsUtilTests.swift */, EAA542761EB4035400945DA7 /* TrackingTests.swift */, EADEB8E81DECD335005322DA /* ContextTest.swift */, EADEB8E91DECD335005322DA /* CryptoTest.swift */, @@ -613,6 +616,7 @@ EADEB8EE1DECD335005322DA /* HTTPClientTest.swift in Sources */, EADEB8F31DECD335005322DA /* AnalyticsTests.swift in Sources */, EADEB8F11DECD335005322DA /* FileStorageTest.swift in Sources */, + F61EB4AF1F996DEF0038C8C0 /* AnalyticsUtilTests.swift in Sources */, EAA542801EB4382100945DA7 /* StoreKitTrackerTests.swift in Sources */, EA8F09741E24C5C600B8B93F /* MiddlewareTests.swift in Sources */, EADEB8EF1DECD335005322DA /* NSData+SEGGUNZIPP.m in Sources */, diff --git a/Analytics/Classes/Internal/SEGAnalyticsUtils.m b/Analytics/Classes/Internal/SEGAnalyticsUtils.m index 50fddde40..9701baa47 100644 --- a/Analytics/Classes/Internal/SEGAnalyticsUtils.m +++ b/Analytics/Classes/Internal/SEGAnalyticsUtils.m @@ -19,7 +19,8 @@ dispatch_once(&onceToken, ^{ dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; - dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS'Z'"; + dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; }); return [dateFormatter stringFromDate:date]; } diff --git a/AnalyticsTests/AnalyticsTests-Bridging-Header.h b/AnalyticsTests/AnalyticsTests-Bridging-Header.h index 88cd870c6..4b4cdb249 100644 --- a/AnalyticsTests/AnalyticsTests-Bridging-Header.h +++ b/AnalyticsTests/AnalyticsTests-Bridging-Header.h @@ -9,6 +9,7 @@ #import #import #import +#import #import "NSData+SEGGUNZIPP.h" // Temp hack. We should fix the LSNocilla podspec to make this header publicly available diff --git a/AnalyticsTests/AnalyticsUtilTests.swift b/AnalyticsTests/AnalyticsUtilTests.swift new file mode 100644 index 000000000..deda55864 --- /dev/null +++ b/AnalyticsTests/AnalyticsUtilTests.swift @@ -0,0 +1,39 @@ +// +// AnalyticsUtilTests.swift +// Analytics +// +// Created by David Fink on 10/18/17. +// Copyright © 2017 Segment. All rights reserved. +// + + +import Quick +import Nimble +import Analytics + +class AnalyticsUtilTests: QuickSpec { + override func spec() { + + it("format NSDate objects to RFC 3339 complaint string") { + let date = Date(timeIntervalSince1970: 0) + let formattedString = iso8601FormattedString(date) + expect(formattedString) == "1970-01-01T00:00:00.000Z" + + var components = DateComponents() + components.year = 1992 + components.month = 8 + components.day = 6 + components.hour = 7 + components.minute = 32 + components.second = 4 + components.nanosecond = 335000000 + let calendar = NSCalendar(calendarIdentifier: .gregorian)! + calendar.timeZone = TimeZone(secondsFromGMT: -4 * 60 * 60)! + let date2 = calendar.date(from: components)! + let formattedString2 = iso8601FormattedString(date2) + expect(formattedString2) == "1992-08-06T11:32:04.335Z" + } + + } + +}