/// <summary> /// Applies .proto rules to ensure that this value is in the expected ranges /// </summary> public Duration Normalize() { var seconds = Seconds; var nanos = Nanoseconds; PrimaryTypeProvider.NormalizeSecondsNanoseconds(ref seconds, ref nanos, false); return(new Duration(seconds, nanos)); }
/// <summary> /// Applies .proto rules to ensure that this value is in the expected ranges /// </summary> public Timestamp Normalize() { var seconds = Seconds; var nanos = Nanoseconds; PrimaryTypeProvider.NormalizeSecondsNanoseconds(ref seconds, ref nanos, true); return(new Timestamp(seconds, nanos)); }
/// <summary>Converts a Duration to a TimeSpan</summary> public TimeSpan AsTimeSpan() => TimeSpan.FromTicks(PrimaryTypeProvider.ToTicks(Seconds, Nanoseconds));
/// <summary>Converts a TimeSpan to a Duration</summary> public Duration(TimeSpan value) { Seconds = PrimaryTypeProvider.ToDurationSeconds(value, out var nanoseconds, false); Nanoseconds = nanoseconds; }
/// <summary>Converts a Timestamp to a DateTime</summary> public DateTime AsDateTime() => TimestampEpoch.AddTicks(PrimaryTypeProvider.ToTicks(Seconds, Nanoseconds));
/// <summary>Converts a DateTime to a Timestamp</summary> public Timestamp(DateTime value) { Seconds = PrimaryTypeProvider.ToDurationSeconds(value - TimestampEpoch, out var nanoseconds, true); Nanoseconds = nanoseconds; }