예제 #1
0
    public void SubtractFluentTimeSpan()
    {
        var            originalPointInTime = new DateTime(1976, 2, 1, 0, 0, 0, DateTimeKind.Local);
        FluentTimeSpan fluentTimeSpan      = 1.Months();

        Assert.Equal(new DateTime(1976, 1, 1, 0, 0, 0, DateTimeKind.Local), originalPointInTime.SubtractFluentTimeSpan(fluentTimeSpan));
    }
예제 #2
0
    public void SubtractFluentTimeSpan()
    {
        var            originalPointInTime = new DateTimeOffset(1976, 2, 1, 0, 0, 0, TimeSpan.Zero);
        FluentTimeSpan fluentTimeSpan      = 1.Months();

        Assert.Equal(new DateTimeOffset(1976, 1, 1, 0, 0, 0, TimeSpan.Zero), originalPointInTime.SubtractFluentTimeSpan(fluentTimeSpan));
    }
 /// <summary>
 /// Adds given <see cref="TimeSpan"/> to supplied <paramref name="originalValue"/> <see cref="DateTime"/> and returns resulting <see cref="DateTime"/> in the future.
 /// </summary>
 public static DateTimeOffset From(this FluentTimeSpan from, DateTimeOffset originalValue)
 {
     return(originalValue.AddMonths(from.Months).AddYears(from.Years).Add(from.TimeSpan));
 }
 /// <summary>
 /// Adds given <see cref="TimeSpan"/> to current <see cref="DateTime.Now"/> and returns resulting <see cref="DateTime"/> in the future.
 /// </summary>
 public static DateTimeOffset FromNow(this FluentTimeSpan from)
 {
     return(from.From(DateTimeOffset.Now));
 }
 /// <summary>
 /// Subtracts given <see cref="TimeSpan"/> from <paramref name="originalValue"/> <see cref="DateTime"/> and returns resulting <see cref="DateTime"/> in the past.
 /// </summary>
 public static DateTimeOffset Ago(this FluentTimeSpan from, DateTimeOffset originalValue)
 {
     return(from.Before(originalValue));
 }
 /// <summary>
 /// Subtracts given <see cref="FluentTimeSpan"/> from current date (<see cref="DateTimeOffset.Now"/>) and returns resulting <see cref="DateTime"/> in the past.
 /// </summary>
 public static DateTimeOffset Ago(this FluentTimeSpan from)
 {
     return(from.Before(DateTimeOffset.Now));
 }
 /// <summary>
 /// Convert a <see cref="TimeSpan"/> to a human readable string.
 /// </summary>
 /// <param name="timeSpan">The <see cref="TimeSpan"/> to convert</param>
 /// <returns>A human readable string for <paramref name="timeSpan"/></returns>
 public static string ToDisplayString(this FluentTimeSpan timeSpan)
 {
     return(((TimeSpan)timeSpan).ToDisplayString());
 }
 /// <summary>
 /// Adds given <see cref="TimeSpan"/> to supplied <paramref name="originalValue"/> <see cref="DateTime"/> and returns resulting <see cref="DateTime"/> in the future.
 /// </summary>
 /// <seealso cref="From(System.TimeSpan,System.DateTimeOffset)"/>
 /// <remarks>
 /// Synonym of <see cref="From(System.TimeSpan,System.DateTimeOffset)"/> method.
 /// </remarks>
 public static DateTimeOffset Since(this FluentTimeSpan from, DateTimeOffset originalValue)
 {
     return(From(from, originalValue));
 }
예제 #9
0
 /// <summary>
 /// Subtracts given <see cref="TimeSpan"/> from <paramref name="originalValue"/> <see cref="DateTime"/> and returns resulting <see cref="DateTime"/> in the past.
 /// </summary>
 public static DateTime Before(this FluentTimeSpan from, DateTime originalValue)
 {
     return(originalValue.AddMonths(-from.Months).AddYears(-from.Years).Add(-from.TimeSpan));
 }
 /// <summary>
 /// Returns a new <see cref="DateTime"/> that subtracts the value of the specified <see cref="FluentTimeSpan"/> to the value of this instance.
 /// </summary>
 public static DateTime SubtractFluentTimeSpan(this DateTime dateTime, FluentTimeSpan timeSpan)
 {
     return(dateTime.AddMonths(-timeSpan.Months)
            .AddYears(-timeSpan.Years)
            .Subtract(timeSpan.TimeSpan));
 }
 /// <summary>
 /// Returns a new <see cref="DateTime"/> that adds the value of the specified <see cref="FluentTimeSpan"/> to the value of this instance.
 /// </summary>
 public static DateTime AddFluentTimeSpan(this DateTime dateTime, FluentTimeSpan timeSpan)
 {
     return(dateTime.AddMonths(timeSpan.Months)
            .AddYears(timeSpan.Years)
            .Add(timeSpan.TimeSpan));
 }
예제 #12
0
 /// <summary>
 /// Returns a new <see cref="DateTime"/> that adds the value of the specified <see cref="FluentTimeSpan"/> to the value of this instance.
 /// </summary>
 public static DateTimeOffset AddFluentTimeSpan(this DateTimeOffset dateTimeOffset, FluentTimeSpan timeSpan)
 {
     return(dateTimeOffset.AddMonths(timeSpan.Months)
            .AddYears(timeSpan.Years)
            .Add(timeSpan.TimeSpan));
 }