TypeConverter.st
changeset 1026 6b18a2f8833f
parent 1002 a237e5fd2be9
child 1027 eb4d24dd7e43
equal deleted inserted replaced
1025:c126b1fcc09b 1026:6b18a2f8833f
   266 
   266 
   267     "Modified: / 26.10.1997 / 13:50:32 / cg"
   267     "Modified: / 26.10.1997 / 13:50:32 / cg"
   268     "Created: / 26.10.1997 / 14:01:02 / cg"
   268     "Created: / 26.10.1997 / 14:01:02 / cg"
   269 !
   269 !
   270 
   270 
       
   271 dateDDMMYYYYFormatToText
       
   272     "setup the converter to convert from a string to a date formatted by printFormat
       
   273      DD:MM:YYYY; see also Date>>printFormat:"
       
   274 
       
   275     self dateToTextFormattedBy: #(1 2 3 $: 1 1 true)
       
   276 !
       
   277 
       
   278 dateMMDDYYYYFormatToText
       
   279     "setup the converter to convert from a string to a date formatted by printFormat
       
   280      MM:DD:YYYY; see also Date>>printFormat:"
       
   281 
       
   282     self dateToTextFormattedBy: #(2 1 3 $: 1 1 true)
       
   283 !
       
   284 
   271 dateOrNil
   285 dateOrNil
   272     "setup the converter to convert from a string to a date
   286     "setup the converter to convert from a string to a date
   273      and vice versa. Invalid dates are converted to nil; likewise,
   287      and vice versa. Invalid dates are converted to nil; likewise,
   274      a nil date is converted to an empty string."
   288      a nil date is converted to an empty string."
   275 
   289 
   330 
   344 
   331         updateBlock: [:m :a :p | true]
   345         updateBlock: [:m :a :p | true]
   332 
   346 
   333     "Created: / 4.3.1997 / 12:32:19 / cg"
   347     "Created: / 4.3.1997 / 12:32:19 / cg"
   334     "Modified: / 26.10.1997 / 13:52:00 / cg"
   348     "Modified: / 26.10.1997 / 13:52:00 / cg"
       
   349 !
       
   350 
       
   351 dateToTextFormattedBy: printFormat
       
   352     "setup the converter to convert from a string to a date formatted by printFormat
       
   353      and vice versa. Nil is converted to todays date-string,
       
   354      likewise, an empty string is converted back to todays date."
       
   355 
       
   356     self
       
   357         getBlock:[:model |
       
   358                 |date|
       
   359 
       
   360                 (date := model value) isNil ifTrue:[   
       
   361                     Date today printFormat:printFormat
       
   362                 ] ifFalse:[             
       
   363                     date printFormat:printFormat
       
   364                 ]]
       
   365 
       
   366         putBlock:
       
   367                 [:model :string |
       
   368 
       
   369                 |value|
       
   370 
       
   371                 string isEmpty ifTrue:[  
       
   372                     value := Date today
       
   373                 ] ifFalse:[                      
       
   374                     value := Date readFrom:string onError:[Date today]
       
   375                 ].
       
   376                 model value:value]
       
   377 
       
   378         updateBlock: [:m :a :p | true]
   335 !
   379 !
   336 
   380 
   337 number
   381 number
   338     "setup the converter to convert from a string to a number
   382     "setup the converter to convert from a string to a number
   339      and vice versa. Invalid numbers are converted to nil."
   383      and vice versa. Invalid numbers are converted to nil."
   621 
   665 
   622     "Created: / 21.2.1997 / 18:58:38 / cg"
   666     "Created: / 21.2.1997 / 18:58:38 / cg"
   623     "Modified: / 26.5.1998 / 15:06:06 / cg"
   667     "Modified: / 26.5.1998 / 15:06:06 / cg"
   624 !
   668 !
   625 
   669 
       
   670 time12HourFormatToText
       
   671     "setup the converter to convert from a string to a time formatted by 12 hours
       
   672      and vice versa."
       
   673 
       
   674     self timeToTextFormattedBy: #print12HourFormat
       
   675 
       
   676 
       
   677 !
       
   678 
       
   679 time24HourFormatToText
       
   680     "setup the converter to convert from a string to a time formatted by 24 hours
       
   681      and vice versa."
       
   682 
       
   683     self timeToTextFormattedBy: #print24HourFormat
       
   684 
       
   685 
       
   686 !
       
   687 
   626 timeOrNil
   688 timeOrNil
   627     "setup the converter to convert from a string to a time
   689     "setup the converter to convert from a string to a time
   628      and vice versa."
   690      and vice versa."
   629 
   691 
   630     self
   692     self
   657 
   719 
   658 timeToText
   720 timeToText
   659     "setup the converter to convert from a string to a time
   721     "setup the converter to convert from a string to a time
   660      and vice versa."
   722      and vice versa."
   661 
   723 
       
   724     self timeToTextFormattedBy: #printString
       
   725 !
       
   726 
       
   727 timeToTextFormattedBy: format
       
   728     "setup the converter to convert from a string to a time formatted by format
       
   729      and vice versa."
       
   730 
   662     self
   731     self
   663         getBlock:[:model |
   732         getBlock:[:model |
   664                 |time|
   733                 |time|
   665 
   734 
   666                 (time := model value) isNil ifTrue:[
   735                 (time := model value) isNil ifTrue:[
   667                     Time now printString
   736                     Time now perform: format
   668                 ] ifFalse:[
   737                 ] ifFalse:[
   669                     time printString
   738                     time perform: format
   670                 ]]
   739                 ]]
   671 
   740 
   672         putBlock:
   741         putBlock:
   673                 [:model :string |
   742                 [:model :string |
   674 
   743 
   675                 |value|
   744                 |value|
   676 
   745 
   677                 string isEmpty ifTrue:[
   746                 string isEmpty ifTrue:[
   678                     value := Time now
   747                     value := Time now
   679                 ] ifFalse:[
   748                 ] ifFalse:[              
   680                     value := Time readFrom:string onError:Time now
   749                     value := Time readFrom:string onError:[Time now]
   681                 ].
   750                 ].
   682                 model value:value]
   751                 model value:value]
   683 
   752 
   684         updateBlock: [:m :a :p | true]
   753         updateBlock: [:m :a :p | true]
   685 
   754 
   688 ! !
   757 ! !
   689 
   758 
   690 !TypeConverter class methodsFor:'documentation'!
   759 !TypeConverter class methodsFor:'documentation'!
   691 
   760 
   692 version
   761 version
   693     ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.19 1998-07-19 18:55:35 tz Exp $'
   762     ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.20 1998-08-02 20:33:59 tz Exp $'
   694 ! !
   763 ! !