[GB.UTIL]
* BUG: Date.ToRFC822() now always use the ':' separator for dates. * BUG: Date.FromRFC822() now should respect the semantics of the RFC correctly. git-svn-id: svn://localhost/gambas/trunk@8124 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
1951a940e4
commit
7f7582e37d
2 changed files with 34 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue