The Trunk: Compression-ar.20.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Compression-ar.20.mcz

commits-2
Andreas Raab uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-ar.20.mcz

==================== Summary ====================

Name: Compression-ar.20
Author: ar
Time: 11 August 2010, 8:45:56.13 pm
UUID: 68bc3e00-b2a1-2e49-851e-e113a3b0824d
Ancestors: Compression-ar.19

Fix handling of leap years in ZipArchive timestamp handling. Provide test governing the change in behavior.

=============== Diff against Compression-ar.19 ===============

Item was added:
+ TestCase subclass: #ZipArchiveTests
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Compression-Archives'!

Item was added:
+ ----- Method: ZipArchiveMember>>dosToSqueakTime: (in category 'private') -----
+ dosToSqueakTime: dt
+ "DOS years start at 1980, so add 1980."
+ | year mon mday hour min sec date time |
+
+ year := (( dt bitShift: -25 ) bitAnd: 16r7F ).
+ mon := (( dt bitShift: -21 ) bitAnd: 16r0F ).
+ mday := (( dt bitShift: -16 ) bitAnd: 16r1F ).
+ date := Date newDay: mday month: mon year: year+1980.
+
+ hour := (( dt bitShift: -11 ) bitAnd: 16r1F ).
+ min := (( dt bitShift: -5 ) bitAnd: 16r3F ).
+ sec := (( dt bitShift: 1 ) bitAnd: 16r3E ).
+ time := ((( hour * 60 ) + min ) * 60 ) + sec.
+
+ ^date asSeconds + time
+
+ !

Item was changed:
  ----- Method: ZipArchiveMember>>setLastModFileDateTimeFrom: (in category 'accessing') -----
  setLastModFileDateTimeFrom: aSmalltalkTime
+
+ lastModFileDateTime := self squeakToDosTime: aSmalltalkTime!
- | unixTime |
- unixTime := aSmalltalkTime -  2177424000. "PST?"
- lastModFileDateTime := self unixToDosTime: unixTime!

Item was added:
+ ----- Method: ZipArchiveMember>>squeakToDosTime: (in category 'private') -----
+ squeakToDosTime: secs
+ | dosTime dateTime |
+
+ dateTime := Time dateAndTimeFromSeconds: secs.
+ dosTime := (dateTime second seconds) bitShift: -1.
+ dosTime := dosTime + ((dateTime second minutes) bitShift: 5).
+ dosTime := dosTime + ((dateTime second hours) bitShift: 11).
+ dosTime := dosTime + ((dateTime first dayOfMonth) bitShift: 16).
+ dosTime := dosTime + ((dateTime first monthIndex) bitShift: 21).
+ dosTime := dosTime + (((dateTime first year) - 1980) bitShift: 25).
+ ^dosTime
+ !

Item was changed:
  ----- Method: ZipArchiveMember>>lastModTime (in category 'accessing') -----
  lastModTime
  "Return my last modification date/time stamp,
  converted to Squeak seconds"
 
+ ^self dosToSqueakTime: lastModFileDateTime!
- ^self unixToSqueakTime: (self dosToUnixTime: lastModFileDateTime)!

Item was added:
+ ----- Method: ZipArchiveTests>>testDate29Feb2000 (in category 'tests') -----
+ testDate29Feb2000
+ "Ensure that dates with leap years don't screw up in the conversion"
+
+ | archive mbr theDate |
+ theDate := Date year: 2000 month: 2 day: 29.
+ archive := ZipArchive new.
+ mbr := archive addDeflateString:'foo' as: 'bar'.
+ mbr setLastModFileDateTimeFrom: theDate asSeconds.
+ self shouldnt:[mbr lastModTime] raise: Error.
+ self assert: (Date fromSeconds: mbr lastModTime) = theDate.!

Item was removed:
- ----- Method: ZipArchiveMember>>unixToDosTime: (in category 'private') -----
- unixToDosTime: unixTime
- | dosTime dateTime secs |
- secs := self unixToSqueakTime: unixTime. "Squeak time (PST?)"
- dateTime := Time dateAndTimeFromSeconds: secs.
- dosTime := (dateTime second seconds) bitShift: -1.
- dosTime := dosTime + ((dateTime second minutes) bitShift: 5).
- dosTime := dosTime + ((dateTime second hours) bitShift: 11).
- dosTime := dosTime + ((dateTime first dayOfMonth) bitShift: 16).
- dosTime := dosTime + ((dateTime first monthIndex) bitShift: 21).
- dosTime := dosTime + (((dateTime first year) - 1980) bitShift: 25).
- ^dosTime
- !

Item was removed:
- ----- Method: ZipArchiveMember>>dosToUnixTime: (in category 'private') -----
- dosToUnixTime: dt
- "DOS years start at 1980, Unix at 1970, and Smalltalk at 1901.
- So the Smalltalk seconds will be high by 69 years when used as Unix time:=t values.
- So shift 1980 back to 1911..."
- | year mon mday hour min sec date time |
-
- year := (( dt bitShift: -25 ) bitAnd: 16r7F ) + 1911.
- mon := (( dt bitShift: -21 ) bitAnd: 16r0F ).
- mday := (( dt bitShift: -16 ) bitAnd: 16r1F ).
- date := Date newDay: mday month: mon year: year.
-
- hour := (( dt bitShift: -11 ) bitAnd: 16r1F ).
- min := (( dt bitShift: -5 ) bitAnd: 16r3F ).
- sec := (( dt bitShift: 1 ) bitAnd: 16r3E ).
- time := ((( hour * 60 ) + min ) * 60 ) + sec.
-
- ^date asSeconds + time
-
- !

Item was removed:
- ----- Method: ZipArchiveMember>>unixToSqueakTime: (in category 'private') -----
- unixToSqueakTime: unixTime
- ^unixTime +  2177424000. "Squeak time (PST?)"!