Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0856d19

Browse files
committedApr 17, 2017
Always initalize DateTime in UTC. Fixes matomo-org#52.
1 parent 5cafde3 commit 0856d19

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed
 

‎Piwik.Tracker.Samples/PiwikTrackerSamples.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static private void RecordSimplePageViewWithCustomProperties()
131131
piwikTracker.SetIp("192.168.52.64");
132132
piwikTracker.SetVisitorId("33c31B01394bdc65");
133133

134-
piwikTracker.SetForceVisitDateTime(new DateTime(2011, 10, 23, 10, 20, 50));
134+
piwikTracker.SetForceVisitDateTime(new DateTime(2011, 10, 23, 10, 20, 50, DateTimeKind.Utc));
135135

136136
piwikTracker.SetResolution(1600, 1400);
137137

@@ -143,7 +143,7 @@ static private void RecordSimplePageViewWithCustomProperties()
143143
piwikTracker.SetPlugins(browserPluginsToSet);
144144
piwikTracker.SetBrowserHasCookies(true);
145145

146-
piwikTracker.SetLocalTime(new DateTime(2000, 1, 1, 9, 10, 25));
146+
piwikTracker.SetLocalTime(new DateTime(2000, 1, 1, 9, 10, 25, DateTimeKind.Utc));
147147

148148
piwikTracker.SetUrl("http://piwik-1.5/supernova");
149149
piwikTracker.SetUrlReferrer("http://supernovadirectory.org");
@@ -201,7 +201,7 @@ static private void GoalConversionWithAttributionInfo()
201201

202202
attributionInfo.CampaignName = "CAMPAIGN NAME";
203203
attributionInfo.CampaignKeyword = "CAMPAIGN KEYWORD";
204-
attributionInfo.ReferrerTimestamp = new DateTime(2011, 04, 08, 23, 48, 24);
204+
attributionInfo.ReferrerTimestamp = new DateTime(2011, 04, 08, 23, 48, 24, DateTimeKind.Utc);
205205
attributionInfo.ReferrerUrl = "http://www.example.org/test/really?q=yes";
206206

207207
piwikTracker.SetAttributionInfo(attributionInfo);

‎Piwik.Tracker.Tests/PiwikTrackerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void SetAttributionInfo_WhenReferrerTimestampSpecified_IsAddedToRequest(s
187187
_sut.SetAttributionInfo(new AttributionInfo { ReferrerTimestamp = referrerTimestamp });
188188
// Assert
189189
var actual = _sut.GetRequest(SiteId);
190-
Assert.That(actual, Does.Contain("&_refts=" + referrerTimestamp.ToUnixTimeSeconds().ToString().Substring(0, 6)));
190+
Assert.That(actual, Does.Contain("&_refts=" + referrerTimestamp.ToUnixTimeSeconds()));
191191
}
192192
}
193193

‎Piwik.Tracker.Web.Samples/samples/ServerSideGoalTracking.aspx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This page tracks a goal conversion with the Server Side tracking API and display
1818
1919
attributionInfo.CampaignName = "CAMPAIGN NAME";
2020
attributionInfo.CampaignKeyword = "CAMPAIGN KEYWORD";
21-
attributionInfo.ReferrerTimestamp = new DateTime(2011, 04, 08, 23, 48, 24);
21+
attributionInfo.ReferrerTimestamp = new DateTime(2011, 04, 08, 23, 48, 24, DateTimeKind.Utc);
2222
attributionInfo.ReferrerUrl = "http://www.example.org/test/really?q=yes";
2323
2424
piwikTracker.SetAttributionInfo(attributionInfo);

‎Piwik.Tracker/AttributionInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public string[] ToArray()
3838
var infos = new string[4];
3939
infos[0] = CampaignName;
4040
infos[1] = CampaignKeyword;
41-
infos[2] = (ReferrerTimestamp - new DateTime(1970, 1, 1)).TotalSeconds.ToString(CultureInfo.InvariantCulture);
41+
infos[2] = (ReferrerTimestamp - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.ToString(CultureInfo.InvariantCulture);
4242
infos[3] = ReferrerUrl;
4343
return infos;
4444
}

‎Piwik.Tracker/PiwikTracker.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public class PiwikTracker
182182
private bool _configCookiesDisabled;
183183
private string _configCookiePath = DefaultCookiePath;
184184
private string _configCookieDomain = "";
185-
private readonly long _currentTs = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds;
185+
private readonly long _currentTs = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
186186
private long _createTs;
187187
private long? _visitCount = 0;
188188
private long? _currentVisitTs;
@@ -1344,7 +1344,7 @@ public AttributionInfo GetAttributionInfo()
13441344

13451345
if (arraySize > 2 && !string.IsNullOrEmpty(cookieDecoded[2]))
13461346
{
1347-
attributionInfo.ReferrerTimestamp = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(Convert.ToInt32(cookieDecoded[2]));
1347+
attributionInfo.ReferrerTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToInt32(cookieDecoded[2]));
13481348
}
13491349

13501350
if (arraySize > 3 && !string.IsNullOrEmpty(cookieDecoded[3]))
@@ -1749,7 +1749,7 @@ private string FormatDateValue(DateTimeOffset date)
17491749

17501750
private string FormatTimestamp(DateTimeOffset date)
17511751
{
1752-
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
1752+
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
17531753
TimeSpan diff = date - origin;
17541754
double seconds = Convert.ToInt32(diff.TotalSeconds);
17551755
return seconds.ToString(CultureInfo.InvariantCulture);

0 commit comments

Comments
 (0)
Please sign in to comment.