Skip to content

Commit e8587b2

Browse files
authored
chore: truncate by millisecond (#95)
* chore: truncate by millisecond * chore: increase resolution
1 parent 8dcc34b commit e8587b2

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Utils/ActivityIdGenerator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public static Guid GenerateId(string foreignId, int epoch)
2525
/// </summary>
2626
public static Guid GenerateId(string foreignId, DateTime timestamp)
2727
{
28-
// The backend doesn't care about milliseconds, so we truncate the date here.
29-
var truncatedDate = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute, timestamp.Second, DateTimeKind.Utc);
28+
var truncatedDate = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute, timestamp.Second, timestamp.Millisecond, DateTimeKind.Utc);
3029

3130
var unixNano = truncatedDate.Ticks - EpochTicks;
3231
var t = (ulong)(UuidEpochDifference + unixNano);
@@ -132,4 +131,4 @@ private static string BytesToGuidString(byte[] b)
132131
return Encoding.UTF8.GetString(retVal);
133132
}
134133
}
135-
}
134+
}

src/Utils/StreamJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class StreamJsonConverter
77
{
88
private static JsonSerializerSettings Settings = new JsonSerializerSettings
99
{
10-
DateFormatString = "yyyy-MM-dd'T'HH:mm:ss",
10+
DateFormatString = "yyyy-MM-dd'T'HH:mm:ss.fff",
1111
ContractResolver = new DefaultContractResolver
1212
{
1313
NamingStrategy = new SnakeCaseNamingStrategy(), // this handles ForeignId => foreign_id etc. conversion for us
@@ -18,4 +18,4 @@ public static class StreamJsonConverter
1818
public static string SerializeObject(object obj) => JsonConvert.SerializeObject(obj, Settings);
1919
public static T DeserializeObject<T>(string json) => JsonConvert.DeserializeObject<T>(json, Settings);
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)