Skip to content

Commit

Permalink
Introduce ZTimestampFormat>>#specificationElements
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvc committed Sep 22, 2023
1 parent 8633921 commit a6637ad
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions repository/ZTimestamp-Core/ZTimestampFormat.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,15 @@ ZTimestampFormat >> actualOffsetForTimestamp: timestamp [

{ #category : #private }
ZTimestampFormat >> compileSpecification [
| offset elements |
elements := Array streamContents: [ :stream |
offset := 1.
[ offset <= specification size ] whileTrue: [
(self nextFormatKeyStartingAt: offset)
ifNotNil: [ :formatKey |
stream nextPut: (self class formats at: formatKey).
offset := offset + formatKey size ]
ifNil: [
stream nextPut: (specification at: offset).
offset := offset + 1 ] ] ].
formatter := elements collect: [ :each |
each isCharacter ifTrue: [ each ] ifFalse: [ (#format:, each, #On:) asSymbol ] ].
parser := elements collect: [ :each |
each isCharacter ifTrue: [ each ] ifFalse: [ (#parse, each capitalized, #From:) asSymbol ] ]
| elements |
elements := self specificationElements.
formatter := elements
collect: [ :each | each isCharacter ifTrue: [ each ] ifFalse: [ (#format: , each , #On:) asSymbol ] ].
parser := elements
collect: [ :each |
each isCharacter
ifTrue: [ each ]
ifFalse: [ (#parse , each capitalized , #From:) asSymbol ] ]
]

{ #category : #accessing }
Expand Down Expand Up @@ -1144,6 +1138,21 @@ ZTimestampFormat >> specification: exampleString [
self compileSpecification
]

{ #category : #private }
ZTimestampFormat >> specificationElements [
| offset |
^ Array
streamContents: [ :stream |
offset := 1.
[ offset <= specification size ]
whileTrue: [ (self nextFormatKeyStartingAt: offset)
ifNotNil: [ :formatKey |
stream nextPut: (self class formats at: formatKey).
offset := offset + formatKey size ]
ifNil: [ stream nextPut: (specification at: offset).
offset := offset + 1 ] ] ]
]

{ #category : #private }
ZTimestampFormat >> string: string contains: subString startingAt: offset [
subString doWithIndex: [ :each :index |
Expand Down

0 comments on commit a6637ad

Please sign in to comment.