private static DateTimeOffset CreateDateTimeOffset(long utcTimestamp, long utcOffset) { var dateTime = EpochHelper.FromUnixTimeUtcTicks(utcTimestamp); var offset = TimeSpan.FromTicks(utcOffset); return(new DateTimeOffset(DateTime.SpecifyKind(dateTime + offset, DateTimeKind.Unspecified), offset)); }
private static DateTimeOffset?ExtractTimestamp(HerculesEvent @event, string timestampTag, string offsetTag) { if ([email protected](timestampTag, out var timestampValue) || [email protected](offsetTag, out var offsetValue)) { return(null); } var utcTimestamp = EpochHelper.FromUnixTimeUtcTicks(timestampValue.AsLong); var utcOffset = TimeSpan.FromTicks(offsetValue.AsLong); return(new DateTimeOffset(DateTime.SpecifyKind(utcTimestamp + utcOffset, DateTimeKind.Unspecified), utcOffset)); }
// ReSharper disable once MemberCanBePrivate.Global public static T ReadEvent <T>(IBinaryReader reader, IHerculesEventBuilder <T> builder) { reader.EnsureBigEndian(); var version = reader.ReadByte(); if (version != Constants.EventProtocolVersion) { throw new NotSupportedException($"Unsupported Hercules protocol version: {version}"); } var utcTimestamp = EpochHelper.FromUnixTimeUtcTicks(reader.ReadInt64()); builder.SetTimestamp(new DateTimeOffset(utcTimestamp, TimeSpan.Zero)); reader.Position += 16; ReadContainer(reader, builder); return(builder.BuildEvent()); }