Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SmtpDateTime.cs
Go to the documentation of this file.
3
4namespace System.Net.Mime;
5
6internal sealed class SmtpDateTime
7{
8 internal static readonly string[] s_validDateTimeFormats = new string[4] { "ddd, dd MMM yyyy HH:mm:ss", "dd MMM yyyy HH:mm:ss", "ddd, dd MMM yyyy HH:mm", "dd MMM yyyy HH:mm" };
9
10 internal static readonly char[] s_allowedWhiteSpaceChars = new char[2] { ' ', '\t' };
11
13
14 private readonly DateTime _date;
15
16 private readonly TimeSpan _timeZone;
17
18 private readonly bool _unknownTimeZone;
19
20 internal DateTime Date
21 {
22 get
23 {
25 {
26 return DateTime.SpecifyKind(_date, DateTimeKind.Unspecified);
27 }
29 }
30 }
31
33 {
35 dictionary.Add("UT", TimeSpan.Zero);
36 dictionary.Add("GMT", TimeSpan.Zero);
37 dictionary.Add("EDT", new TimeSpan(-4, 0, 0));
38 dictionary.Add("EST", new TimeSpan(-5, 0, 0));
39 dictionary.Add("CDT", new TimeSpan(-5, 0, 0));
40 dictionary.Add("CST", new TimeSpan(-6, 0, 0));
41 dictionary.Add("MDT", new TimeSpan(-6, 0, 0));
42 dictionary.Add("MST", new TimeSpan(-7, 0, 0));
43 dictionary.Add("PDT", new TimeSpan(-7, 0, 0));
44 dictionary.Add("PST", new TimeSpan(-8, 0, 0));
45 return dictionary;
46 }
47
49 {
50 _date = value;
51 switch (value.Kind)
52 {
53 case DateTimeKind.Local:
54 {
57 break;
58 }
59 case DateTimeKind.Unspecified:
60 _unknownTimeZone = true;
61 break;
62 case DateTimeKind.Utc:
64 break;
65 }
66 }
67
68 internal SmtpDateTime(string value)
69 {
72 {
73 _unknownTimeZone = true;
74 }
75 }
76
77 public override string ToString()
78 {
79 return FormatDate(_date) + " " + (_unknownTimeZone ? "-0000" : TimeSpanToOffset(_timeZone));
80 }
81
83 {
84 if (offset.Length != 5)
85 {
87 }
88 positive = offset.StartsWith('+');
89 if (!int.TryParse(offset.AsSpan(1, 2), NumberStyles.None, CultureInfo.InvariantCulture, out hours))
90 {
92 }
93 if (!int.TryParse(offset.AsSpan(3, 2), NumberStyles.None, CultureInfo.InvariantCulture, out minutes))
94 {
96 }
97 if (minutes > 59)
98 {
100 }
101 }
102
104 {
105 for (int i = 0; i < value.Length; i++)
106 {
107 if (!char.IsLetter(value, i))
108 {
110 }
111 }
112 }
113
114 internal string FormatDate(DateTime value)
115 {
116 return value.ToString("ddd, dd MMM yyyy HH:mm:ss", CultureInfo.InvariantCulture);
117 }
118
119 internal DateTime ParseValue(string data, out string timeZone)
120 {
121 if (string.IsNullOrEmpty(data))
122 {
124 }
125 int num = data.IndexOf(':');
126 if (num == -1)
127 {
129 }
130 int num2 = data.IndexOfAny(s_allowedWhiteSpaceChars, num);
131 if (num2 == -1)
132 {
134 }
135 string s = data.AsSpan(0, num2).Trim().ToString();
137 {
139 }
140 string text = data.AsSpan(num2).Trim().ToString();
141 int num3 = text.IndexOfAny(s_allowedWhiteSpaceChars);
142 if (num3 != -1)
143 {
144 text = text.Substring(0, num3);
145 }
146 if (string.IsNullOrEmpty(text))
147 {
149 }
150 timeZone = text;
151 return result;
152 }
153
155 {
156 if (timeZoneString == "-0000")
157 {
159 return false;
160 }
161 if (timeZoneString[0] == '+' || timeZoneString[0] == '-')
162 {
164 if (!positive)
165 {
166 if (hours != 0)
167 {
168 hours *= -1;
169 }
170 else if (minutes != 0)
171 {
172 minutes *= -1;
173 }
174 }
175 timeZone = new TimeSpan(hours, minutes, 0);
176 return true;
177 }
180 }
181
183 {
184 TimeSpan result = new TimeSpan(span.Days, span.Hours, span.Minutes, 0, 0);
185 if (Math.Abs(result.Ticks) > 3599400000000L)
186 {
188 }
189 return result;
190 }
191
193 {
194 if (span.Ticks == 0L)
195 {
196 return "+0000";
197 }
198 uint num = (uint)Math.Abs(Math.Floor(span.TotalHours));
199 uint num2 = (uint)Math.Abs(span.Minutes);
200 string text = ((span.Ticks > 0) ? "+" : "-");
201 if (num < 10)
202 {
203 text += "0";
204 }
205 text += num;
206 if (num2 < 10)
207 {
208 text += "0";
209 }
210 return text + num2;
211 }
212}
static CultureInfo InvariantCulture
static double Abs(double value)
static double Floor(double d)
void ValidateAndGetTimeZoneOffsetValues(string offset, out bool positive, out int hours, out int minutes)
override string ToString()
static readonly char[] s_allowedWhiteSpaceChars
static Dictionary< string, TimeSpan > InitializeShortHandLookups()
void ValidateTimeZoneShortHandValue(string value)
readonly TimeSpan _timeZone
bool TryParseTimeZoneString(string timeZoneString, out TimeSpan timeZone)
string TimeSpanToOffset(TimeSpan span)
DateTime ParseValue(string data, out string timeZone)
TimeSpan ValidateAndGetSanitizedTimeSpan(TimeSpan span)
static readonly string[] s_validDateTimeFormats
static readonly Dictionary< string, TimeSpan > s_timeZoneOffsetLookup
string FormatDate(DateTime value)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string MailDateInvalidFormat
Definition SR.cs:36
static string MailHeaderFieldInvalidCharacter
Definition SR.cs:140
Definition SR.cs:7
static TimeZoneInfo Local
static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
Definition DateTime.cs:756
static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true)] string? format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
Definition DateTime.cs:1171
static readonly TimeSpan Zero
Definition TimeSpan.cs:21