umogen-ng/src/Nyanlabs.Umogen.Core/Models/ValidTime.cs

32 lines
933 B
C#

namespace Nyanlabs.Umogen.Core.Models;
public readonly struct ValidTime : INLSerializable, IDocSerializable
{
public ValidTime(DateTime start, DateTime end)
{
Start = start;
End = end;
}
public ValidTime(DateTime start, TimeSpan duration)
{
Start = start;
End = start + duration;
}
public static readonly ValidTime Invalid = new(DateTime.MaxValue, DateTime.MinValue);
public readonly DateTime Start { get; }
public readonly DateTime End { get; }
public readonly TimeSpan Duration => End - Start;
public string NLQuerySerialize()
{
return this.Start != DateTime.MaxValue ? $"from {Start:dd MMM yyyy} until {End:dd MMM yyyy}" : "for unspecified time";
}
public string SerializeToDocument()
{
return this.Start != DateTime.MaxValue ? $"na czas od {Start:dd.MM.yyyy} do {End:dd.MM.yyyy}" : "na czas nieokreślony";
}
}