Skip to content

Commit ebb665f

Browse files
committed
Refactor CreatedAt property to use DateTime and UTC
Refactored the `CreatedAt` property in `Blink.Models.BlinkVideoInfo`: - Changed type from `string` to `DateTime`. - Added getter and setter to handle null values and ensure UTC. - Removed redundant `CreatedAtUtc` property. - Introduced private nullable `_createdAt` field for storage. These changes improve time zone handling and code simplicity.
1 parent 2105905 commit ebb665f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Sources/Blink/Models/BlinkVideoInfo.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,28 @@ public class BlinkVideoInfo
2727
public string CameraName { get; set; } = string.Empty;
2828

2929
/// <summary>
30-
/// Video timestamp
30+
/// Video timestamp in UTC
3131
/// </summary>
3232
[JsonPropertyName("created_at")]
33-
public string CreatedAt { get; set; } = string.Empty;
33+
public DateTime CreatedAt
34+
{
35+
get => _createdAt ?? DateTime.MinValue;
36+
set
37+
{
38+
// their format is 2024-09-23T01:01:43+00:00 and it's UTC time,
39+
// but JSON parsing as local time, so we need to convert it to UTC
40+
if (value.Kind == DateTimeKind.Local)
41+
{
42+
_createdAt = value.ToUniversalTime();
43+
}
44+
else
45+
{
46+
_createdAt = value;
47+
}
48+
}
49+
}
3450

35-
/// <summary>
36-
/// Video timestamp in UTC DateTime
37-
/// </summary>
38-
[JsonIgnore]
39-
public DateTime CreatedAtUtc => DateTime.Parse(CreatedAt + "Z");
51+
private DateTime? _createdAt;
4052

4153
/// <summary>
4254
/// Network ID

0 commit comments

Comments
 (0)