-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto scheduling parameter to missions
- Loading branch information
Showing
17 changed files
with
1,710 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
#pragma warning disable CS8618 | ||
namespace Api.Database.Models | ||
{ | ||
[Owned] | ||
public class AutoScheduleFrequency | ||
{ | ||
[Required] | ||
// In local time | ||
public IList<TimeOnly> TimesOfDay { get; set; } | ||
|
||
[Required] | ||
public IList<DayOfWeek> DaysOfWeek { get; set; } | ||
|
||
public void ValidateAutoScheduleFrequency() | ||
{ | ||
if (TimesOfDay.Count == 0) | ||
{ | ||
throw new ArgumentException( | ||
"AutoScheduleFrequency must have at least one time of day" | ||
); | ||
} | ||
|
||
if (DaysOfWeek.Count == 0) | ||
{ | ||
throw new ArgumentException( | ||
"AutoScheduleFrequency must have at least one day of week" | ||
); | ||
} | ||
} | ||
|
||
public IList<TimeSpan>? GetSchedulingTimesForNext24Hours() | ||
{ | ||
// NCS is always in CET | ||
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById( | ||
"Central European Standard Time" | ||
); | ||
DateTime nowLocal = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi); | ||
TimeOnly nowLocalTimeOnly = new TimeOnly( | ||
nowLocal.Hour, | ||
nowLocal.Minute, | ||
nowLocal.Second | ||
); | ||
|
||
var autoScheduleNext24Hours = new List<TimeSpan>(); | ||
if (DaysOfWeek.Contains(nowLocal.DayOfWeek)) | ||
{ | ||
foreach (TimeOnly time in TimesOfDay) | ||
{ | ||
if (time > nowLocalTimeOnly) | ||
{ | ||
autoScheduleNext24Hours.Add(time - nowLocalTimeOnly); | ||
} | ||
} | ||
} | ||
if (DaysOfWeek.Contains(nowLocal.DayOfWeek + 1)) | ||
{ | ||
foreach (TimeOnly time in TimesOfDay) | ||
{ | ||
if (time <= nowLocalTimeOnly) | ||
{ | ||
autoScheduleNext24Hours.Add(time - nowLocalTimeOnly); | ||
} | ||
} | ||
} | ||
if (autoScheduleNext24Hours.Count > 0) | ||
{ | ||
return autoScheduleNext24Hours; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.