| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace ZeroC.Slice; |
| | 4 | |
|
| | 5 | | /// <summary>Provides an extension method for <see cref="SliceDecoder" /> to decode a |
| | 6 | | /// <c>WellKnownTypes::TimeStamp</c> into a <see cref="DateTime" />.</summary> |
| | 7 | | public static class TimeStampSliceDecoderExtensions |
| | 8 | | { |
| | 9 | | /// <summary>Decodes a time stamp.</summary> |
| | 10 | | /// <param name="decoder">The Slice decoder.</param> |
| | 11 | | /// <returns>The time stamp decoded as a <see cref="DateTime"/>.</returns> |
| | 12 | | public static DateTime DecodeTimeStamp(this ref SliceDecoder decoder) |
| 43 | 13 | | { |
| 43 | 14 | | long value = decoder.DecodeInt64(); |
| | 15 | | try |
| 43 | 16 | | { |
| 43 | 17 | | return new DateTime(value, DateTimeKind.Utc); |
| | 18 | | } |
| 0 | 19 | | catch (ArgumentOutOfRangeException exception) |
| 0 | 20 | | { |
| 0 | 21 | | throw new InvalidDataException(message: null, exception); |
| | 22 | | } |
| 43 | 23 | | } |
| | 24 | | } |