416 yearAlreadyRead:nil |
416 yearAlreadyRead:nil |
417 onError:exceptionValue |
417 onError:exceptionValue |
418 ! |
418 ! |
419 |
419 |
420 readRFC1123FormatFrom:rfc1123String onError:exceptionBlock |
420 readRFC1123FormatFrom:rfc1123String onError:exceptionBlock |
421 |parts day year time monthName month| |
421 |parts indexModifier utcOffsetString utcOffset day year time monthName month| |
422 |
422 |
423 self error:'not completly implemented, please wait for newer version'. |
423 "/ All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), |
|
424 "/ also known as Greenwich Mean Time (GMT), without exception. |
|
425 "/ This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, |
|
426 "/ and should be assumed when reading the asctime format. |
|
427 "/ |
|
428 "/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
429 "/ |
|
430 "/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
|
431 "/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
|
432 "/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
433 "/ |
|
434 "/ date1 = 2DIGIT SP month SP 4DIGIT |
|
435 "/ ; day month year (e.g., 02 Jun 1982) |
|
436 "/ date2 = 2DIGIT "-" month "-" 2DIGIT |
|
437 "/ ; day-month-year (e.g., 02-Jun-82) |
|
438 "/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
439 "/ ; month day (e.g., Jun 2) |
|
440 "/ |
|
441 "/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
|
442 "/ ; 00:00:00 - 23:59:59 |
|
443 "/ |
|
444 "/ wkday = "Mon" | "Tue" | "Wed" |
|
445 "/ | "Thu" | "Fri" | "Sat" | "Sun" |
|
446 "/ |
|
447 "/ weekday = "Monday" | "Tuesday" | "Wednesday" |
|
448 "/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
|
449 "/ |
|
450 "/ month = "Jan" | "Feb" | "Mar" | "Apr" |
|
451 "/ | "May" | "Jun" | "Jul" | "Aug" |
|
452 "/ | "Sep" | "Oct" | "Nov" | "Dec" |
|
453 "/ |
|
454 "/ Mon, 17 Aug 2009 11:11:15 GMT |
424 |
455 |
425 rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value]. |
456 rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value]. |
426 |
457 |
427 parts := rfc1123String subStrings:Character space. |
458 parts := rfc1123String subStrings:Character space. |
428 parts size ~~ 6 ifTrue:[^ exceptionBlock value]. |
459 parts size == 6 ifTrue:[ |
429 self halt. |
460 indexModifier := 0. |
430 (parts at:6) = 'GMT' ifFalse:[^ exceptionBlock value]. |
461 ] ifFalse:[ |
431 |
462 parts size == 5 ifTrue:[ |
432 day := Integer readFrom:(parts at:2) onError:[^ exceptionBlock]. |
463 indexModifier := -1. |
433 year := Integer readFrom:(parts at:4) onError:[^ exceptionBlock]. |
464 ] ifFalse:[ |
434 time := Time readFrom:(parts at:5) onError:[^ exceptionBlock]. |
465 ^ exceptionBlock value |
435 monthName := parts at:3. |
466 ]. |
|
467 ]. |
|
468 |
|
469 utcOffsetString := (parts at:6 + indexModifier). |
|
470 (utcOffsetString = 'GMT' or:[utcOffsetString = 'UTC']) ifFalse:[ |
|
471 self assert:utcOffsetString size == 5. |
|
472 |
|
473 utcOffset := (utcOffsetString from:4 to:5) asString asNumber * 60. |
|
474 utcOffset := utcOffset + ((utcOffsetString from:2 to:3) asString asNumber * 60 * 60). |
|
475 |
|
476 (utcOffsetString at:1) asSymbol == #- ifTrue:[ |
|
477 utcOffset := -1 * utcOffset. |
|
478 ]. |
|
479 ]. |
|
480 |
|
481 day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock]. |
|
482 year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock]. |
|
483 time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock]. |
|
484 monthName := parts at:3 + indexModifier. |
436 |
485 |
437 month := (1 to:12) asOrderedCollection detect:[:i | |
486 month := (1 to:12) asOrderedCollection detect:[:i | |
438 (Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName |
487 (Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName |
439 ] ifNone:[^ exceptionBlock]. |
488 ] ifNone:[^ exceptionBlock]. |
440 |
489 |
441 ^ Timestamp |
490 ^ (Timestamp |
442 fromDate:(Date newDay:day monthIndex:month year:year) |
491 fromDate:(Date newDay:day monthIndex:month year:year) |
443 andTime:time |
492 andTime:time) + utcOffset |
444 ! |
493 ! |
445 |
494 |
446 secondsSince1970:sec |
495 secondsSince1970:sec |
447 "set time from elapsed seconds since 1-1-1970, 0:0:0. |
496 "set time from elapsed seconds since 1-1-1970, 0:0:0. |
448 This is the format used in the UNIX world" |
497 This is the format used in the UNIX world" |