Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format NSDate objects to RFC 3339 compliant strings. #723

Merged
merged 2 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -163,6 +164,7 @@
EADEB8FF1DED3711005322DA /* circle.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = circle.yml; sourceTree = "<group>"; };
EADEB9001DED3711005322DA /* Analytics.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Analytics.podspec; sourceTree = "<group>"; };
EADEB9011DED3711005322DA /* Podfile.lock */ = {isa = PBXFileReference; lastKnownFileType = text; path = Podfile.lock; sourceTree = "<group>"; };
F61EB4AE1F996DEF0038C8C0 /* AnalyticsUtilTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyticsUtilTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
3 changes: 2 additions & 1 deletion Analytics/Classes/Internal/SEGAnalyticsUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions AnalyticsTests/AnalyticsTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <Analytics/NSData+SEGGZIP.h>
#import <Analytics/SEGStoreKitTracker.h>
#import <Analytics/UIViewController+SEGScreen.h>
#import <Analytics/SEGAnalyticsUtils.h>

#import "NSData+SEGGUNZIPP.h"
// Temp hack. We should fix the LSNocilla podspec to make this header publicly available
Expand Down
39 changes: 39 additions & 0 deletions AnalyticsTests/AnalyticsUtilTests.swift
Original file line number Diff line number Diff line change
@@ -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"
}

}

}