Skip to content

Commit a2b83fd

Browse files
committed
allow capture to override timestamp with datetime or datetimeoffset
1 parent b8cf64d commit a2b83fd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/PostHog/PostHogClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,17 @@ public bool Capture(
131131
GroupCollection? groups,
132132
bool sendFeatureFlags)
133133
{
134+
// Check for custom timestamp in properties
135+
var timestamp = properties?.TryGetValue("timestamp", out var timestampValue) == true &&
136+
(timestampValue is DateTimeOffset customTimestampOffset || timestampValue is DateTime customTimestamp)
137+
? timestampValue is DateTimeOffset dtOffset ? dtOffset : new DateTimeOffset((DateTime)timestampValue)
138+
: _timeProvider.GetUtcNow();
139+
134140
var capturedEvent = new CapturedEvent(
135141
eventName,
136142
distinctId,
137143
properties,
138-
timestamp: _timeProvider.GetUtcNow());
144+
timestamp: timestamp);
139145

140146
if (groups is { Count: > 0 })
141147
{

0 commit comments

Comments
 (0)