Date.st
author Claus Gittinger <cg@exept.de>
Wed, 16 Jul 2003 14:04:44 +0200
changeset 7512 07c56e8934f4
parent 7327 ab17eb5f11a6
child 7646 94ae479eedbb
permissions -rw-r--r--
OS returns OSTimeInfo (instead of an Array)
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
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   405
!Date class methodsFor:'Compatibility-Squeak'!
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   406
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   407
fromSeconds:seconds
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   408
    "Answer an instance of me which is 'seconds' seconds after January 1, 1901."
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   409
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   410
    | secondsInDay |
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   411
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   412
    secondsInDay := 24 * 60 * 60.
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   413
    ^self fromDays: seconds // secondsInDay
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   414
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   415
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   416
     Date fromSeconds:0
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   417
     Date fromSeconds:(24 * 60 * 60 * 365)
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   418
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   419
! !
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   420
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   421
!Date class methodsFor:'general queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   422
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   423
abbreviatedNameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   424
    "given a day index (1..7), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   425
     of the day"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   426
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   427
    (DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   428
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   429
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   430
    ^ DayAbbrevs at:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   431
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   432
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   433
     Date abbreviatedNameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   434
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   435
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   436
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   437
abbreviatedNameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   438
    "given a month index (1..12), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   439
     of the month"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   440
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   441
    (MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   442
        self initNames
699
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
    ^ MonthAbbrevs at:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   445
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
     Date abbreviatedNameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
     Date abbreviatedNameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   449
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   450
!
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
dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   453
    "return an array containing the date and time of now"
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
    ^ Time dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   456
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
     Date dateAndTimeNow
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
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   461
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   462
dayOfFirstWeekInYear:aYear
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   463
    "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
   464
     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
   465
     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
   466
     (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
   467
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   468
    |day dayInWeekOf1stJan firstThursday firstDayInWeek|
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   469
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   470
    "/ find the first thursday ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   471
    day := AbsoluteTime newDay:1 year:aYear.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   472
    dayInWeekOf1stJan := day dayInWeek.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   473
    dayInWeekOf1stJan > 4 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   474
        firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   475
    ] ifFalse:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   476
        firstThursday := day addDays:(4 - dayInWeekOf1stJan).
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
    "/ back to the preceeding monday
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   479
    firstDayInWeek := firstThursday subtractDays:3.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   480
    ^ firstDayInWeek
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   481
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   482
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   483
     Date dayOfFirstWeekInYear:1998   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   484
     Date dayOfFirstWeekInYear:1999    
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   485
     Date dayOfFirstWeekInYear:2000  
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   486
     Date dayOfFirstWeekInYear:2001   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   487
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   488
!
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   489
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   490
dayOfWeek:dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   491
    "given the name of a day (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   492
     return the day-index (1 for monday; 7 for sunday).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   493
     Return 0 for invalid day name"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   494
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   495
    |idx|
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   496
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   497
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   498
        self initNames
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   499
    ].
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   500
    idx := DayNames indexOf:dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   501
    idx == 0 ifTrue:[
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   502
        idx := DayNames indexOf:dayName asLowercase.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   503
    ].
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   504
    ^ idx
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   505
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   506
    "
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   507
     Date dayOfWeek:'wednesday' 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   508
     Date dayOfWeek:'Wednesday' 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   509
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   510
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   511
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   512
daysInMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   513
    "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
   514
     of days this month has (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   515
     return 0 if the month name was invalid.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   516
     For your convenience, month maybe an integer or name-string."
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
    |monthIndex "{ Class: SmallInteger }"|
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
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   521
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   522
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   523
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   524
    ].
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
    ^ self daysInMonthIndex:monthIndex forYear:yearInteger
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   529
     Date daysInMonth:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   530
     Date daysInMonth:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   531
     Date daysInMonth:'feb' forYear:1981
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   535
daysInYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   536
    "return the number of days in a year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   537
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
    (self leapYear:yearInteger) ifTrue:[^ 366].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   539
    ^ 365
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
     Date daysInYear:1900  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   543
     Date daysInYear:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   544
     Date daysInYear:1904 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   545
     Date daysInYear:1980 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   546
     Date daysInYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   547
    "
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
daysUntilMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   551
    "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
   552
     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
   553
     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
   554
     For your convenience, month maybe an integer or name-string."
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
    |monthIndex "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   557
     sumDays    "{ Class: SmallInteger }" |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   558
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   559
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   560
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   561
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   562
	monthIndex := self indexOfMonth:month
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 between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   565
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   566
    sumDays := 0.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   567
    1 to:monthIndex-1 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   568
	sumDays := sumDays + (self daysInMonthIndex:m forYear:yearInteger)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   569
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   570
    ^ sumDays
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   573
     Date daysUntilMonth:'feb' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   574
     Date daysUntilMonth:'jan' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   575
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   576
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   577
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   578
firstDayOfYear:inYear
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   579
    "return the weekDay-index of the 1st-january of the given year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   580
     1->monday, 2->tuesday, ... 7->sunday"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   581
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   582
    | t d |
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   583
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   584
    ((inYear < 1) or:[ inYear > 9999]) ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   585
        ^ 0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   586
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   587
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   588
    "/ normal Gregorian calendar: one extra day per four years 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   589
    t := 4 + inYear + ((inYear + 3) // 4).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   590
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   591
    inYear > 1800 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   592
        "/ Julian calendar: regular Gregorian less 3 days per 400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   593
        t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400).
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
    inYear > 1752 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   596
        "/ calendar changeover
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   597
        t := t + 3.
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
    d := t \\ 7.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   600
    "/ convert from 0 (sunday) .. 6 (saturday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   601
    "/ to 1 (munday) .. 7 (sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   602
    d == 0 ifTrue:[^ 7].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   603
    ^ d
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   604
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   605
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   606
     self firstDayOfYear:2000           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   607
     (Date newDay:1 year:2000) dayInWeek 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   608
     self firstDayOfYear:1999      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   609
     (Date newDay:1 year:1999) dayInWeek
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   610
     self firstDayOfYear:1998      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   611
     (Date newDay:1 year:1998) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   612
     self firstDayOfYear:2001           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   613
     (Date newDay:1 year:2001) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   614
     self firstDayOfYear:2002           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   615
     (Date newDay:1 year:2002) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   616
     self firstDayOfYear:2006           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   617
     (Date newDay:1 year:2006) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   618
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   619
     self firstDayOfYear:1800           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   620
     (Date newDay:1 year:1800) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   621
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   622
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   623
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   624
indexOfMonth:aMonthString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   625
    "given the name of a month (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   626
     return the month-index (1 for jan; 12 for december).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   627
     The given string may be a full or abbreviated name,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   628
     case is ignored.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   629
     Return 0 for invalid month name."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   630
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   631
    |idx name|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   632
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   633
    EnvironmentChange ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   634
	self initNames
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   635
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   636
    name := aMonthString asLowercase.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   637
    idx := MonthAbbrevs indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   638
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   639
    idx := MonthNames indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   640
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   641
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   642
    name at:1 put:(name at:1) asUppercase.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   643
    idx := MonthAbbrevs indexOf:name.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   644
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   645
    idx := MonthNames 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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
    ^ 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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   651
     Date indexOfMonth:'jan'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   652
     Date indexOfMonth:'Jan'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   653
     Date indexOfMonth:'December'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   654
    "
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   657
isLeapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
    "Return true, if a year is a leap year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   659
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   660
	 Please use the ST-80 compatible #leapYear for new programs, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   661
	 since this method will vanish."
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
    ^ self leapYear:yearInteger
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   666
leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   667
    "return true, if yearInteger is a leap year."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   668
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   669
    |y "{ Class: SmallInteger }"|
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
    y := yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   672
    (y \\ 4 == 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   673
	(y \\ 100 ~~ 0) ifTrue:[^ true].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   674
	(y \\ 400 == 0) ifTrue:[^ true]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   675
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   676
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   677
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
     Date leapYear:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   680
     Date leapYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   681
     Date leapYear:1900
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   682
     Date leapYear:2000
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
!
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
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   687
    "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
   688
     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
   689
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   690
    |restDays daysInMonth|
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
    restDays := aDayInYear.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   693
    restDays < 1 ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   694
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   695
    1 to:12 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   696
	daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   697
	restDays <= daysInMonth ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   698
	    ^ Array with:m with:restDays
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 := restDays - daysInMonth 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   701
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   702
    restDays > daysInMonth ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   703
    ^ Array with:12 with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   704
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   705
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   706
     Date monthAndDayFromDayInYear:66 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   707
     Date monthAndDayFromDayInYear:66 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   708
    "
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   711
nameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   712
    "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
   713
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   714
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   715
        self initNames
699
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
    ^ DayNames at:dayIndex
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   720
     Date nameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   721
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   722
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   723
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   724
nameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   725
    "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
   726
5830
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   727
    (MonthNames isNil or:[EnvironmentChange]) ifTrue:[
ddf555d12ef1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5827
diff changeset
   728
        self initNames
699
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
    ^ MonthNames at:monthIndex
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   733
     Date nameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   734
     Date nameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   735
     Date nameOfMonth:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   736
    "
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
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   739
weekInYearOf:aDateOrTimestamp
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   740
    "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
   741
     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
   742
     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
   743
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   744
    |dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   745
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   746
    dayInYear := aDateOrTimestamp dayInYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   747
    dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   748
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   749
    numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   750
    "/ 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
   751
    numDays < 0 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   752
        "/ not in a week here ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   753
        "/ 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
   754
        ^ 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
   755
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   756
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   757
    "/ compute the week 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   758
    week := numDays // 7 + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   759
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   760
    "/ 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
   761
    week == 53 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   762
        dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   763
        aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   764
            ^ 1
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   765
        ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   766
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   767
    ^ week
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   768
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   769
    "
5663
32a8acdf3e3b fixed weekInYearOf:
Claus Gittinger <cg@exept.de>
parents: 5662
diff changeset
   770
     AbsoluteTime now weekInYear    
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   771
     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
   772
     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
   773
     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
   774
     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
   775
     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
   776
     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
   777
     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
   778
     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
   779
     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
   780
     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
   781
     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
   782
     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
   783
     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
   784
     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
   785
     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
   786
     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
   787
     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
   788
     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
   789
     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
   790
     Date weekInYearOf:(Date day:1 month:1 year:2002)    
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   791
     Date weekInYearOf:(Date day:2 month:1 year:2002)      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   792
     Date weekInYearOf:(Date day:7 month:1 year:2002)      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   793
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   794
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   795
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   796
yearAsDays: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   797
    "Returns the number of days since Jan 1, 1901. (GNU)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   798
     to the first Jan of the year, yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   799
     For 1901 this is zero, for 1902 its 365.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   800
     Defined for years >= 1901"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   801
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   802
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   803
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   804
    y := yearInteger - 1900.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   805
    y := y - 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   806
    ^ (y * 365)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   807
	+ (y // 4)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   808
	- (y // 100)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   809
	+ ((y + 300) // 400)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   810
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
     Date yearAsDays:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   813
     Date yearAsDays:1902   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   814
     Date yearAsDays:1903   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   815
     Date yearAsDays:1904    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   816
     Date yearAsDays:1905     
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   817
     Date yearAsDays:1994   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   818
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
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
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   821
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   822
!Date class methodsFor:'handling language changes'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   823
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   824
initialize
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   825
    "check for case where Resource-classes are absent"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   826
    ResourcePack isNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   827
	self initNames
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   828
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   829
	Smalltalk addDependent:self.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   830
	EnvironmentChange := true
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
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   833
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   834
update:something with:aParameter from:changedObject
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   835
    ((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   836
        "just remember change for next access"
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   837
        EnvironmentChange := true
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   838
    ]
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   839
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   840
    "Created: 15.6.1996 / 15:19:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   841
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   842
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   843
!Date class methodsFor:'obsolete instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   844
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   845
day:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   846
    "return a new Date, given the day, month and year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   847
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   848
	use newDay:month:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   849
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   850
    ^ self newDay:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   851
!
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   852
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   853
day:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   854
    "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
   855
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   856
	use newDay:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   857
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   858
    ^ self newDay:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   859
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   860
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   861
!Date class methodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   862
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   863
daysInMonthIndex: monthIndex forYear: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   864
    "return the number of days in month monthIndex of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   865
     year yearInteger (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   866
     Return 0 for invalid month index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   867
     This is the internal version of daysInMonth:forYear:"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   868
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   869
    |days|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   870
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   871
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   872
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   873
    days := #(31 28 31           "Jan Feb Mar"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   874
	      30 31 30           "Apr May Jun"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   875
	      31 31 30           "Jul Aug Sep"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   876
	      31 30 31           "Oct Nov Dec"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   877
	     ) at: monthIndex.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   878
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   879
    (monthIndex == 2) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   880
	(self leapYear:yearInteger) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   881
	    ^ days + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   882
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   883
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   884
    ^ days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   885
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   886
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   887
     Date daysInMonthIndex:2 forYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   888
     Date daysInMonthIndex:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   889
     Date daysInMonthIndex:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   890
    "
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   893
initNames
a27a279701f8 Initial revision
claus
parents:
diff changeset
   894
    "read the language specific names"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   895
10
claus
parents: 5
diff changeset
   896
    |resources|
claus
parents: 5
diff changeset
   897
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   898
    DayNames := #('monday'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   899
		  'tuesday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   900
		  'wednesday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   901
		  'thursday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   902
		  'friday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   903
		  'saturday'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   904
		  'sunday').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   905
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   906
    DayAbbrevs := #('mon' 
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   907
		    'tue' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   908
		    'wed'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   909
		    'thu' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   910
		    'fri' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   911
		    'sat' 
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   912
		    'sun').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   913
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   914
    MonthNames := #('january'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   915
		    'february'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   916
		    'march'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   917
		    'april'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   918
		    'may'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   919
		    'june'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   920
		    'july'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   921
		    'august'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   922
		    'september'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   923
		    'october'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   924
		    'november'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   925
		    'december').
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   926
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   927
    MonthAbbrevs := #('jan'
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   928
		      'feb'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   929
		      'mar'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   930
		      'apr'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   931
		      'may'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   932
		      'jun'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   933
		      'jul'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   934
		      'aug'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   935
		      'sep'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   936
		      'oct'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   937
		      'nov'
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   938
		      'dec').
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   939
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   940
    "check for case where Resource-classes are absent"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   941
    ResourcePack notNil ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   942
	resources := ResourcePack for:self.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   943
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   944
	DayNames := resources array:DayNames.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   945
	DayAbbrevs := resources array:DayAbbrevs.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   946
	MonthNames := resources array:MonthNames.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
   947
	MonthAbbrevs := resources array:MonthAbbrevs.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   948
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   949
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
   950
    EnvironmentChange := false
10
claus
parents: 5
diff changeset
   951
claus
parents: 5
diff changeset
   952
    "Date initNames"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   953
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   954
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
   955
!Date class methodsFor:'private-encoding'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   956
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   957
encodeYear:y month:m day:d
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   958
    "the internal encoding is stricktly private, 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   959
     and should not be used outside."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   960
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
   961
    ^ (((y * 100) + m) * 100) + d
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-instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   965
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   966
fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   967
    "return a date, representing the date given by the operatingSystem time.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   968
     This somewhat clumsy implementation hides the OS's date representation
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   969
     (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
   970
     Dont use this method, the osTime representation is totally unportable."
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   971
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   972
    ^ self basicNew fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   973
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
     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
   976
				    thats where Unix time starts
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   977
				    On other systems, it may be something different.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   978
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   979
     Date fromOSTime:#(86400 0)  -> on UNIX: the day after
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
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   982
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   983
!Date methodsFor:'Compatibility-ANSI'!
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   984
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   985
dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   986
    "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
   987
     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
   988
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   989
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   990
    |d|
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   991
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   992
    d := self dayInWeek.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   993
    d == 7 ifTrue:[
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   994
        ^ 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   995
    ].
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   996
    ^ d + 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
   997
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
     Date today dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1000
     Date today dayInWeek
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
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1003
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1004
dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1005
    "return the short week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1006
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1007
     Expect things like 'mon', 'tue' ..."
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
    ^ self abbreviatedDayName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1010
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
     Date today dayOfWeekAbbreviation
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
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1015
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1016
dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1017
    "return the week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1018
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1019
     Expect things like 'monday', 'tuesday' ..."
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
    ^ self weekday
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1022
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
     Date today dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1025
     Date today dayOfWeekAbbreviation 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1026
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1027
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1028
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1029
dayOfYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1030
    "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
  1031
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1032
    ^ self dayInYear
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
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1035
     Date today dayOfYear 
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
isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1040
    "return true, if the receivers year is a leap year"
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 leap
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 isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1046
     (Date day:1 month:1 year:1992) isLeapYear
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
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1050
monthAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1051
    "return the month of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1052
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1053
     Expect things like 'jan', 'feb' ..."
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
    ^ self abbreviatedMonthName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1056
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
     Date today monthAbbreviation  
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
! !
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1061
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1062
!Date methodsFor:'Compatibility-ST80'!
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1063
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1064
previous:dayName 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1065
    "Return the previous date whose weekday name is dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1066
     Caveat; dayName is expected to be in the current language"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1067
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1068
    ^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1)
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1069
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1070
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1071
     Date today                 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1072
     Date today previous:#Monday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1073
     Date today previous:#Friday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1074
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1075
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1076
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1077
printFormat:aFormatArray
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1078
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1079
     Return a string containing a printed representation of the receiver.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1080
     The formatArray argument consists of 6 or 7 integers which control
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1081
     the resulting string. The entries are:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1082
     1   day position (1, 2 or 3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1083
     2   month position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1084
     3   year position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1085
     4   asciiValue of separator character or separator character
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1086
         or collection of 2 separator characters
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1087
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1088
         4: abbreviated uppercase 5: full uppercase)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1089
     6   year format (1 include century; 2 exclude century)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1090
     7  (optional) true/false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1091
         if true, print numbers in 2-digit format
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1092
         (i.e. with leading zeros); 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1093
         Taken as false, if ommited
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1094
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1095
     Day and monthnames are in the currently active language.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1096
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1097
     This method supports more options than the ST-80 version; month formats 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1098
     4 and 5, non-numeric separators and the optional 7th parameter are not 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1099
     supported by ST-80. Be aware of this for compatibility reasons.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1100
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1101
     Notice that not all formats can be scanned (correctly) by #readFrom:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1102
     This is an ST-80 compatibility method - I would have choosen another
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1103
     (less cryptic) formatString ...
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1104
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1105
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1106
    |mf upperCase day month year components sep1 sep2 leadingZeros|
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1107
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1108
    aFormatArray size > 6 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1109
        leadingZeros := aFormatArray at:7
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1110
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1111
        leadingZeros := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1112
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1113
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1114
    components := Array new:3.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1115
    day := self day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1116
    leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1117
        day := day printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1118
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1119
        day := day printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1120
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1121
    components at:(aFormatArray at:1) put:day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1122
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1123
    upperCase := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1124
    mf := aFormatArray at:5.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1125
    (mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1126
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1127
    mf == 1 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1128
        month := self month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1129
        leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1130
            month := month printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1131
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1132
            month := month printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1133
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1134
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1135
        mf == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1136
            month := self abbreviatedMonthName
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1137
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1138
            month := self monthName
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1139
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1140
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1141
    upperCase ifTrue:[month := month asUppercase].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1142
    components at:(aFormatArray at:2) put:month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1143
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1144
    year := self year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1145
    (aFormatArray at:6) == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1146
        year := year \\ 100.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1147
        year := year printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1148
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1149
    year := year printString.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1150
    components at:(aFormatArray at:3) put:year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1151
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1152
    sep1 := sep2 := (aFormatArray at:4).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1153
    sep1 isString ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1154
        sep1 isCollection ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1155
            sep2 := (sep1 at:2).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1156
            sep1 := (sep1 at:1).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1157
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1158
            sep1 := sep2 := sep1 asCharacter
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1159
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1160
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1161
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1162
    ^ (components at:1)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1163
      , sep1 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1164
      , (components at:2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1165
      , sep2 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1166
      , (components at:3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1167
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1168
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1169
     Date today printFormat:#(1 2 3 '' 1 2)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1170
     Date today printFormat:#(1 2 3 $- 1 2)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1171
     Date today printFormat:#(1 2 3 $. 1 2 true)     
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1172
     Date today printFormat:#(2 1 3 32 3 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1173
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1174
     Date today printFormat:#(1 2 3 $- 2 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1175
     Date today printFormat:#(1 2 3 $- 4 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1176
    "
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
printFormat:aFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1180
    "Obsolete, backward ST-80 compatible formatted printing - see comment
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1181
     in printFormat:.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1182
     Append a printed representation of the receiver to aStream.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1183
     The argument, aFormatString controls the format, as described
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1184
     in the #printFormat: method.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1185
     Notice that not all formats can be scanned (correctly) by #readFrom:"
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1186
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1187
    aStream nextPutAll:(self printFormat:aFormatArray)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1188
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1189
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1190
    "european formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1191
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1192
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1193
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1194
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1195
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1196
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1197
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1198
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1199
     US formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1200
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1201
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1202
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1203
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1204
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1205
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1206
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1207
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1208
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1209
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1210
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1211
shortPrintString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1212
    "dummy - for now"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1213
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1214
    ^ self printString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1215
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1216
    "Created: 20.6.1997 / 17:16:48 / cg"
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1217
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1218
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1219
weekdayIndex
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1220
    "Return the day index; Monday=1, ... , Sunday=7"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1221
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1222
    ^ (self asDays + 1) \\ 7 + 1  "1 January 1901 was a Tuesday"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1223
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1224
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1225
     Date today dayName
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1226
     Date today weekdayIndex      
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1227
    "
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1228
! !
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1229
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1230
!Date methodsFor:'Compatibility-Squeak'!
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1231
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1232
mmddyyyy
4462
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1233
    "return a printed representation of the receiver in the
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1234
     form mmddyyyy.
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1235
     The receiver can be reconstructed with: 
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1236
        Date readMMDDYYYYFrom:aStringOrStream onError:[...]"
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1237
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1238
    ^ (self month printStringLeftPaddedTo:2 with:$0)
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1239
       , (self day printStringLeftPaddedTo:2 with:$0) 
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1240
       , (self year printStringLeftPaddedTo:4 with:$0)
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
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1243
     Date today mmddyyyy
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1244
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1245
! !
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1246
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1247
!Date methodsFor:'accessing'!
241
6f30be88e314 *** empty log message ***
claus
parents: 202
diff changeset
  1248
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1249
abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1250
    "return the short week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1251
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1252
     Expect things like 'mon', 'tue' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1253
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1254
    ^ self class abbreviatedNameOfDay:(self dayInWeek)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1255
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1256
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1257
     Date today abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1258
     (Date day:15 month:4 year:1959) abbreviatedDayName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1259
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1260
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1261
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1262
abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1263
    "return the month of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1264
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1265
     Expect things like 'jan', 'feb' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1266
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1267
    ^ self class abbreviatedNameOfMonth:(self month)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1268
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1269
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1270
     Date today abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1271
     (Date day:15 month:4 year:1959) abbreviatedMonthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1272
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1273
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1274
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1275
asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1276
    "return the number of days elapsed since 01-Jan-1901
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1277
     and the receiver's day; starts with 0 for 1-1-1901.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1278
     Date>>fromDays: is the reverse operation.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1279
     For ST-80 compatibility."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1280
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1281
    |yr|
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1282
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1283
    yr := self year.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1284
    ^ (self class yearAsDays:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1285
      + (self class daysUntilMonth:self month forYear:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1286
      + self day
85
claus
parents: 77
diff changeset
  1287
      - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1288
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1289
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1290
     (Date day: 5 month: 8 year: 1962) asDays  -> should be 22496
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1291
     (Date day: 1 month: 1 year: 1901) asDays  -> 0
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1292
     Date today asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1293
     Date fromDays:(Date today asDays + 7)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1294
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1295
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1296
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1297
asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1298
    "return the seconds between 1.jan.1901 and the same time in the receivers 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1299
     day. (i.e. midnight to midnight).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1300
     This does not include any leapSeconds ... strictly speaking, this is incorrect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1301
     ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1302
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1303
    ^ 60*60*24 * self asDays
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1304
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1305
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1306
     (Date day: 5 month: 8 year: 1962) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1307
     (Date day: 1 month: 1 year: 1901) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1308
     (Date today addDays:7) asSeconds - Date today asSeconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1309
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1310
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1311
    "Modified: 1.7.1996 / 14:19:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1312
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1313
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1314
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1315
    "return the day (1..31) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1316
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1317
    ^ dateEncoding \\ 100
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1318
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1319
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1320
     Date today day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1321
    "
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
dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1325
    "return the number of days since 1st. Jan. 1901;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1326
     starting with 0 for this date.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1327
     Date>>fromDays: is the reverse operation.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1328
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1329
	 please use asDays for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1330
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1331
    ^ self asDays.
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
     (Date day:1 month:1 year:1901) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
     Date fromDays:(Date day:1 month:1 year:1994) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1336
     Date today dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1337
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1338
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1339
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1340
dayInWeek
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1341
    "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
  1342
     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
  1343
     WARNING: does not care for pre-julian dates 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1344
        (i.e. do not use this for dates before 1752)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1345
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1346
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1347
    |wday|
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1348
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1349
    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
  1350
            + self asDays) \\ 7 + 1.
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1351
    wday < 1 ifTrue:[
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1352
        wday := wday + 7
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1353
    ].
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1354
    ^ wday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1355
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1356
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1357
     Date today dayInWeek      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1358
     Date tomorrow dayInWeek 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1359
     Date yesterday dayInWeek 
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1360
     (Date today subtractDays:2) dayInWeek 
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1361
     Date today weekday 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1362
     Date tomorrow weekday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1363
     Date yesterday weekday 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1364
     (Date day:15 month:4 year:1959) dayInWeek 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1365
     (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
  1366
     (Date day:31 month:12 year:1899) dayInWeek 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1367
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1368
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1369
    "Modified: / 1.2.1998 / 14:10:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1370
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1371
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1372
dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1373
    "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
  1374
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1375
    ^ self asAbsoluteTime dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1376
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1377
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1378
     Date today dayInYear 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1379
     (Date newDay:1 year:1999) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1380
     (Date newDay:1 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1381
     (Date newDay:2 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1382
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1383
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1384
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1385
dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1386
    "return the week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1387
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1388
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1389
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1390
	use #weekday for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1391
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1392
    ^ self weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1393
!
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1394
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1395
dayOfMonth
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1396
    "Answer the day of the month represented by me.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1397
     Same as day; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1398
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1399
    ^ self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1400
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1401
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1402
     Date today dayOfMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1403
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1404
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1405
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1406
daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1407
    "return the number of days in the month of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1408
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1409
    ^ Date daysInMonth:(self month) forYear:(self year)
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 daysInMonth
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
daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1417
    "return the number of days in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1418
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1419
    ^ Date daysInYear:(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 daysInYear
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
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1426
daysLeftInMonth
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1427
    "return the number of days left in the month of the receiver"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1428
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1429
    ^ self daysInMonth - self day
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1430
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1431
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1432
     Date today daysLeftInMonth             
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1433
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1434
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1435
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1436
daysLeftInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1437
    "return the number of days left in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1438
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1439
    ^ (Date daysInYear:(self year)) - self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1440
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1441
    "
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1442
     Date today daysLeftInYear             
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1443
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1444
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1445
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1446
leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1447
    "return true, if the receivers year is a leap year"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1448
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1449
    ^ Date leapYear:(self year)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1450
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1451
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1452
     Date today leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1453
     (Date day:1 month:1 year:1992) leap
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1454
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1455
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1456
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1457
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1458
    "return the month (1..12) of the receiver"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1459
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1460
    ^ (dateEncoding // 100) \\ 100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1461
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1462
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1463
     Date today month
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
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1467
monthIndex
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1468
    "return the index of the month (e.g. Feb.=2).
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1469
     Same as month; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1470
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1471
    ^ self month  
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1472
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1473
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1474
monthName
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1475
    "return the month of the receiver as a string.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1476
     The returned string depends on the language setting.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1477
     Expect things like 'january', 'february' ..."
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1478
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1479
    ^ self class nameOfMonth:(self month)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1480
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1481
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1482
     Date today monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1483
     (Date day:15 month:4 year:1959) monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1484
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1485
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1486
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1487
weekInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1488
    "return the week number of the receiver - 1 for Jan, 1st.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1489
     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
  1490
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1491
    ^ self class weekInYearOf:self
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1492
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1493
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1494
     Date today weekInYear    
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1495
     (Date newDay:1 year:2000) weekInYear   was a saturday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1496
     (Date newDay:2 year:2000) weekInYear   was a sunday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1497
     (Date newDay:3 year:2000) weekInYear   was a monday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1498
     (Date newDay:4 year:2000) weekInYear   was a tuesday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1499
     (Date newDay:5 year:2000) weekInYear   was a wed
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1500
     (Date newDay:6 year:2000) weekInYear   was a thursday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1501
     (Date newDay:7 year:2000) weekInYear   was a fri
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1502
     (Date newDay:8 year:2000) weekInYear   was a sat
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1503
     (Date newDay:9 year:2000) weekInYear   was a sun
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1504
     (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
  1505
     (Date day:3 month:1 year:2001) weekInYear 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1506
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1507
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1508
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1509
weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1510
    "return the week-day of the receiver as a string.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1511
     The returned string depends on the language setting.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1512
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1513
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1514
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1515
    ^ self class nameOfDay:(self dayInWeek)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1516
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1517
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1518
     Date today weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1519
     (Date day:15 month:4 year:1959) weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1520
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1521
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1522
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1523
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1524
    "return the year (1..12) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1525
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1526
    ^ dateEncoding // (100*100)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1527
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1528
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1529
     Date today year
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
!Date methodsFor:'arithmetic'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1534
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1535
addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1536
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1537
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1538
     For ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1539
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1540
    ^ self class fromDays:(self asDays + days)
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 today addDays:7
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
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1546
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1547
daysUntil:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1548
    "return the number of days between the receiver and the argument,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1549
     aDate, whuch should be some kind of date"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1550
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1551
    ^ aDate asDays - self asDays
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1552
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1553
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1554
     (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
  1555
     (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
  1556
     (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
  1557
    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1558
     |delta|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1559
     delta := Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1560
		daysUntil:(Date day:25 month:12 year:Date today year).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1561
     Transcript show:'still ';
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1562
		show:delta ;
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1563
		showCR:' days till xmas'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1564
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1565
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1566
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1567
minusDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1568
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1569
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1570
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1571
	 Please dont use this method since it will vanish.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1572
	 Use #subtractDays: instead for ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1573
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1574
    ^ self subtractDays:days
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
plusDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1578
    "return a new date representing 'days' after 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 #addDays: 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 addDays: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
subtractDate:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1588
    "return the number of days between the receiver and aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1589
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1590
    ^ self asDays - aDate asDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1591
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1592
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1593
    (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
  1594
    (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
  1595
    (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
  1596
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1597
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1598
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1599
subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1600
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1601
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1602
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1603
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1604
    ^ self class fromDays:(self asDays - days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1605
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
     Date today subtractDays:7
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1608
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1609
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1610
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1611
!Date methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1612
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1613
< aDate
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1614
    "return true, if the date represented by the receiver
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1615
     is before the argument, aDate"
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1616
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1617
    (aDate isMemberOf:Date) ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1618
	^ dateEncoding < aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1619
    ].
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1620
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1621
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1622
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1623
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1624
    ^ dateEncoding < (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1625
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1626
				  day:aDate day)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1627
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1628
    "Date today < (Date day:24 month:12 year:2000)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1629
    "Date today < (Date day:24 month:12 year:1900)"
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  1630
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1631
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1632
= aDate
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1633
    "return true, if the date represented by the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1634
     is the same as the one represented by argument, aDate"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1635
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1636
    (aDate isMemberOf:Date) ifFalse:[^ false].
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1637
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1638
    ^ dateEncoding = aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1639
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1640
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1641
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1642
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1643
"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1644
    ^ dateEncoding = (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1645
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1646
				  day:aDate day)
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  1647
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1648
    "Date today = ((Date today plusDays:7) minusDays:7)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1649
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1650
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1651
> aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1652
    "return true, if the date represented by the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1653
     is after the argument, aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1654
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1655
    (aDate isMemberOf:Date) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1656
	^ dateEncoding > aDate dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1657
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1658
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1659
    "the argument must understand year, month and day to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1660
     comparable, whatever it is"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1661
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1662
    ^ dateEncoding > (Date encodeYear:aDate year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1663
				month:aDate month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1664
				  day:aDate day)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1665
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1666
    "Date today > (Date day:24 month:12 year:2000)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1667
    "Date today > (Date day:24 month:12 year:1900)"
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
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1670
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1671
    "return an integer useful for hashing on dates"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1672
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1673
    ^ dateEncoding
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1674
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1675
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1676
!Date methodsFor:'converting'!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1677
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1678
asAbsoluteTime
5679
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1679
    "return an absoluteTime instance, representing midnight of last night"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1680
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1681
    ^ AbsoluteTime year:(self year) month:(self month) day:(self day)  
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1682
                   hour:0 minute:0 second:0 millisecond:0
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1683
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1684
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1685
     Date today asAbsoluteTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1686
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1687
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1688
    "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
  1689
    "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
  1690
!
4408
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1691
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1692
asDate
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1693
    "return the receiver"
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1694
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1695
    ^ self
5679
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1696
!
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1697
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1698
asTimestamp
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1699
    "return an absoluteTime instance, representing midnight of last night"
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1700
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1701
    ^ self asAbsoluteTime
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1702
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1703
    "
fd5cf73dabe4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5663
diff changeset
  1704
     Date today asTimestamp
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1705
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1706
! !
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1707
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1708
!Date methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1709
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1710
addPrintBindingsTo:aDictionary
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1711
    "add bindings for printing to aDictionary."
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1712
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1713
    |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
  1714
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1715
    d := self day.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1716
    ds := d printString.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1717
    dsB := d printStringLeftPaddedTo:2.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1718
    ds0 := d printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1719
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1720
    m := self month.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1721
    ms := m printString.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1722
    msB := m printStringLeftPaddedTo:2.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1723
    ms0 := m printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1724
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1725
    y := self year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1726
    w := self weekInYear.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1727
    ws := w printString.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1728
    ws0 := w printStringLeftPaddedTo:2 with:$0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1729
    mn := self monthName.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1730
    dn := self dayName.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1731
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1732
    aDictionary at:#day put:ds0.        "/ 0-padded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1733
    aDictionary at:#dayPadded put:dsB.  "/ Blank-padded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1734
    aDictionary at:#Day put:ds.         "/ unpadded
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1735
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1736
    aDictionary at:#month put:ms0.  "/ 0-padded
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1737
    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
  1738
    aDictionary at:#Month put:ms.   "/ unpadded
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1739
    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
  1740
    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
  1741
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1742
    aDictionary at:#year put:y.     "/ padded
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1743
    aDictionary at:#week put:ws0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1744
    aDictionary at:#Week put:ws.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1745
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1746
    y ~~ Date today year ifTrue:[
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1747
        aDictionary at:#yearOrTime put:(' ' , y printString).
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1748
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1749
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1750
    aDictionary at:$d put:ds0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1751
    aDictionary at:$D put:ds.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1752
    aDictionary at:$m put:ms0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1753
    aDictionary at:$M put:ms.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1754
    aDictionary at:$y put:y.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1755
    aDictionary at:$Y put:((y \\ 100)printStringLeftPaddedTo:2 with:$0).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1756
    aDictionary at:$w put:ws0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1757
    aDictionary at:$W put:ws.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1758
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1759
    aDictionary at:#monthName put:mn.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1760
    aDictionary at:#MonthName put:mn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1761
    aDictionary at:#MONTHNAME put:mn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1762
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1763
    aDictionary at:#dayName put:dn.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1764
    aDictionary at:#DayName put:dn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1765
    aDictionary at:#DAYNAME put:dn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1766
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1767
    aDictionary at:#weekDay put:(dw := self dayInWeek).
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1768
    aDictionary at:#weekDayUS put:(dw := self dayOfWeek).
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1769
5827
71a6e54e02e5 same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents: 5778
diff changeset
  1770
    aDictionary at:#dayInWeek put:dw.     "/ for backward compatibility only
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1771
    aDictionary at:#shortDayName put:(dn := self abbreviatedDayName).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1772
    aDictionary at:#ShortDayName put:dn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1773
    aDictionary at:#SHORTDAYNAME put:dn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1774
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1775
    aDictionary at:#shortMonthName put:(mn := self abbreviatedMonthName).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1776
    aDictionary at:#ShortMonthName put:mn asUppercaseFirst.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1777
    aDictionary at:#SHORTMONTHNAME put:mn asUppercase.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1778
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1779
    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
  1780
                                     "/ 0   1    2    3    4    5    6    7    8    9
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1781
    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
  1782
                                     "/ 0   1    2    3    4    5    6      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1783
    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
  1784
                                     "/ 0   1    2    3    4    5    6    7    8    9     
5778
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
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1787
printOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1788
    "append a printed representation of the receiver to aStream"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1789
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1790
    self printFormat:#(1 2 3 $- 2 1) on:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1791
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1792
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1793
     Date today printOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1794
     Date today printNL
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1795
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1796
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1797
    "Modified: 27.8.1995 / 01:01:49 / claus"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1798
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1799
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1800
printOn:aStream format:aFormatStringOrSqueakFormatArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1801
    "print using a format string;
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1802
     valid format items are:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1803
        %d      day, 01..31                    0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1804
        %m      month, 01..12                  0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1805
        %w      week in year, 00..53           0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1806
        %y      year, full                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1807
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1808
     special:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1809
        %D      day - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1810
        %M      month - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1811
        %W      week in year - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1812
        %Y      year, last 2 digits only (danger)                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1813
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1814
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1815
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1816
        %dayName        - full day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1817
        %DayName        - full day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1818
        %DAYNAME        - full day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1819
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1820
        %monthName      - full month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1821
        %MonthName      - full month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1822
        %MONTHNAME      - full month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1823
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1824
        %shortDayName   - short (abbreviated) day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1825
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1826
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1827
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1828
        %shortMonthName - short (abbreviated) month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1829
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1830
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1831
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1832
        %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
  1833
        %weekDayNth    - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1834
        %weekNth       - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1835
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1836
     for ST80/squeak compatibility (which expects a format-array), the following is also supported:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1837
        #(item item item sep monthfmt yearfmt twoDigits)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1838
            items:  1=day  2=month  3=year  will appear in the order given,
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1839
            separated by sep which is eaither an ascii code or character.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1840
            monthFmt:  1=09  2=Sep  3=September
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1841
            yearFmt:  1=1996  2=96
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1842
            digits:  (missing or)1=9  2=09.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1843
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1844
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1845
    aFormatStringOrSqueakFormatArray isArray ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1846
        "/ a squeak format array
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1847
        ^ self printFormat:aFormatStringOrSqueakFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1848
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1849
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1850
    aStream nextPutAll:(self printStringFormat:aFormatStringOrSqueakFormatArray)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1851
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1852
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1853
     Date today printOn:Transcript format:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1854
     Date today printOn:Transcript format:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1855
     Date today printOn:Transcript format:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1856
     Date today printOn:Transcript format:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1857
     Date today printOn:Transcript format:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1858
     Date today printOn:Transcript format:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1859
     Date today printOn:Transcript format:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1860
     Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1861
     Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1862
     Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1863
     Date today printOn:Transcript format:'%d%m%Y'                                      (millenium bug format - danger)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1864
     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
  1865
    "
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1866
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1867
     String streamContents:[:s |
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1868
        Date today printOn:s format:#(1 2 3 $/ 1 2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1869
     ]   
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1870
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1871
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1872
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1873
printStringFormat:aFormatStringOrArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1874
    "print using a format string;
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1875
     valid format items are:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1876
        %d      day, 01..31                    0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1877
        %m      month, 01..12                  0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1878
        %w      week in year, 00..53           0-padded to length 2
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1879
        %y      year, full                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1880
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1881
     special:
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1882
        %D      day - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1883
        %M      month - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1884
        %W      week in year - unpadded
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1885
        %Y      year, last 2 digits only (danger)                     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1886
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1887
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1888
        %weekDayUS      - day in week (1->sunday, 2->monday, ... ,7->saturday)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1889
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1890
        %dayName        - full day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1891
        %DayName        - full day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1892
        %DAYNAME        - full day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1893
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1894
        %monthName      - full month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1895
        %MonthName      - full month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1896
        %MONTHNAME      - full month name, all uppercase       
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
        %shortDayName   - short (abbreviated) day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1899
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1900
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1901
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1902
        %shortMonthName - short (abbreviated) month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1903
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1904
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1905
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1906
        %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
  1907
        %weekDayNth    - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1908
        %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
  1909
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1910
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1911
    |dict|
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
    dict := IdentityDictionary new.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1914
    self addPrintBindingsTo:dict.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1915
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1916
    ^ (aFormatStringOrArray expandPlaceholdersWith:dict)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1917
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1918
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1919
     Date today printStringFormat:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1920
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1921
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1922
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1923
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1924
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1925
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1926
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1927
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1928
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1929
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1930
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1931
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  1932
     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
  1933
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1934
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1935
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1936
storeOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1937
    "append a representation to aStream, from which the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1938
     can be reconstructed"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1939
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1940
    aStream nextPutAll:'('; nextPutAll:'Date day:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1941
    self day printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1942
    aStream nextPutAll:' month:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1943
    self month printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1944
    aStream nextPutAll:' year:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1945
    self year printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1946
    aStream nextPutAll:')'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1947
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1948
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1949
     Date today storeOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1950
     Date today storeString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1951
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1952
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1953
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  1954
!Date methodsFor:'private-accessing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1955
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1956
dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1957
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1958
     and should not be used outside."
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
    ^ dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1961
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1962
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1963
dateEncoding:anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1964
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1965
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1966
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1967
    dateEncoding := anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1968
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1969
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1970
fromOSTime:osTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1971
    "set my dateEncoding from an OS time.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1972
     This somewhat clumsy implementation hides the OS's date representation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1973
     (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
  1974
     Dont use this method, the osTime representation is totally unportable."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1975
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1976
    |v y m d|
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1977
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1978
    v := OperatingSystem computeTimeAndDateFrom:osTime.
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1979
    y := v year.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1980
    m := v month.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1981
    d := v day.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1982
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  1983
    dateEncoding := (((y * 100) + m) * 100) + d
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1984
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1985
    "Modified: 1.7.1996 / 15:23:12 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1986
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1987
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1988
!Date class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1989
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1990
version
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1991
    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.74 2003-07-16 12:04:37 cg Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1992
! !
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  1993
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1994
Date initialize!