-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReminderModels.cs
89 lines (70 loc) · 2.71 KB
/
ReminderModels.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Globalization;
public class ReminderModel
{
public ReminderModel()
{
}
public ReminderModel(string hour, string message)
{
Hour = hour;
Message = message;
}
// public DateTime CreatedTime { get; set; } = DateTime.Now;
public string Hour { get; set; }
public string Message { get; set; }
public int HourInt => Convert.ToInt32(Hour);
public int HourSort => HourInt + (HourInt < 6 ? 24 : 0);
public string HourFormatted => DateTime.ParseExact($"{Hour}:00", "H:mm", CultureInfo.InvariantCulture).ToString("h tt");
}
public class ReminderTableEntity : TableEntity
{
// public DateTime CreatedTime { get; set; } = DateTime.Now;
public string Hour { get; set; }
public string Message { get; set; }
}
public static class Utilities {
public static DateTime GetEasternDateTime(ILogger log) {
DateTime timeUtc = DateTime.UtcNow;
DateTime estTime = DateTime.Now;
try
{
TimeZoneInfo estZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
estTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, estZone);
log.LogInformation($"The date and time are {estTime} {(estZone.IsDaylightSavingTime(estTime) ? estZone.DaylightName : estZone.StandardName)}.");
}
catch (TimeZoneNotFoundException)
{
log.LogInformation($"The registry does not define the Central Standard Time zone.");
}
catch (InvalidTimeZoneException)
{
log.LogInformation($"Registry data on the Central STandard Time zone has been corrupted.");
}
return estTime;
}
}
public static class Mappings {
public const string PartitionKey = "REMINDER-KEY";
public static ReminderTableEntity ToTableEntity(this ReminderModel reminder)
{
return new ReminderTableEntity()
{
PartitionKey = PartitionKey,
RowKey = reminder.Hour,
// CreatedTime = reminder.CreatedTime,
Message = reminder.Message
};
}
public static ReminderModel ToModel(this ReminderTableEntity reminder)
{
return new ReminderModel()
{
Hour = reminder.RowKey,
// CreatedTime = reminder.CreatedTime,
Message = reminder.Message
};
}
}