GetValue() public method

Get the value of the double at a given instant in time. If using the current system time, the preferred way to get the value is not to call this method but to simply access the Value field.
public GetValue ( System.TimeSpan halfLife, System.DateTime whenUtc = null ) : double
halfLife System.TimeSpan The half life to use when determining the current value.
whenUtc System.DateTime The instant of time for which the value should be calcualted, factoring in /// the decay rate. The default time is the current UTC time.
return double
 public void AddInPlace()
 {
     DecayingDouble d = new DecayingDouble(4, FirstDayOfCentury);
     // Two days later the double should be 1, so adding 1 should yield 4
     d.AddInPlace(OneDay, 3, TwoDaysLater);
     Assert.InRange(d.ValueAtTimeOfLastUpdate, 3.99999, 4.000001);
     double shouldBeVeryCloseTo1 = d.GetValue(OneDay, FourDaysLater);
     Assert.InRange(shouldBeVeryCloseTo1, .99999, 1.000001);
 }
Example #2
0
 public DecayingDouble Add(TimeSpan halfLife, DecayingDouble amountToAdd)
 {
     if (!LastUpdatedUtc.HasValue)
     {
         return(new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, amountToAdd.LastUpdatedUtc));
     }
     else if (!amountToAdd.LastUpdatedUtc.HasValue)
     {
         return(new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, LastUpdatedUtc));
     }
     else if (LastUpdatedUtc.Value > amountToAdd.LastUpdatedUtc.Value)
     {
         return(new DecayingDouble(
                    ValueAtTimeOfLastUpdate + amountToAdd.GetValue(halfLife, LastUpdatedUtc.Value),
                    LastUpdatedUtc.Value));
     }
     else
     {
         return(new DecayingDouble(amountToAdd.ValueAtTimeOfLastUpdate + GetValue(halfLife, amountToAdd.LastUpdatedUtc.Value), amountToAdd.LastUpdatedUtc.Value));
     }
 }
Example #3
0
 public DecayingDouble Subtract(TimeSpan halfLife, DecayingDouble amountToRemove)
 {
     if (!LastUpdatedUtc.HasValue)
     {
         return(new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, amountToRemove.LastUpdatedUtc));
     }
     else if (!amountToRemove.LastUpdatedUtc.HasValue)
     {
         return(new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, LastUpdatedUtc));
     }
     else if (LastUpdatedUtc.Value > amountToRemove.LastUpdatedUtc.Value)
     {
         return
             (new DecayingDouble(
                  ValueAtTimeOfLastUpdate - amountToRemove.GetValue(halfLife, LastUpdatedUtc.Value),
                  LastUpdatedUtc.Value));
     }
     else
     {
         return(new DecayingDouble(amountToRemove.ValueAtTimeOfLastUpdate - GetValue(halfLife, amountToRemove.LastUpdatedUtc.Value), amountToRemove.LastUpdatedUtc.Value));
     }
 }
Example #4
0
 public DecayingDouble Add(TimeSpan halfLife, DecayingDouble amountToAdd)
 {
     if (!LastUpdatedUtc.HasValue)
     {
         return new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, amountToAdd.LastUpdatedUtc);
     }
     else if (!amountToAdd.LastUpdatedUtc.HasValue)
     {
         return new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, LastUpdatedUtc);
     }
     else if (LastUpdatedUtc.Value > amountToAdd.LastUpdatedUtc.Value)
     {
         return new DecayingDouble(
                 ValueAtTimeOfLastUpdate + amountToAdd.GetValue(halfLife, LastUpdatedUtc.Value),
                 LastUpdatedUtc.Value);
     }
     else
     {
         return new DecayingDouble(amountToAdd.ValueAtTimeOfLastUpdate + GetValue(halfLife, amountToAdd.LastUpdatedUtc.Value), amountToAdd.LastUpdatedUtc.Value);
     }
 }
Example #5
0
 public DecayingDouble Subtract(TimeSpan halfLife, DecayingDouble amountToRemove)
 {
     if (!LastUpdatedUtc.HasValue)
     {
         return new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, amountToRemove.LastUpdatedUtc);
     }
     else if (!amountToRemove.LastUpdatedUtc.HasValue)
     {
         return new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, LastUpdatedUtc);
     } else if (LastUpdatedUtc.Value > amountToRemove.LastUpdatedUtc.Value)
     {
         return
             new DecayingDouble(
                 ValueAtTimeOfLastUpdate - amountToRemove.GetValue(halfLife, LastUpdatedUtc.Value),
                 LastUpdatedUtc.Value);
     }
     else
     {
         return new DecayingDouble(amountToRemove.ValueAtTimeOfLastUpdate - GetValue(halfLife, amountToRemove.LastUpdatedUtc.Value), amountToRemove.LastUpdatedUtc.Value);
     }
 }