diff --git a/comp/src/gb.util/.src/Date.module b/comp/src/gb.util/.src/Date.module index c45c5c461..c88537441 100644 --- a/comp/src/gb.util/.src/Date.module +++ b/comp/src/gb.util/.src/Date.module @@ -92,7 +92,7 @@ Public Sub ToRFC822({Date} As Date, Optional TimeZone As String = "GMT") As Stri InitDaysMonths {Date} += System.TimeZone / 86400 + GetRFC822Zone(TimeZone) - Return $aDay[WeekDay({Date})] & ", " & Format(Day({Date}), "00") & " " & $aMonth[Month({Date}) - 1] & " " & Year({Date}) & " " & Format(Time({Date}), "hh:nn:ss") & " " & TimeZone + Return $aDay[WeekDay({Date})] & ", " & Format(Day({Date}), "00") & " " & $aMonth[Month({Date}) - 1] & " " & Year({Date}) & " " & Hour({Date}) & ":" & Minute({Date}) & ":" & Second({Date}) & " " & TimeZone End @@ -100,17 +100,41 @@ Public Sub FromRFC822(Value As String) As Date Dim aDate As String[] Dim dDate As Date - Dim fZone As Float - Dim sZone As String - - aDate = Scan(Value, "*, * * * *:*:* *") - If aDate.Count <> 8 Then Return + Dim iPos As Integer + Dim iWeekDay As Integer + Dim iYear As Integer InitDaysMonths - dDate = Date(CInt(aDate[3]), $aMonth.Find(aDate[2]) + 1, CInt(aDate[1]), CInt(aDate[4]), CInt(aDate[5]), CInt(aDate[6])) - dDate -= Frac(Date(Now)) + Value = Trim(Value) + + iPos = InStr(Value, ", ") + If iPos Then + iWeekDay = $aDay.Find(Trim(Left(Value, iPos - 1))) + If iWeekDay < 0 Then Error.Raise("Unknown week day") + Value = Trim(Mid$(Value, iPos + 2)) + Else + iWeekDay = -1 + Endif + + aDate = Scan(Value, "* * * *:* *") + If aDate.Count <> 6 Then Return + + iPos = InStr(aDate[4], ":") + If iPos Then + aDate.Add(Mid$(aDate[4], iPos + 1), 5) + aDate[4] = Left(aDate[4], iPos - 1) + Else + aDate.Add("0", 5) + Endif + + iYear = CInt(aDate[2]) + If iYear >= 0 And If iYear <= 99 Then iYear += 1900 + dDate = Date(iYear, $aMonth.Find(aDate[1]) + 1, CInt(aDate[0]), CInt(aDate[3]), CInt(aDate[4]), CInt(aDate[5])) + If iWeekDay >= 0 And If WeekDay(dDate) <> iWeekDay Then Error.Raise("Incorrect week day") + + dDate -= Frac(Date(Now)) + dDate += GetRFC822Zone(aDate[6]) - dDate += GetRFC822Zone(aDate[7]) Return dDate Catch diff --git a/comp/src/gb.util/.src/MMain.module b/comp/src/gb.util/.src/MMain.module index 1bcd0c75a..c803f8892 100644 --- a/comp/src/gb.util/.src/MMain.module +++ b/comp/src/gb.util/.src/MMain.module @@ -2,6 +2,6 @@ Public Sub Main() - Print Date.ToRFC822(Date.FromRFC822("Sun, 23 Apr 2017 19:55:10 +0200"), "-0100") + Print Date.ToRFC822(Date.FromRFC822("23 Apr 17 19:55:10 +0200"), "-0100") End