Exemple #1
0
        public object Read(byte[] buffer, int index)
        {
            if (DateTimeByteHelper.TryParseDateTime(buffer, index, entries, kind, out var result))
            {
                if (kind == DateTimeKind.Unspecified)
                {
                    return(new DateTimeOffset(result, TimeSpan.Zero));
                }

                if (kind == DateTimeKind.Utc)
                {
                    return(new DateTimeOffset(result));
                }

                var offset  = TimeZoneInfo.Local.GetUtcOffset(result);
                var utcTick = result.Ticks - offset.Ticks;
                if (DateTimeHelper.IsValidTicks(utcTick))
                {
                    return(new DateTimeOffset(result, offset));
                }
            }

            return(defaultValue);
        }
Exemple #2
0
 public object Read(byte[] buffer, int index)
 {
     return(DateTimeByteHelper.TryParseDateTime(buffer, index, entries, kind, out var result)
         ? result
         : defaultValue);
 }