-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
44 lines (39 loc) · 1.54 KB
/
Utils.cs
File metadata and controls
44 lines (39 loc) · 1.54 KB
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
using System;
using System.Globalization;
namespace RssReader;
public static class Utils
{
public static DateTime? ConvertToDateTime(string value)
{
try
{
return DateTime.ParseExact(value, CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern,
CultureInfo.InvariantCulture.DateTimeFormat);
}
catch (FormatException)
{
// The format used by RSS for date time is the RFC 1123, which only recognizes the GMT timezone
// However, the received date may not conform to that pattern, so we need to do the conversion
// TODO: Create timezone codes list
/*
var pattern = @"[a-zA-Z]+, [0-9]+ [a-zA-Z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ (?<timezone>[a-zA-Z]+)";
Regex findTimezone = new Regex(pattern, RegexOptions.Compiled);
var timezoneCode = findTimezone.Match(value).Groups["timezone"].Value;
TimeZoneInfo timezone;
TimeZoneInfo.TryFindSystemTimeZoneById(timezoneCode, out timezone);
if(timezone is not null)
{
// Changes the format from TMZ to HH:MM
var newTimeZone = findTimezone.Replace("$timezone", timezone.BaseUtcOffset.ToString());
return DateTime.Parse(newTimeZone);
}
else
{
Console.Error.WriteLine($"Timezone {timezoneCode} not found");
return null;
}
*/
return null;
}
}
}