Merge branch 'master' of gitlab.com:gambas/gambas
This commit is contained in:
commit
8796ddfdcf
4 changed files with 52 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
[Component]
|
||||
Key=gb.util
|
||||
Version=3.12.0
|
||||
Version=3.12.90
|
||||
State=1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Gambas Project File 3.0
|
||||
Title=Gambas utilities
|
||||
Startup=MMain
|
||||
Version=3.12.0
|
||||
Version=3.12.90
|
||||
VersionFile=1
|
||||
TabSize=2
|
||||
Language=fr
|
||||
|
|
|
@ -51,10 +51,15 @@ Private Sub InitDaysMonths()
|
|||
End
|
||||
|
||||
Public Sub ToUTC({Date} As Date) As Date
|
||||
|
||||
{Date} += System.TimeZone / 86400
|
||||
Return {Date}
|
||||
|
||||
|
||||
Return {Date} + System.TimeZone / 86400
|
||||
|
||||
End
|
||||
|
||||
Public Sub FromUTC({Date} As Date) As Date
|
||||
|
||||
Return {Date} - System.TimeZone / 86400
|
||||
|
||||
End
|
||||
|
||||
Private Sub GetRFC822Zone(sZone As String) As Float
|
||||
|
@ -83,7 +88,7 @@ Private Sub GetRFC822Zone(sZone As String) As Float
|
|||
Case Like "[+-][0-1][0-9][0-5][0-9]"
|
||||
fZone = CInt(Left(sZone, 3)) + CInt(Mid$(sZone, 4)) / 60
|
||||
Case Else
|
||||
Error.Raise("Unknown timezone")
|
||||
Error.Raise(Subst$("Unknown timezone '&1'", sZone))
|
||||
End Select
|
||||
|
||||
Return fZone / 24
|
||||
|
@ -95,12 +100,12 @@ End
|
|||
Public Sub ToRFC822({Date} As Date, Optional TimeZone As String = "GMT") As String
|
||||
|
||||
InitDaysMonths
|
||||
{Date} += System.TimeZone / 86400 + GetRFC822Zone(TimeZone)
|
||||
{Date} = ToUTC({Date}) + GetRFC822Zone(TimeZone)
|
||||
Return $aDay[WeekDay({Date})] & ", " & Format(Day({Date}), "00") & " " & $aMonth[Month({Date}) - 1] & " " & Year({Date}) & " " & Format(Hour({Date}), "00") & ":" & Format(Minute({Date}), "00") & ":" & Format(Second({Date}), "00") & " " & TimeZone
|
||||
|
||||
End
|
||||
|
||||
Public Sub FromRFC822(Value As String) As Date
|
||||
Public Sub FromRFC822(Value As String, Optional ByRef TimeZone As String) As Date
|
||||
|
||||
Dim aDate As String[]
|
||||
Dim dDate As Date
|
||||
|
@ -136,13 +141,14 @@ Public Sub FromRFC822(Value As String) As Date
|
|||
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 = FromUTC(dDate) - GetRFC822Zone(aDate[6])
|
||||
|
||||
TimeZone = aDate[6]
|
||||
Return dDate
|
||||
|
||||
Catch
|
||||
|
||||
If Error.Class.Name = "Date" Then Error.Propagate
|
||||
Error.Raise("Not a RFC822 date format")
|
||||
|
||||
End
|
||||
|
|
|
@ -19,5 +19,40 @@
|
|||
Public Sub Main()
|
||||
|
||||
Print CStr(CDate("1/1/1970"))
|
||||
RFC822Test()
|
||||
|
||||
End
|
||||
|
||||
Public Sub RFC822Test()
|
||||
|
||||
Dim sTimeZone As String
|
||||
|
||||
' Must be correct in the local timezone
|
||||
Print CStr(Now)
|
||||
Print Format(Now)
|
||||
Print CStr(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0000"))
|
||||
Print Format$(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0000"))
|
||||
Print Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0100")
|
||||
Print Date.FromRFC822("Tue, 1 Jan 2019 00:00:00 +0800")
|
||||
Print Date.ToRFC822(Now)
|
||||
Print Date.ToRFC822(Now, "+0100")
|
||||
Print "---"
|
||||
' Timezone to-from conversion should be the identity mapping
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0000"), "+0000")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0000"), "+0100")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0000"), "+0800")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0100"), "+0000")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0100"), "+0100")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0100"), "+0800")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0800"), "+0000")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0800"), "+0100")
|
||||
Print Date.ToRFC822(Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0800"), "+0800")
|
||||
Print "---"
|
||||
' Ability to extract timezone
|
||||
Date.FromRFC822("Sun, 21 Apr 2019 05:00:00 +0100", ByRef sTimeZone)
|
||||
Print sTimeZone
|
||||
' 21 Apr 2019 is not a Wednesday
|
||||
Try Date.FromRFC822("Wed, 21 Apr 2019 05:00:00 +0100")
|
||||
If Error Then Print Error.Text
|
||||
|
||||
End
|
||||
|
|
Loading…
Reference in a new issue