#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2015 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#endregion
using System;
namespace Google.Protobuf.WellKnownTypes
{
///
/// Extension methods on BCL time-related types, converting to protobuf types.
///
public static class TimeExtensions
{
///
/// Converts the given to a .
///
/// The date and time to convert to a timestamp.
/// The value has a other than Utc.
/// The converted timestamp.
public static Timestamp ToTimestamp(this DateTime dateTime)
{
return Timestamp.FromDateTime(dateTime);
}
///
/// Converts the given to a
///
/// The offset is taken into consideration when converting the value (so the same instant in time
/// is represented) but is not a separate part of the resulting value. In other words, there is no
/// roundtrip operation to retrieve the original DateTimeOffset.
/// The date and time (with UTC offset) to convert to a timestamp.
/// The converted timestamp.
public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)
{
return Timestamp.FromDateTimeOffset(dateTimeOffset);
}
///
/// Converts the given to a .
///
/// The time span to convert.
/// The converted duration.
public static Duration ToDuration(this TimeSpan timeSpan)
{
return Duration.FromTimeSpan(timeSpan);
}
}
}