mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Replace calendar service with new .NET version
This commit is contained in:
13
Calendar/Service/Models/CalendarEntry.cs
Normal file
13
Calendar/Service/Models/CalendarEntry.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Ical.Net.CalendarComponents;
|
||||
using Ical.Net.DataTypes;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models;
|
||||
|
||||
[PublicAPI]
|
||||
public class CalendarEntry(Occurrence occurrence)
|
||||
{
|
||||
public string Summary { get; set; } = ((CalendarEvent)occurrence.Source).Summary;
|
||||
public DateTimeOffset Start { get; set; } = occurrence.Period.StartTime.AsUtc;
|
||||
public DateTimeOffset End { get; set; } = occurrence.Period.EndTime.AsUtc;
|
||||
}
|
||||
19
Calendar/Service/Models/Duration.cs
Normal file
19
Calendar/Service/Models/Duration.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models;
|
||||
|
||||
public class Duration
|
||||
{
|
||||
public int Days { get; set; }
|
||||
public int Hours { get; set; }
|
||||
public int Minutes { get; set; }
|
||||
public int Seconds { get; set; }
|
||||
|
||||
public Duration(DateTimeOffset date)
|
||||
{
|
||||
var now = DateTimeOffset.Now;
|
||||
var duration = date - now;
|
||||
Days = duration.Days;
|
||||
Hours = duration.Hours;
|
||||
Minutes = duration.Minutes;
|
||||
Seconds = duration.Seconds;
|
||||
}
|
||||
}
|
||||
17
Calendar/Service/Models/HolidayEntry.cs
Normal file
17
Calendar/Service/Models/HolidayEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models;
|
||||
|
||||
public class HolidayEntry
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public DateTimeOffset Date { get; set; }
|
||||
public bool IsToday { get; set; }
|
||||
public Duration DurationUntil { get; set; }
|
||||
|
||||
public HolidayEntry(CalendarEntry calendarEntry, TimeZoneInfo timeZoneInfo)
|
||||
{
|
||||
Name = calendarEntry.Summary;
|
||||
Date = TimeZoneInfo.ConvertTime(calendarEntry.Start, timeZoneInfo).Subtract(timeZoneInfo.GetUtcOffset(calendarEntry.Start));
|
||||
IsToday = Date.Date == DateTimeOffset.UtcNow.Date;
|
||||
DurationUntil = new Duration(Date);
|
||||
}
|
||||
}
|
||||
10
Calendar/Service/Models/HolidayResponse.cs
Normal file
10
Calendar/Service/Models/HolidayResponse.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models;
|
||||
|
||||
[PublicAPI]
|
||||
public class HolidayResponse(HolidayEntry holidayEntry, TimeZoneInfo timeZoneInfo)
|
||||
{
|
||||
public DateTimeOffset ResponseTime { get; set; } = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, timeZoneInfo);
|
||||
public HolidayEntry? Event { get; set; } = holidayEntry;
|
||||
}
|
||||
Reference in New Issue
Block a user