Example #1
0
        /// <summary>
        /// Converts this time value to a <see cref="TimeSpan"/> instance.
        /// </summary>
        /// <value>Equivalent <see cref="TimeSpan"/> value</value>
        /// <exception cref="ValueTruncationException">If a truncation occurs during conversion</exception>
        public TimeSpan ToTimeSpan()
        {
            TemporalHelpers.AssertNoTruncation(this, nameof(TimeSpan));

            return(new TimeSpan(0, Hour, Minute, Second).Add(
                       TimeSpan.FromTicks(TemporalHelpers.ExtractTicksFromNanosecond(Nanosecond))));
        }
Example #2
0
        /// <summary>
        /// Converts this date value to a <see cref="DateTime"/> instance.
        /// </summary>
        /// <value>Equivalent <see cref="DateTime"/> value</value>
        /// <exception cref="ValueOverflowException">If the value cannot be represented with DateTime</exception>
        /// <exception cref="ValueTruncationException">If a truncation occurs during conversion</exception>
        /// <returns>A <see cref="DateTime"/> instance.</returns>
        public DateTime ToDateTime()
        {
            TemporalHelpers.AssertNoTruncation(this, nameof(System.DateTime));
            TemporalHelpers.AssertNoOverflow(this, nameof(System.DateTime));

            return(new DateTime(Year, Month, Day, Hour, Minute, Second).AddTicks(
                       TemporalHelpers.ExtractTicksFromNanosecond(Nanosecond)));
        }
        /// <summary>
        /// Converts this instance to an equivalent <see cref="DateTimeOffset"/> value
        /// </summary>
        /// <returns>Equivalent <see cref="DateTimeOffset"/> value</returns>
        /// <exception cref="ValueOverflowException">If the value cannot be represented with DateTimeOffset</exception>
        /// <exception cref="ValueTruncationException">If a truncation occurs during conversion</exception>
        public DateTimeOffset ToDateTimeOffset()
        {
            // we first get DateTime instance to force Truncation / Overflow checks
            var dateTime = DateTime;
            var offset   = Offset;

            TemporalHelpers.AssertNoTruncation(offset, nameof(DateTimeOffset));
            TemporalHelpers.AssertNoOverflow(offset, nameof(DateTimeOffset));

            return(new DateTimeOffset(dateTime, offset));
        }