Date.st
changeset 18446 621525712675
parent 18444 f70da4b43b10
child 18448 47f63bccdee0
equal deleted inserted replaced
18445:6184d4210c89 18446:621525712675
   488      aFormatStringOrSqueakFormatArray may either be a squeak formatArray
   488      aFormatStringOrSqueakFormatArray may either be a squeak formatArray
   489          1   day position (1, 2 or 3)
   489          1   day position (1, 2 or 3)
   490          2   month position (1..3)
   490          2   month position (1..3)
   491          3   year position (1..3)
   491          3   year position (1..3)
   492      or a formatString (see printing instance protocol).
   492      or a formatString (see printing instance protocol).
   493      For now %d, %m, %monthName, %shortMonthName, %y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString.
   493      For now %d, %m, %monthName, %shortMonthName, %y, %Y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString.
   494      y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
   494      y1900 converts 2-digit year YY into 19YY, 
   495      y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. 
   495      y2000 into 20YY.
       
   496      y1950, y1980 and Y are special; 
       
   497      if the year is below 50/80/70, it is converted to 20YY, otherwise to 19YY. 
   496      The formatString can have any of these characters '-.:,;/' as separator.
   498      The formatString can have any of these characters '-.:,;/' as separator.
   497      The format may be preceeded by a single numeric length (as in %2d) to specify how many
   499      The format may be preceeded by a single numeric length (as in %2d) to specify how many
   498      characters to read.
   500      characters to read.
   499      The formatString can also use a space as separator (for  ex. '%d %m %y') and any separator will be allowed.
   501      The formatString can also use a space as separator (for  ex. '%d %m %y') and any separator will be allowed.
   500      However, when a character separator is defined, only that separator will be expected.
   502      However, when a character separator is defined, only that separator will be expected.
   610      Date readFrom:'01' printFormat:'%y' onError:'fail'       
   612      Date readFrom:'01' printFormat:'%y' onError:'fail'       
   611      Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'     
   613      Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'     
   612      Date readFrom:'300180' printFormat:'%2d%2m%2y' onError:'fail' 
   614      Date readFrom:'300180' printFormat:'%2d%2m%2y' onError:'fail' 
   613      
   615      
   614      Date readFrom:'300170' printFormat:'%2d%2m%2y' onError:'fail'      - gives 2070 as year
   616      Date readFrom:'300170' printFormat:'%2d%2m%2y' onError:'fail'      - gives 2070 as year
       
   617      Date readFrom:'300170' printFormat:'%2d%2m%2Y' onError:'fail'      - gives 1970 as year
       
   618      Date readFrom:'300169' printFormat:'%2d%2m%2y' onError:'fail'      - gives 2069 as year
       
   619      Date readFrom:'300169' printFormat:'%2d%2m%2Y' onError:'fail'      - gives 2069 as year
       
   620 
   615      Date readFrom:'300170' printFormat:'%2d%2m%2(y1950)' onError:'fail'  - gives 1970 as year   
   621      Date readFrom:'300170' printFormat:'%2d%2m%2(y1950)' onError:'fail'  - gives 1970 as year   
   616      Date readFrom:'300170' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 2070 as year   
   622      Date readFrom:'300170' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 2070 as year   
   617      Date readFrom:'300181' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 1981 as year   
   623      Date readFrom:'300181' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 1981 as year   
   618 
   624 
   619      Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail'          
   625      Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail'          
   638          2   month position (1..3)
   644          2   month position (1..3)
   639          3   year position (1..3)
   645          3   year position (1..3)
   640      or a formatString (see printing instance protocol).
   646      or a formatString (see printing instance protocol).
   641      All of the %-formats as in the printString are supported here.
   647      All of the %-formats as in the printString are supported here.
   642      (i.e. %d, %m and %y, %shortMonthName and %monthName)
   648      (i.e. %d, %m and %y, %shortMonthName and %monthName)
   643      In addition, %y1900, %y2000, %y1950 and %y1980 are supported:
   649      In addition, %Y, %y1900, %y2000, %y1950 and %y1980 are supported:
   644      y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
   650      y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
   645      y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. 
   651      y1950, y1980 and Y are special; if the year is below 50/80/70, it is converted to 20YY, otherwise to 19YY. 
   646      TODO: make this a general feature of all DateAndTime classes.
   652      TODO: make this a general feature of all DateAndTime classes.
   647     "
   653     "
   648 
   654 
   649     ^ self
   655     ^ self
   650         readFrom:aStringOrStream 
   656         readFrom:aStringOrStream 
  1987     ((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[
  1993     ((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[
  1988         "/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding
  1994         "/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding
  1989         dayName := string.
  1995         dayName := string.
  1990         ^ nil.
  1996         ^ nil.
  1991     ].
  1997     ].
  1992     (format sameAs:'d') ifTrue:[
  1998     ((format sameAs:'d') or:[format sameAs:'day']) ifTrue:[
  1993         day := Integer readFrom:string.
  1999         day := Integer readFrom:string.
  1994         ^ #day -> day
  2000         ^ #day -> day
  1995     ].
  2001     ].
  1996 
  2002 
  1997     (format sameAs:'m') ifTrue:[
  2003     ((format sameAs:'m') or:[format sameAs:'month']) ifTrue:[
  1998         month := Integer readFrom:string.      
  2004         month := Integer readFrom:string.      
  1999         ^ #month -> month
  2005         ^ #month -> month
  2000     ].
  2006     ].
  2001     (format sameAs:'monthName') ifTrue:[
  2007     (format sameAs:'monthName') ifTrue:[
  2002         monthName := string.
  2008         monthName := string.
  2041             ^ #year -> (year + 1900)
  2047             ^ #year -> (year + 1900)
  2042         ].
  2048         ].
  2043         ^ #year -> year
  2049         ^ #year -> year
  2044     ].
  2050     ].
  2045 
  2051 
  2046     (format sameAs: 'y') ifTrue:[
  2052     (format = 'Y') ifTrue:[
       
  2053         "shift YY into 1970..2069; for 2k support of old date strings" 
       
  2054         year := Integer readFrom:string.
       
  2055         year < 100 ifTrue:[
       
  2056             year < 70 ifTrue:[
       
  2057                 ^ #year -> (year + 2000)
       
  2058             ].
       
  2059             ^ #year -> (year + 1900)
       
  2060         ].
       
  2061         ^ #year -> year
       
  2062     ].
       
  2063     
       
  2064     ((format = 'y') or:[format sameAs:'year']) ifTrue:[
  2047         year := Integer readFrom:string.
  2065         year := Integer readFrom:string.
  2048         year < 100 ifTrue:[
  2066         year < 100 ifTrue:[
  2049             ^ #year -> (year + 2000)
  2067             ^ #year -> (year + 2000)
  2050         ].
  2068         ].
  2051         ^ #year -> year
  2069         ^ #year -> year
  3708 ! !
  3726 ! !
  3709 
  3727 
  3710 !Date class methodsFor:'documentation'!
  3728 !Date class methodsFor:'documentation'!
  3711 
  3729 
  3712 version
  3730 version
  3713     ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.172 2015-06-06 10:26:43 cg Exp $'
  3731     ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.173 2015-06-06 10:50:46 cg Exp $'
  3714 !
  3732 !
  3715 
  3733 
  3716 version_CVS
  3734 version_CVS
  3717     ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.172 2015-06-06 10:26:43 cg Exp $'
  3735     ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.173 2015-06-06 10:50:46 cg Exp $'
  3718 ! !
  3736 ! !
  3719 
  3737 
  3720 
  3738 
  3721 Date initialize!
  3739 Date initialize!