--- a/TypeConverter.st Thu Jan 10 13:50:22 2008 +0100
+++ b/TypeConverter.st Thu Jan 17 10:57:17 2008 +0100
@@ -711,29 +711,9 @@
"setup the converter to convert from a string to a number
and vice versa. Invalid numbers are converted to nil."
- self
- getBlock:[:model |
- |numericValue|
-
- (numericValue := model value) isNil ifTrue:[
- String new
- ] ifFalse:[
- numericValue printString
- ]]
+ self objectOrNilOfType:Number
- putBlock:
- [:model :string |
-
- |value|
-
- string size > 0 ifTrue:[
- value := Number readFrom:string onError:nil
- ].
- model value:value]
-
- updateBlock: [:m :a :p | true]
-
- "Created: 21.2.1997 / 18:58:38 / cg"
+ "Modified: / 12-01-2008 / 19:08:42 / cg"
!
numberOrNilToTextMinValue:minVal maxValue:maxVal
@@ -1100,6 +1080,36 @@
"Modified: 21.2.1997 / 18:59:44 / cg"
!
+objectOrNilOfType:timeOrDateClass
+ "common code for timeOrNil, dateOrNil and timeStampOrNil"
+
+ self
+ getBlock:[:model |
+ |timeOrDate|
+
+ (timeOrDate := model value) isNil ifTrue:[
+ ''
+ ] ifFalse:[
+ timeOrDate printString
+ ]]
+
+ putBlock:
+ [:model :string |
+
+ |value|
+
+ string isEmpty ifTrue:[
+ value := nil
+ ] ifFalse:[
+ value := timeOrDateClass readFrom:string onError:nil
+ ].
+ model value:value]
+
+ updateBlock: [:m :a :p | true]
+
+ "Created: / 12-01-2008 / 19:05:18 / cg"
+!
+
smalltalkObject
"setup the converter to convert from a string to any smalltalk object
and vice versa. The string used is the objects storeString.
@@ -1315,35 +1325,20 @@
!
timeOrNil
- "setup the converter to convert from a string to a time
- and vice versa."
+ "setup the converter to convert from a string to a time and vice versa."
- self
- getBlock:[:model |
- |time|
-
- (time := model value) isNil ifTrue:[
- ''
- ] ifFalse:[
- time printString
- ]]
+ self objectOrNilOfType:Time
- putBlock:
- [:model :string |
-
- |value|
+ "Created: / 04-03-1997 / 11:52:47 / cg"
+ "Modified: / 12-01-2008 / 19:06:21 / cg"
+!
- string isEmpty ifTrue:[
- value := nil
- ] ifFalse:[
- value := Time readFrom:string onError:nil
- ].
- model value:value]
+timeStampOrNil
+ "setup the converter to convert from a string to a timeStamp and vice versa."
- updateBlock: [:m :a :p | true]
+ self objectOrNilOfType:Timestamp
- "Created: 4.3.1997 / 11:52:47 / cg"
- "Modified: 4.3.1997 / 12:05:48 / cg"
+ "Modified: / 12-01-2008 / 19:06:06 / cg"
!
timeToText
@@ -1388,5 +1383,5 @@
!TypeConverter class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.49 2008-01-08 19:47:04 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.50 2008-01-17 09:57:17 cg Exp $'
! !