tbf/TBF/Boxes/DateTimeBox.cs

88 lines
2.0 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
namespace TBF.Boxes
{
public class DateTimeBox : IBox
{
private DateTime val;
public DateTime Val
{
get { return val; }
set { val = value; valid = true; }
}
/// Box name
string name;
public string Name
{
get { return name; }
set { name = value; }
}
/// Validity flag: true = the box value is valid
private bool valid = false;
public bool Valid
{
get { return valid; }
}
/// <summary> Parameterless constructor </summary>
public DateTimeBox()
{
val = DateTime.MinValue;
}
/// <summary> Constructor that initializes the value </summary>
public DateTimeBox(DateTime val)
{
this.val = val;
}
/// <summary>
/// Clear the box value and the valid flag
/// </summary>
public void Clear()
{
val = DateTime.MinValue;
valid = false;
}
/// <summary>
/// Validate the string representation of the box value
/// </summary>
/// <param name="strVal">String representation of the parameter</param>
/// <returns>true = string is OK, false = string is wrong (see 'message')</returns>
public bool ValidateParam(string strVal)
{
return false;
}
/// <summary>
/// Update the parameter from a string
/// </summary>
/// <param name="strVal">String representation of the box value</param>
public void UpdateParam(string strVal)
{
}
public DateTimeBox Clone()
{
DateTimeBox newBox = new DateTimeBox();
newBox.name = name;
newBox.val = val;
newBox.valid = valid;
return newBox;
}
public static double DurationSec(DateTimeBox start, DateTimeBox end)
{
if (start == null || end == null) return 0;
return (end.Val - start.Val).TotalSeconds;
}
}
}