Date.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 07 Jul 2011 23:08:07 +0100
branchjv
changeset 17845 7e0cfaac936d
parent 17841 7abcc4aef871
child 17846 24edc476ac18
permissions -rw-r--r--
Merged with /trunk
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
"
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    12
"{ Package: 'stx:libbasic' }"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    13
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    14
Magnitude subclass:#Date
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    15
	instanceVariableNames:'dateEncoding'
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    16
	classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs DefaultFormats
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    17
		ShortFormats LongFormats EnvironmentChange'
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    18
	poolDictionaries:''
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
    19
	category:'Magnitude-Time'
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 :-)
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
    50
    Notice: no correction for pre-Gregorian dates (< 1583) 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
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    80
!Date class methodsFor:'initialization'!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    81
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    82
initDefaultNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    83
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    84
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    85
    |enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
    86
     enDefaultFormat enLongFormat enShortFormat |
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    87
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    88
    DayNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    89
    DayAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    90
    MonthNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    91
    MonthAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    92
    DefaultFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    93
    LongFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    94
    ShortFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    95
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    96
    enDayNames := #('monday'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
    97
                    'tuesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
    98
                    'wednesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
    99
                    'thursday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   100
                    'friday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   101
                    'saturday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   102
                    'sunday').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   103
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   104
    enDayAbbrevs := #('mon' 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   105
                      'tue' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   106
                      'wed'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   107
                      'thu' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   108
                      'fri' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   109
                      'sat' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   110
                      'sun').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   111
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   112
    enMonthNames := #('january'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   113
                      'february'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   114
                      'march'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   115
                      'april'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   116
                      'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   117
                      'june'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   118
                      'july'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   119
                      'august'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   120
                      'september'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   121
                      'october'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   122
                      'november'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   123
                      'december').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   124
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   125
    enMonthAbbrevs := #('jan'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   126
                        'feb'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   127
                        'mar'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   128
                        'apr'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   129
                        'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   130
                        'jun'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   131
                        'jul'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   132
                        'aug'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   133
                        'sep'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   134
                        'oct'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   135
                        'nov'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   136
                        'dec').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   137
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   138
    DayNames at:#'en' put:enDayNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   139
    DayAbbrevs at:#'en' put:enDayAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   140
    MonthNames at:#'en' put:enMonthNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   141
    MonthAbbrevs at:#'en' put:enMonthAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   142
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   143
    DefaultFormats at:#'en' put:(enDefaultFormat := '%d-%m-%y').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   144
    ShortFormats at:#'en' put:(enShortFormat := '%d-%m-%y').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   145
    LongFormats at:#'en' put:(enLongFormat := '%(dayName), %d-%m-%y').
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   146
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   147
    "/ take the "master" language here, for the caching
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   148
    EnvironmentChange := (Smalltalk language asSymbol ~~ #'en').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   149
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   150
    "
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   151
     Date initDefaultNames
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   152
    "
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   153
!
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   154
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   155
initNames
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   156
    "read the language specific names."
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   157
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   158
    |lang|
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   159
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   160
    DayNames isNil ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   161
        self initDefaultNames.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   162
    ].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   163
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   164
    lang := Smalltalk language asSymbol.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   165
    lang ~~ #'en' ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   166
        self initNamesForLanguage: lang.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   167
    ].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   168
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   169
    EnvironmentChange := false
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   170
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   171
    "
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   172
     Date initNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   173
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   174
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   175
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   176
initNamesForLanguage:language
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   177
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   178
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   179
    |resources lang 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   180
     enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs monthAbbrevKeys
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   181
     enDefaultFormat enLongFormat enShortFormat may|
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   182
8943
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   183
    DayNames isNil ifTrue:[
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   184
        self initDefaultNames.
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   185
    ].
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   186
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   187
    lang := language asSymbol.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   188
    lang ~~ #'en' ifTrue:[
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   189
        resources := ResourcePack forPackage:'stx:libbasic' resourceFileName: language,'.rs' cached:false .
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   190
        resources notNil ifTrue:[
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   191
            enDayNames := DayNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   192
            enDayAbbrevs := DayAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   193
            enMonthNames := MonthNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   194
            enMonthAbbrevs := MonthAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   195
            monthAbbrevKeys := enMonthAbbrevs copy.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   196
            monthAbbrevKeys at:5 put:'MAY_ABBREV'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   197
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   198
            enDefaultFormat := DefaultFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   199
            enShortFormat := ShortFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   200
            enLongFormat := LongFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   201
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   202
            DefaultFormats at:lang put:(resources at:'DATEFORMAT' default:enDefaultFormat).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   203
            ShortFormats at:lang put:(resources at:'SHORTDATEFORMAT' default:enShortFormat).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   204
            LongFormats at:lang put:(resources at:'LONGDATEFORMAT' default:enLongFormat).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   205
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   206
            DayNames at:lang put:(resources array:enDayNames).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   207
            DayAbbrevs at:lang put:(resources array:enDayAbbrevs).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   208
            MonthNames at:lang put:(resources array:enMonthNames).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   209
            MonthAbbrevs at:lang put:(resources array:monthAbbrevKeys).
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   210
            "/ may needs special care (same key for long and short name)
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   211
            may := resources string:'MAY_ABBREV' default:nil.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   212
            may isNil ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   213
                may := resources string:'may'.
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   214
            ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   215
            (MonthAbbrevs at:lang) at:5 put:may.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   216
        ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   217
    ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   218
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   219
    "
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   220
     Date initNamesForLanguage:#de.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   221
     Date initNamesForLanguage:#fr.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   222
     Date initNamesForLanguage:#es.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   223
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   224
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   225
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   226
initialize
8943
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   227
    DayNames isNil ifTrue:[
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   228
        self initDefaultNames.
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   229
    ].
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   230
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   231
    Smalltalk addDependent:self.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   232
    Language ~= 'en' ifTrue:[
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   233
        EnvironmentChange := true
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   234
    ]
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   235
! !
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   236
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   237
!Date class methodsFor:'instance creation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   238
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   239
fromDays:dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   240
    "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
   241
     (i.e. 'Date fromDays:0' returns 1st Jan. 1901).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   242
     Date asDays is the reverse operation.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   243
     Added for GNU/ST-80 compatibility"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   244
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   245
    |year rest d yearIncrement|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   246
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   247
    "approx. year"
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   248
    year := (dayCount // 366) + 1901.
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   249
    dayCount < 0 ifTrue:[
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   250
        rest := dayCount negated - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   251
        yearIncrement := -1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   252
    ] ifFalse:[
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   253
        rest := dayCount - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   254
        yearIncrement := 1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   255
    ].
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   256
    rest > 365 ifTrue:[
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   257
        [d := self daysInYear:year. rest > d] whileTrue:[
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   258
            "adjust"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   259
            year := year + yearIncrement.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   260
            rest := rest - d.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   261
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   264
    ^ self newDay:rest year:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   265
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   266
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   267
     Date fromDays:0     -> 1 jan 1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   268
     Date fromDays:365   -> 1 jan 1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   269
     Date fromDays:730   -> 1 jan 1903
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   270
     Date fromDays:1095  -> 1 jan 1904
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   271
     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
   272
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   273
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   274
    "Modified: 1.7.1996 / 14:24:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   275
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   276
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   277
newDay:day month:month year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   278
    "return a new Date, given the day, month and year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
     For your convenience, month may be either an integer 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   280
     or the months name as a string. 
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   281
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   282
     WARNING: semantics changed: 0..99 is no longer treated as 1900..1999,
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   283
              but as 0..99 now.
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   284
              Any such adjustments must be made by the caller of this method now
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   285
              (see those, for example readFrom:onError:)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   286
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   287
    |monthIndex ok|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   288
8446
e19765545de6 Dont generate a warning for years between -1 and -99
Stefan Vogel <sv@exept.de>
parents: 8247
diff changeset
   289
    (year < 100 and:[year > 0]) ifTrue:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   290
        'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   291
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   292
    month isInteger ifTrue:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   293
        monthIndex := month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
    ] ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   295
        monthIndex := self indexOfMonth:month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   296
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   297
    (monthIndex == 2 and:[day == 29]) ifTrue:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   298
        ok := self leapYear:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   299
    ] ifFalse:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   300
        ok := day <= (self daysInMonth:month forYear:year)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   301
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   302
    ((day > 0) and:[ok]) ifTrue:[
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   303
        ^ self basicNew year:year month:monthIndex day:day.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   304
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   305
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   306
    "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
   307
     invalid year/month/day combination;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   308
     Such as 29-feb-year, where year is no leap year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   309
    "
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   310
    self conversionErrorSignal raiseErrorString:' - invalid date'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   311
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   312
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   313
     Date newDay:8  month:'may' year:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   314
     Date newDay:8  month:5     year:1994
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   315
     Date newDay:29 month:'feb' year:2004
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   316
     Date newDay:29 month:'feb' year:2003
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   317
     Date newDay:28 month:'feb' year:5   
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   318
     Date newDay:28 month:'feb' year:95  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   319
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   320
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   321
    "Modified: 19.4.1996 / 15:28:15 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   322
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   323
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   324
newDay:dayInYear year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   325
    "return a new Date, given the year and the day-in-year (starting at 1).
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   326
     See also: Date today / Time now / Timestamp now.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
     ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   329
    |monthAndDay|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   330
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   331
    (dayInYear between:1 and:365) ifFalse:[
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   332
        (dayInYear > 0 or:[(dayInYear == 366) and:[self leapYear:year]]) ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   333
            "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   334
             this error is triggered, when you try to create a
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   335
             day from an invalid day-in-year; 
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   336
             for example, 366 in a non-leap year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   337
             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
   338
            "
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   339
            ^ self conversionErrorSignal raiseErrorString:' - invalid day in year'.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   340
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   342
    monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   343
    ^ self basicNew year:year month:(monthAndDay at:1) day:(monthAndDay at:2)  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
     Date newDay:150 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
     Date newDay:1 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
     Date newDay:1 year:1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   349
     Date newDay:1 year:1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   350
     Date newDay:365 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
     Date newDay:366 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   352
     Date newDay:365 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   353
     Date newDay:366 year:1994
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   354
     Date newDay:0 year:1994
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   355
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   356
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   357
    "Modified: 1.7.1996 / 14:22:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   358
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
readFrom:aStringOrStream onError:exceptionBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   361
    "return a new Date, reading a printed representation from aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
     Notice, that this is not the storeString format and 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
     is different from the format expected by readFrom:.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
     BUG:
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   365
       This method handles american format (i.e. month/day/year),
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   366
       common format with letter month in the middle (10 December 2007)
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   367
       and ISO format (yyyy-mm-dd) - as long as yyyy is > 12.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   368
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   369
       It does not handle the german/french and other dd-mm-yyyy.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   370
       use readFrom:printFormat:onError: for this."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   371
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   372
    ^ [
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   373
        |str items first second month day year|
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   374
        str := aStringOrStream readStream.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   375
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   376
        items := #(1 2 3) collect:[:idx|
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   377
            [str peek isLetterOrDigit] whileFalse:[str next].
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   378
            (str peek isDigit) ifTrue:[
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   379
                Integer readFrom:str
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   380
            ] ifFalse:[
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   381
                str nextAlphaNumericWord
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   382
            ].
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   383
        ].
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   384
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   385
        first := items at:1.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   386
        second := items at:2.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   387
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   388
        (first isInteger and:[second isInteger and:[first > 12]]) ifTrue:[
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   389
            "ISO Date: yyyy-mm-dd"
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   390
            year := first.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   391
            month := second.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   392
            day := items at:3.
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   393
        ] ifFalse:[
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   394
            second isInteger ifTrue:[
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   395
                "must be an american date mm/dd/yy"
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   396
                month := first.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   397
                day := second.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   398
            ] ifFalse:[
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   399
                "3 Dec 2007"
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   400
                day := first.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   401
                month := second.
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   402
            ].
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   403
            year := items at:3.
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   404
        ].
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   405
        (year between:0 and:99) ifTrue:[
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   406
            year := UserPreferences current twoDigitDateHandler value:year.
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   407
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   408
        self newDay:day month:month year:year
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   409
    ] on:Error do:exceptionBlock.
699
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   412
     Date readFromString:'31 December 1992'  
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   413
     Date readFrom:'19:11:1999'  
10760
70bdfdb519e3 #readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents: 10056
diff changeset
   414
     Date readFrom:'2007-12-31' onError:'wrong date'.  
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   415
     Date readFromString:'December, 5 1992'  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   416
     Date readFromString:'12/31/1992'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   417
     Date readFromString:'3-jan-95'           
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   418
     Date readFromString:'3-jan-01'           
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   419
     Date readFromString:'12/31/01'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   420
     Date readFromString:'15.4.1992'         -> german; leads to an error
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   421
     Date readFromString:'10.4.1992'         -> german; leads to a wrong date
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   422
     Date readFromString:'10.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   423
     Date readFromString:'32.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   424
     Date readFromString:'fooBar' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   425
     Date readFromString:'10.4' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   426
     Date readFromString:'10041999' onError:['wrong date']  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   427
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   428
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   429
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   430
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   431
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   432
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   433
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   434
    "return a new Date, reading a printed representation from aStream.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   435
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   436
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   437
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   438
         3   year position (1..3)
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   439
     or a formatString (see printing instance protocol)."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   440
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   441
    ^ self 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   442
        readFrom:aStringOrStream
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   443
        printFormat:aSqueakFormatArrayOrFormatString 
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   444
        onError:[ self conversionErrorSignal raise ]
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   445
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   446
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   447
     Date readFrom:'19:11:1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   448
     Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   449
     Date readFrom:'19:11:1999' printFormat:#( 2 1 3 )  -> exception: wrong month
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   450
     Date readFrom:'5:12:1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   451
     Date readFrom:'may-12-1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   452
     Date readFrom:'1999 may 12' printFormat:#( 3 2 1 )  
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   453
     Date readFrom:'12/31/2001' printFormat:#( 2 1 3 ) 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   454
     Date readFrom:' 31.08.2001' printFormat:#( 1 2 3 )    
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   455
     Date readFrom:' 31.dec.2001' printFormat:#( 1 2 3 )    
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   456
     Date readFrom:' 31.Dec.2001' printFormat:#( 1 2 3 )    
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   457
     Date readFrom:' 31.dez.2001' printFormat:#( 1 2 3 )    
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   458
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   459
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   460
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   461
     Date readFrom:'01' printFormat:'%y' onError:'fail'        
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   462
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'       
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   463
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   464
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   465
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   466
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   467
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   468
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   469
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString language:languageOrNil onError:exceptionBlock
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   470
    "return a new Date, reading a printed representation from aStream.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   471
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   472
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   473
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   474
         3   year position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   475
     or a formatString (see printing instance protocol).
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   476
     For now %d, %m, %monthName, %shortMonthName and %y are supported in the formatString.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   477
     The formatString can have any of these characters '-.:,;/' as separator. 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   478
     The formatString can also use a space as separator (for  ex. '%d %m %y') and any separator will be allowed.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   479
     However, when a character separator is defined, only that separator will be expected.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   480
     TODO: make this a general feature of all DateAndTime classes.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   481
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   482
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   483
    |str day month year somePartAssoc|
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   484
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   485
    str := aStringOrStream readStream.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   486
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   487
    aSqueakFormatArrayOrFormatString isArray 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   488
        ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   489
            [
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   490
                |arg|
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   491
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   492
                arg := Array new:3.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   493
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   494
                1 to:3 do:[:i||v|
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   495
                    [str peek isLetterOrDigit] whileFalse:[str next].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   496
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   497
                    v := (str peek isDigit) ifTrue:[Integer readFrom:str]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   498
                                           ifFalse:[str nextAlphaNumericWord].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   499
                    arg at:i put:v
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   500
                ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   501
                year := (arg at:(aSqueakFormatArrayOrFormatString at:3)).
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   502
                day := arg at:(aSqueakFormatArrayOrFormatString at:1).
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   503
                month := arg at:(aSqueakFormatArrayOrFormatString at:2).
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   504
            ] on:Error do:[:ex| ^ exceptionBlock value].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   505
        ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   506
            [
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   507
                |formatStream fc c sel|
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   508
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   509
                formatStream := aSqueakFormatArrayOrFormatString readStream.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   510
                
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   511
                [formatStream atEnd] whileFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   512
                    fc := formatStream next.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   513
                    fc == $% ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   514
                        sel := ''.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   515
                        (fc := formatStream peek) notNil ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   516
                            fc = $( ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   517
                                formatStream next.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   518
                                sel := formatStream upTo:$)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   519
                            ] ifFalse:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   520
                                sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter])
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   521
                            ]
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   522
                        ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   523
                        somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   524
                        somePartAssoc key == #day ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   525
                            day := somePartAssoc value.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   526
                        ] ifFalse:[
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   527
                            somePartAssoc key == #month ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   528
                                month := somePartAssoc value.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   529
                            ] ifFalse:[
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   530
                                somePartAssoc key == #year ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   531
                                    year := somePartAssoc value.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   532
                                ] ifFalse:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   533
                                    self error:'oops'
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   534
                                ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   535
                            ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   536
                        ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   537
                    ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   538
                        fc == Character space ifTrue:[
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   539
                            "/ Skip most possible separator characters 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   540
                            "/ (if not enought, should check for isNationalAlphaNumeric instead)
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   541
                            [(c := str peek) isSeparator or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c ] ] whileTrue:[ str next ].    
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   542
                        ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   543
                            str skipSeparators.
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   544
                            str next == fc ifFalse:[^ exceptionBlock value].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   545
                            str skipSeparators.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   546
                        ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   547
                    ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   548
                ].
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   549
            ] on:Error do:[:ex| ^ exceptionBlock value].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   550
        ].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   551
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   552
    day isNil ifTrue:[ day := 1 ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   553
    month isNil ifTrue:[ month := 1 ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   554
    year isNil ifTrue:[ year := Date today year ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   555
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   556
    (year between:0 and:99) ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   557
        year := UserPreferences current twoDigitDateHandler value:year.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   558
    ].
8878
7c7825a1f269 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8795
diff changeset
   559
    [
7c7825a1f269 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8795
diff changeset
   560
        ^ self newDay:day month:month year:year.
7c7825a1f269 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8795
diff changeset
   561
    ] on:Error do:[:ex| ^ exceptionBlock value].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   562
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   563
    "
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   564
     Date readFrom:'31 December 1992' printFormat:#(1 2 3) onError:'fail' 
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   565
     Date readFrom:'19:11:1999' printFormat:#(1 2 3) onError:'fail'  
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   566
     Date readFrom:'December, 5 1992' printFormat:#(1 2 3) onError:'fail' 
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   567
     Date readFrom:'3-jan-95' printFormat:#(1 2 3) onError:'fail'          
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   568
     Date readFrom:'12/31/1992' printFormat:#(1 2 3) onError:'fail'       
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   569
     Date readFrom:'15.4.1992' printFormat:#(1 2 3) onError:'wrong date'  -> german
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   570
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:'fail'        -> german
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   571
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   572
     Date readFrom:'32.4.1992' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   573
     Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   574
     Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date']
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   575
     Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date']  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   576
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   577
     Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail'       
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   578
     Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail'       
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   579
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   580
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   581
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   582
     Date readFrom:'01' printFormat:'%y' onError:'fail'       
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   583
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'     
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   584
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   585
     Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail'          
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   586
     Date readFrom:'3-März-1995' printFormat:'%d %monthName %y' language: #de onError:'fail'          
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   587
     Date readFrom:'3-mär-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'   
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   588
     Date readFrom:'3/mär/1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'  
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   589
     Date readFrom:'3/mär/1995' printFormat:'%d-%shortMonthName-%y' language: #de onError:'fail'          
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   590
     Date readFrom:'3-dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'          
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   591
     Date readFrom:'3-Dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'          
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   592
     Date readFrom:'3-Dezember-1995' printFormat:'%d %monthName %y' language: #de onError:'fail'          
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
   593
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   594
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   595
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   596
    "Created: 16.11.1995 / 22:50:17 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   597
    "Modified: 8.10.1996 / 19:25:39 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   598
!
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   599
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   600
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   601
    "return a new Date, reading a printed representation from aStream.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   602
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   603
         1   day position (1, 2 or 3)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   604
         2   month position (1..3)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   605
         3   year position (1..3)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   606
     or a formatString (see printing instance protocol).
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   607
     All of the %-formats as in the printString are supported here.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   608
     (i.e. %d, %m and %y, %shortMonthName and %monthName)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   609
     TODO: make this a general feature of all DateAndTime classes.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   610
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   611
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   612
    ^ self
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   613
        readFrom:aStringOrStream 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   614
        printFormat:aSqueakFormatArrayOrFormatString 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   615
        language:nil 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   616
        onError:exceptionBlock
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   617
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   618
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   619
     Date readFrom:'31 December 1992' printFormat:#(1 2 3) onError:'fail' 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   620
     Date readFrom:'19:11:1999' printFormat:#(1 2 3) onError:'fail'  
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   621
     Date readFrom:'December, 5 1992' printFormat:#(1 2 3) onError:'fail' 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   622
     Date readFrom:'3-jan-95' printFormat:#(1 2 3) onError:'fail'          
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   623
     Date readFrom:'12/31/1992' printFormat:#(1 2 3) onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   624
     Date readFrom:'15.4.1992' printFormat:#(1 2 3) onError:'wrong date'  -> german
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   625
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:'fail'        -> german
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   626
     Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:['wrong date']
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   627
     Date readFrom:'32.4.1992' printFormat:#(1 2 3) onError:['wrong date']
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   628
     Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date']
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   629
     Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date']
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   630
     Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date']  
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   631
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   632
     Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   633
     Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   634
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   635
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   636
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   637
     Date readFrom:'01' printFormat:'%y' onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   638
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   639
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   640
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   641
    "Created: 16.11.1995 / 22:50:17 / cg"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   642
    "Modified: 8.10.1996 / 19:25:39 / cg"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   643
!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   644
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   645
today
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   646
    "return a date, representing today.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   647
     See also: Time now / Timestamp now."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   649
    ^ self fromOSTime:(OperatingSystem getOSTime)
699
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
     Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   653
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   654
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   655
    "Modified: 1.7.1996 / 15:20:16 / cg"
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   656
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   657
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   658
tomorrow
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   659
    "return a date, representing tomorrow.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   660
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   661
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   662
    ^ Date today addDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   663
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   664
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   665
     Date tomorrow 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   666
     Date tomorrow dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   667
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   668
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   669
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   670
utcToday
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   671
    "return a date, representing today.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   672
     See also: Time now / Timestamp now."
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   673
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   674
    ^ self new fromUtcOSTime:(OperatingSystem getOSTime)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   675
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   676
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   677
     Date today
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   678
     Date utcToday
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   679
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   680
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   681
    "Modified: 1.7.1996 / 15:20:16 / cg"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   682
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   683
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   684
yesterday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   685
    "return a date, representing yesterday.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   686
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   687
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   688
    ^ Date today subtractDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   689
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   690
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   691
     Date yesterday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   692
     Date yesterday dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   693
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   694
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   695
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   696
!Date class methodsFor:'Compatibility-Dolphin'!
6872
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   697
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   698
newDay:day monthIndex:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   699
    ^ self newDay:day month:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   700
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   701
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   702
     Date newDay:8 monthIndex:5 year:1993
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   703
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   704
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   705
    "Modified: 19.4.1996 / 15:28:15 / cg"
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   706
! !
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   707
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   708
!Date class methodsFor:'Compatibility-ST80'!
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   709
7648
61b7826a9a0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7646
diff changeset
   710
newDay:day monthNumber:monthIndex year:year
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   711
    "ST80 compatibility"
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   712
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   713
    ^ self newDay:day month:monthIndex year:year
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   714
! !
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   715
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   716
!Date class methodsFor:'Compatibility-Squeak'!
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   717
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   718
current
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   719
    "return the current date"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   720
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   721
    ^ self today
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   722
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   723
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   724
     Date current
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   725
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   726
!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   727
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   728
fromSeconds:seconds
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   729
    "Answer an instance of me which is 'seconds' seconds after January 1, 1901."
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   730
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   731
    | secondsInDay |
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   732
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   733
    secondsInDay := 24 * 60 * 60.
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   734
    ^self fromDays: seconds // secondsInDay
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   735
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   736
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   737
     Date fromSeconds:0
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   738
     Date fromSeconds:(24 * 60 * 60 * 365)
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   739
    "
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   740
!
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   741
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   742
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   743
    "return a new Date, reading a printed representation from aStream.
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   744
     Notice, that this is not the storeString format and 
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   745
     is different from the format expected by readFrom:"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   746
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   747
    ^ [
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   748
        |str monthString month dayString day year yearString|
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   749
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   750
        str := aStringOrStream readStream.
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   751
        monthString := str next:2.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   752
        dayString := str next:2.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   753
        yearString := str next:4.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   754
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   755
        day := Integer readFrom:dayString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   756
        month := Integer readFrom:monthString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   757
        year := Integer readFrom:yearString.
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   758
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   759
        self newDay:day month:month year:year
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   760
    ] on:Error do:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   761
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   762
    "
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   763
     Date readMMDDYYYYFrom:'10041999' onError:['wrong date']  
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   764
     Date readMMDDYYYYFrom:'100419' onError:['wrong date']  
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   765
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   766
     Date readMMDDYYYYFrom:'10040001' onError:['wrong date']  
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   767
    "
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   768
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   769
    "Created: 16.11.1995 / 22:50:17 / cg"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   770
    "Modified: 8.10.1996 / 19:25:39 / cg"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   771
!
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   772
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   773
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   774
    "return a new Date, reading a printed representation from aStream.
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   775
     Notice, that this is not the storeString format and 
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   776
     is different from the format expected by readFrom:"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   777
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   778
    ^ [
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   779
        |str monthString month dayString day yearString year|
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   780
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   781
        str := aStringOrStream readStream.
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   782
        yearString := str next:4.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   783
        monthString := str next:2.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   784
        dayString := str next:2.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   785
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   786
        day := Integer readFrom:dayString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   787
        month := Integer readFrom:monthString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   788
        year := Integer readFrom:yearString.
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   789
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   790
        self newDay:day month:month year:year
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   791
    ] on:Error do:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   792
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   793
    "
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   794
     Date readYYYYMMDDFrom:'19991004' onError:['wrong date']  
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   795
     Date readYYYYMMDDFrom:'911004' onError:['wrong date']  
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   796
    "
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   797
! !
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   798
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   799
11553
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   800
!Date class methodsFor:'change & update'!
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   801
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   802
update:something with:aParameter from:changedObject
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   803
    ((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   804
        "just remember change for next access"
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   805
        EnvironmentChange := true
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   806
    ]
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   807
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   808
    "Created: 15.6.1996 / 15:19:25 / cg"
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   809
! !
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
   810
11127
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   811
!Date class methodsFor:'error handling'!
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   812
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   813
conversionErrorSignal
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   814
    "return the signal used for conversion error handling"
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   815
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   816
    ^ DateConversionError
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   817
! !
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   818
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   819
!Date class methodsFor:'general queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   820
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   821
abbreviatedNameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   822
    "given a day index (1..7), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   823
     of the day"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   824
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   825
    ^ self abbreviatedNameOfDay:dayIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   826
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   827
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   828
     Date abbreviatedNameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   829
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   830
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   831
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   832
abbreviatedNameOfDay:dayIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   833
    "given a day index (1..7), return the abbreviated name
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   834
     of the day.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   835
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   836
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   837
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   838
    ^ (self dayAbbrevsForLanguage:lang) at:dayIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   839
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   840
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   841
     Date abbreviatedNameOfDay:4 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   842
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   843
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   844
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   845
abbreviatedNameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   846
    "given a month index (1..12), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   847
     of the month"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   848
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   849
    ^ self abbreviatedNameOfMonth:monthIndex language:nil
699
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   852
     Date abbreviatedNameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   853
     Date abbreviatedNameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   854
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   855
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   856
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   857
abbreviatedNameOfMonth:monthIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   858
    "given a month index (1..12), return the abbreviated name
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   859
     of the month.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   860
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   861
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   862
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   863
    ^ (self monthAbbrevsForLanguage:lang) at:monthIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   864
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   865
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   866
     Date abbreviatedNameOfMonth:11 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   867
     Date abbreviatedNameOfMonth:12 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   868
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   869
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   870
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   871
dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   872
    "return an array containing the date and time of now"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   873
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   874
    ^ Time dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   875
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   876
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   877
     Date dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   878
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   879
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   880
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   881
dayOfFirstWeekInYear:aYear
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   882
    "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
   883
     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
   884
     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
   885
     (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
   886
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   887
    |day dayInWeekOf1stJan firstThursday firstDayInWeek|
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   888
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   889
    "/ find the first thursday ...
11127
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
   890
    day := Date newDay:1 year:aYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   891
    dayInWeekOf1stJan := day dayInWeek.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   892
    dayInWeekOf1stJan > 4 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   893
        firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   894
    ] ifFalse:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   895
        firstThursday := day addDays:(4 - dayInWeekOf1stJan).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   896
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   897
    "/ back to the preceeding monday
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   898
    firstDayInWeek := firstThursday subtractDays:3.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   899
    ^ firstDayInWeek
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   900
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   901
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   902
     Date dayOfFirstWeekInYear:1998   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   903
     Date dayOfFirstWeekInYear:1999    
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   904
     Date dayOfFirstWeekInYear:2000  
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   905
     Date dayOfFirstWeekInYear:2001   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   906
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   907
!
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   908
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   909
dayOfWeek:dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   910
    "given the name of a day (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   911
     return the day-index (1 for monday; 7 for sunday).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   912
     Return 0 for invalid day name"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   913
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   914
    |d|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   915
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   916
    d := self dayOfWeek:dayName language:nil.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   917
    d == 0 ifTrue:[
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   918
        d := self dayOfWeek:dayName language:'en'.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   919
    ].
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   920
    ^ d
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   921
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   922
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   923
     Date dayOfWeek:'wednesday' 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   924
     Date dayOfWeek:'Wednesday' 
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
   925
     Date dayOfWeek:'Mittwoch' 
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   926
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   927
!
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   928
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   929
dayOfWeek:dayName language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   930
    "given the name of a day (either string or symbol),
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   931
     return the day-index (1 for monday; 7 for sunday).
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   932
     Return 0 for invalid day name.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   933
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   934
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   935
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   936
    |idx langDayNames|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   937
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   938
    langDayNames := self dayNamesForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   939
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   940
    idx := langDayNames indexOf:dayName.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   941
    idx == 0 ifTrue:[
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   942
        idx := langDayNames indexOf:dayName asLowercase.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   943
    ].
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   944
    ^ idx
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   945
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   946
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   947
     Date dayOfWeek:'wednesday' language:'en'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   948
     Date dayOfWeek:'Wednesday' language:'en'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   949
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   950
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   951
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   952
daysInMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   953
    "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
   954
     of days this month has (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   955
     return 0 if the month name was invalid.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   956
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   957
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   958
    |monthIndex "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   959
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   960
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   961
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   962
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   963
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   964
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   965
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   966
    ^ self daysInMonthIndex:monthIndex forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   967
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   968
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   969
     Date daysInMonth:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   970
     Date daysInMonth:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   971
     Date daysInMonth:'feb' forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   972
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   973
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   974
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   975
daysInYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   976
    "return the number of days in a year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   977
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   978
    (self leapYear:yearInteger) ifTrue:[^ 366].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   979
    ^ 365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   981
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   982
     Date daysInYear:1900  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   983
     Date daysInYear:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   984
     Date daysInYear:1904 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   985
     Date daysInYear:1980 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   986
     Date daysInYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   987
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   988
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   989
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   990
daysUntilMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   991
    "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
   992
     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
   993
     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
   994
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   995
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
   996
    |monthIndex|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   997
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   998
    month isInteger ifTrue:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
   999
        monthIndex := month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1000
    ] ifFalse:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1001
        monthIndex := self indexOfMonth:month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1002
    ].
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1003
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1004
    ^ self daysUntilMonthIndex:monthIndex forYear:yearInteger
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1005
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1006
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1007
     Date daysUntilMonth:'feb' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1008
     Date daysUntilMonth:'jan' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1009
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1010
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1011
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1012
defaultFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1013
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1014
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1015
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1016
    ^ DefaultFormats at:Language ifAbsent:(DefaultFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1017
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1018
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1019
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1020
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1021
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1022
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1023
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1024
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1025
firstDayOfYear:inYear
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1026
    "return the weekDay-index of the 1st-january of the given year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1027
     1->monday, 2->tuesday, ... 7->sunday"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1028
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1029
    | t d |
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1030
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1031
    ((inYear < 1) or:[ inYear > 9999]) ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1032
        ^ 0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1033
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1034
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1035
    "/ normal Gregorian calendar: one extra day per four years 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1036
    t := 4 + inYear + ((inYear + 3) // 4).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1037
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1038
    inYear > 1800 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1039
        "/ Julian calendar: regular Gregorian less 3 days per 400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1040
        t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1041
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1042
    inYear > 1752 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1043
        "/ calendar changeover
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1044
        t := t + 3.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1045
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1046
    d := t \\ 7.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1047
    "/ convert from 0 (sunday) .. 6 (saturday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1048
    "/ to 1 (munday) .. 7 (sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1049
    d == 0 ifTrue:[^ 7].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1050
    ^ d
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1051
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1052
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1053
     self firstDayOfYear:2000           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1054
     (Date newDay:1 year:2000) dayInWeek 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1055
     self firstDayOfYear:1999      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1056
     (Date newDay:1 year:1999) dayInWeek
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1057
     self firstDayOfYear:1998      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1058
     (Date newDay:1 year:1998) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1059
     self firstDayOfYear:2001           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1060
     (Date newDay:1 year:2001) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1061
     self firstDayOfYear:2002           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1062
     (Date newDay:1 year:2002) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1063
     self firstDayOfYear:2006           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1064
     (Date newDay:1 year:2006) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1065
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1066
     self firstDayOfYear:1800           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1067
     (Date newDay:1 year:1800) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1068
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1069
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1070
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1071
indexOfMonth:aMonthString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1072
    "given the name of a month (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1073
     return the month-index (1 for jan; 12 for december).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1074
     The given string may be a full or abbreviated name,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1075
     case is ignored.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1076
     Return 0 for invalid month name."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1077
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1078
    |monthIndex|
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1079
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1080
    monthIndex := self indexOfMonth:aMonthString language:nil.
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1081
    "/ if not found, retry in english
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1082
    (monthIndex == 0 and:[ Smalltalk language ~= 'en' ])
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1083
    ifTrue:[
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1084
        monthIndex := self indexOfMonth:aMonthString language:'en'.
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1085
    ].
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1086
    ^ monthIndex
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1087
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1088
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1089
     Date indexOfMonth:'jan'
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1090
     Date indexOfMonth:'Jan'  
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1091
     Date indexOfMonth:'December'
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1092
     Date indexOfMonth:'Dezember' 
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1093
     Date indexOfMonth:'december' 
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1094
     Date indexOfMonth:'dezember' 
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1095
    "
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1096
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1097
    "Modified: / 08-10-2006 / 14:22:06 / cg"
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1098
!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1099
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1100
indexOfMonth:aMonthString language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1101
    "given the name of a month (either string or symbol),
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1102
     return the month-index (1 for jan; 12 for december).
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1103
     The given string may be a full or abbreviated name,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1104
     case is ignored.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1105
     Return 0 for invalid month name.
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1106
     For nil, Smalltalk language (i.e. the current language setting) is used,
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1107
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1108
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1109
    |idx name langMonthNames langMonthAbbrevs|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1110
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1111
    langMonthNames := self monthNamesForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1112
    langMonthAbbrevs := self monthAbbrevsForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1113
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1114
    name := aMonthString asLowercase.
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1115
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1116
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1117
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1118
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1119
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1120
    name at:1 put:(name at:1) asUppercase.
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1121
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1122
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1123
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1124
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1125
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1126
    ^ idx
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1127
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1128
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1129
     Date indexOfMonth:'jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1130
     Date indexOfMonth:'Jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1131
     Date indexOfMonth:'December' language:#en 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1132
    "
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1133
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1134
    "Modified: / 08-10-2006 / 14:20:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1135
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1136
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1137
leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1138
    "return true, if yearInteger is a leap year."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1139
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1140
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1141
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1142
    y := yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1143
    (y \\ 4 == 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1144
	(y \\ 100 ~~ 0) ifTrue:[^ true].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1145
	(y \\ 400 == 0) ifTrue:[^ true]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1146
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1147
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1148
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1149
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1150
     Date leapYear:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1151
     Date leapYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1152
     Date leapYear:1900
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1153
     Date leapYear:2000
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1154
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1155
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1156
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1157
longFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1158
    (LongFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1159
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1160
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1161
    ^ LongFormats at:Language ifAbsent:(LongFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1162
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1163
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1164
     Date today printStringFormat:(Date defaultFormatString). 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1165
     Date today printStringFormat:(Date longFormatString).    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1166
     Date today printStringFormat:(Date shortFormatString).   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1167
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1168
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1169
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1170
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1171
    "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
  1172
     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
  1173
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1174
    |restDays daysInMonth|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1175
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1176
    restDays := aDayInYear.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1177
    restDays < 1 ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1178
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1179
    1 to:12 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1180
	daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1181
	restDays <= daysInMonth ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1182
	    ^ Array with:m with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1183
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1184
	restDays := restDays - daysInMonth 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1185
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1186
    restDays > daysInMonth ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1187
    ^ Array with:12 with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1188
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1189
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1190
     Date monthAndDayFromDayInYear:66 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1191
     Date monthAndDayFromDayInYear:66 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1192
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1193
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1194
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1195
nameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1196
    "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
  1197
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1198
    ^ self nameOfDay:dayIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1199
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1200
    "
8795
7fc3fbba3b63 comment
Claus Gittinger <cg@exept.de>
parents: 8626
diff changeset
  1201
     Date nameOfDay:1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1202
     Date nameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1203
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1204
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1205
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1206
nameOfDay:dayIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1207
    "given a day index (1..7), return the name of the day.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1208
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1209
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1210
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1211
    ^ (self dayNamesForLanguage:lang) at:dayIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1212
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1213
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1214
     Date nameOfDay:4 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1215
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1216
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1217
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1218
nameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1219
    "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
  1220
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1221
    ^ self nameOfMonth:monthIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1222
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1223
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1224
     Date nameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1225
     Date nameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1226
     Date nameOfMonth:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1227
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1228
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1229
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1230
nameOfMonth:monthIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1231
    "given a month index (1..12), return the name of the month.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1232
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1233
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1234
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1235
    ^ (self monthNamesForLanguage:lang) at:monthIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1236
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1237
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1238
     Date nameOfMonth:11 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1239
     Date nameOfMonth:12 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1240
     Date nameOfMonth:4  language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1241
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1242
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1243
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1244
shortFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1245
    (ShortFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1246
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1247
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1248
    ^ ShortFormats at:Language ifAbsent:(ShortFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1249
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1250
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1251
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1252
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1253
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1254
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1255
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1256
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1257
weekInYearOf:aDateOrTimestamp
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1258
    "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
  1259
     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
  1260
     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
  1261
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1262
    |date dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1263
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1264
    date := aDateOrTimestamp asDate.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1265
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1266
    dayInYear := date dayInYear.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1267
    dayOfFirstWeekInYear := self dayOfFirstWeekInYear:date year.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1268
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1269
    numDays := date subtractDate:dayOfFirstWeekInYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1270
    "/ 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
  1271
    numDays < 0 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1272
        "/ not in a week here ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1273
        "/ can be either 52 or 53, depending on the previous year.
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1274
        ^ self weekInYearOf:(Date newDay:31 month:12 year:date year - 1)
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1275
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1276
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1277
    "/ compute the week 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1278
    week := numDays // 7 + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1279
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1280
    "/ 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
  1281
    week == 53 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1282
        dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1.
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  1283
        date >= dayOfFirstWeekInNextYear ifTrue:[
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1284
            ^ 1
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1285
        ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1286
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1287
    ^ week
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1288
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1289
    "
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1290
     Timestamp now weekInYear    
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1291
     Date weekInYearOf:(Date newDay:31 month:12 year:1999)     was a friday; 
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1292
     Date weekInYearOf:(Timestamp newDay:1 year:2000)    was a saturday; therefore last week of 1999
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1293
     Date weekInYearOf:(Timestamp newDay:2 year:2000)    was a sunday; therefore last week of 1999
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1294
     Date weekInYearOf:(Timestamp newDay:3 year:2000)    was a monday -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1295
     Date weekInYearOf:(Timestamp newDay:4 year:2000)    was a tuesday -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1296
     Date weekInYearOf:(Timestamp newDay:5 year:2000)    was a wed    -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1297
     Date weekInYearOf:(Timestamp newDay:6 year:2000)    was a thursday -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1298
     Date weekInYearOf:(Timestamp newDay:7 year:2000)    was a fri    -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1299
     Date weekInYearOf:(Timestamp newDay:8 year:2000)    was a sat   -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1300
     Date weekInYearOf:(Timestamp newDay:9 year:2000)    was a sun   -> W01
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1301
     Date weekInYearOf:(Timestamp newDay:10 year:2000)   was a monday -> W02
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1302
     Date weekInYearOf:(Timestamp newDay:16 year:2000)   was a sunday -> W02
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1303
     Date weekInYearOf:(Timestamp newDay:17 year:2000)   was a monday -> W03
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1304
     Date weekInYearOf:(Date newDay:1 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1305
     Date weekInYearOf:(Date newDay:2 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1306
     Date weekInYearOf:(Date newDay:3 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1307
     Date weekInYearOf:(Date newDay:24 month:12 year:2001)   -> W52
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1308
     Date weekInYearOf:(Date newDay:30 month:12 year:2001)   -> W52
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1309
     Date weekInYearOf:(Date newDay:31 month:12 year:2001)   -> W01
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1310
     Date weekInYearOf:(Date newDay:1 month:1 year:2002)    
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1311
     Date weekInYearOf:(Date newDay:2 month:1 year:2002)      
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1312
     Date weekInYearOf:(Date newDay:7 month:1 year:2002)      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1313
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1314
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1315
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1316
yearAsDays: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1317
    "Returns the number of days since Jan 1, 1901. (GNU)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1318
     to the first Jan of the year, yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1319
     For 1901 this is zero, for 1902 its 365.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1320
     Defined for years >= 1901"
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
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1323
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1324
    y := yearInteger - 1900.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1325
    y := y - 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1326
    ^ (y * 365)
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1327
        + (y // 4)
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1328
        - (y // 100)
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1329
        + ((y + 300) // 400)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1330
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1331
    "
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1332
     Date yearAsDays:5 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1333
     Date yearAsDays:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1334
     Date yearAsDays:1902   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
     Date yearAsDays:1903   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1336
     Date yearAsDays:1904    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1337
     Date yearAsDays:1905     
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1338
     Date yearAsDays:1994   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1339
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1340
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1341
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1342
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1343
!Date class methodsFor:'obsolete'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1344
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1345
day:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1346
    "return a new Date, given the day, month and year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1347
     Obsolete:
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1348
        use newDay:month:year: for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1349
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1350
    <resource: #obsolete>
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1351
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1352
    ^ self newDay:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1353
!
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1354
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1355
day:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1356
    "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
  1357
     Obsolete:
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1358
        use newDay:year: for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1359
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1360
    <resource: #obsolete>
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1361
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1362
    ^ self newDay:dayInYear year:year
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1363
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1364
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1365
isLeapYear:yearInteger
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1366
    "Return true, if a year is a leap year.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1367
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1368
         Please use the ST-80 compatible #leapYear for new programs, 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1369
         since this method will vanish."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1370
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1371
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1372
    ^ self leapYear:yearInteger
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1373
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1374
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1375
!Date class methodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1376
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1377
abbreviatedMonthNamesForLanguage:language
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1378
    |langMonthAbbrevs lang|
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1379
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1380
    (MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1381
        self initNames
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1382
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1383
    lang := language ? Smalltalk language.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1384
    langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:nil.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1385
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1386
    "/ If language is not found, try to initialize it from the resources and try again
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1387
    langMonthAbbrevs isNil ifTrue:[ 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1388
        self initNamesForLanguage: lang.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1389
        "/ If language initialization failed, take english monthAbbrevs
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1390
        langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:[MonthAbbrevs at:#en.].
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1391
    ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1392
    ^ langMonthAbbrevs
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1393
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1394
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1395
     self abbreviatedMonthNamesForLanguage:#en
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1396
     self abbreviatedMonthNamesForLanguage:#de
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1397
     self abbreviatedMonthNamesForLanguage:#fr
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1398
     self abbreviatedMonthNamesForLanguage:#es
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1399
    "
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1400
!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1401
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1402
dayAbbrevsForLanguage:language
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1403
    |langDayAbbrevs lang|
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1404
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1405
    (DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1406
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1407
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1408
    lang := language ? Smalltalk language.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1409
    langDayAbbrevs := DayAbbrevs at:lang ifAbsent:nil.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1410
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1411
    "/ If language is not found, try to initialize it from the resources and try again
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1412
    langDayAbbrevs isNil ifTrue:[ 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1413
        self initNamesForLanguage: lang.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1414
        "/ If language initialization failed, take english dayAbbrevs
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1415
        langDayAbbrevs := DayAbbrevs at:lang ifAbsent:[DayAbbrevs at:#en.].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1416
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1417
    ^ langDayAbbrevs
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1418
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1419
    "
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1420
     self dayAbbrevsForLanguage:#en
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1421
     self dayAbbrevsForLanguage:#de
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1422
     self dayAbbrevsForLanguage:#fr
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1423
     self dayAbbrevsForLanguage:#es
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1424
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1425
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1426
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1427
dayNamesForLanguage:language
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1428
    |langDayNames lang|
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1429
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1430
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1431
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1432
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1433
    lang := language ? Smalltalk language.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1434
    langDayNames := DayNames at:lang ifAbsent:nil.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1435
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1436
    "/ If language is not found, try to initialize it from the resources and try again
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1437
    langDayNames isNil ifTrue:[ 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1438
        self initNamesForLanguage: lang.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1439
        "/ If language initialization failed, take english dayNames
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1440
        langDayNames := DayNames at:lang ifAbsent:[DayNames at:#en].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1441
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1442
    ^ langDayNames
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1443
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1444
    "
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1445
     self dayNamesForLanguage:#en
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1446
     self dayNamesForLanguage:#de
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1447
     self dayNamesForLanguage:#fr
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1448
     self dayNamesForLanguage:#es
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1449
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1450
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1451
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1452
daysInMonthIndex: monthIndex forYear: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1453
    "return the number of days in month monthIndex of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1454
     year yearInteger (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1455
     Return 0 for invalid month index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1456
     This is the internal version of daysInMonth:forYear:"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1457
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1458
    |days|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1459
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1460
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1461
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1462
    days := #(31 28 31           "Jan Feb Mar"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1463
	      30 31 30           "Apr May Jun"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1464
	      31 31 30           "Jul Aug Sep"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1465
	      31 30 31           "Oct Nov Dec"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1466
	     ) at: monthIndex.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1467
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1468
    (monthIndex == 2) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1469
	(self leapYear:yearInteger) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1470
	    ^ days + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1471
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1472
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1473
    ^ days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1474
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1475
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1476
     Date daysInMonthIndex:2 forYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1477
     Date daysInMonthIndex:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1478
     Date daysInMonthIndex:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1479
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1480
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1481
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1482
daysUntilMonthIndex: monthIndex forYear: yearInteger
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1483
    "return the number of days in month monthIndex of
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1484
     year yearInteger (modified GNU).
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1485
     Return 0 for invalid month index.
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1486
     This is the internal version of daysInMonth:forYear:"
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1487
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1488
    |days|
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1489
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1490
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1491
       |sum|
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1492
       sum := 0.
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1493
       #(31 28 31          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1494
         30 31 30          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1495
         31 31 30          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1496
         31 30 31          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1497
        ) collect:[:each | |first| first:= sum. sum := sum + each. first]
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1498
                #(0 31 59 90 120 151 181 212 243 273 304 334)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1499
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1500
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1501
    (monthIndex between:1 and:12) ifFalse:[^ 0].
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1502
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1503
    days := #(0 31 59 90 120 151 181 212 243 273 304 334) at: monthIndex.
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1504
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1505
    (monthIndex > 2) ifTrue:[
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1506
        (self leapYear:yearInteger) ifTrue:[
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1507
            ^ days + 1
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1508
        ]
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1509
    ].
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1510
    ^ days
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1511
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1512
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1513
     Date daysUntilMonthIndex:3 forYear:1994
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1514
     Date daysUntilMonthIndex:3 forYear:1980
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1515
     Date daysUntilMonthIndex:3 forYear:1981
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1516
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1517
!
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1518
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1519
monthAbbrevsForLanguage:language
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1520
    <resource: #obsolete>
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1521
    "obsolete"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1522
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1523
    ^ self abbreviatedMonthNamesForLanguage:language
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1524
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1525
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1526
monthNamesForLanguage:language
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1527
    |langMonthNames lang|
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1528
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1529
    (MonthNames isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1530
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1531
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1532
    lang := language ? Smalltalk language.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1533
    langMonthNames := MonthNames at:lang ifAbsent:nil.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1534
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1535
    "/ If language is not found, try to initialize it from the resources and try again
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1536
    langMonthNames isNil ifTrue:[ 
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1537
        self initNamesForLanguage: lang.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1538
        "/ If language initialization failed, take english monthNames
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1539
        langMonthNames := MonthNames at:lang ifAbsent:[MonthNames at:#en.].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1540
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1541
    ^ langMonthNames
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1542
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1543
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1544
!Date class methodsFor:'private-encoding/decoding'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1545
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1546
encodeYear:y month:m day:d
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1547
    "the internal encoding is strictly private, 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1548
     and should not be used outside."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1549
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1550
    ^ (((y * 100) + m) * 100) + d
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1551
!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1552
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1553
readDatePartFrom:str format:fmt language:languageOrNil
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1554
    "read a single component (such as %shortName) from str"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1555
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1556
    |dayName monthName day month year format string |
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1557
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1558
    format := fmt.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1559
    string := str throughAnyForWhich:[:ch | ch isNationalAlphaNumeric].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1560
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1561
    ((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1562
        "/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1563
        dayName := string.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1564
        ^ nil.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1565
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1566
    (format sameAs:'d') ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1567
        day := Integer readFrom:string.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1568
        ^ #day -> day
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1569
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1570
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1571
    (format sameAs:'m') ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1572
        month := Integer readFrom:string.      
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1573
        ^ #month -> month
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1574
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1575
    (format sameAs:'monthName') ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1576
        monthName := string.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1577
        month := (Date monthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1578
"/        month == 0 ifTrue:[self error:'invalid month name'].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1579
        ^ #month -> month
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1580
    ].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1581
    (format sameAs:'shortMonthName') ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1582
        monthName := string.
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1583
        month := (Date abbreviatedMonthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1584
"/        month == 0 ifTrue:[self error:'invalid month name'].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1585
        ^ #month -> month
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1586
    ].
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1587
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1588
    format = 'y' ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1589
        year := Integer readFrom:string.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1590
        year < 100 ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1591
            ^ #year -> (year + 2000)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1592
        ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1593
        ^ #year -> year
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1594
    ].
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1595
    format = 'Y' ifTrue:[
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  1596
        year := Integer readFrom:string.
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1597
        year >= 100 ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1598
            ^ #year -> year
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1599
        ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1600
        ^ #year -> (year + 2000) 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1601
    ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1602
    self error:'unknown format specifier'
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1603
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1604
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  1605
!Date class methodsFor:'private-instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1606
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1607
fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1608
    "return a date, representing the date given by the operatingSystem time.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1609
     This somewhat clumsy implementation hides the OS's date representation
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1610
     (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
  1611
     Dont use this method, the osTime representation is totally unportable."
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1612
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1613
    ^ self basicNew fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1614
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1615
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1616
     Date fromOSTime:0              -> on UNIX: this should return 1st Jan 1970
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1617
                                       thats where Unix time starts
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1618
                                       On other systems, it may be something different.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1619
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1620
     Date fromOSTime:(24*60*60*1000) -> on UNIX: the day after
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1621
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1622
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1623
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  1624
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1625
!Date methodsFor:'Compatibility-ANSI'!
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1626
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1627
dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1628
    "return the week-day of the receiver - 1 is sunday, 7 for saturday.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1629
     WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday).  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1630
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1631
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1632
    |d|
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1633
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1634
    d := self dayInWeek.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1635
    d == 7 ifTrue:[
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1636
        ^ 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1637
    ].
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1638
    ^ d + 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1639
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1640
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1641
     Date today dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1642
     Date today dayInWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1643
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1644
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1645
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1646
dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1647
    "return the short week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1648
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1649
     Expect things like 'mon', 'tue' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1650
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1651
    ^ self abbreviatedDayName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1652
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1653
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1654
     Date today dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1655
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1656
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1657
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1658
dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1659
    "return the week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1660
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1661
     Expect things like 'monday', 'tuesday' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1662
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1663
    ^ self weekday
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1664
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1665
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1666
     Date today dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1667
     Date today dayOfWeekAbbreviation 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1668
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1669
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1670
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1671
dayOfYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1672
    "return the day-nr within the year of the receiver - 1..365/366"
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1673
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1674
    ^ self dayInYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1675
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1676
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1677
     Date today dayOfYear 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1678
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1679
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1680
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1681
monthAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1682
    "return the month of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1683
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1684
     Expect things like 'jan', 'feb' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1685
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1686
    ^ self abbreviatedMonthName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1687
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1688
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1689
     Date today monthAbbreviation  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1690
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1691
! !
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1692
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1693
!Date methodsFor:'Compatibility-ST80'!
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1694
11740
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1695
firstDayInMonth
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1696
    "Return the first day in the month of the receiver"
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1697
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1698
    ^ self subtractDays:(self dayOfMonth - 1)
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1699
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1700
    "
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1701
     Date today               
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1702
     Date today firstDayInMonth    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1703
     Date today firstDayInMonth subtractDays:1   
11740
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1704
     (Date today subtractDays:30) firstDayInMonth   
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1705
     (Date today subtractDays:122) firstDayInMonth   
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1706
     (Date today subtractDays:154) firstDayInMonth
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1707
    "
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1708
!
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  1709
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1710
lastDayInMonth 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1711
    "Return the last day in the month in which the receiver is."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1712
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1713
    ^ self addDays:(self daysInMonth - self day).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1714
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1715
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1716
     Date today       
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1717
     Date today lastDayInMonth        
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1718
     Date today lastDayInMonth addDays:1  
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1719
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1720
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1721
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1722
next:dayName 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1723
    "Return the next date whose weekday name is dayName.
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1724
     Caveat; dayName is expected to be in the current language"
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1725
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1726
    |ti ni|
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1727
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1728
    ti := self weekdayIndex.
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1729
    ni := (self class dayOfWeek:dayName).
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1730
    ^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ])
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1731
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1732
    "
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1733
     Date today              
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1734
     Date today next:#Friday
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1735
     Date today next:#Sunday 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1736
     Date today next:#Monday 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1737
     Date today next:#Thursday
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1738
     Date today next:#WednesDay
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1739
    "
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1740
!
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1741
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1742
nextDayWithIndex:dayIndex 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1743
    "Return the next date whose weekday name is dayName.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1744
     dayIndex is Monday=1, ... , Sunday=7"
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1745
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1746
    |ti|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1747
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1748
    self assert:(dayIndex between:1 and:7).
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1749
    ti := self weekdayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1750
    ^ self addDays:(dayIndex > ti ifTrue:[ dayIndex-ti ] ifFalse:[ 7+dayIndex-ti ])
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1751
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1752
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1753
     Date today              
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1754
     Date today nextDayWithIndex:5 - next Friday
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1755
     Date today nextDayWithIndex:7  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1756
     Date today nextDayWithIndex:1  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1757
     Date today nextDayWithIndex:4  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1758
     Date today nextDayWithIndex:3  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1759
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1760
!
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1761
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1762
previous:dayName 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1763
    "Return the previous date whose weekday name is dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1764
     Caveat; dayName is expected to be in the current language"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1765
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1766
    ^ self previousDayWithIndex:(self class dayOfWeek:dayName).
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1767
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1768
    "
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1769
     Date today                    
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1770
     Date today previous:#Montag 
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1771
     Date today previous:#Monday 
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1772
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1773
     Date today previous:#Friday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1774
     Date today previous:#Sunday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1775
     Date today previous:#Monday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1776
     Date today previous:#Thursday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1777
     Date today previous:#WednesDay 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  1778
     Date today previous:#TuesDay  
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1779
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1780
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1781
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1782
previousDayWithIndex:dayIndex
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1783
    "Return the previous date whose weekday name is dayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1784
     dayIndex is Monday=1, ... , Sunday=7"
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1785
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1786
    |ti|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1787
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1788
    self assert:(dayIndex between:1 and:7).
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1789
    ti := self weekdayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1790
    ^ self subtractDays:(((ti - dayIndex - 1) \\ 7) + 1)
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1791
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1792
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1793
     Date today                    
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1794
     Date today previousDayWithIndex:1 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1795
     Date today previousDayWithIndex:5  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1796
     Date today previousDayWithIndex:7  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1797
     Date today previousDayWithIndex:4  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1798
     Date today previousDayWithIndex:3 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1799
     Date today previousDayWithIndex:2  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1800
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1801
!
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1802
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1803
printFormat:aFormatArray
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1804
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1805
     Return a string containing a printed representation of the receiver.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1806
     The formatArray argument consists of 6 or 7 integers which control
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1807
     the resulting string. The entries are:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1808
     1   day position (1, 2 or 3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1809
     2   month position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1810
     3   year position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1811
     4   asciiValue of separator character or separator character
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1812
         or collection of 2 separator characters
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1813
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1814
         4: abbreviated uppercase 5: full uppercase)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1815
     6   year format (1 include century; 2 exclude century)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1816
     7  (optional) true/false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1817
         if true, print numbers in 2-digit format
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1818
         (i.e. with leading zeros); 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1819
         Taken as false, if ommited
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1820
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1821
     Day and monthnames are in the currently active language.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1822
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1823
     This method supports more options than the ST-80 version; month formats 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1824
     4 and 5, non-numeric separators and the optional 7th parameter are not 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1825
     supported by ST-80. Be aware of this for compatibility reasons.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1826
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1827
     Notice that not all formats can be scanned (correctly) by #readFrom:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1828
     This is an ST-80 compatibility method - I would have choosen another
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1829
     (less cryptic) formatString ...
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1830
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1831
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1832
    ^ self printFormat:aFormatArray forLanguage:nil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1833
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1834
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1835
     Date today printFormat:#(1 2 3 '' 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1836
     Date today printFormat:#(1 2 3 $- 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1837
     Date today printFormat:#(1 2 3 $. 1 2 true)     
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1838
     Date today printFormat:#(2 1 3 32 3 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1839
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1840
     Date today printFormat:#(1 2 3 $- 2 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1841
     Date today printFormat:#(1 2 3 $- 4 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1842
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1843
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1844
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1845
printFormat:aFormatArray forLanguage:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1846
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1847
     Return a string containing a printed representation of the receiver.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1848
     The formatArray argument consists of 6 or 7 integers which control
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1849
     the resulting string. The entries are:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1850
     1   day position (1, 2 or 3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1851
     2   month position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1852
     3   year position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1853
     4   asciiValue of separator character or separator character
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1854
         or collection of 2 separator characters
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1855
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1856
         4: abbreviated uppercase 5: full uppercase)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1857
     6   year format (1 include century; 2 exclude century)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1858
     7  (optional) true/false.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1859
         if true, print numbers in 2-digit format
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1860
         (i.e. with leading zeros); 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1861
         Taken as false, if ommited
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1862
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1863
     Day and monthnames are in the currently active language.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1864
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1865
     This method supports more options than the ST-80 version; month formats 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1866
     4 and 5, non-numeric separators and the optional 7th parameter are not 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1867
     supported by ST-80. Be aware of this for compatibility reasons.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1868
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1869
     Notice that not all formats can be scanned (correctly) by #readFrom:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1870
     This is an ST-80 compatibility method - I would have choosen another
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1871
     (less cryptic) formatString ...
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1872
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1873
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1874
    |mf upperCase day month year components sep1 sep2 leadingZeros|
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1875
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1876
    aFormatArray size > 6 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1877
        leadingZeros := aFormatArray at:7
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1878
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1879
        leadingZeros := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1880
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1881
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1882
    components := Array new:3.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1883
    day := self day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1884
    leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1885
        day := day printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1886
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1887
        day := day printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1888
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1889
    components at:(aFormatArray at:1) put:day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1890
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1891
    upperCase := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1892
    mf := aFormatArray at:5.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1893
    (mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1894
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1895
    mf == 1 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1896
        month := self month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1897
        leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1898
            month := month printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1899
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1900
            month := month printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1901
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1902
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1903
        mf == 2 ifTrue:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1904
            month := self abbreviatedMonthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1905
        ] ifFalse:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1906
            month := self monthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1907
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1908
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1909
    upperCase ifTrue:[month := month asUppercase].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1910
    components at:(aFormatArray at:2) put:month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1911
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1912
    year := self year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1913
    (aFormatArray at:6) == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1914
        year := year \\ 100.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1915
        year := year printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1916
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1917
    year := year printString.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1918
    components at:(aFormatArray at:3) put:year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1919
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1920
    sep1 := sep2 := (aFormatArray at:4).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1921
    sep1 isString ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1922
        sep1 isCollection ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1923
            sep2 := (sep1 at:2).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1924
            sep1 := (sep1 at:1).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1925
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1926
            sep1 := sep2 := sep1 asCharacter
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1927
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1928
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1929
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1930
    ^ (components at:1)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1931
      , sep1 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1932
      , (components at:2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1933
      , sep2 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1934
      , (components at:3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1935
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1936
    "
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1937
     Date today printFormat:#(1 2 3 '' 1 2)         
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1938
     Date today printFormat:#(1 2 3 $- 1 2)         
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1939
     Date today printFormat:#(1 2 3 $. 1 2 true)     
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1940
     Date today printFormat:#(2 1 3 32 3 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1941
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1942
     Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en           
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1943
     Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1944
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1945
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1946
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1947
printFormat:aFormatArray forLanguage:languageOrNil on:aStream
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1948
    "Obsolete, backward ST-80 compatible formatted printing - see comment
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1949
     in printFormat:.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1950
     Append a printed representation of the receiver to aStream.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1951
     The argument, aFormatString controls the format, as described
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1952
     in the #printFormat: method.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1953
     Notice that not all formats can be scanned (correctly) by #readFrom:"
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1954
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1955
    aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1956
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1957
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1958
    "european formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1959
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1960
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1961
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1962
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1963
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1964
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1965
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1966
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1967
     US formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1968
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1969
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1970
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1971
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1972
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1973
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1974
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1975
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1976
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1977
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1978
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1979
printFormat:aFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1980
    "Obsolete, backward ST-80 compatible formatted printing - see comment
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1981
     in printFormat:.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1982
     Append a printed representation of the receiver to aStream.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1983
     The argument, aFormatString controls the format, as described
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1984
     in the #printFormat: method.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1985
     Notice that not all formats can be scanned (correctly) by #readFrom:"
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1986
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1987
    aStream nextPutAll:(self printFormat:aFormatArray)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1988
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1989
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1990
    "european formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1991
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1992
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1993
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1994
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1995
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1996
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1997
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1998
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1999
     US formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2000
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2001
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2002
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2003
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2004
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2005
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2006
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2007
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2008
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2009
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2010
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2011
shortPrintString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2012
    "dummy - for now"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2013
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2014
    ^ self printString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2015
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2016
    "Created: 20.6.1997 / 17:16:48 / cg"
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2017
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2018
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2019
weekdayIndex
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2020
    "Return the day index; Monday=1, ... , Sunday=7"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2021
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2022
    ^ (self asDays + 1) \\ 7 + 1  "1 January 1901 was a Tuesday"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2023
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2024
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2025
     Date today dayName
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2026
     Date today weekdayIndex      
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2027
    "
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2028
! !
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2029
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2030
!Date methodsFor:'Compatibility-Squeak'!
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2031
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2032
mmddyyyy
4462
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2033
    "return a printed representation of the receiver in the
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2034
     form mmddyyyy.
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2035
     The receiver can be reconstructed with: 
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2036
        Date readMMDDYYYYFrom:aStringOrStream onError:[...]"
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2037
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2038
    ^ self printStringFormat:'%m%d%y'
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2039
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2040
"/    ^ (self month printStringLeftPaddedTo:2 with:$0)
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2041
"/       , (self day printStringLeftPaddedTo:2 with:$0) 
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2042
"/       , (self year printStringLeftPaddedTo:4 with:$0)
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2043
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2044
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2045
     Date today mmddyyyy
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2046
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2047
! !
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2048
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2049
!Date methodsFor:'accessing'!
241
6f30be88e314 *** empty log message ***
claus
parents: 202
diff changeset
  2050
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2051
abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2052
    "return the short week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2053
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2054
     Expect things like 'mon', 'tue' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2055
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2056
    ^ self class abbreviatedNameOfDay:(self dayInWeek)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2057
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2058
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2059
     Date today abbreviatedDayName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2060
     (Date newDay:15 month:4 year:1959) abbreviatedDayName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2061
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2062
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2063
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2064
abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2065
    "return the month of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2066
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2067
     Expect things like 'jan', 'feb' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2068
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2069
    ^ self class abbreviatedNameOfMonth:(self month)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2070
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2071
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2072
     Date today abbreviatedMonthName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2073
     (Date newDay:15 month:4 year:1959) abbreviatedMonthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2074
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2075
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2076
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2077
abbreviatedMonthNameForLanguage:lang
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2078
    "return the month of the receiver as a string.
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2079
     The returned string depends on the language setting.
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2080
     Expect things like 'jan', 'feb' ..."
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2081
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2082
    ^ self class abbreviatedNameOfMonth:(self month) language:lang
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2083
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2084
    "
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2085
     Date today abbreviatedMonthNameForLanguage:#en 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2086
     Date today abbreviatedMonthNameForLanguage:#de 
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2087
    "
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2088
!
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2089
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2090
asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2091
    "return the number of days elapsed since 01-Jan-1901
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2092
     and the receiver's day; starts with 0 for 1-1-1901.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2093
     Date>>fromDays: is the reverse operation.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2094
     For ST-80 compatibility."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2095
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2096
    |yr|
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2097
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2098
    yr := self year.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2099
    ^ (self class yearAsDays:yr)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2100
      + (self class daysUntilMonthIndex:self month forYear:yr)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2101
      + self day
85
claus
parents: 77
diff changeset
  2102
      - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2103
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2104
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2105
     (Date newDay: 5 month: 8 year: 1962) asDays  -> should be 22496
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2106
     (Date newDay: 1 month: 1 year: 1901) asDays  -> 0
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2107
     Date today asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2108
     Date fromDays:(Date today asDays + 7)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2109
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2110
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2111
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2112
asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2113
    "return the seconds between 1.jan.1901 and the same time in the receivers 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2114
     day. (i.e. midnight to midnight).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2115
     This does not include any leapSeconds ... strictly speaking, this is incorrect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2116
     ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2117
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2118
    ^ 60*60*24 * self asDays
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2119
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2120
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2121
     (Date newDay: 5 month: 8 year: 1962) asSeconds
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2122
     (Date newDay: 1 month: 1 year: 1901) asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2123
     (Date today addDays:7) asSeconds - Date today asSeconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2124
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2125
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2126
    "Modified: 1.7.1996 / 14:19:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2127
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2128
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2129
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2130
    "return the day (1..31) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2131
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2132
    ^ dateEncoding \\ 100
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2133
8626
ae1fcb227a45 example
penk
parents: 8480
diff changeset
  2134
    "example:
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2135
     Date today day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2136
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2137
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2138
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2139
dayInWeek
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2140
    "return the week-day of the receiver - 1 for monday, 7 for sunday.
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2141
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2142
     WARNING: does not care for pre-gregorian dates 
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2143
        (i.e. do not use this for dates before 1583)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2144
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2145
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2146
    |wday|
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2147
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2148
    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
  2149
            + self asDays) \\ 7 + 1.
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2150
    wday < 1 ifTrue:[
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2151
        wday := wday + 7
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2152
    ].
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2153
    ^ wday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2154
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2155
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2156
     Date today dayInWeek      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2157
     Date tomorrow dayInWeek 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2158
     Date yesterday dayInWeek 
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2159
     (Date today subtractDays:2) dayInWeek 
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2160
     Date today weekday 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2161
     Date tomorrow weekday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2162
     Date yesterday weekday 
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2163
     (Date newDay:15 month:4 year:1959) dayInWeek 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2164
     (Date newDay:1 month:1 year:1901) dayInWeek 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2165
     (Date newDay:31 month:12 year:1900) dayInWeek 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2166
     (Date newDay:31 month:12 year:1899) dayInWeek 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2167
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2168
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2169
    "Modified: / 1.2.1998 / 14:10:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2170
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2171
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2172
dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2173
    "return the day-nr within the year of the receiver - 1 .. 365/366"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2174
    
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2175
    "
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2176
        |daysSoFar|
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2177
        daysSoFar := 0.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2178
        #(0 31 28 31 30 31 30 31 31 30 31 30) collect:[:i| daysSoFar := daysSoFar + i]
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2179
    "
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2180
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2181
    |days month|
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2182
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2183
    month := self month.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2184
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2185
    days := #(0 31 59 90 120 151 181 212 243 273 304 334) at:month.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2186
    days := days + self day.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2187
    (month > 2 and:[self class leapYear:self year]) ifTrue:[
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2188
        days := days + 1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2189
    ].
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2190
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2191
    ^ days
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2192
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2193
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2194
     Date today dayInYear 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2195
     (Date newDay:1 year:1999) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2196
     (Date newDay:1 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2197
     (Date newDay:2 year:2000) dayInYear
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2198
     (Date newDay:59 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2199
     (Date newDay:60 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2200
     (Date newDay:61 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2201
     (Date newDay:366 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2202
     (Date newDay:59 year:2005) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2203
     (Date newDay:60 year:2005) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2204
     (Date newDay:365 year:2005) dayInYear
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2205
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2206
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2207
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2208
dayOfMonth
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2209
    "Answer the day of the month represented by me.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2210
     Same as day; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2211
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2212
    ^ self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2213
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2214
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2215
     Date today dayOfMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2216
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2217
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2218
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2219
daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2220
    "return the number of days in the month of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2221
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2222
    ^ Date daysInMonth:(self month) forYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2223
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2224
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2225
     Date today daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2226
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2227
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2228
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2229
daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2230
    "return the number of days in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2231
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2232
    ^ Date daysInYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2233
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2234
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2235
     Date today daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2236
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2237
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2238
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2239
daysLeftInMonth
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2240
    "return the number of days left in the month of the receiver"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2241
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2242
    ^ self daysInMonth - self day
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2243
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2244
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2245
     Date today daysLeftInMonth             
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2246
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2247
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2248
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2249
daysLeftInYear
11079
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2250
    "return the number of days left in the year of the receiver.
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2251
     Today is excluded from the count (i.e. in a non-leap-year,
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2252
     the first january will return 364)"
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2253
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2254
    ^ (Date daysInYear:(self year)) - self dayOfYear
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2255
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2256
    "
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  2257
     Date today daysLeftInYear             
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2258
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2259
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2260
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2261
isLeapYear
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2262
    "return true, if the receivers year is a leap year"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2263
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2264
    ^ Date leapYear:(self year)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2265
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2266
    "
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2267
     Date today isLeapYear
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2268
     (Date newDay:1 month:1 year:1992) isLeapYear
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2269
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2270
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2271
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2272
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2273
    "return the month (1..12) of the receiver"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2274
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2275
    ^ (dateEncoding // 100) \\ 100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2276
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2277
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2278
     Date today month
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2279
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2280
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2281
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2282
monthIndex
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2283
    "return the index of the month (e.g. Feb.=2).
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2284
     Same as month; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2285
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2286
    ^ self month  
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2287
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2288
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2289
monthName
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2290
    "return the month of the receiver as a string.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2291
     The returned string depends on the language setting.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2292
     Expect things like 'january', 'february' ..."
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2293
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2294
    ^ self class nameOfMonth:(self month)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2295
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2296
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2297
     Date today monthName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2298
     (Date newDay:15 month:4 year:1959) monthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2299
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2300
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2301
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2302
monthNameForLanguage:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2303
    "return the month of the receiver as a string.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2304
     The returned string depends on the language setting.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2305
     Expect things like 'january', 'february' ..."
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2306
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2307
    ^ self class nameOfMonth:(self month) language:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2308
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2309
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2310
     Date today monthName
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2311
     Date today monthNameForLanguage:#en
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2312
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2313
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2314
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2315
weekInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2316
    "return the week number of the receiver - 1 for Jan, 1st.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2317
     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
  2318
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2319
    ^ self class weekInYearOf:self
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2320
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2321
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2322
     Date today weekInYear    
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2323
     (Date newDay:1 year:2000) weekInYear   was a saturday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2324
     (Date newDay:2 year:2000) weekInYear   was a sunday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2325
     (Date newDay:3 year:2000) weekInYear   was a monday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2326
     (Date newDay:4 year:2000) weekInYear   was a tuesday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2327
     (Date newDay:5 year:2000) weekInYear   was a wed
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2328
     (Date newDay:6 year:2000) weekInYear   was a thursday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2329
     (Date newDay:7 year:2000) weekInYear   was a fri
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2330
     (Date newDay:8 year:2000) weekInYear   was a sat
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2331
     (Date newDay:9 year:2000) weekInYear   was a sun
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2332
     (Date newDay:10 year:2000) weekInYear  was a monday
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2333
     (Date newDay:3 month:1 year:2001) weekInYear 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2334
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2335
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2336
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2337
weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2338
    "return the week-day of the receiver as a string.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2339
     The returned string depends on the language setting.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2340
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2341
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2342
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2343
    ^ self class nameOfDay:(self dayInWeek)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2344
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2345
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2346
     Date today weekday
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2347
     (Date newDay:15 month:4 year:1959) weekday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2348
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2349
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2350
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2351
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2352
    "return the year (1..12) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2353
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2354
    ^ dateEncoding // (100*100)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2355
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2356
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2357
     Date today year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2358
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2359
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2360
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2361
year:year month:month day:day
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2362
    dateEncoding := self class encodeYear:year month:month day:day
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2363
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2364
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2365
!Date methodsFor:'arithmetic'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2366
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2367
+ days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2368
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2369
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2370
     This is the same as #addDays."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2371
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2372
    ^ self class fromDays:(self asDays + days)
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2373
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2374
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2375
     Date today + 7.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2376
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2377
     Date today to:(Date today + 28) by:7 do:[:date|
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2378
        Transcript show:date weekday; show:', '; showCr:date
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2379
     ].
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2380
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2381
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2382
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2383
- aDateOrNumberOfDays
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2384
    "return the delta in days (anInteger) between 2 dates or 
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2385
     subtract a number of days from a date returning a Date"
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2386
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2387
    aDateOrNumberOfDays class == self class ifTrue:[
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2388
        ^ self asDays - aDateOrNumberOfDays asDays
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2389
    ].
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2390
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2391
    ^ self class fromDays:(self asDays - aDateOrNumberOfDays asInteger)
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2392
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2393
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2394
        Date today - Date yesterday
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2395
        Date today - 3
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2396
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2397
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2398
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2399
addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2400
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2401
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2402
     For ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2403
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2404
    ^ self class fromDays:(self asDays + days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2405
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2406
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2407
     Date today addDays:7
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2408
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2409
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2410
9262
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2411
daysSince:aDate
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2412
    "return the number of days between the receiver and the argument,
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2413
     aDate, which should be some kind of date"
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2414
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2415
    ^ self asDays - aDate asDays
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2416
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2417
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2418
     Date today daysSince:(Date newDay:1 month:1 year:1901) 
9262
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2419
    "
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2420
!
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  2421
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2422
daysUntil:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2423
    "return the number of days between the receiver and the argument,
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2424
     aDate, which should be some kind of date"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2425
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2426
    ^ aDate asDays - self asDays
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2427
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2428
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2429
     (Date newDay:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2430
     (Date newDay:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2431
     (Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2432
    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2433
     |delta|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2434
     delta := Date today
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2435
                daysUntil:(Date newDay:25 month:12 year:Date today year).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2436
     Transcript show:'still ';
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2437
                show:delta ;
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2438
                showCR:' days till xmas'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2439
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2440
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2441
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2442
firstDayInPreviousMonth:nMonths
11742
09f7e7b1c93b changed #firstDayInPreviousMonth:
Claus Gittinger <cg@exept.de>
parents: 11741
diff changeset
  2443
    "Return the first day of a previous month (0=this month, 1=prev. month, etc.)"
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2444
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2445
    |month year|
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2446
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2447
    month := self month.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2448
    year := self year.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2449
    month := month - nMonths.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2450
    month < 1 ifTrue:[
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2451
        year := year - 1 - (month negated // 12).
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2452
        month := (12 - (month negated \\ 12)).
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2453
    ].
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2454
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2455
    ^ Date newDay:1 month:month year:year.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2456
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2457
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2458
     (Date newDay:3 month:6 year:2009) firstDayInMonth     
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2459
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:0    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2460
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:5    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2461
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:6    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2462
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:7    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2463
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:17    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2464
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:18    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2465
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2466
!
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2467
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2468
firstDayOfPreviousMonth:nMonths
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2469
    "Return the first day of a previous month (0=this month)"
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2470
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2471
    |month year|
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2472
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2473
    month := self month.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2474
    year := self year.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2475
    month := month - nMonths.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2476
    month < 1 ifTrue:[
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2477
        year := year - 1 - (month negated // 12).
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2478
        month := (12 - (month negated \\ 12)).
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2479
    ].
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2480
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2481
    ^ Date newDay:1 month:month year:year.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2482
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2483
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2484
     (Date newDay:3 month:6 year:2009) firstDayInMonth     
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2485
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2486
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2487
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2488
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2489
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2490
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2491
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2492
!
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  2493
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2494
subtractDate:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2495
    "return the number of days between the receiver and aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2496
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2497
    ^ self asDays - aDate asDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2498
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2499
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2500
    (Date newDay:1 month:1 year:1995) subtractDate:(Date newDay:24 month:12 year:1994)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2501
    (Date newDay:1 month:3 year:1992) subtractDate:(Date newDay:1 month:2 year:1992)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2502
    (Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2503
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2504
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2505
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2506
subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2507
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2508
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2509
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2510
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2511
    ^ self class fromDays:(self asDays - days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2512
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2513
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2514
     Date today subtractDays:7
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2515
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2516
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2517
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2518
!Date methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2519
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2520
< aDate
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2521
    "return true, if the date represented by the receiver
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2522
     is before the argument, aDate"
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2523
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2524
    (aDate isMemberOf:Date) ifTrue:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2525
        ^ dateEncoding < aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2526
    ].
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2527
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2528
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2529
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2530
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  2531
    ^ dateEncoding < (Date encodeYear:aDate year month:aDate month day:aDate day)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2532
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2533
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2534
        Date today < (Date day:24 month:12 year:2000)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2535
        Date today < (Date day:24 month:12 year:1900)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2536
        Date today < Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2537
        Date today-1 < Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2538
    "
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2539
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2540
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2541
= aDate
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2542
    "return true, if the date represented by the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2543
     is the same as the one represented by argument, aDate"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2544
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2545
    (aDate isMemberOf:Date) ifFalse:[^ false].
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2546
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2547
    ^ dateEncoding = aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2548
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2549
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2550
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2551
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2552
"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2553
    ^ dateEncoding = (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2554
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2555
				  day:aDate day)
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2556
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2557
    "Date today = ((Date today plusDays:7) minusDays:7)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2558
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2559
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2560
> aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2561
    "return true, if the date represented by the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2562
     is after the argument, aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2563
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2564
    (aDate isMemberOf:Date) ifTrue:[
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2565
        ^ dateEncoding > aDate dateEncoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2566
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2567
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2568
    "the argument must understand year, month and day to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2569
     comparable, whatever it is"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2570
17757
73caeb68bf1f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17751
diff changeset
  2571
    ^ dateEncoding > (Date encodeYear:aDate year month:aDate month day:aDate day)
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2572
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2573
    "
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2574
      Date today > (Date newDay:24 month:12 year:2099)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2575
      Date today > (Date newDay:24 month:12 year:1900)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2576
      Date today > Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2577
      Date today+1 > Timestamp now
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2578
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2579
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2580
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2581
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2582
    "return an integer useful for hashing on dates"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2583
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2584
    ^ dateEncoding
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2585
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2586
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2587
!Date methodsFor:'converting'!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2588
4408
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2589
asDate
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2590
    "return the receiver"
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2591
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2592
    ^ self
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2593
!
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2594
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2595
asLocalTimestamp
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2596
    "return an TimeStamp instance, representing midnight of last night"
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2597
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2598
    ^ Timestamp 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2599
        year:(self year) month:(self month) day:(self day)  
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2600
        hour:0 minute:0 second:0 millisecond:0
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2601
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2602
    "
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2603
     Date today asLocalTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2604
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2605
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2606
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2607
asTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2608
    "return an TimeStamp instance, representing midnight of last night"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2609
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2610
    ^ self asLocalTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2611
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2612
    "
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2613
     Date today asTimestamp
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2614
    "
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2615
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2616
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2617
asUtcTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2618
    "return an TimeStamp instance, representing midnight of last night"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2619
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2620
    ^ UtcTimestamp 
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2621
        year:(self year) month:(self month) day:(self day)  
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2622
        hour:0 minute:0 second:0 millisecond:0
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2623
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2624
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2625
     Date today asUtcTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2626
    "
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  2627
! !
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2628
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2629
!Date methodsFor:'obsolete'!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2630
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2631
asAbsoluteTime
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2632
    "deprecated, use #asTimestamp"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2633
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2634
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2635
    self obsoleteMethodWarning:'use #asTimestamp'.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2636
    ^ self asTimestamp
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2637
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2638
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2639
dayCount
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2640
    "return the number of days since 1st. Jan. 1901;
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2641
     starting with 0 for this date.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2642
     Date>>fromDays: is the reverse operation.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2643
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2644
         please use asDays for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2645
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2646
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2647
    ^ self asDays.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2648
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2649
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2650
dayName
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2651
    "return the week-day of the receiver as a string.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2652
     The returned string depends on the language setting.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2653
     Expect things like 'monday', 'tuesday' ...
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2654
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2655
        use #weekday for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2656
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2657
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2658
    ^ self weekday
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2659
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2660
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2661
leap
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2662
    "return true, if the receivers year is a leap year"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2663
    <resource: #obsolete>
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2664
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2665
    ^ self isLeapYear
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2666
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2667
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2668
     Date today leap
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2669
     (Date newDay:1 month:1 year:1992) leap
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2670
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2671
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2672
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2673
minusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2674
    "return a new date representing 'days' before the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2675
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2676
     Obsolete:
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2677
         Please dont use this method since it will vanish.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2678
         Use #subtractDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2679
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2680
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2681
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2682
    self obsoleteMethodWarning:'use #substractDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2683
    ^ self subtractDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2684
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2685
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2686
plusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2687
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2688
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2689
     Obsolete:
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2690
         Please dont use this method since it will vanish.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2691
         Use #addDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2692
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2693
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2694
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2695
    self obsoleteMethodWarning:'use #addDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2696
    ^ self addDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2697
! !
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2698
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  2699
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2700
!Date methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2701
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2702
addPrintBindingsTo:aDictionary
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2703
    self addPrintBindingsTo:aDictionary language:nil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2704
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2705
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2706
addPrintBindingsTo:aDictionary language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2707
    "private print support: add bindings for printing to aDictionary.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2708
     languageOrNil can only be #en or nil for the current language.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2709
     valid format items are:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2710
        %d              - day, 01..31                    0-padded to length 2
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2711
        %m              - month, 01..12                  0-padded to length 2
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2712
        %w              - week in year, 00..53           0-padded to length 2
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2713
        %y              - year, full                     i.e. 1999, 2004
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2714
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2715
     special:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2716
        %D              - day - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2717
        %M              - month - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2718
        %W              - week in year - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2719
        %Y              - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug)                     
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2720
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2721
        %(weekDay)      - day in week (1->monday, 2->tuesday, ... ,7->sunday)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2722
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2723
        %(dayName)      - full day name     
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2724
        %(DayName)      - full day name, first character uppercase      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2725
        %(DAYNAME)      - full day name, all uppercase       
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2726
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2727
        %(monthName)    - full month name     
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2728
        %(MonthName)    - full month name, first character uppercase      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2729
        %(MONTHNAME)    - full month name, all uppercase       
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2730
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2731
        %(shortDayName) - short (abbreviated) day name     
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2732
        %(ShortDayName) - short (abbreviated) day name, first character uppercase      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2733
        %(SHORTDAYNAME) - short (abbreviated) day name, all uppercase       
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2734
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2735
        %(shortMonthName) - short (abbreviated) month name     
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2736
        %(ShortMonthName) - short (abbreviated) month name, first character uppercase      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2737
        %(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase       
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2738
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2739
        %(nth)          - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2740
        %(weekDayNth)   - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2741
        %(weekNth)      - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')"     
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2742
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2743
    |day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2744
     year weekInYear monthName shortMonthName 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2745
     dayInWeek dayOfWeek dayName shortDayName ws wsPadded0|
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2746
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2747
    day := self day.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2748
    ds := day printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2749
    dsPaddedB := day printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2750
    dsPadded0 := day printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2751
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2752
    month := self month.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2753
    ms := month printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2754
    msPaddedB := month printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2755
    msPadded0 := month printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2756
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2757
    year := self year.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2758
    weekInYear := self weekInYear.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2759
    ws := weekInYear printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2760
    wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2761
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2762
    dayInWeek := self dayInWeek.   "/ 1 .. 7
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2763
    dayOfWeek := self dayOfWeek.   "/ 0 .. 6
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2764
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2765
    monthName := self class nameOfMonth:(self month) language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2766
    dayName := self class nameOfDay:dayInWeek language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2767
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2768
    aDictionary at:#day put:dsPadded0.          "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2769
    aDictionary at:#daypadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2770
    aDictionary at:#dayPadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2771
    aDictionary at:#Day put:ds.                 "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2772
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2773
    aDictionary at:#month put:msPadded0.        "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2774
    aDictionary at:#monthPadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2775
    aDictionary at:#monthpadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2776
    aDictionary at:#Month put:ms.               "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2777
    aDictionary at:#mon put:msPadded0.          "/ 0-padded - for backward compatibility only
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2778
    aDictionary at:#Mon put:ms.                 "/ unpadded - for backward compatibility only
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2779
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2780
    aDictionary at:#year put:year.              "/ padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2781
    aDictionary at:#week put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2782
    aDictionary at:#Week put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2783
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2784
    year ~~ Date today year ifTrue:[
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2785
        aDictionary at:#yearOrTime put:(' ' , year printString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2786
    ].
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2787
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2788
    aDictionary at:$d put:dsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2789
    aDictionary at:$D put:ds.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2790
    aDictionary at:$m put:msPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2791
    aDictionary at:$M put:ms.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2792
    aDictionary at:$y put:year.
17747
f978415ba3d3 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  2793
    aDictionary at:$Y put:((year \\ 100) printStringLeftPaddedTo:2 with:$0).
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2794
    aDictionary at:$w put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2795
    aDictionary at:$W put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2796
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2797
    aDictionary at:#monthName put:monthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2798
    aDictionary at:#monthname put:monthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2799
    aDictionary at:#MonthName put:monthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2800
    aDictionary at:#MONTHNAME put:monthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2801
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2802
    aDictionary at:#dayName put:dayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2803
    aDictionary at:#dayname put:dayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2804
    aDictionary at:#DayName put:dayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2805
    aDictionary at:#DAYNAME put:dayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2806
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2807
    aDictionary at:#weekDay put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2808
    aDictionary at:#weekday put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2809
    aDictionary at:#weekDayUS put:dayOfWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2810
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2811
    aDictionary at:#shortDayName put:(shortDayName := self class abbreviatedNameOfDay:(self dayInWeek) language:languageOrNil).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2812
    aDictionary at:#shortdayname put:shortDayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2813
    aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2814
    aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2815
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2816
    aDictionary at:#shortMonthName put:(shortMonthName := self class abbreviatedNameOfMonth:(self month) language:languageOrNil).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2817
    aDictionary at:#shortmonthname put:shortMonthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2818
    aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2819
    aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2820
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2821
    aDictionary at:#nth        put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:day \\ 10 + 1).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2822
                                     "/ 0   1    2    3    4    5    6    7    8    9
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2823
    aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). 
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2824
                                     "/ 0   1    2    3    4    5    6      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2825
    aDictionary at:#weekNth    put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:weekInYear \\ 10 + 1).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2826
                                     "/ 0   1    2    3    4    5    6    7    8    9     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2827
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2828
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2829
printOn:aStream
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2830
    "append a printed representation of the receiver to aStream"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2831
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2832
    self printOn:aStream format:(self class defaultFormatString) language:nil.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2833
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2834
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2835
     Date today printOn:Transcript. Transcript cr.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2836
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2837
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2838
    "Modified: 27.8.1995 / 01:01:49 / claus"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2839
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2840
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2841
printOn:aStream format:aFormatStringOrSqueakFormatArray
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2842
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2843
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2844
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2845
    self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2846
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2847
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2848
     Date today printOn:Transcript format:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2849
     Date today printOn:Transcript format:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2850
     Date today printOn:Transcript format:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2851
     Date today printOn:Transcript format:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2852
     Date today printOn:Transcript format:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2853
     Date today printOn:Transcript format:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2854
     Date today printOn:Transcript format:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2855
     Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2856
     Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2857
     Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2858
     Date today printOn:Transcript format:'%d%m%Y'                                      (millenium bug format - danger)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2859
     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
  2860
    "
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2861
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2862
     String streamContents:[:s |
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2863
        Date today printOn:s format:#(1 2 3 $/ 1 2)
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2864
     ]    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2865
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2866
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2867
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2868
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2869
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2870
     languageOrNil can only be #en or nil for the current language.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2871
     see #addPrintBindingsTo: for a list of valid format strings"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2872
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2873
    |dict|
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2874
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2875
    aFormatStringOrSqueakFormatArray isArray ifTrue:[
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2876
        "backward compatibility: a squeak/st80 format array"
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2877
        self printFormat:aFormatStringOrSqueakFormatArray on:aStream.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2878
        ^ self.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2879
    ].
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2880
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2881
    dict := IdentityDictionary new.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2882
    self addPrintBindingsTo:dict language:languageOrNil.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2883
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2884
    aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2885
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2886
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2887
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2888
     Date today 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2889
        printOn:Transcript 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2890
        format:'%y%m%d'                             
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2891
        language:#en                             
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2892
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2893
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2894
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2895
printOn:aStream language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2896
    "append a printed representation of the receiver to aStream.
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2897
     The argument languageOrNil can only be #en or nil for the current language."
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2898
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2899
    |format|
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2900
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2901
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
  2902
        self class initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2903
    ].
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2904
    format := DefaultFormats at:(languageOrNil ? Language) ifAbsent:[DefaultFormats at:#en].
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2905
    self printOn:aStream format:format language:languageOrNil.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2906
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2907
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2908
     Date today printOn:Transcript language:#en
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  2909
     Date today printOn:Transcript language:#de
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2910
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2911
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2912
    "Modified: / 27-08-1995 / 01:01:49 / claus"
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2913
    "Modified: / 12-03-2004 / 19:23:54 / cg"
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2914
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2915
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2916
printStringFormat:aFormatStringOrArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2917
    "print using a format string;
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2918
     see #addPrintBindingsTo: for a list of valid format strings"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2919
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2920
    ^ self printStringFormat:aFormatStringOrArray language:nil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2921
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2922
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2923
     Date today printStringFormat:'%y%m%d'                                      (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2924
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2925
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2926
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2927
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2928
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2929
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2930
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2931
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2932
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2933
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2934
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2935
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2936
     Date today printStringFormat:'Today is the %(Day)%(nth) day of the month'           
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2937
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2938
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2939
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2940
printStringFormat:aFormatStringOrArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2941
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2942
     languageOrNil can only be #en or nil for the current language.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2943
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2944
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2945
    |s|
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2946
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2947
    s := WriteStream on:(String new:20).
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2948
    self printOn:s format:aFormatStringOrArray language:languageOrNil.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  2949
    ^ s contents.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2950
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2951
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2952
     Date today printStringFormat:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2953
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2954
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2955
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2956
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2957
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2958
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2959
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2960
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2961
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2962
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2963
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2964
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2965
     Date today printStringFormat:'Today is the %(Day)%(nth) day of the month'           
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2966
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2967
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2968
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2969
storeOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2970
    "append a representation to aStream, from which the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2971
     can be reconstructed"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2972
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2973
    aStream nextPutAll:'('; nextPutAll:'Date day:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2974
    self day printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2975
    aStream nextPutAll:' month:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2976
    self month printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2977
    aStream nextPutAll:' year:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2978
    self year printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2979
    aStream nextPutAll:')'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2981
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2982
     Date today storeOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2983
     Date today storeString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2984
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2985
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2986
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  2987
!Date methodsFor:'private-accessing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2988
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2989
dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2990
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2991
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2993
    ^ dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2994
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2995
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2996
dateEncoding:anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2997
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2998
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2999
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3000
    dateEncoding := anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3001
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3002
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3003
fromOSTime:osTime
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3004
    "set my dateEncoding as date in the local timezone from an OS time.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3005
     This somewhat clumsy implementation hides the OS's date representation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3006
     (i.e. makes this class independent of what the OS starts its time values with).
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3007
     Don't use this method, the osTime representation is totally unportable."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3008
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3009
    |v|
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  3010
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  3011
    v := OperatingSystem computeTimeAndDateFrom:osTime.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3012
    dateEncoding := self class encodeYear:v year month:v month day:v day
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  3013
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  3014
    "Modified: 1.7.1996 / 15:23:12 / cg"
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3015
!
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3016
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3017
fromUtcOSTime:osTime
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3018
    "set my dateEncoding as UTC date from an OS time.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3019
     This somewhat clumsy implementation hides the OS's date representation
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3020
     (i.e. makes this class independent of what the OS starts its time values with).
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3021
     Don't use this method, the osTime representation is totally unportable."
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3022
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3023
    |v|
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3024
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3025
    v := OperatingSystem computeUTCTimeAndDateFrom:osTime.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3026
    dateEncoding := self class encodeYear:v year month:v month day:v day
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3027
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3028
    "Modified: 1.7.1996 / 15:23:12 / cg"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3029
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
  3030
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3031
getMilliseconds
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3032
    "compatibility with Timestamp for comparing"
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3033
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3034
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3035
       ((Timestamp epoch addDays:365) asDate asDays - 365)      -> 25202
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3036
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3037
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3038
    ^ 1000 * 60*60*24 * (self asDays - 25202)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3039
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3040
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3041
     Date today asTimestamp getMilliseconds
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3042
        -
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3043
     Date today getMilliseconds
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3044
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3045
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3046
11176
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3047
!Date methodsFor:'visiting'!
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3048
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3049
acceptVisitor:aVisitor with:aParameter
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3050
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3051
    ^ aVisitor visitDate:self with:aParameter
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3052
! !
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  3053
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  3054
!Date class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3055
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3056
version
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  3057
    ^ '$Id: Date.st 10656 2011-07-07 22:08:07Z vranyj1 $'
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  3058
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  3059
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  3060
version_CVS
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  3061
    ^ '§Header: /cvs/stx/stx/libbasic/Date.st,v 1.138 2011/01/24 19:56:01 stefan Exp §'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3062
! !
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  3063
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  3064
Date initialize!