--- a/TypeConverter.st Thu Feb 26 22:30:32 2009 +0100
+++ b/TypeConverter.st Thu Mar 05 21:34:28 2009 +0100
@@ -383,6 +383,55 @@
"Created: / 26.10.1997 / 14:01:02 / cg"
!
+convertOldVWDateFormatSpecifierToNewSTXFormat:oldFormatSpec
+ "private helper to convert an old (VW) format-Array
+ of the form:
+ 'mm/dd/yyyy' (VW-backward compatibility)
+ into:
+ '%m %d %y' (new ST/X format)
+ "
+
+ |in out c nDigits|
+
+ oldFormatSpec isArray ifTrue:[^ oldFormatSpec].
+
+ out := '' writeStream.
+ in := oldFormatSpec readStream.
+ [in atEnd] whileFalse:[
+ c := in next.
+ nDigits := 1.
+ c == $m ifTrue:[
+ [in peek == $m] whileTrue:[ nDigits := nDigits + 1. in next ].
+ nDigits == 1 ifTrue:[
+ out nextPutAll:'%M'. "/ unpadded
+ ] ifFalse:[
+ out nextPutAll:'%m'.
+ ].
+ ] ifFalse:[
+ c == $d ifTrue:[
+ [in peek == $d] whileTrue:[ nDigits := nDigits + 1. in next ].
+ nDigits == 1 ifTrue:[
+ out nextPutAll:'%D'. "/ unpadded
+ ] ifFalse:[
+ out nextPutAll:'%d'.
+ ].
+ ] ifFalse:[
+ c == $y ifTrue:[
+ [in peek == $y] whileTrue:[ nDigits := nDigits + 1. in next ].
+ nDigits == 2 ifTrue:[
+ out nextPutAll:'%Y'. "/ 2 digits only
+ ] ifFalse:[
+ out nextPutAll:'%y'.
+ ].
+ ] ifFalse:[
+ out nextPut:c.
+ ].
+ ].
+ ].
+ ].
+ ^ out contents.
+!
+
date
"setup the converter to convert from a string to a date
and vice versa. Nil is converted to todays date-string,
@@ -393,16 +442,62 @@
dateDDMMYYYY
"setup the converter to convert from a string to a date formatted by printFormat
- DD-MM-YYYY; see also Date>>printFormat:"
+ DD-MM-YYYY; see also Date>>printFormat:
+ This is a backward compatibility method for very old code to print european-style dates.
+ Please use dateWithFormat: which is much more flexible."
self dateToTextFormattedBy: #(1 2 3 $- 1 1 true)
+
+ "
+ |vh|
+
+ vh := Date today asValue.
+ TypeConverter new
+ dateDDMMYYYY
+ model:vh;
+ value.
+ vh value
+ "
+ "
+ |vh|
+
+ vh := Date today asValue.
+ TypeConverter new
+ dateDDMMYYYY
+ model:vh;
+ value:'12-01-2008'.
+ vh value
+ "
!
dateMMDDYYYY
"setup the converter to convert from a string to a date formatted by printFormat
- MM:DD:YYYY; see also Date>>printFormat:"
+ MM/DD/YYYY; see also Date>>printFormat:
+ This is a backward compatibility method for very old code to print us-style dates.
+ Please use dateWithFormat: which is much more flexible."
self dateToTextFormattedBy: #(2 1 3 $/ 1 1 true)
+
+ "
+ |vh|
+
+ vh := Date today asValue.
+ TypeConverter new
+ dateMMDDYYYY
+ model:vh;
+ value.
+ vh value
+ "
+ "
+ |vh|
+
+ vh := Date today asValue.
+ TypeConverter new
+ dateMMDDYYYY
+ model:vh;
+ value:'01/12/2008'.
+ vh value
+ "
!
dateOrNil
@@ -451,9 +546,22 @@
'mm/dd/yyyy' (for VW-backward compatibility)
or:
'%m %d %y'
+
+ see Date addPrintBindingsTo:language: for a format description.
"
^ self dateWithFormat:aFormatString orDefault:Date today
+
+ "
+ |vh|
+
+ vh := Date today asValue.
+ (TypeConverter new
+ dateWithFormat:'%m%d%y')
+ model:vh;
+ value.
+ vh value
+ "
!
dateWithFormat:aFormatString orDefault:defaultValue
@@ -464,9 +572,11 @@
'mm/dd/yyyy' (for VW-backward compatibility)
or:
'%m %d %y'
+
+ see Date addPrintBindingsTo:language: for a format description.
"
- |in out stxFormat c nDigits|
+ |stxFormat|
aFormatString notNil ifTrue:[
(aFormatString includes:$%) ifTrue:[
@@ -474,41 +584,7 @@
stxFormat := aFormatString
] ifFalse:[
"/ an old (VW) formatString
- out := '' writeStream.
- in := aFormatString readStream.
- [in atEnd] whileFalse:[
- c := in next.
- nDigits := 1.
- c == $m ifTrue:[
- [in peek == $m] whileTrue:[ nDigits := nDigits + 1. in next ].
- nDigits == 1 ifTrue:[
- out nextPutAll:'%M'. "/ unpadded
- ] ifFalse:[
- out nextPutAll:'%m'.
- ].
- ] ifFalse:[
- c == $d ifTrue:[
- [in peek == $d] whileTrue:[ nDigits := nDigits + 1. in next ].
- nDigits == 1 ifTrue:[
- out nextPutAll:'%D'. "/ unpadded
- ] ifFalse:[
- out nextPutAll:'%d'.
- ].
- ] ifFalse:[
- c == $y ifTrue:[
- [in peek == $y] whileTrue:[ nDigits := nDigits + 1. in next ].
- nDigits == 2 ifTrue:[
- out nextPutAll:'%Y'. "/ 2 digits only
- ] ifFalse:[
- out nextPutAll:'%y'.
- ].
- ] ifFalse:[
- out nextPut:c.
- ].
- ].
- ].
- ].
- stxFormat := out contents.
+ stxFormat := self convertOldVWDateFormatSpecifierToNewSTXFormat:aFormatString
].
].
@@ -1499,5 +1575,5 @@
!TypeConverter class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.57 2008-11-03 13:22:48 sr Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.58 2009-03-05 20:34:28 cg Exp $'
! !