Timestamp.st
changeset 11862 9c314f3a40df
parent 11857 adaac1fd5452
child 11876 2a14d6e5479c
--- a/Timestamp.st	Sun Aug 16 23:30:49 2009 +0200
+++ b/Timestamp.st	Mon Aug 17 13:57:08 2009 +0200
@@ -418,29 +418,78 @@
 !
 
 readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
-    |parts day year time monthName month|
+    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
 
-    self error:'not completly implemented, please wait for newer version'.
+"/    All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), 
+"/    also known as Greenwich Mean Time (GMT), without exception. 
+"/    This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, 
+"/    and should be assumed when reading the asctime format.
+"/
+"/    HTTP-date      = rfc1123-date | rfc850-date | asctime-date
+"/
+"/    rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
+"/    rfc850-date    = weekday "," SP date2 SP time SP "GMT"
+"/    asctime-date   = wkday SP date3 SP time SP 4DIGIT
+"/
+"/    date1          = 2DIGIT SP month SP 4DIGIT
+"/                     ; day month year (e.g., 02 Jun 1982)
+"/    date2          = 2DIGIT "-" month "-" 2DIGIT
+"/                     ; day-month-year (e.g., 02-Jun-82)
+"/    date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
+"/                     ; month day (e.g., Jun  2)
+"/
+"/    time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
+"/                     ; 00:00:00 - 23:59:59
+"/
+"/    wkday          = "Mon" | "Tue" | "Wed"
+"/                   | "Thu" | "Fri" | "Sat" | "Sun"
+"/
+"/    weekday        = "Monday" | "Tuesday" | "Wednesday"
+"/                   | "Thursday" | "Friday" | "Saturday" | "Sunday"
+"/
+"/    month          = "Jan" | "Feb" | "Mar" | "Apr"
+"/                   | "May" | "Jun" | "Jul" | "Aug"
+"/                   | "Sep" | "Oct" | "Nov" | "Dec"
+"/
+"/    Mon, 17 Aug 2009 11:11:15 GMT
 
     rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
 
     parts := rfc1123String subStrings:Character space.
-    parts size ~~ 6 ifTrue:[^ exceptionBlock value].
-                            self halt.
-    (parts at:6) = 'GMT' ifFalse:[^ exceptionBlock value].
+    parts size == 6 ifTrue:[
+        indexModifier := 0.
+    ] ifFalse:[
+        parts size == 5 ifTrue:[
+            indexModifier := -1.
+        ] ifFalse:[
+            ^ exceptionBlock value
+        ].
+    ].
 
-    day := Integer readFrom:(parts at:2) onError:[^ exceptionBlock].
-    year := Integer readFrom:(parts at:4) onError:[^ exceptionBlock].
-    time := Time readFrom:(parts at:5) onError:[^ exceptionBlock].
-    monthName := parts at:3.
+    utcOffsetString := (parts at:6 + indexModifier).
+    (utcOffsetString = 'GMT' or:[utcOffsetString = 'UTC']) ifFalse:[ 
+        self assert:utcOffsetString size == 5.
+
+        utcOffset := (utcOffsetString from:4 to:5) asString asNumber * 60.
+        utcOffset := utcOffset + ((utcOffsetString from:2 to:3) asString asNumber * 60 * 60).
+
+        (utcOffsetString at:1) asSymbol == #- ifTrue:[
+            utcOffset := -1 * utcOffset.
+        ].
+    ].
+
+    day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
+    year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
+    time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
+    monthName := parts at:3 + indexModifier.
 
     month := (1 to:12) asOrderedCollection detect:[:i | 
         (Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName 
     ] ifNone:[^ exceptionBlock].    
 
-    ^ Timestamp 
+    ^ (Timestamp 
         fromDate:(Date newDay:day monthIndex:month year:year) 
-        andTime:time   
+        andTime:time) + utcOffset       
 !
 
 secondsSince1970:sec
@@ -1438,6 +1487,7 @@
     "
 ! !
 
+
 !Timestamp methodsFor:'visiting'!
 
 acceptVisitor:aVisitor with:aParameter
@@ -1448,7 +1498,7 @@
 !Timestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.118 2009-08-14 21:05:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.119 2009-08-17 11:57:08 sr Exp $'
 ! !
 
 Timestamp initialize!