-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimestampCorrection.cs
30 lines (26 loc) · 1.13 KB
/
TimestampCorrection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UXC.Utils.CorrectTimestamps
{
public class TimestampCorrection
{
public static IEnumerable<DoublyTimestampedDataPayload> Correct(IEnumerable<DoublyTimestampedDataPayload> source)
{
List<DoublyTimestampedDataPayload> data = source.ToList();
data.Sort((a, b) => a.ReferenceTimestamp.CompareTo(b.ReferenceTimestamp));
long minTicksDiff = data.Select(d => d.Timestamp.ToUniversalTime().Ticks - d.ReferenceTimestamp.ToUniversalTime().Ticks)
.DefaultIfEmpty(0)
.Min();
return data.Select(d => new DoublyTimestampedDataPayload(
d.Payload,
d.ReferenceTimestamp
.AddTicks(minTicksDiff)
.ToOffset(d.Timestamp.Offset),
d.ReferenceTimestamp)
);
}
}
}