mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:50:36 +01:00
Add TimeSettings (Start, End and TTL) (#661)
* time * . * UT * using JetBrains.Annotations;
This commit is contained in:
35
src/WireMock.Net/Extensions/TimeSettingsExtensions.cs
Normal file
35
src/WireMock.Net/Extensions/TimeSettingsExtensions.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Extensions
|
||||
{
|
||||
internal static class TimeSettingsExtensions
|
||||
{
|
||||
public static bool IsValid([CanBeNull] this ITimeSettings settings)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
var start = settings.Start != null ? settings.Start.Value : now;
|
||||
DateTime end;
|
||||
if (settings.End != null)
|
||||
{
|
||||
end = settings.End.Value;
|
||||
}
|
||||
else if (settings.TTL != null)
|
||||
{
|
||||
end = start.AddSeconds(settings.TTL.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
end = DateTime.MaxValue;
|
||||
}
|
||||
|
||||
return now >= start && now <= end;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user