Commit 6eddc7dc by Sebastián Katzer

trigger.every enhancements (Windows)

parent 320e32f4
...@@ -30,58 +30,33 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -30,58 +30,33 @@ namespace LocalNotificationProxy.LocalNotification
/// <summary> /// <summary>
/// Gets or sets the minute. /// Gets or sets the minute.
/// </summary> /// </summary>
public int Minute { get; set; } public int? Minute { get; set; }
/// <summary> /// <summary>
/// Gets or sets the hour. /// Gets or sets the hour.
/// </summary> /// </summary>
public int Hour { get; set; } public int? Hour { get; set; }
/// <summary> /// <summary>
/// Gets or sets the day. /// Gets or sets the day.
/// </summary> /// </summary>
public int Day { get; set; } public int? Day { get; set; }
/// <summary> /// <summary>
/// Gets or sets the month. /// Gets or sets the month.
/// </summary> /// </summary>
public int Month { get; set; } public int? Month { get; set; }
/// <summary> /// <summary>
/// Gets or sets the year. /// Gets or sets the year.
/// </summary> /// </summary>
public int Year { get; set; } public int? Year { get; set; }
/// <summary>
/// Gets a value indicating whether the minute is not fix.
/// </summary>
internal bool MinuteIsVariable { get => this.Minute == 0; }
/// <summary>
/// Gets a value indicating whether the hour is not fix.
/// </summary>
internal bool HourIsVariable { get => this.Hour == 0; }
/// <summary>
/// Gets a value indicating whether the day is not fix.
/// </summary>
internal bool DayIsVariable { get => this.Day == 0; }
/// <summary>
/// Gets a value indicating whether the month is not fix.
/// </summary>
internal bool MonthIsVariable { get => this.Month == 0; }
/// <summary>
/// Gets a value indicating whether the year is not fix.
/// </summary>
internal bool YearIsVariable { get => this.Year == 0; }
/// <summary> /// <summary>
/// Gets the interval as a string representation. /// Gets the interval as a string representation.
/// </summary> /// </summary>
/// <returns>year, month, ...</returns> /// <returns>year, month, ...</returns>
internal string Interval { get => Intervals[Array.IndexOf(this.ToArray(), 0) + 1]; } internal string Interval { get => Intervals[Array.IndexOf(this.ToArray(), null) + 1]; }
/// <summary> /// <summary>
/// Converts the date time components into a datetime object. /// Converts the date time components into a datetime object.
...@@ -92,20 +67,22 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -92,20 +67,22 @@ namespace LocalNotificationProxy.LocalNotification
var p = this.ToArray(); var p = this.ToArray();
var today = DateTime.Today; var today = DateTime.Today;
p[2] = this.DayIsVariable ? today.Day : this.Day; p[0] = this.Minute.GetValueOrDefault();
p[3] = this.MonthIsVariable ? today.Month : this.Month; p[1] = this.Hour.GetValueOrDefault();
p[4] = this.YearIsVariable ? today.Year : this.Year; p[2] = this.Day.GetValueOrDefault(today.Day);
p[3] = this.Month.GetValueOrDefault(today.Month);
p[4] = this.Year.GetValueOrDefault(today.Year);
return new DateTime(p[4], p[3], p[2], p[1], p[0], 0); return new DateTime(p[4].Value, p[3].Value, p[2].Value, p[1].Value, p[0].Value, 0);
} }
/// <summary> /// <summary>
/// Gets an array of all date parts to construct a datetime instance. /// Gets an array of all date parts to construct a datetime instance.
/// </summary> /// </summary>
/// <returns>[min, hour, day, month, year]</returns> /// <returns>[min, hour, day, month, year]</returns>
private int[] ToArray() private int?[] ToArray()
{ {
return new int[] { this.Minute, this.Hour, this.Day, this.Month, this.Year }; return new int?[] { this.Minute, this.Hour, this.Day, this.Month, this.Year };
} }
} }
} }
...@@ -191,7 +191,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -191,7 +191,7 @@ namespace LocalNotificationProxy.LocalNotification
case "minute": case "minute":
case "hour": case "hour":
case "day": case "day":
if (every.YearIsVariable) if (!every.Year.HasValue)
{ {
return date.AddYears(now.Year - date.Year + 1); return date.AddYears(now.Year - date.Year + 1);
} }
...@@ -207,11 +207,11 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -207,11 +207,11 @@ namespace LocalNotificationProxy.LocalNotification
{ {
case "minute": case "minute":
case "hour": case "hour":
if (every.MonthIsVariable) if (!every.Month.HasValue)
{ {
return date.AddMonths(now.Month - date.Month + 1); return date.AddMonths(now.Month - date.Month + 1);
} }
else if (every.YearIsVariable) else if (!every.Year.HasValue)
{ {
return date.AddYears(now.Year - date.Year + 1); return date.AddYears(now.Year - date.Year + 1);
} }
...@@ -228,11 +228,11 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -228,11 +228,11 @@ namespace LocalNotificationProxy.LocalNotification
switch (every.Interval) switch (every.Interval)
{ {
case "minute": case "minute":
if (every.DayIsVariable) if (!every.Day.HasValue)
{ {
return date.AddDays(now.Day - date.Day + 1); return date.AddDays(now.Day - date.Day + 1);
} }
else if (every.MonthIsVariable) else if (!every.Month.HasValue)
{ {
return date.AddMonths(now.Month - date.Month + 1); return date.AddMonths(now.Month - date.Month + 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment