Some integrations

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

Some integrations

dario trussardi
Dale,

        i report some integrations port from Pharo to GLASS and other changes:

A) Class Duration

        roundTo: aDuration
  "e.g. if the receiver is 5 minutes, 37 seconds, and aDuration is 2 minutes, answer 6 minutes."
 
  ^ self class nanoSeconds: (self asNanoSeconds roundTo: aDuration asNanoSeconds)


B) Class DateAndTime
       
        new
        "Answer a DateAndTime representing the Squeak epoch: 1 January 1901"

        ^ self epoch

C) Class ScaledDecimal

C1) asString

"Returns a String of the form '123.56 for a number with scale = 2."
" DTR add decimalPoint only if with decimals.   10,   isn't beautiful"

| str mstr sc sz len isNeg m dpStr nDigits |
(m := mantissa) ifNil:[ ^ 'ScaledDecimalNaN' ].
mstr := m asString .
len := mstr size .
sz := len .
sc := scale.
nDigits := sz .
(isNeg := (mstr at: 1) == $-) ifTrue:[ nDigits := nDigits - 1 ].
dpStr := Locale decimalPoint .
str := String new .
nDigits <= sc  ifTrue:[ | prefix zeros zerosLen zcount idx srcIdx |
  isNeg ifTrue:[ str add: $- ] .
  str add: $0 ; add: dpStr .
  zeros := '00000000000000000000000000000000000000000000000000000000000000000' .
  zerosLen := zeros size .
  zcount := sc - nDigits .
  [ zcount >= zerosLen ] whileTrue:[
    str add: zeros .
    zcount := zcount - zerosLen .
  ].
  zcount > 0 ifTrue:[
    "zeros copyFrom: 1 to: zcount into: str startingAt: str size + 1"
    idx := str size .
    str replaceFrom: idx + 1 to: idx + zcount with: zeros startingAt: 1 .
  ].
  "mstr copyFrom: len - nDigits + 1 to: len into: str startingAt: str size + 1"
  idx := str size + 1 .
  srcIdx := len - nDigits + 1 .
  str replaceFrom: idx  to: idx + nDigits - 1  with: mstr startingAt: srcIdx
 ] ifFalse:[  
  str := mstr .
 " add dpStr only if with decimals "
 sc>0 ifTrue:[ str insertAll: dpStr at: (sz + 1 - sc )] .
].
^ str

C2) _printAsDateAndTimeANSISecondsOn: aStream

        | string i  dp |
        "dtr adding Locale decimalPoint reference "

        dp := Locale decimalPoint first.
        "Adding 100 causes a very tiny loss of precission but makes parsing much easier"
        string := (self + 100) asString.
        (string at: 4) = dp ifFalse: [self error: 'unexpected format'].
        i := string size.
        [
                (string at: i) = $0 or: [ (string at: i) = $. ].
        ] whileTrue: [
                i := i - 1.
        ].
        aStream nextPutAll: (string copyFrom: 2 to: i).


If you look good, you may integrate in a new release?

        Thanks,

                Ciao, Dario



Reply | Threaded
Open this post in threaded view
|

Re: Some integrations

Dale Henrichs
Dario,

The best way to get these changes integrated is to create a new version of the relevant packages and commit them to gemsource. Then send me mail with the new version numbers and I I'll edit the GLASS configurations for the next release ...

I'm hoping that we'll be able to start using github for managing the GLASS packages soon, then with travis CI and pull requests integration will be a much simpler process

Dale

----- Original Message -----
| From: "Dario Trussardi" <[hidden email]>
| To: "beta discussion Gemstone Seaside" <[hidden email]>
| Sent: Thursday, March 28, 2013 3:33:35 AM
| Subject: [GS/SS Beta] Some integrations
|
| Dale,
|
| i report some integrations port from Pharo to GLASS and other changes:
|
| A) Class Duration
|
| roundTo: aDuration
|   "e.g. if the receiver is 5 minutes, 37 seconds, and aDuration is 2 minutes,
|   answer 6 minutes."
|  
|   ^ self class nanoSeconds: (self asNanoSeconds roundTo: aDuration
|   asNanoSeconds)
|
|
| B) Class DateAndTime
|
| new
| "Answer a DateAndTime representing the Squeak epoch: 1 January 1901"
|
| ^ self epoch
|
| C) Class ScaledDecimal
|
| C1) asString
|
| "Returns a String of the form '123.56 for a number with scale = 2."
| " DTR add decimalPoint only if with decimals.   10,   isn't beautiful"
|
| | str mstr sc sz len isNeg m dpStr nDigits |
| (m := mantissa) ifNil:[ ^ 'ScaledDecimalNaN' ].
| mstr := m asString .
| len := mstr size .
| sz := len .
| sc := scale.
| nDigits := sz .
| (isNeg := (mstr at: 1) == $-) ifTrue:[ nDigits := nDigits - 1 ].
| dpStr := Locale decimalPoint .
| str := String new .
| nDigits <= sc  ifTrue:[ | prefix zeros zerosLen zcount idx srcIdx |
|   isNeg ifTrue:[ str add: $- ] .
|   str add: $0 ; add: dpStr .
|   zeros :=
|   '00000000000000000000000000000000000000000000000000000000000000000' .
|   zerosLen := zeros size .
|   zcount := sc - nDigits .
|   [ zcount >= zerosLen ] whileTrue:[
|     str add: zeros .
|     zcount := zcount - zerosLen .
|   ].
|   zcount > 0 ifTrue:[
|     "zeros copyFrom: 1 to: zcount into: str startingAt: str size + 1"
|     idx := str size .
|     str replaceFrom: idx + 1 to: idx + zcount with: zeros startingAt: 1 .
|   ].
|   "mstr copyFrom: len - nDigits + 1 to: len into: str startingAt: str size +
|   1"
|   idx := str size + 1 .
|   srcIdx := len - nDigits + 1 .
|   str replaceFrom: idx  to: idx + nDigits - 1  with: mstr startingAt: srcIdx
|  ] ifFalse:[
|   str := mstr .
|  " add dpStr only if with decimals "
|  sc>0 ifTrue:[ str insertAll: dpStr at: (sz + 1 - sc )] .
| ].
| ^ str
|
| C2) _printAsDateAndTimeANSISecondsOn: aStream
|
| | string i  dp |
| "dtr adding Locale decimalPoint reference "
|
| dp := Locale decimalPoint first.
| "Adding 100 causes a very tiny loss of precission but makes parsing much
| easier"
| string := (self + 100) asString.
| (string at: 4) = dp ifFalse: [self error: 'unexpected format'].
| i := string size.
| [
| (string at: i) = $0 or: [ (string at: i) = $. ].
| ] whileTrue: [
| i := i - 1.
| ].
| aStream nextPutAll: (string copyFrom: 2 to: i).
|
|
| If you look good, you may integrate in a new release?
|
| Thanks,
|
| Ciao, Dario
|
|
|
|