Date.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Oct 2003 18:09:39 +0200
changeset 7648 61b7826a9a0e
parent 7646 94ae479eedbb
child 7649 1e907123a5c2
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    13
"{ Package: 'stx:libbasic' }"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    14
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    15
Magnitude subclass:#Date
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    16
	instanceVariableNames:'dateEncoding'
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    17
	classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs EnvironmentChange'
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    18
	poolDictionaries:''
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    19
	category:'Magnitude-General'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    22
!Date class methodsFor:'documentation'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    38
documentation
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    39
"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    40
    Instances of Date represent dates as year, month and day encoded in the 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
    (private & hidden) instance dateEncoding. The value found there is 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    year*100*100 + month*100 + day (which makes magnitude-like comparison of 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    dates easy, but is not guaranteed for future versions).
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    44
    Do not depend on the internal representation.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    45
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    46
    The old representation used days since 1st Jan. 1901 internally - 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
    with the new implementation, it is possible to reasonably represent almost 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    48
    any Date.  (which insurance companies will like, since they can now 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    49
    represent even very old peoples birthday :-)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    50
    Notice: no correction for pre-Julian dates is done.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    51
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
    The printed representation of dates is controlled by resource definitions -
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    thus national variants are already supported (see file 'resources/Date.rs').
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
    Compatibility notice:
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    56
        due to some historic reasons, there are some methods found twice
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    57
        with different names in this class. The old ST/X methods will vanish in
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    58
        one of the next releases, and kept for a while to support existing
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    59
        applications (the info on how these methods should be named came 
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    60
        somewhat late from the testers ..).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    61
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    62
        Please do not use methods marked as obsolete in their comment.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    63
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    64
    Most useful methods:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    65
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    66
        Date today
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    67
        (Date today) addDays:
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    68
        (Date today) subtractDays:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    69
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    70
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    71
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    72
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    73
    [see also:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    74
        Time AbstractTime
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    75
        Filename
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    76
        OperatingSystem
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    77
"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    78
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    79
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    80
!Date class methodsFor:'instance creation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    81
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    82
fromDays:dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    83
    "return a new Date, given the day-number starting with 0 at 1.Jan 1901;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    84
     (i.e. 'Date fromDays:0' returns 1st Jan. 1901).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    85
     Date asDays is the reverse operation.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
    86
     Added for GNU/ST-80 compatibility"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    87
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    88
    |yr rest d|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    89
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    90
    "approx. year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    91
    yr := (dayCount // 366) + 1901.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    92
    rest := dayCount - (self yearAsDays:yr) + 1. "+1 for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    93
    d := self daysInYear:yr.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    94
    (rest > d) ifTrue:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
    95
        "adjust"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
    96
        yr := yr + 1.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
    97
        rest := rest - d.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    98
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
    99
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   100
    ^ self newDay:rest year:yr
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   101
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   102
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   103
     Date fromDays:0     -> 1 jan 1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   104
     Date fromDays:365   -> 1 jan 1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   105
     Date fromDays:730   -> 1 jan 1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   106
     Date fromDays:1095  -> 1 jan 1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   107
     Date fromDays:1460  ->31 dec 1904 since 1904 was a leap year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   108
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   109
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   110
    "Modified: 1.7.1996 / 14:24:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   111
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   112
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   113
newDay:day month:month year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   114
    "return a new Date, given the day, month and year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   115
     For your convenience, month may be either an integer 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   116
     or the months name as a string. 
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   117
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   118
     WARNING: semantics changed: 0..99 is no longer treated as 1900..1999,
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   119
              but as 0..99 now.
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   120
              Any such adjustments must be made by the caller of this method now
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   121
              (see those, for example readFrom:onError:)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   122
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   123
    |monthIndex ok|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   124
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   125
    year < 100 ifTrue:[
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   126
        'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   127
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   128
    month isInteger ifTrue:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   129
        monthIndex := month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   130
    ] ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   131
        monthIndex := self indexOfMonth:month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   132
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   133
    (monthIndex == 2 and:[day == 29]) ifTrue:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   134
        ok := self leapYear:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   135
    ] ifFalse:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   136
        ok := day <= (self daysInMonth:month forYear:year)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   137
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   138
    ((day > 0) and:[ok]) ifTrue:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   139
        ^ self basicNew dateEncoding:(((year * 100) + monthIndex) * 100) + day
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   140
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   141
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   142
    "this error is triggered if you try to create a date from an
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   143
     invalid year/month/day combination;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   144
     Such as 29-feb-year, where year is no leap year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   145
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   146
    self error:'invalid date'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   147
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   148
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   149
     Date newDay:8  month:'may' year:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   150
     Date newDay:8  month:5     year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   151
     Date newDay:29 month:'feb' year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   152
     Date newDay:29 month:'feb' year:1993
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   153
     Date newDay:28 month:'feb' year:5   
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   154
     Date newDay:28 month:'feb' year:95  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   155
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   156
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   157
    "Modified: 19.4.1996 / 15:28:15 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   158
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   159
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   160
newDay:dayInYear year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   161
    "return a new Date, given the year and the day-in-year (starting at 1).
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   162
     See also: Date today / Time now / AbsoluteTime now.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   163
     ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   164
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   165
    |monthAndDay|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   166
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   167
    (dayInYear between:1 and:365) ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   168
        ((dayInYear == 366) and:[self leapYear:year]) ifFalse:[
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   169
            "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   170
             this error is triggered, when you try to create a
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   171
             day from an invalid day-in-year; 
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   172
             for example, 366 in a non-leap year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   173
             I dont know, if ST-80 wraps to the next year(s) in this case.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   174
            "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   175
            ^ self error:'invalid date'
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   176
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   177
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   178
    monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   179
    ^ self newDay:(monthAndDay at:2) month:(monthAndDay at:1) year:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   180
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   181
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   182
     Date newDay:150 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   183
     Date newDay:1 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   184
     Date newDay:1 year:1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   185
     Date newDay:1 year:1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   186
     Date newDay:365 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   187
     Date newDay:366 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   188
     Date newDay:365 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   189
     Date newDay:366 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   190
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   191
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   192
    "Modified: 1.7.1996 / 14:22:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   193
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   194
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   195
readFrom:aStringOrStream onError:exceptionBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   196
    "return a new Date, reading a printed representation from aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   197
     Notice, that this is not the storeString format and 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   198
     is different from the format expected by readFrom:.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   199
     BUG:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   200
       This method assumes american format (i.e. month-day-year) instead
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   201
       of the german/french and other day-month-year.
4998
010c3ab0cdc6 Comments
Stefan Vogel <sv@exept.de>
parents: 4997
diff changeset
   202
       There ought to be a internationalized variant of this."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   203
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   204
    ^ [
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   205
        |str month day year|
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   206
        str := aStringOrStream readStream.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   207
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   208
        [str peek isLetterOrDigit] whileFalse:[str next].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   209
        (str peek isDigit) ifTrue:[
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   210
            day := Integer readFrom:str
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   211
        ].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   212
        [str peek isLetterOrDigit] whileFalse:[str next].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   213
        (str peek isLetter) ifTrue:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   214
            month := str nextAlphaNumericWord.
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   215
            day isNil ifTrue:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   216
                [str peek isLetterOrDigit] whileFalse:[str next].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   217
                day := Integer readFrom:str.
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   218
            ]
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   219
        ] ifFalse:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   220
            month := self nameOfMonth:day.
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   221
            day := Integer readFrom:str
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   222
        ].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   223
        [str peek isLetterOrDigit] whileFalse:[str next].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   224
        year := Integer readFrom:str.
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   225
        (year between:0 and:99) ifTrue:[
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   226
            year := UserPreferences current twoDigitDateHandler value:year.
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   227
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   228
        self newDay:day month:month year:year
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   229
    ] on:Error do:exceptionBlock.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   230
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   231
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   232
     Date readFromString:'31 December 1992'  
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   233
     Date readFrom:'19:11:1999'  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   234
     Date readFromString:'December, 5 1992'  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   235
     Date readFromString:'12/31/1992'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   236
     Date readFromString:'3-jan-95'           
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   237
     Date readFromString:'3-jan-01'           
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   238
     Date readFromString:'12/31/01'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   239
     Date readFromString:'15.4.1992'         -> german; leads to an error
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   240
     Date readFromString:'10.4.1992'         -> german; leads to a wrong date
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   241
     Date readFromString:'10.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   242
     Date readFromString:'32.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   243
     Date readFromString:'fooBar' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   244
     Date readFromString:'10.4' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   245
     Date readFromString:'10041999' onError:['wrong date']  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   246
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   247
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   248
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   249
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   250
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   251
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   252
readFrom:aStringOrStream printFormat:aFormatArray
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   253
    "return a new Date, reading a printed representation from aStream.
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   254
     1   day position (1, 2 or 3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   255
     2   month position (1..3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   256
     3   year position (1..3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   257
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   258
    ^ self readFrom:aStringOrStream
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   259
        printFormat:aFormatArray 
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   260
            onError:[self error:'expected: ' , self name]
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   261
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   262
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   263
     Date readFrom:'19:11:1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   264
     Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   265
     Date readFrom:'19:11:1999' printFormat:#( 2 1 3 )  -> exception: wrong month
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   266
     Date readFrom:'5:12:1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   267
     Date readFrom:'may-12-1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   268
     Date readFrom:'1999 may 12' printFormat:#( 3 2 1 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   269
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   270
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   271
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   272
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   273
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   274
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   275
readFrom:aStringOrStream printFormat:aFormatArray onError:exceptionBlock
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   276
    "return a new Date, reading a printed representation from aStream.
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   277
     1   day position (1, 2 or 3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   278
     2   month position (1..3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   279
     3   year position (1..3)
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   280
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   281
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   282
    ^ [
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   283
        |str arg year|
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   284
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   285
        str := aStringOrStream readStream.
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   286
        arg := Array new:3.
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   287
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   288
        1 to:3 do:[:i||v|
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   289
            [str peek isLetterOrDigit] whileFalse:[str next].
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   290
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   291
            v := (str peek isDigit) ifTrue:[Integer readFrom:str]
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   292
                                   ifFalse:[str nextAlphaNumericWord].
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   293
            arg at:i put:v
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   294
        ].
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   295
        year := (arg at:(aFormatArray at:3)).
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   296
        (year between:0 and:99) ifTrue:[
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   297
            year := UserPreferences current twoDigitDateHandler value:year.
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   298
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   299
        self newDay:(arg at:(aFormatArray at:1))
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   300
              month:(arg at:(aFormatArray at:2))
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   301
               year:year
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   302
    ] on:Error do:exceptionBlock.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   303
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   304
    "
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   305
     Date readFrom:'31 December 1992' printFormat:#(1 2 3) onError:'fail' 
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   306
     Date readFrom:'19:11:1999' printFormat:#(1 2 3) onError:'fail'  
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   307
     Date readFrom:'December, 5 1992' printFormat:#(1 2 3) onError:'fail' 
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   308
     Date readFrom:'3-jan-95' printFormat:#(1 2 3) onError:'fail'          
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   309
     Date readFrom:'12/31/1992' printFormat:#(1 2 3) onError:'fail'       
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   310
     Date readFrom:'15.4.1992' printFormat:#(1 2 3) onError:'wrong date'  -> german
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   311
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:'fail'        -> german
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   312
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   313
     Date readFrom:'32.4.1992' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   314
     Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   315
     Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   316
     Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date']  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   317
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   318
     Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail'       
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   319
     Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail'       
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   320
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   321
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   322
    "Created: 16.11.1995 / 22:50:17 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   323
    "Modified: 8.10.1996 / 19:25:39 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   324
!
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   325
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   326
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   327
    "return a new Date, reading a printed representation from aStream.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   328
     Notice, that this is not the storeString format and 
4998
010c3ab0cdc6 Comments
Stefan Vogel <sv@exept.de>
parents: 4997
diff changeset
   329
     is different from the format expected by readFrom:"
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   330
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   331
    ^ [
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   332
        |str month day year|
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   333
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   334
        str := aStringOrStream readStream.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   335
        month := str next:2.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   336
        month := Integer readFrom:month.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   337
        day := str next:2.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   338
        day := Integer readFrom:day.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   339
        year := str next:4.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   340
        year := Integer readFrom:year.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   341
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   342
        self newDay:day month:month year:year
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   343
    ] on:Error do:exceptionBlock
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   344
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   345
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   346
     Date readMMDDYYYYFrom:'10041999' onError:['wrong date']  
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   347
     Date readMMDDYYYYFrom:'100419' onError:['wrong date']  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   348
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   349
     Date readMMDDYYYYFrom:'10040001' onError:['wrong date']  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   350
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   352
    "Created: 16.11.1995 / 22:50:17 / cg"
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   353
    "Modified: 8.10.1996 / 19:25:39 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   354
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   355
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   356
today
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   357
    "return a date, representing today.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   358
     See also: Time now / AbsoluteTime now."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   360
    ^ self fromOSTime:(OperatingSystem getOSTime)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   361
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
     Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   365
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   366
    "Modified: 1.7.1996 / 15:20:16 / cg"
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   367
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   368
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   369
tomorrow
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   370
    "return a date, representing tomorrow.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   371
     See also: Time now / AbsoluteTime now."
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   372
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   373
    ^ Date today addDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   374
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   375
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   376
     Date tomorrow 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   377
     Date tomorrow dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   378
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   379
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   380
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   381
yesterday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   382
    "return a date, representing yesterday.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   383
     See also: Time now / AbsoluteTime now."
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   384
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   385
    ^ Date today subtractDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   386
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   387
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   388
     Date yesterday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   389
     Date yesterday dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   390
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   391
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   392
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   393
!Date class methodsFor:'Compatibility-Dolphin'!
6872
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   394
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   395
newDay:day monthIndex:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   396
    ^ self newDay:day month:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   397
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   398
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   399
     Date newDay:8 monthIndex:5 year:1993
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   400
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   401
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   402
    "Modified: 19.4.1996 / 15:28:15 / cg"
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   403
! !
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   404
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   405
!Date class methodsFor:'Compatibility-ST80'!
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   406
7648
61b7826a9a0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7646
diff changeset
   407
newDay:day monthNumber:monthIndex year:year
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   408
    "ST80 compatibility"
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   409
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   410
    ^ self newDay:day month:monthIndex year:year
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   411
! !
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   412
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   413
!Date class methodsFor:'Compatibility-Squeak'!
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   414
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   415
fromSeconds:seconds
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   416
    "Answer an instance of me which is 'seconds' seconds after January 1, 1901."
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   417
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   418
    | secondsInDay |
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   419
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   420
    secondsInDay := 24 * 60 * 60.
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   421
    ^self fromDays: seconds // secondsInDay
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   422
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   423
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   424
     Date fromSeconds:0
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   425
     Date fromSeconds:(24 * 60 * 60 * 365)
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   426
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   427
! !
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   428
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   429
!Date class methodsFor:'general queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   430
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   431
abbreviatedNameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   432
    "given a day index (1..7), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   433
     of the day"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   434
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   435
    (DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   436
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   437
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   438
    ^ DayAbbrevs at:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   439
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   440
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   441
     Date abbreviatedNameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   442
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   443
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   444
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   445
abbreviatedNameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
    "given a month index (1..12), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
     of the month"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   449
    (MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   450
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   451
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   452
    ^ MonthAbbrevs at:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   453
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   454
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   455
     Date abbreviatedNameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   456
     Date abbreviatedNameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   457
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   458
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   459
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   460
dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   461
    "return an array containing the date and time of now"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   462
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   463
    ^ Time dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   464
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   465
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   466
     Date dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   467
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   468
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   469
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   470
dayOfFirstWeekInYear:aYear
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   471
    "for a given year, return the day corresponding to that years monday of week-01.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   472
     The 1st week is the one, in which the first thursday is found;
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   473
     and the 1st day of that week is the preceeding monday 
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   474
     (that means: that the returned day might be a day of the previous year)"
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   475
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   476
    |day dayInWeekOf1stJan firstThursday firstDayInWeek|
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   477
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   478
    "/ find the first thursday ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   479
    day := AbsoluteTime newDay:1 year:aYear.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   480
    dayInWeekOf1stJan := day dayInWeek.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   481
    dayInWeekOf1stJan > 4 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   482
        firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   483
    ] ifFalse:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   484
        firstThursday := day addDays:(4 - dayInWeekOf1stJan).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   485
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   486
    "/ back to the preceeding monday
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   487
    firstDayInWeek := firstThursday subtractDays:3.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   488
    ^ firstDayInWeek
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   489
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   490
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   491
     Date dayOfFirstWeekInYear:1998   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   492
     Date dayOfFirstWeekInYear:1999    
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   493
     Date dayOfFirstWeekInYear:2000  
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   494
     Date dayOfFirstWeekInYear:2001   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   495
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   496
!
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   497
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   498
dayOfWeek:dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   499
    "given the name of a day (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   500
     return the day-index (1 for monday; 7 for sunday).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   501
     Return 0 for invalid day name"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   502
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   503
    |idx|
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   504
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   505
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   506
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   507
    ].
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   508
    idx := DayNames indexOf:dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   509
    idx == 0 ifTrue:[
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   510
        idx := DayNames indexOf:dayName asLowercase.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   511
    ].
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   512
    ^ idx
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   513
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   514
    "
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   515
     Date dayOfWeek:'wednesday' 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   516
     Date dayOfWeek:'Wednesday' 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   517
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   518
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   519
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   520
daysInMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   521
    "given the name of a month and a year, return the number 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   522
     of days this month has (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   523
     return 0 if the month name was invalid.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   524
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   525
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   526
    |monthIndex "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   527
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   528
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   529
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   530
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   531
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   532
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   533
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   534
    ^ self daysInMonthIndex:monthIndex forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   535
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   536
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   537
     Date daysInMonth:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
     Date daysInMonth:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   539
     Date daysInMonth:'feb' forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   540
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   541
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   542
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   543
daysInYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   544
    "return the number of days in a year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   545
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   546
    (self leapYear:yearInteger) ifTrue:[^ 366].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   547
    ^ 365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   548
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   549
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   550
     Date daysInYear:1900  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   551
     Date daysInYear:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   552
     Date daysInYear:1904 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   553
     Date daysInYear:1980 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   554
     Date daysInYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   555
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   556
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   557
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   558
daysUntilMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   559
    "given the name of a month and a year, return the number 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   560
     of days from 1st january to last of prev month of that year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   561
     Return 0 if the month name/index is invalid or is january.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   562
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   563
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   564
    |monthIndex "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   565
     sumDays    "{ Class: SmallInteger }" |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   566
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   567
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   568
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   569
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   570
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   571
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   572
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   573
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   574
    sumDays := 0.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   575
    1 to:monthIndex-1 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   576
	sumDays := sumDays + (self daysInMonthIndex:m forYear:yearInteger)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   577
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   578
    ^ sumDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   579
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   580
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   581
     Date daysUntilMonth:'feb' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   582
     Date daysUntilMonth:'jan' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   583
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   584
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   585
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   586
firstDayOfYear:inYear
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   587
    "return the weekDay-index of the 1st-january of the given year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   588
     1->monday, 2->tuesday, ... 7->sunday"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   589
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   590
    | t d |
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   591
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   592
    ((inYear < 1) or:[ inYear > 9999]) ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   593
        ^ 0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   594
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   595
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   596
    "/ normal Gregorian calendar: one extra day per four years 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   597
    t := 4 + inYear + ((inYear + 3) // 4).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   598
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   599
    inYear > 1800 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   600
        "/ Julian calendar: regular Gregorian less 3 days per 400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   601
        t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   602
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   603
    inYear > 1752 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   604
        "/ calendar changeover
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   605
        t := t + 3.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   606
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   607
    d := t \\ 7.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   608
    "/ convert from 0 (sunday) .. 6 (saturday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   609
    "/ to 1 (munday) .. 7 (sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   610
    d == 0 ifTrue:[^ 7].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   611
    ^ d
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   612
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   613
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   614
     self firstDayOfYear:2000           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   615
     (Date newDay:1 year:2000) dayInWeek 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   616
     self firstDayOfYear:1999      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   617
     (Date newDay:1 year:1999) dayInWeek
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   618
     self firstDayOfYear:1998      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   619
     (Date newDay:1 year:1998) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   620
     self firstDayOfYear:2001           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   621
     (Date newDay:1 year:2001) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   622
     self firstDayOfYear:2002           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   623
     (Date newDay:1 year:2002) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   624
     self firstDayOfYear:2006           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   625
     (Date newDay:1 year:2006) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   626
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   627
     self firstDayOfYear:1800           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   628
     (Date newDay:1 year:1800) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   629
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   630
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   631
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   632
indexOfMonth:aMonthString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   633
    "given the name of a month (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   634
     return the month-index (1 for jan; 12 for december).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   635
     The given string may be a full or abbreviated name,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   636
     case is ignored.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   637
     Return 0 for invalid month name."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   638
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   639
    |idx name|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   640
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   641
    EnvironmentChange ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   642
	self initNames
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   643
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   644
    name := aMonthString asLowercase.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   645
    idx := MonthAbbrevs indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   646
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   647
    idx := MonthNames indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   649
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   650
    name at:1 put:(name at:1) asUppercase.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   651
    idx := MonthAbbrevs indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   652
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   653
    idx := MonthNames indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   654
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   655
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   656
    ^ idx
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   657
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   659
     Date indexOfMonth:'jan'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   660
     Date indexOfMonth:'Jan'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   661
     Date indexOfMonth:'December'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   662
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   663
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   664
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   665
isLeapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   666
    "Return true, if a year is a leap year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   667
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   668
	 Please use the ST-80 compatible #leapYear for new programs, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   669
	 since this method will vanish."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   670
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   671
    ^ self leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   672
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   673
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   674
leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   675
    "return true, if yearInteger is a leap year."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   676
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   677
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   678
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   679
    y := yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   680
    (y \\ 4 == 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   681
	(y \\ 100 ~~ 0) ifTrue:[^ true].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   682
	(y \\ 400 == 0) ifTrue:[^ true]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   683
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   684
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   685
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   686
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   687
     Date leapYear:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   688
     Date leapYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   689
     Date leapYear:1900
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   690
     Date leapYear:2000
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   691
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   692
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   693
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   694
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   695
    "given a day-in-year (1..365) return an Array containing the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   696
     month index and the day-in-month. Return nil if the argument is invalid."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   697
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   698
    |restDays daysInMonth|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   700
    restDays := aDayInYear.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   701
    restDays < 1 ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   702
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   703
    1 to:12 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   704
	daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   705
	restDays <= daysInMonth ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   706
	    ^ Array with:m with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   707
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   708
	restDays := restDays - daysInMonth 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   709
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   710
    restDays > daysInMonth ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   711
    ^ Array with:12 with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   712
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   713
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   714
     Date monthAndDayFromDayInYear:66 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   715
     Date monthAndDayFromDayInYear:66 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   716
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   717
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   718
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   719
nameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   720
    "given a day index (1..7), return the name of the day" 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   721
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   722
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   723
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   724
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   725
    ^ DayNames at:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   726
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   727
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   728
     Date nameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   729
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   730
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   731
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   732
nameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   733
    "given a month index (1..12), return the name of the month"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   734
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   735
    (MonthNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   736
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   737
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   738
    ^ MonthNames at:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   739
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   740
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   741
     Date nameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   742
     Date nameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   743
     Date nameOfMonth:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   744
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   745
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   746
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   747
weekInYearOf:aDateOrTimestamp
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   748
    "for a given date or timeStamp, return the week-number.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   749
     the returned week number starts with 1 for the first week which has a thursday in it.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   750
     The above definition can lead to the 1st week starting in the old year!!"
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   751
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   752
    |dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   753
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   754
    dayInYear := aDateOrTimestamp dayInYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   755
    dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   756
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   757
    numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   758
    "/ careful with the first days - could be W52/W53 of the previous year ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   759
    numDays < 0 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   760
        "/ not in a week here ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   761
        "/ can be either 52 or 53, depending on the previous year.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   762
        ^ self weekInYearOf:(Date day:31 month:12 year:aDateOrTimestamp year - 1)
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   763
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   764
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   765
    "/ compute the week 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   766
    week := numDays // 7 + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   767
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   768
    "/ careful with the last days - could be W01 of the next year ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   769
    week == 53 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   770
        dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   771
        aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   772
            ^ 1
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   773
        ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   774
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   775
    ^ week
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   776
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   777
    "
5663
32a8acdf3e3b fixed weekInYearOf:
Claus Gittinger <cg@exept.de>
parents: 5662
diff changeset
   778
     AbsoluteTime now weekInYear    
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   779
     Date weekInYearOf:(Date day:31 month:12 year:1999)     was a friday; 
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   780
     Date weekInYearOf:(AbsoluteTime newDay:1 year:2000)    was a saturday; therefore last week of 1999
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   781
     Date weekInYearOf:(AbsoluteTime newDay:2 year:2000)    was a sunday; therefore last week of 1999
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   782
     Date weekInYearOf:(AbsoluteTime newDay:3 year:2000)    was a monday -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   783
     Date weekInYearOf:(AbsoluteTime newDay:4 year:2000)    was a tuesday -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   784
     Date weekInYearOf:(AbsoluteTime newDay:5 year:2000)    was a wed    -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   785
     Date weekInYearOf:(AbsoluteTime newDay:6 year:2000)    was a thursday -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   786
     Date weekInYearOf:(AbsoluteTime newDay:7 year:2000)    was a fri    -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   787
     Date weekInYearOf:(AbsoluteTime newDay:8 year:2000)    was a sat   -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   788
     Date weekInYearOf:(AbsoluteTime newDay:9 year:2000)    was a sun   -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   789
     Date weekInYearOf:(AbsoluteTime newDay:10 year:2000)   was a monday -> W02
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   790
     Date weekInYearOf:(AbsoluteTime newDay:16 year:2000)   was a sunday -> W02
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   791
     Date weekInYearOf:(AbsoluteTime newDay:17 year:2000)   was a monday -> W03
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   792
     Date weekInYearOf:(Date day:1 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   793
     Date weekInYearOf:(Date day:2 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   794
     Date weekInYearOf:(Date day:3 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   795
     Date weekInYearOf:(Date day:24 month:12 year:2001)   -> W52
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   796
     Date weekInYearOf:(Date day:30 month:12 year:2001)   -> W52
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   797
     Date weekInYearOf:(Date day:31 month:12 year:2001)   -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   798
     Date weekInYearOf:(Date day:1 month:1 year:2002)    
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   799
     Date weekInYearOf:(Date day:2 month:1 year:2002)      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   800
     Date weekInYearOf:(Date day:7 month:1 year:2002)      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   801
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   802
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   803
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   804
yearAsDays: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   805
    "Returns the number of days since Jan 1, 1901. (GNU)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   806
     to the first Jan of the year, yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   807
     For 1901 this is zero, for 1902 its 365.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   808
     Defined for years >= 1901"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   809
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   810
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   811
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   812
    y := yearInteger - 1900.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   813
    y := y - 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   814
    ^ (y * 365)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   815
	+ (y // 4)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   816
	- (y // 100)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   817
	+ ((y + 300) // 400)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   818
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   819
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   820
     Date yearAsDays:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   821
     Date yearAsDays:1902   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   822
     Date yearAsDays:1903   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   823
     Date yearAsDays:1904    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   824
     Date yearAsDays:1905     
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   825
     Date yearAsDays:1994   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   826
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   827
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   828
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   829
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   830
!Date class methodsFor:'handling language changes'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   831
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   832
initialize
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   833
    "check for case where Resource-classes are absent"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   834
    ResourcePack isNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   835
	self initNames
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   836
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   837
	Smalltalk addDependent:self.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   838
	EnvironmentChange := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   839
    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   840
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   841
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   842
update:something with:aParameter from:changedObject
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   843
    ((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   844
        "just remember change for next access"
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   845
        EnvironmentChange := true
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   846
    ]
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   847
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   848
    "Created: 15.6.1996 / 15:19:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   849
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   850
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   851
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   852
!Date class methodsFor:'obsolete instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   853
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   854
day:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   855
    "return a new Date, given the day, month and year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   856
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   857
	use newDay:month:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   858
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   859
    ^ self newDay:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   860
!
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   861
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   862
day:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   863
    "return a new Date, given the year and the day-in-year (starting at 1).
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   864
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   865
	use newDay:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   866
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   867
    ^ self newDay:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   868
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   869
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   870
!Date class methodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   871
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   872
daysInMonthIndex: monthIndex forYear: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   873
    "return the number of days in month monthIndex of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   874
     year yearInteger (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   875
     Return 0 for invalid month index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   876
     This is the internal version of daysInMonth:forYear:"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   877
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   878
    |days|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   879
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   880
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   881
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   882
    days := #(31 28 31           "Jan Feb Mar"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   883
	      30 31 30           "Apr May Jun"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   884
	      31 31 30           "Jul Aug Sep"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   885
	      31 30 31           "Oct Nov Dec"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   886
	     ) at: monthIndex.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   887
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   888
    (monthIndex == 2) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   889
	(self leapYear:yearInteger) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   890
	    ^ days + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   891
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   892
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   893
    ^ days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   894
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   895
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   896
     Date daysInMonthIndex:2 forYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   897
     Date daysInMonthIndex:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   898
     Date daysInMonthIndex:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   899
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   900
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   901
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   902
initNames
a27a279701f8 Initial revision
claus
parents:
diff changeset
   903
    "read the language specific names"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   904
10
claus
parents: 5
diff changeset
   905
    |resources|
claus
parents: 5
diff changeset
   906
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   907
    DayNames := #('monday'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   908
		  'tuesday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   909
		  'wednesday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   910
		  'thursday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   911
		  'friday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   912
		  'saturday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   913
		  'sunday').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   914
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   915
    DayAbbrevs := #('mon' 
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   916
		    'tue' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   917
		    'wed'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   918
		    'thu' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   919
		    'fri' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   920
		    'sat' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   921
		    'sun').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   922
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   923
    MonthNames := #('january'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   924
		    'february'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   925
		    'march'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   926
		    'april'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   927
		    'may'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   928
		    'june'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   929
		    'july'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   930
		    'august'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   931
		    'september'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   932
		    'october'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   933
		    'november'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   934
		    'december').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   935
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   936
    MonthAbbrevs := #('jan'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   937
		      'feb'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   938
		      'mar'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   939
		      'apr'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   940
		      'may'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   941
		      'jun'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   942
		      'jul'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   943
		      'aug'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   944
		      'sep'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   945
		      'oct'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   946
		      'nov'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   947
		      'dec').
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   948
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   949
    "check for case where Resource-classes are absent"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   950
    ResourcePack notNil ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   951
	resources := ResourcePack for:self.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   952
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   953
	DayNames := resources array:DayNames.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   954
	DayAbbrevs := resources array:DayAbbrevs.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   955
	MonthNames := resources array:MonthNames.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   956
	MonthAbbrevs := resources array:MonthAbbrevs.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   957
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   958
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
   959
    EnvironmentChange := false
10
claus
parents: 5
diff changeset
   960
claus
parents: 5
diff changeset
   961
    "Date initNames"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   962
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   963
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
   964
!Date class methodsFor:'private-encoding'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   965
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   966
encodeYear:y month:m day:d
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   967
    "the internal encoding is stricktly private, 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   968
     and should not be used outside."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   969
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   970
    ^ (((y * 100) + m) * 100) + d
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   971
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   972
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
   973
!Date class methodsFor:'private-instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   974
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   975
fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   976
    "return a date, representing the date given by the operatingSystem time.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   977
     This somewhat clumsy implementation hides the OS's date representation
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   978
     (i.e. makes this class independent of what the OS starts its time values with).
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   979
     Dont use this method, the osTime representation is totally unportable."
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   980
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   981
    ^ self basicNew fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   982
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   983
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   984
     Date fromOSTime:#(0 0)      -> on UNIX: this should return 1st Jan 1970
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   985
				    thats where Unix time starts
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   986
				    On other systems, it may be something different.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   987
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   988
     Date fromOSTime:#(86400 0)  -> on UNIX: the day after
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   989
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   990
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   991
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   992
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   993
!Date methodsFor:'Compatibility-ANSI'!
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   994
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   995
dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   996
    "return the week-day of the receiver - 1 is sunday, 7 for saturday.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   997
     WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday).  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   998
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   999
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1000
    |d|
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1001
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1002
    d := self dayInWeek.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1003
    d == 7 ifTrue:[
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1004
        ^ 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1005
    ].
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1006
    ^ d + 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1007
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1008
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1009
     Date today dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1010
     Date today dayInWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1011
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1012
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1013
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1014
dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1015
    "return the short week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1016
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1017
     Expect things like 'mon', 'tue' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1018
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1019
    ^ self abbreviatedDayName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1020
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1021
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1022
     Date today dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1023
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1024
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1025
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1026
dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1027
    "return the week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1028
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1029
     Expect things like 'monday', 'tuesday' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1030
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1031
    ^ self weekday
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1032
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1033
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1034
     Date today dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1035
     Date today dayOfWeekAbbreviation 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1036
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1037
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1038
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1039
dayOfYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1040
    "return the day-nr within the year of the receiver - 1..365/366"
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1041
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1042
    ^ self dayInYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1043
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1044
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1045
     Date today dayOfYear 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1046
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1047
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1048
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1049
isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1050
    "return true, if the receivers year is a leap year"
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1051
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1052
    ^ self leap
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1053
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1054
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1055
     Date today isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1056
     (Date day:1 month:1 year:1992) isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1057
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1058
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1059
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1060
monthAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1061
    "return the month of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1062
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1063
     Expect things like 'jan', 'feb' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1064
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1065
    ^ self abbreviatedMonthName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1066
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1067
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1068
     Date today monthAbbreviation  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1069
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1070
! !
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1071
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1072
!Date methodsFor:'Compatibility-ST80'!
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1073
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1074
previous:dayName 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1075
    "Return the previous date whose weekday name is dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1076
     Caveat; dayName is expected to be in the current language"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1077
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1078
    ^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1)
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1079
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1080
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1081
     Date today                 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1082
     Date today previous:#Monday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1083
     Date today previous:#Friday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1084
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1085
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1086
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1087
printFormat:aFormatArray
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1088
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1089
     Return a string containing a printed representation of the receiver.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1090
     The formatArray argument consists of 6 or 7 integers which control
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1091
     the resulting string. The entries are:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1092
     1   day position (1, 2 or 3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1093
     2   month position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1094
     3   year position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1095
     4   asciiValue of separator character or separator character
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1096
         or collection of 2 separator characters
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1097
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1098
         4: abbreviated uppercase 5: full uppercase)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1099
     6   year format (1 include century; 2 exclude century)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1100
     7  (optional) true/false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1101
         if true, print numbers in 2-digit format
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1102
         (i.e. with leading zeros); 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1103
         Taken as false, if ommited
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1104
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1105
     Day and monthnames are in the currently active language.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1106
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1107
     This method supports more options than the ST-80 version; month formats 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1108
     4 and 5, non-numeric separators and the optional 7th parameter are not 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1109
     supported by ST-80. Be aware of this for compatibility reasons.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1110
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1111
     Notice that not all formats can be scanned (correctly) by #readFrom:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1112
     This is an ST-80 compatibility method - I would have choosen another
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1113
     (less cryptic) formatString ...
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1114
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1115
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1116
    |mf upperCase day month year components sep1 sep2 leadingZeros|
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1117
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1118
    aFormatArray size > 6 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1119
        leadingZeros := aFormatArray at:7
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1120
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1121
        leadingZeros := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1122
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1123
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1124
    components := Array new:3.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1125
    day := self day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1126
    leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1127
        day := day printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1128
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1129
        day := day printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1130
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1131
    components at:(aFormatArray at:1) put:day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1132
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1133
    upperCase := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1134
    mf := aFormatArray at:5.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1135
    (mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1136
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1137
    mf == 1 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1138
        month := self month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1139
        leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1140
            month := month printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1141
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1142
            month := month printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1143
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1144
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1145
        mf == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1146
            month := self abbreviatedMonthName
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1147
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1148
            month := self monthName
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1149
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1150
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1151
    upperCase ifTrue:[month := month asUppercase].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1152
    components at:(aFormatArray at:2) put:month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1153
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1154
    year := self year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1155
    (aFormatArray at:6) == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1156
        year := year \\ 100.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1157
        year := year printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1158
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1159
    year := year printString.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1160
    components at:(aFormatArray at:3) put:year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1161
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1162
    sep1 := sep2 := (aFormatArray at:4).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1163
    sep1 isString ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1164
        sep1 isCollection ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1165
            sep2 := (sep1 at:2).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1166
            sep1 := (sep1 at:1).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1167
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1168
            sep1 := sep2 := sep1 asCharacter
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1169
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1170
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1171
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1172
    ^ (components at:1)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1173
      , sep1 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1174
      , (components at:2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1175
      , sep2 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1176
      , (components at:3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1177
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1178
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1179
     Date today printFormat:#(1 2 3 '' 1 2)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1180
     Date today printFormat:#(1 2 3 $- 1 2)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1181
     Date today printFormat:#(1 2 3 $. 1 2 true)     
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1182
     Date today printFormat:#(2 1 3 32 3 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1183
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1184
     Date today printFormat:#(1 2 3 $- 2 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1185
     Date today printFormat:#(1 2 3 $- 4 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1186
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1187
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1188
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1189
printFormat:aFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1190
    "Obsolete, backward ST-80 compatible formatted printing - see comment
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1191
     in printFormat:.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1192
     Append a printed representation of the receiver to aStream.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1193
     The argument, aFormatString controls the format, as described
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1194
     in the #printFormat: method.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1195
     Notice that not all formats can be scanned (correctly) by #readFrom:"
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1196
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1197
    aStream nextPutAll:(self printFormat:aFormatArray)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1198
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1199
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1200
    "european formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1201
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1202
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1203
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1204
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1205
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1206
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1207
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1208
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1209
     US formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1210
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1211
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1212
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1213
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1214
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1215
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1216
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1217
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1218
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1219
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1220
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1221
shortPrintString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1222
    "dummy - for now"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1223
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1224
    ^ self printString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1225
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1226
    "Created: 20.6.1997 / 17:16:48 / cg"
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1227
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1228
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1229
weekdayIndex
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1230
    "Return the day index; Monday=1, ... , Sunday=7"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1231
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1232
    ^ (self asDays + 1) \\ 7 + 1  "1 January 1901 was a Tuesday"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1233
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1234
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1235
     Date today dayName
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1236
     Date today weekdayIndex      
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1237
    "
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1238
! !
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1239
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1240
!Date methodsFor:'Compatibility-Squeak'!
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1241
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1242
mmddyyyy
4462
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1243
    "return a printed representation of the receiver in the
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1244
     form mmddyyyy.
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1245
     The receiver can be reconstructed with: 
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1246
        Date readMMDDYYYYFrom:aStringOrStream onError:[...]"
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1247
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1248
    ^ (self month printStringLeftPaddedTo:2 with:$0)
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1249
       , (self day printStringLeftPaddedTo:2 with:$0) 
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1250
       , (self year printStringLeftPaddedTo:4 with:$0)
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1251
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1252
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1253
     Date today mmddyyyy
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1254
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1255
! !
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1256
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1257
!Date methodsFor:'accessing'!
241
6f30be88e314 *** empty log message ***
claus
parents: 202
diff changeset
  1258
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1259
abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1260
    "return the short week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1261
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1262
     Expect things like 'mon', 'tue' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1263
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1264
    ^ self class abbreviatedNameOfDay:(self dayInWeek)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1265
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1266
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1267
     Date today abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1268
     (Date day:15 month:4 year:1959) abbreviatedDayName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1269
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1270
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1271
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1272
abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1273
    "return the month of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1274
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1275
     Expect things like 'jan', 'feb' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1276
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1277
    ^ self class abbreviatedNameOfMonth:(self month)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1278
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1279
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1280
     Date today abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1281
     (Date day:15 month:4 year:1959) abbreviatedMonthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1282
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1283
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1284
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1285
asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1286
    "return the number of days elapsed since 01-Jan-1901
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1287
     and the receiver's day; starts with 0 for 1-1-1901.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1288
     Date>>fromDays: is the reverse operation.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1289
     For ST-80 compatibility."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1290
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1291
    |yr|
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1292
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1293
    yr := self year.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1294
    ^ (self class yearAsDays:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1295
      + (self class daysUntilMonth:self month forYear:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1296
      + self day
85
claus
parents: 77
diff changeset
  1297
      - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1298
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1299
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1300
     (Date day: 5 month: 8 year: 1962) asDays  -> should be 22496
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1301
     (Date day: 1 month: 1 year: 1901) asDays  -> 0
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1302
     Date today asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1303
     Date fromDays:(Date today asDays + 7)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1304
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1305
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1306
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1307
asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1308
    "return the seconds between 1.jan.1901 and the same time in the receivers 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1309
     day. (i.e. midnight to midnight).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1310
     This does not include any leapSeconds ... strictly speaking, this is incorrect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1311
     ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1312
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1313
    ^ 60*60*24 * self asDays
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1314
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1315
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1316
     (Date day: 5 month: 8 year: 1962) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1317
     (Date day: 1 month: 1 year: 1901) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1318
     (Date today addDays:7) asSeconds - Date today asSeconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1319
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1320
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1321
    "Modified: 1.7.1996 / 14:19:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1322
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1323
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1324
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1325
    "return the day (1..31) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1326
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1327
    ^ dateEncoding \\ 100
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1328
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1329
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1330
     Date today day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1331
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1332
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1333
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1334
dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
    "return the number of days since 1st. Jan. 1901;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1336
     starting with 0 for this date.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1337
     Date>>fromDays: is the reverse operation.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1338
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1339
	 please use asDays for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1340
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1341
    ^ self asDays.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1342
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1343
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1344
     (Date day:1 month:1 year:1901) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1345
     Date fromDays:(Date day:1 month:1 year:1994) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1346
     Date today dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1347
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1348
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1349
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1350
dayInWeek
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1351
    "return the week-day of the receiver - 1 for monday, 7 for sunday.
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1352
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1353
     WARNING: does not care for pre-julian dates 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1354
        (i.e. do not use this for dates before 1752)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1355
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1356
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1357
    |wday|
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1358
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1359
    wday := (1 "knowing, that 1st Jan 1901 was a tuesday"
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1360
            + self asDays) \\ 7 + 1.
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1361
    wday < 1 ifTrue:[
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1362
        wday := wday + 7
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1363
    ].
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1364
    ^ wday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1366
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1367
     Date today dayInWeek      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1368
     Date tomorrow dayInWeek 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1369
     Date yesterday dayInWeek 
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1370
     (Date today subtractDays:2) dayInWeek 
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1371
     Date today weekday 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1372
     Date tomorrow weekday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1373
     Date yesterday weekday 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1374
     (Date day:15 month:4 year:1959) dayInWeek 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1375
     (Date day:1 month:1 year:1901) dayInWeek 
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1376
     (Date day:31 month:12 year:1899) dayInWeek 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1377
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1378
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1379
    "Modified: / 1.2.1998 / 14:10:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1380
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1381
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1382
dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1383
    "return the day-nr within the year of the receiver - 1 .. 365/366"
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1384
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1385
    ^ self asAbsoluteTime dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1386
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1387
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1388
     Date today dayInYear 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1389
     (Date newDay:1 year:1999) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1390
     (Date newDay:1 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1391
     (Date newDay:2 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1392
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1393
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1394
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1395
dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1396
    "return the week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1397
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1398
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1399
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1400
	use #weekday for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1401
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1402
    ^ self weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1403
!
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1404
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1405
dayOfMonth
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1406
    "Answer the day of the month represented by me.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1407
     Same as day; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1408
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1409
    ^ self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1410
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1411
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1412
     Date today dayOfMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1413
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1414
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1415
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1416
daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1417
    "return the number of days in the month of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1418
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1419
    ^ Date daysInMonth:(self month) forYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1420
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1421
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1422
     Date today daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1423
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1424
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1425
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1426
daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1427
    "return the number of days in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1428
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1429
    ^ Date daysInYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1430
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1431
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1432
     Date today daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1433
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1434
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1435
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1436
daysLeftInMonth
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1437
    "return the number of days left in the month of the receiver"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1438
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1439
    ^ self daysInMonth - self day
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1440
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1441
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1442
     Date today daysLeftInMonth             
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1443
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1444
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1445
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1446
daysLeftInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1447
    "return the number of days left in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1448
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1449
    ^ (Date daysInYear:(self year)) - self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1450
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1451
    "
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1452
     Date today daysLeftInYear             
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1453
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1454
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1455
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1456
leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1457
    "return true, if the receivers year is a leap year"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1458
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1459
    ^ Date leapYear:(self year)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1460
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1461
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1462
     Date today leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1463
     (Date day:1 month:1 year:1992) leap
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1464
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1465
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1466
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1467
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1468
    "return the month (1..12) of the receiver"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1469
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1470
    ^ (dateEncoding // 100) \\ 100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1471
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1472
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1473
     Date today month
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1474
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1475
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1476
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1477
monthIndex
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1478
    "return the index of the month (e.g. Feb.=2).
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1479
     Same as month; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1480
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1481
    ^ self month  
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1482
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1483
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1484
monthName
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1485
    "return the month of the receiver as a string.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1486
     The returned string depends on the language setting.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1487
     Expect things like 'january', 'february' ..."
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1488
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1489
    ^ self class nameOfMonth:(self month)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1490
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1491
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1492
     Date today monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1493
     (Date day:15 month:4 year:1959) monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1494
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1495
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1496
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1497
weekInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1498
    "return the week number of the receiver - 1 for Jan, 1st.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1499
     each week is Mon .. Sun (i.e. Sunday belongs to the previous week)"
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1500
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1501
    ^ self class weekInYearOf:self
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1502
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1503
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1504
     Date today weekInYear    
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1505
     (Date newDay:1 year:2000) weekInYear   was a saturday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1506
     (Date newDay:2 year:2000) weekInYear   was a sunday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1507
     (Date newDay:3 year:2000) weekInYear   was a monday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1508
     (Date newDay:4 year:2000) weekInYear   was a tuesday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1509
     (Date newDay:5 year:2000) weekInYear   was a wed
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1510
     (Date newDay:6 year:2000) weekInYear   was a thursday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1511
     (Date newDay:7 year:2000) weekInYear   was a fri
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1512
     (Date newDay:8 year:2000) weekInYear   was a sat
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1513
     (Date newDay:9 year:2000) weekInYear   was a sun
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1514
     (Date newDay:10 year:2000) weekInYear  was a monday
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1515
     (Date day:3 month:1 year:2001) weekInYear 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1516
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1517
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1518
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1519
weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1520
    "return the week-day of the receiver as a string.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1521
     The returned string depends on the language setting.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1522
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1523
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1524
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1525
    ^ self class nameOfDay:(self dayInWeek)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1526
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1527
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1528
     Date today weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1529
     (Date day:15 month:4 year:1959) weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1530
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1531
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1532
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1533
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1534
    "return the year (1..12) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1535
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1536
    ^ dateEncoding // (100*100)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1537
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1538
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1539
     Date today year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1540
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1541
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1542
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1543
!Date methodsFor:'arithmetic'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1544
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1545
addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1546
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1547
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1548
     For ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1549
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1550
    ^ self class fromDays:(self asDays + days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1551
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1552
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1553
     Date today addDays:7
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1554
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1555
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1556
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1557
daysUntil:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1558
    "return the number of days between the receiver and the argument,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1559
     aDate, whuch should be some kind of date"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1560
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1561
    ^ aDate asDays - self asDays
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1562
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1563
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1564
     (Date day:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1565
     (Date day:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1566
     (Date day:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1567
    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1568
     |delta|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1569
     delta := Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1570
		daysUntil:(Date day:25 month:12 year:Date today year).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1571
     Transcript show:'still ';
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1572
		show:delta ;
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1573
		showCR:' days till xmas'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1574
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1575
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1576
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1577
minusDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1578
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1579
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1580
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1581
	 Please dont use this method since it will vanish.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1582
	 Use #subtractDays: instead for ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1583
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1584
    ^ self subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1585
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1586
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1587
plusDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1588
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1589
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1590
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1591
	 Please dont use this method since it will vanish.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1592
	 Use #addDays: instead for ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1593
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1594
    ^ self addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1595
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1596
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1597
subtractDate:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1598
    "return the number of days between the receiver and aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1599
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1600
    ^ self asDays - aDate asDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1601
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1602
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1603
    (Date day:1 month:1 year:1995) subtractDate:(Date day:24 month:12 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1604
    (Date day:1 month:3 year:1992) subtractDate:(Date day:1 month:2 year:1992)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1605
    (Date day:1 month:3 year:1994) subtractDate:(Date day:1 month:2 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1606
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1607
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1608
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1609
subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1610
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1611
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1612
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1613
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1614
    ^ self class fromDays:(self asDays - days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1615
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1616
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1617
     Date today subtractDays:7
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1618
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1619
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1620
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1621
!Date methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1622
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1623
< aDate
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1624
    "return true, if the date represented by the receiver
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1625
     is before the argument, aDate"
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1626
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1627
    (aDate isMemberOf:Date) ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1628
	^ dateEncoding < aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1629
    ].
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1630
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1631
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1632
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1633
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1634
    ^ dateEncoding < (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1635
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1636
				  day:aDate day)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1637
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1638
    "Date today < (Date day:24 month:12 year:2000)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1639
    "Date today < (Date day:24 month:12 year:1900)"
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1640
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1641
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1642
= aDate
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1643
    "return true, if the date represented by the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1644
     is the same as the one represented by argument, aDate"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1645
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1646
    (aDate isMemberOf:Date) ifFalse:[^ false].
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1647
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1648
    ^ dateEncoding = aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1649
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1650
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1651
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1652
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1653
"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1654
    ^ dateEncoding = (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1655
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1656
				  day:aDate day)
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1657
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1658
    "Date today = ((Date today plusDays:7) minusDays:7)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1659
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1660
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1661
> aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1662
    "return true, if the date represented by the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1663
     is after the argument, aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1664
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1665
    (aDate isMemberOf:Date) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1666
	^ dateEncoding > aDate dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1667
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1668
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1669
    "the argument must understand year, month and day to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1670
     comparable, whatever it is"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1671
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1672
    ^ dateEncoding > (Date encodeYear:aDate year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1673
				month:aDate month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1674
				  day:aDate day)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1675
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1676
    "Date today > (Date day:24 month:12 year:2000)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1677
    "Date today > (Date day:24 month:12 year:1900)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1678
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1679
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1680
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1681
    "return an integer useful for hashing on dates"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1682
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1683
    ^ dateEncoding
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1684
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1685
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1686
!Date methodsFor:'converting'!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1687
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1688
asAbsoluteTime
5679
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1689
    "return an absoluteTime instance, representing midnight of last night"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1690
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1691
    ^ AbsoluteTime year:(self year) month:(self month) day:(self day)  
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1692
                   hour:0 minute:0 second:0 millisecond:0
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1693
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1694
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1695
     Date today asAbsoluteTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1696
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1697
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1698
    "Modified: / 1.7.1996 / 14:53:32 / cg"
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1699
    "Modified: / 13.7.1999 / 12:31:47 / stefan"
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1700
!
4408
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1701
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1702
asDate
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1703
    "return the receiver"
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1704
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1705
    ^ self
5679
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1706
!
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1707
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1708
asTimestamp
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1709
    "return an absoluteTime instance, representing midnight of last night"
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1710
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1711
    ^ self asAbsoluteTime
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1712
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1713
    "
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1714
     Date today asTimestamp
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1715
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1716
! !
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1717
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  1718
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1719
!Date methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1720
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1721
addPrintBindingsTo:aDictionary
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1722
    "add bindings for printing to aDictionary."
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1723
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1724
    |d ds ds0 dsB m ms ms0 msB y w mn dn ws ws0 dw|
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1725
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1726
    d := self day.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1727
    ds := d printString.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1728
    dsB := d printStringLeftPaddedTo:2.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1729
    ds0 := d printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1730
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1731
    m := self month.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1732
    ms := m printString.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1733
    msB := m printStringLeftPaddedTo:2.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1734
    ms0 := m printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1735
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1736
    y := self year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1737
    w := self weekInYear.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1738
    ws := w printString.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1739
    ws0 := w printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1740
    mn := self monthName.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1741
    dn := self dayName.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1742
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1743
    aDictionary at:#day put:ds0.        "/ 0-padded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1744
    aDictionary at:#dayPadded put:dsB.  "/ Blank-padded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1745
    aDictionary at:#Day put:ds.         "/ unpadded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1746
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1747
    aDictionary at:#month put:ms0.  "/ 0-padded
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1748
    aDictionary at:#monthPadded put:ms0.  "/ Blank-padded
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1749
    aDictionary at:#Month put:ms.   "/ unpadded
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1750
    aDictionary at:#mon put:ms0.    "/ 0-padded - for backward compatibility only
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1751
    aDictionary at:#Mon put:ms.     "/ unpadded - for backward compatibility only
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1752
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1753
    aDictionary at:#year put:y.     "/ padded
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1754
    aDictionary at:#week put:ws0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1755
    aDictionary at:#Week put:ws.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1756
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1757
    y ~~ Date today year ifTrue:[
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1758
        aDictionary at:#yearOrTime put:(' ' , y printString).
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1759
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1760
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1761
    aDictionary at:$d put:ds0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1762
    aDictionary at:$D put:ds.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1763
    aDictionary at:$m put:ms0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1764
    aDictionary at:$M put:ms.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1765
    aDictionary at:$y put:y.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1766
    aDictionary at:$Y put:((y \\ 100)printStringLeftPaddedTo:2 with:$0).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1767
    aDictionary at:$w put:ws0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1768
    aDictionary at:$W put:ws.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1769
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1770
    aDictionary at:#monthName put:mn.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1771
    aDictionary at:#MonthName put:mn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1772
    aDictionary at:#MONTHNAME put:mn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1773
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1774
    aDictionary at:#dayName put:dn.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1775
    aDictionary at:#DayName put:dn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1776
    aDictionary at:#DAYNAME put:dn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1777
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1778
    aDictionary at:#weekDay put:(dw := self dayInWeek).
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1779
    aDictionary at:#weekDayUS put:(dw := self dayOfWeek).
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1780
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1781
    aDictionary at:#dayInWeek put:dw.     "/ for backward compatibility only
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1782
    aDictionary at:#shortDayName put:(dn := self abbreviatedDayName).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1783
    aDictionary at:#ShortDayName put:dn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1784
    aDictionary at:#SHORTDAYNAME put:dn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1785
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1786
    aDictionary at:#shortMonthName put:(mn := self abbreviatedMonthName).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1787
    aDictionary at:#ShortMonthName put:mn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1788
    aDictionary at:#SHORTMONTHNAME put:mn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1789
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1790
    aDictionary at:#nth        put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:d \\ 10 + 1).
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1791
                                     "/ 0   1    2    3    4    5    6    7    8    9
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1792
    aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:dw-1 \\ 10 + 1).
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1793
                                     "/ 0   1    2    3    4    5    6      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1794
    aDictionary at:#weekNth    put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:w \\ 10 + 1).
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1795
                                     "/ 0   1    2    3    4    5    6    7    8    9     
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1796
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1797
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1798
printOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1799
    "append a printed representation of the receiver to aStream"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1800
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1801
    self printFormat:#(1 2 3 $- 2 1) on:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1802
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1803
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1804
     Date today printOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1805
     Date today printNL
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1806
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1807
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1808
    "Modified: 27.8.1995 / 01:01:49 / claus"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1809
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1810
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1811
printOn:aStream format:aFormatStringOrSqueakFormatArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1812
    "print using a format string;
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1813
     valid format items are:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1814
        %d      day, 01..31                    0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1815
        %m      month, 01..12                  0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1816
        %w      week in year, 00..53           0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1817
        %y      year, full                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1818
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1819
     special:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1820
        %D      day - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1821
        %M      month - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1822
        %W      week in year - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1823
        %Y      year, last 2 digits only (danger)                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1824
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1825
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1826
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1827
        %dayName        - full day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1828
        %DayName        - full day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1829
        %DAYNAME        - full day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1830
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1831
        %monthName      - full month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1832
        %MonthName      - full month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1833
        %MONTHNAME      - full month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1834
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1835
        %shortDayName   - short (abbreviated) day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1836
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1837
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1838
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1839
        %shortMonthName - short (abbreviated) month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1840
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1841
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1842
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1843
        %nth           - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1844
        %weekDayNth    - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1845
        %weekNth       - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1846
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1847
     for ST80/squeak compatibility (which expects a format-array), the following is also supported:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1848
        #(item item item sep monthfmt yearfmt twoDigits)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1849
            items:  1=day  2=month  3=year  will appear in the order given,
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1850
            separated by sep which is eaither an ascii code or character.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1851
            monthFmt:  1=09  2=Sep  3=September
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1852
            yearFmt:  1=1996  2=96
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1853
            digits:  (missing or)1=9  2=09.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1854
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1855
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1856
    aFormatStringOrSqueakFormatArray isArray ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1857
        "/ a squeak format array
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1858
        ^ self printFormat:aFormatStringOrSqueakFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1859
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1860
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1861
    aStream nextPutAll:(self printStringFormat:aFormatStringOrSqueakFormatArray)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1862
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1863
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1864
     Date today printOn:Transcript format:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1865
     Date today printOn:Transcript format:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1866
     Date today printOn:Transcript format:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1867
     Date today printOn:Transcript format:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1868
     Date today printOn:Transcript format:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1869
     Date today printOn:Transcript format:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1870
     Date today printOn:Transcript format:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1871
     Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1872
     Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1873
     Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1874
     Date today printOn:Transcript format:'%d%m%Y'                                      (millenium bug format - danger)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1875
     Date today printOn:Transcript format:'Today is the %(weekDay) day of the week'     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1876
    "
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1877
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1878
     String streamContents:[:s |
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1879
        Date today printOn:s format:#(1 2 3 $/ 1 2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1880
     ]   
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1881
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1882
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1883
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1884
printStringFormat:aFormatStringOrArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1885
    "print using a format string;
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1886
     valid format items are:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1887
        %d      day, 01..31                    0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1888
        %m      month, 01..12                  0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1889
        %w      week in year, 00..53           0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1890
        %y      year, full                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1891
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1892
     special:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1893
        %D      day - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1894
        %M      month - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1895
        %W      week in year - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1896
        %Y      year, last 2 digits only (danger)                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1897
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1898
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1899
        %weekDayUS      - day in week (1->sunday, 2->monday, ... ,7->saturday)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1900
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1901
        %dayName        - full day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1902
        %DayName        - full day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1903
        %DAYNAME        - full day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1904
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1905
        %monthName      - full month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1906
        %MonthName      - full month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1907
        %MONTHNAME      - full month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1908
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1909
        %shortDayName   - short (abbreviated) day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1910
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1911
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1912
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1913
        %shortMonthName - short (abbreviated) month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1914
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1915
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1916
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1917
        %nth           - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1918
        %weekDayNth    - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1919
        %weekNth       - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1920
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1921
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1922
    |dict|
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1923
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1924
    dict := IdentityDictionary new.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1925
    self addPrintBindingsTo:dict.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1926
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1927
    ^ (aFormatStringOrArray expandPlaceholdersWith:dict)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1928
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1929
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1930
     Date today printStringFormat:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1931
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1932
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1933
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1934
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1935
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1936
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1937
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1938
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1939
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1940
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1941
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1942
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1943
     Date today printStringFormat:'Today is the %(Day)%(nth) day of the month'           
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1944
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1945
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1946
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1947
storeOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1948
    "append a representation to aStream, from which the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1949
     can be reconstructed"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1950
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1951
    aStream nextPutAll:'('; nextPutAll:'Date day:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1952
    self day printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1953
    aStream nextPutAll:' month:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1954
    self month printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1955
    aStream nextPutAll:' year:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1956
    self year printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1957
    aStream nextPutAll:')'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1958
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1959
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1960
     Date today storeOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1961
     Date today storeString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1962
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1963
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1964
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  1965
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  1966
!Date methodsFor:'private-accessing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1967
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1968
dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1969
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1970
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1971
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1972
    ^ dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1973
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1974
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1975
dateEncoding:anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1976
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1977
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1978
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1979
    dateEncoding := anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1980
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1982
fromOSTime:osTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1983
    "set my dateEncoding from an OS time.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1984
     This somewhat clumsy implementation hides the OS's date representation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1985
     (i.e. makes this class independent of what the OS starts its time values with).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1986
     Dont use this method, the osTime representation is totally unportable."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1987
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1988
    |v y m d|
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1989
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1990
    v := OperatingSystem computeTimeAndDateFrom:osTime.
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1991
    y := v year.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1992
    m := v month.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1993
    d := v day.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1994
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1995
    dateEncoding := (((y * 100) + m) * 100) + d
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1996
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1997
    "Modified: 1.7.1996 / 15:23:12 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1998
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1999
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2000
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  2001
!Date class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2002
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2003
version
7648
61b7826a9a0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7646
diff changeset
  2004
    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.76 2003-10-09 16:09:39 cg Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2005
! !
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  2006
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2007
Date initialize!