diff -r c126b1fcc09b -r 6b18a2f8833f TypeConverter.st --- a/TypeConverter.st Sun Aug 02 22:22:49 1998 +0200 +++ b/TypeConverter.st Sun Aug 02 22:33:59 1998 +0200 @@ -268,6 +268,20 @@ "Created: / 26.10.1997 / 14:01:02 / cg" ! +dateDDMMYYYYFormatToText + "setup the converter to convert from a string to a date formatted by printFormat + DD:MM:YYYY; see also Date>>printFormat:" + + self dateToTextFormattedBy: #(1 2 3 $: 1 1 true) +! + +dateMMDDYYYYFormatToText + "setup the converter to convert from a string to a date formatted by printFormat + MM:DD:YYYY; see also Date>>printFormat:" + + self dateToTextFormattedBy: #(2 1 3 $: 1 1 true) +! + dateOrNil "setup the converter to convert from a string to a date and vice versa. Invalid dates are converted to nil; likewise, @@ -334,6 +348,36 @@ "Modified: / 26.10.1997 / 13:52:00 / cg" ! +dateToTextFormattedBy: printFormat + "setup the converter to convert from a string to a date formatted by printFormat + and vice versa. Nil is converted to todays date-string, + likewise, an empty string is converted back to todays date." + + self + getBlock:[:model | + |date| + + (date := model value) isNil ifTrue:[ + Date today printFormat:printFormat + ] ifFalse:[ + date printFormat:printFormat + ]] + + putBlock: + [:model :string | + + |value| + + string isEmpty ifTrue:[ + value := Date today + ] ifFalse:[ + value := Date readFrom:string onError:[Date today] + ]. + model value:value] + + updateBlock: [:m :a :p | true] +! + number "setup the converter to convert from a string to a number and vice versa. Invalid numbers are converted to nil." @@ -623,6 +667,24 @@ "Modified: / 26.5.1998 / 15:06:06 / cg" ! +time12HourFormatToText + "setup the converter to convert from a string to a time formatted by 12 hours + and vice versa." + + self timeToTextFormattedBy: #print12HourFormat + + +! + +time24HourFormatToText + "setup the converter to convert from a string to a time formatted by 24 hours + and vice versa." + + self timeToTextFormattedBy: #print24HourFormat + + +! + timeOrNil "setup the converter to convert from a string to a time and vice versa." @@ -659,14 +721,21 @@ "setup the converter to convert from a string to a time and vice versa." + self timeToTextFormattedBy: #printString +! + +timeToTextFormattedBy: format + "setup the converter to convert from a string to a time formatted by format + and vice versa." + self getBlock:[:model | |time| (time := model value) isNil ifTrue:[ - Time now printString + Time now perform: format ] ifFalse:[ - time printString + time perform: format ]] putBlock: @@ -676,8 +745,8 @@ string isEmpty ifTrue:[ value := Time now - ] ifFalse:[ - value := Time readFrom:string onError:Time now + ] ifFalse:[ + value := Time readFrom:string onError:[Time now] ]. model value:value] @@ -690,5 +759,5 @@ !TypeConverter class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.19 1998-07-19 18:55:35 tz Exp $' + ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.20 1998-08-02 20:33:59 tz Exp $' ! !