Google.Protobuf.WellKnownTypes.TimeExtensions

Extension methods on BCL time-related types, converting to protobuf types.

Summary

Public static functions

ToDuration(this TimeSpan timeSpan)
Converts the given TimeSpan to a Duration.
ToTimestamp(this DateTime dateTime)
Converts the given DateTime to a Timestamp.
ToTimestamp(this DateTimeOffset dateTimeOffset)
Converts the given DateTimeOffset to a Timestamp

Public static functions

ToDuration

Duration ToDuration(
  this TimeSpan timeSpan
)

Converts the given TimeSpan to a Duration.

Details
Parameters
timeSpan
The time span to convert.
Returns
The converted duration.

ToTimestamp

Timestamp ToTimestamp(
  this DateTime dateTime
)

Converts the given DateTime to a Timestamp.

Details
Parameters
dateTime
The date and time to convert to a timestamp.
Exceptions
ArgumentException
The dateTime value has a DateTime.Kindother than Utc.
Returns
The converted timestamp.

ToTimestamp

Timestamp ToTimestamp(
  this DateTimeOffset dateTimeOffset
)

Converts the given DateTimeOffset to a Timestamp

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.

Details
Parameters
dateTimeOffset
The date and time (with UTC offset) to convert to a timestamp.
Returns
The converted timestamp.