using System.Text.Json.Serialization;
namespace gehGassi.LocalNotifications
{
///
/// Repräsentiert eine Zeit-Einstellung
///
public class Time
{
///
/// Stunde
///
public int Hour { get; }
///
/// Minute
///
public int Minute { get; }
///
/// Sekunde
///
public int Second { get; }
///
/// Erstellt eine Instanz
///
/// Stunde
/// Minute
/// Sekunde
[JsonConstructor]
public Time(int hour = 0, int minute = 0, int second = 0)
{
Validation(hour, minute, second);
Hour = hour;
Minute = minute;
Second = second;
}
///
/// Erstellt eine Instanz
///
/// Zeit als string hh:mm:ss
///
public Time(string time)
{
if (string.IsNullOrEmpty(time))
throw new NullReferenceException("time");
TimeSpan span = TimeSpan.Parse(time);
Validation(span.Hours, span.Minutes, span.Seconds);
Hour = span.Hours;
Minute = span.Minutes;
Second = span.Seconds;
}
///
/// Validieren der Zeit-Einstellung
///
/// Stunde
/// Minute
/// Sekunde
///
private void Validation(int hour, int minute, int second)
{
if (hour >= 24)
throw new ArgumentOutOfRangeException("Accepted range is 0 to 23 inclusive.");
if (minute >= 60)
throw new ArgumentOutOfRangeException("Accepted range is 0 to 59 inclusive.");
if (second >= 60)
throw new ArgumentOutOfRangeException("Accepted range is 0 to 59 inclusive.");
}
}
}