コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        // 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());
        }