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