TypeConverter.st
changeset 2982 6018ea07390a
parent 2941 f650030b77ee
child 3000 e303c208bf15
--- a/TypeConverter.st	Thu Dec 29 19:17:15 2011 +0100
+++ b/TypeConverter.st	Sun Jan 22 11:35:31 2012 +0100
@@ -782,6 +782,16 @@
     self integerToText
 !
 
+integerOrNil
+    "setup the converter to convert from a string to an integer
+     and vice versa. Invalid numbers are converted to nil."
+
+    self objectOrNilOfType:Integer
+
+    "Modified: / 12-01-2008 / 19:08:42 / cg"
+    "Created: / 22-01-2012 / 11:28:24 / cg"
+!
+
 integerToHexTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
     "setup the converter to convert from a string to a number
      and vice versa, but clamping the number into the range."
@@ -1747,7 +1757,7 @@
 
     self
         getBlock:[:model |
-                |time|
+                |time fmt|
 
                 (time := model value) isNil ifTrue:[
                     time := defaultValue
@@ -1755,11 +1765,15 @@
                 time isNil ifTrue:[
                     ''
                 ] ifFalse:[
-                    aFormatString isNil ifTrue:[
-                        time printStringFormat:(timeClass defaultFormatString) language:langOrNil
-                    ] ifFalse:[
-                        time printStringFormat:aFormatString language:langOrNil
-                ]]]
+                    (fmt := aFormatString) isNil ifTrue:[
+                        timeClass = TimeDuration ifTrue:[
+                            fmt := time formatForPrinting
+                        ] ifFalse:[
+                            fmt := timeClass defaultFormatString
+                        ].
+                    ].
+                    time printStringFormat:fmt language:langOrNil
+                ]]
 
         putBlock:
                 [:model :string |
@@ -1854,9 +1868,9 @@
 !TypeConverter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.65 2011-09-15 08:44:45 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.66 2012-01-22 10:35:31 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.65 2011-09-15 08:44:45 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.66 2012-01-22 10:35:31 cg Exp $'
 ! !