Date.st
author Stefan Vogel <sv@exept.de>
Wed, 26 Jan 2005 15:41:06 +0100
changeset 8709 25088287bbd0
parent 8626 ae1fcb227a45
child 8795 7fc3fbba3b63
permissions -rw-r--r--
Catch #fromString: (for autoloaded classes from Dolphin)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    13
"{ Package: 'stx:libbasic' }"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    14
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    15
Magnitude subclass:#Date
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    16
	instanceVariableNames:'dateEncoding'
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    17
	classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs DefaultFormats
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    18
		ShortFormats LongFormats EnvironmentChange'
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    19
	poolDictionaries:''
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
    20
	category:'Magnitude-Time'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    23
!Date class methodsFor:'documentation'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    28
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    39
documentation
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    40
"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
    Instances of Date represent dates as year, month and day encoded in the 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    (private & hidden) instance dateEncoding. The value found there is 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    year*100*100 + month*100 + day (which makes magnitude-like comparison of 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    44
    dates easy, but is not guaranteed for future versions).
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    45
    Do not depend on the internal representation.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    46
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
    The old representation used days since 1st Jan. 1901 internally - 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    48
    with the new implementation, it is possible to reasonably represent almost 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    49
    any Date.  (which insurance companies will like, since they can now 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    50
    represent even very old peoples birthday :-)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    51
    Notice: no correction for pre-Julian dates is done.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    52
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    The printed representation of dates is controlled by resource definitions -
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
    thus national variants are already supported (see file 'resources/Date.rs').
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    56
    Compatibility notice:
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    57
        due to some historic reasons, there are some methods found twice
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    58
        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
    59
        one of the next releases, and kept for a while to support existing
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    60
        applications (the info on how these methods should be named came 
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    61
        somewhat late from the testers ..).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    62
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    63
        Please do not use methods marked as obsolete in their comment.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    64
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    65
    Most useful methods:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    66
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    67
        Date today
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    68
        (Date today) addDays:
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    69
        (Date today) subtractDays:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    70
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    71
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    72
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    73
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    74
    [see also:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    75
        Time AbstractTime
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    76
        Filename
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    77
        OperatingSystem
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    78
"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    79
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    80
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    81
!Date class methodsFor:'initialization'!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    82
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    83
initDefaultNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    84
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    85
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    86
    |enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    87
     enDefaultFormat enLongFormat enShortFormat|
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    88
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    89
    DayNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    90
    DayAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    91
    MonthNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    92
    MonthAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    93
    DefaultFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    94
    LongFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    95
    ShortFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    96
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    97
    enDayNames := #('monday'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
    98
                    'tuesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
    99
                    'wednesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   100
                    'thursday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   101
                    'friday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   102
                    'saturday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   103
                    'sunday').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   104
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   105
    enDayAbbrevs := #('mon' 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   106
                      'tue' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   107
                      'wed'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   108
                      'thu' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   109
                      'fri' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   110
                      'sat' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   111
                      'sun').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   112
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   113
    enMonthNames := #('january'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   114
                      'february'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   115
                      'march'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   116
                      'april'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   117
                      'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   118
                      'june'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   119
                      'july'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   120
                      'august'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   121
                      'september'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   122
                      'october'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   123
                      'november'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   124
                      'december').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   125
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   126
    enMonthAbbrevs := #('jan'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   127
                        'feb'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   128
                        'mar'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   129
                        'apr'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   130
                        'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   131
                        'jun'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   132
                        'jul'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   133
                        'aug'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   134
                        'sep'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   135
                        'oct'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   136
                        'nov'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   137
                        'dec').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   138
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   139
    DayNames at:#'en' put:enDayNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   140
    DayAbbrevs at:#'en' put:enDayAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   141
    MonthNames at:#'en' put:enMonthNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   142
    MonthAbbrevs at:#'en' put:enMonthAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   143
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   144
    DefaultFormats at:#'en' put:(enDefaultFormat := '%d-%m-%y').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   145
    ShortFormats at:#'en' put:(enShortFormat := '%d-%m-%y').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   146
    LongFormats at:#'en' put:(enLongFormat := '%(dayName), %d-%m-%y').
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   147
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
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   151
     Date initNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   152
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   153
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   154
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   155
initNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   156
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   157
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   158
    |resources lang 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   159
     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
   160
     enDefaultFormat enLongFormat enShortFormat may|
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   161
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   162
    lang := Smalltalk language asSymbol.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   163
    lang ~~ #'en' ifTrue:[
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   164
        ResourcePack notNil ifTrue:[
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   165
            enDayNames := DayNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   166
            enDayAbbrevs := DayAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   167
            enMonthNames := MonthNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   168
            enMonthAbbrevs := MonthAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   169
            monthAbbrevKeys := enMonthAbbrevs copy.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   170
            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
   171
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   172
            enDefaultFormat := DefaultFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   173
            enShortFormat := ShortFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   174
            enLongFormat := LongFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   175
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   176
            resources := ResourcePack forPackage:(self package).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   177
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   178
            DefaultFormats at:lang put:(resources at:'DATEFORMAT' default:enDefaultFormat).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   179
            ShortFormats at:lang put:(resources at:'SHORTDATEFORMAT' default:enShortFormat).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   180
            LongFormats at:lang put:(resources at:'LONGDATEFORMAT' default:enLongFormat).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   181
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   182
            DayNames at:lang put:(resources array:enDayNames).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   183
            DayAbbrevs at:lang put:(resources array:enDayAbbrevs).
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   184
            MonthNames at:lang put:(resources array:enMonthNames).
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   185
            MonthAbbrevs at:lang put:(resources array:monthAbbrevKeys).
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   186
            "/ may needs special care (same key for long and short name)
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   187
            may := resources at:'MAY_ABBREV' ifAbsent:nil.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   188
            may isNil ifTrue:[
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   189
                may := resources at:'may'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   190
            ].
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   191
            (MonthAbbrevs at:lang) at:5 put:may.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   192
        ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   193
    ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   194
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   195
    EnvironmentChange := false
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   196
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   197
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   198
     Date initNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   199
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   200
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   201
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   202
initialize
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   203
    "check for case where Resource-classes are absent"
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   204
    self initDefaultNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   205
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   206
    Smalltalk addDependent:self.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   207
    Language ~= 'en' ifTrue:[
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   208
        EnvironmentChange := true
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   209
    ]
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   210
! !
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   211
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   212
!Date class methodsFor:'instance creation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   213
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   214
fromDays:dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   215
    "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
   216
     (i.e. 'Date fromDays:0' returns 1st Jan. 1901).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   217
     Date asDays is the reverse operation.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   218
     Added for GNU/ST-80 compatibility"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   219
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   220
    |yr rest d|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   221
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   222
    "approx. year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   223
    yr := (dayCount // 366) + 1901.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   224
    rest := dayCount - (self yearAsDays:yr) + 1. "+1 for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   225
    d := self daysInYear:yr.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   226
    (rest > d) ifTrue:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   227
        "adjust"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   228
        yr := yr + 1.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   229
        rest := rest - d.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   230
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   231
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   232
    ^ self newDay:rest year:yr
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   233
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   234
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   235
     Date fromDays:0     -> 1 jan 1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   236
     Date fromDays:365   -> 1 jan 1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   237
     Date fromDays:730   -> 1 jan 1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   238
     Date fromDays:1095  -> 1 jan 1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   239
     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
   240
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   241
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   242
    "Modified: 1.7.1996 / 14:24:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   243
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   244
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   245
newDay:day month:month year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   246
    "return a new Date, given the day, month and year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   247
     For your convenience, month may be either an integer 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   248
     or the months name as a string. 
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   249
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   250
     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
   251
              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
   252
              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
   253
              (see those, for example readFrom:onError:)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   254
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   255
    |monthIndex ok|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   256
8446
e19765545de6 Dont generate a warning for years between -1 and -99
Stefan Vogel <sv@exept.de>
parents: 8247
diff changeset
   257
    (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
   258
        '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
   259
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   260
    month isInteger ifTrue:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   261
        monthIndex := month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
    ] ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   263
        monthIndex := self indexOfMonth:month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   264
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   265
    (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
   266
        ok := self leapYear:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   267
    ] ifFalse:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   268
        ok := day <= (self daysInMonth:month forYear:year)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   269
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   270
    ((day > 0) and:[ok]) ifTrue:[
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   271
        ^ self basicNew dateEncoding:(((year * 100) + monthIndex) * 100) + day
699
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   274
    "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
   275
     invalid year/month/day combination;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   276
     Such as 29-feb-year, where year is no leap year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   277
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   278
    self error:'invalid date'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   280
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   281
     Date newDay:8  month:'may' year:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   282
     Date newDay:8  month:5     year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   283
     Date newDay:29 month:'feb' year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   284
     Date newDay:29 month:'feb' year:1993
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   285
     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
   286
     Date newDay:28 month:'feb' year:95  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   287
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   288
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   289
    "Modified: 19.4.1996 / 15:28:15 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   290
!
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
newDay:dayInYear year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   293
    "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
   294
     See also: Date today / Time now / Timestamp now.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   295
     ST-80 compatibility"
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
    |monthAndDay|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   298
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   299
    (dayInYear between:1 and:365) ifFalse:[
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   300
        ((dayInYear == 366) and:[self leapYear:year]) ifFalse:[
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   301
            "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   302
             this error is triggered, when you try to create a
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   303
             day from an invalid day-in-year; 
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   304
             for example, 366 in a non-leap year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   305
             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
   306
            "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   307
            ^ self error:'invalid date'
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   308
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   309
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   310
    monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   311
    ^ self newDay:(monthAndDay at:2) month:(monthAndDay at:1) year:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   312
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   313
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   314
     Date newDay:150 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   315
     Date newDay:1 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   316
     Date newDay:1 year:1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   317
     Date newDay:1 year:1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   318
     Date newDay:365 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   319
     Date newDay:366 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   320
     Date newDay:365 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   321
     Date newDay:366 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   322
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   323
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   324
    "Modified: 1.7.1996 / 14:22:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   325
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   326
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
readFrom:aStringOrStream onError:exceptionBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
    "return a new Date, reading a printed representation from aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   329
     Notice, that this is not the storeString format and 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   330
     is different from the format expected by readFrom:.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   331
     BUG:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
       This method assumes american format (i.e. month-day-year) instead
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
       of the german/french and other day-month-year.
4998
010c3ab0cdc6 Comments
Stefan Vogel <sv@exept.de>
parents: 4997
diff changeset
   334
       There ought to be a internationalized variant of this."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   335
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   336
    ^ [
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   337
        |str month day year|
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   338
        str := aStringOrStream readStream.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   339
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   340
        [str peek isLetterOrDigit] whileFalse:[str next].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   341
        (str peek isDigit) ifTrue:[
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   342
            day := Integer readFrom:str
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   343
        ].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   344
        [str peek isLetterOrDigit] whileFalse:[str next].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   345
        (str peek isLetter) ifTrue:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   346
            month := str nextAlphaNumericWord.
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   347
            day isNil ifTrue:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   348
                [str peek isLetterOrDigit] whileFalse:[str next].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   349
                day := Integer readFrom:str.
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   350
            ]
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   351
        ] ifFalse:[
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   352
            month := self nameOfMonth:day.
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   353
            day := Integer readFrom:str
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   354
        ].
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   355
        [str peek isLetterOrDigit] whileFalse:[str next].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3257
diff changeset
   356
        year := Integer readFrom:str.
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   357
        (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
   358
            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
   359
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   360
        self newDay:day month:month year:year
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   361
    ] on:Error do:exceptionBlock.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
     Date readFromString:'31 December 1992'  
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   365
     Date readFrom:'19:11:1999'  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   366
     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
   367
     Date readFromString:'12/31/1992'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   368
     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
   369
     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
   370
     Date readFromString:'12/31/01'        
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   371
     Date readFromString:'15.4.1992'         -> german; leads to an error
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   372
     Date readFromString:'10.4.1992'         -> german; leads to a wrong date
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   373
     Date readFromString:'10.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   374
     Date readFromString:'32.4.1992' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   375
     Date readFromString:'fooBar' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   376
     Date readFromString:'10.4' onError:['wrong date']
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   377
     Date readFromString:'10041999' onError:['wrong date']  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   378
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   379
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   380
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   381
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   382
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   383
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   384
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   385
    "return a new Date, reading a printed representation from aStream.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   386
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   387
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   388
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   389
         3   year position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   390
     or a formatString (see printing instance protocol).
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   391
    "
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   392
    ^ self 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   393
        readFrom:aStringOrStream
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   394
        printFormat:aSqueakFormatArrayOrFormatString 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   395
        onError:[self error:'expected: ' , self name]
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   396
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   397
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   398
     Date readFrom:'19:11:1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   399
     Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 )
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   400
     Date readFrom:'19:11:1999' printFormat:#( 2 1 3 )  -> exception: wrong month
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   401
     Date readFrom:'5:12:1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   402
     Date readFrom:'may-12-1999' printFormat:#( 2 1 3 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   403
     Date readFrom:'1999 may 12' printFormat:#( 3 2 1 )  
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   404
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   405
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   406
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   407
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   408
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   409
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   410
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   411
    "return a new Date, reading a printed representation from aStream.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   412
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   413
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   414
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   415
         3   year position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   416
     or a formatString (see printing instance protocol).
7651
e128b10201fb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7650
diff changeset
   417
     For now, only %d, %m and %y are supported in the formatString.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   418
     TODO: make this a general feature of all DateAndTime classes.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   419
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   420
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   421
    |str day month year|
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   422
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   423
    str := aStringOrStream readStream.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   424
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   425
    aSqueakFormatArrayOrFormatString isArray 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   426
        ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   427
            [
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   428
                |arg|
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   429
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   430
                arg := Array new:3.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   431
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   432
                1 to:3 do:[:i||v|
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   433
                    [str peek isLetterOrDigit] whileFalse:[str next].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   434
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   435
                    v := (str peek isDigit) ifTrue:[Integer readFrom:str]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   436
                                           ifFalse:[str nextAlphaNumericWord].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   437
                    arg at:i put:v
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   438
                ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   439
                year := (arg at:(aSqueakFormatArrayOrFormatString at:3)).
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   440
                day := arg at:(aSqueakFormatArrayOrFormatString at:1).
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   441
                month := arg at:(aSqueakFormatArrayOrFormatString at:2).
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   442
            ] on:Error do:[:ex| ^ exceptionBlock value].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   443
        ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   444
            [
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   445
                |formatStream fc c sel|
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   446
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   447
                formatStream := aSqueakFormatArrayOrFormatString readStream.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   448
                [formatStream atEnd] whileFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   449
                    fc := formatStream next.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   450
                    fc == $% ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   451
                        sel := ''.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   452
                        [(fc := formatStream peek) notNil and:[ fc isLetter]] whileTrue:[ sel := sel , (formatStream next) ].
7650
11ef2ccbfb2e better date conversion.
Claus Gittinger <cg@exept.de>
parents: 7649
diff changeset
   453
                        (sel asLowercase = 'd') ifTrue:[
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   454
                            day := Integer readFrom:str
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   455
                        ] ifFalse:[
7650
11ef2ccbfb2e better date conversion.
Claus Gittinger <cg@exept.de>
parents: 7649
diff changeset
   456
                            (sel asLowercase = 'm') ifTrue:[
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   457
                                month := Integer readFrom:str
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   458
                            ] ifFalse:[
7650
11ef2ccbfb2e better date conversion.
Claus Gittinger <cg@exept.de>
parents: 7649
diff changeset
   459
                                (sel asLowercase = 'y') ifTrue:[
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   460
                                    year := Integer readFrom:str
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   461
                                ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   462
                            ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   463
                        ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   464
                    ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   465
                        fc == Character space ifTrue:[
8480
e7635256139d reading: skip over '-'-characters
Claus Gittinger <cg@exept.de>
parents: 8446
diff changeset
   466
                            [(c := str peek) isSeparator or:[ '-.:,;/' includes:c ] ] whileTrue:[ str next ].    
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   467
                        ] ifFalse:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   468
                            str skipSeparators.
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   469
                            str next == fc ifFalse:[^ exceptionBlock value].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   470
                            str skipSeparators.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   471
                        ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   472
                    ]
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   473
                ].
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
   474
            ] on:Error do:[:ex| ^ exceptionBlock value].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   475
        ].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   476
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   477
    day isNil ifTrue:[ day := 1 ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   478
    month isNil ifTrue:[ month := 1 ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   479
    year isNil ifTrue:[ year := Date today year ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   480
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   481
    (year between:0 and:99) ifTrue:[
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   482
        year := UserPreferences current twoDigitDateHandler value:year.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   483
    ].
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   484
    ^ self newDay:day month:month year:year.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   485
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   486
    "
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   487
     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
   488
     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
   489
     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
   490
     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
   491
     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
   492
     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
   493
     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
   494
     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
   495
     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
   496
     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
   497
     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
   498
     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
   499
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   500
     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
   501
     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
   502
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   503
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   504
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   505
     Date readFrom:'01' printFormat:'%y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   506
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'       
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   507
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   508
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   509
    "Created: 16.11.1995 / 22:50:17 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   510
    "Modified: 8.10.1996 / 19:25:39 / cg"
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   511
!
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   512
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   513
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   514
    "return a new Date, reading a printed representation from aStream.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   515
     Notice, that this is not the storeString format and 
4998
010c3ab0cdc6 Comments
Stefan Vogel <sv@exept.de>
parents: 4997
diff changeset
   516
     is different from the format expected by readFrom:"
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   517
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   518
    ^ [
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   519
        |str month day year|
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   520
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   521
        str := aStringOrStream readStream.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   522
        month := str next:2.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   523
        month := Integer readFrom:month.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   524
        day := str next:2.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   525
        day := Integer readFrom:day.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   526
        year := str next:4.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   527
        year := Integer readFrom:year.
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   528
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   529
        self newDay:day month:month year:year
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   530
    ] on:Error do:exceptionBlock
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   531
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   532
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   533
     Date readMMDDYYYYFrom:'10041999' onError:['wrong date']  
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   534
     Date readMMDDYYYYFrom:'100419' onError:['wrong date']  
6952
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   535
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   536
     Date readMMDDYYYYFrom:'10040001' onError:['wrong date']  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   537
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   539
    "Created: 16.11.1995 / 22:50:17 / cg"
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   540
    "Modified: 8.10.1996 / 19:25:39 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   541
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   542
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   543
today
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   544
    "return a date, representing today.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   545
     See also: Time now / Timestamp now."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   546
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   547
    ^ self fromOSTime:(OperatingSystem getOSTime)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   548
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   549
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   550
     Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   551
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   552
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   553
    "Modified: 1.7.1996 / 15:20:16 / cg"
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   554
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   555
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   556
tomorrow
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   557
    "return a date, representing tomorrow.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   558
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   559
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   560
    ^ Date today addDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   561
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   562
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   563
     Date tomorrow 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   564
     Date tomorrow dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   565
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   566
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   567
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   568
yesterday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   569
    "return a date, representing yesterday.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   570
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   571
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   572
    ^ Date today subtractDays:1
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   573
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   574
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   575
     Date yesterday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   576
     Date yesterday dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   577
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   578
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   579
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   580
!Date class methodsFor:'Compatibility-Dolphin'!
6872
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   581
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   582
newDay:day monthIndex:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   583
    ^ self newDay:day month:month year:year
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   584
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   585
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   586
     Date newDay:8 monthIndex:5 year:1993
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   587
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   588
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   589
    "Modified: 19.4.1996 / 15:28:15 / cg"
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   590
! !
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   591
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   592
!Date class methodsFor:'Compatibility-ST80'!
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   593
7648
61b7826a9a0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7646
diff changeset
   594
newDay:day monthNumber:monthIndex year:year
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   595
    "ST80 compatibility"
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   596
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   597
    ^ self newDay:day month:monthIndex year:year
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   598
! !
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   599
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   600
!Date class methodsFor:'Compatibility-Squeak'!
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   601
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   602
fromSeconds:seconds
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   603
    "Answer an instance of me which is 'seconds' seconds after January 1, 1901."
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   604
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   605
    | secondsInDay |
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   606
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   607
    secondsInDay := 24 * 60 * 60.
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   608
    ^self fromDays: seconds // secondsInDay
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   609
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   610
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   611
     Date fromSeconds:0
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   612
     Date fromSeconds:(24 * 60 * 60 * 365)
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   613
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   614
! !
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   615
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   616
!Date class methodsFor:'general queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   617
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   618
abbreviatedNameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   619
    "given a day index (1..7), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   620
     of the day"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   621
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   622
    ^ self abbreviatedNameOfDay:dayIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   623
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   624
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   625
     Date abbreviatedNameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   626
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   627
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   628
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   629
abbreviatedNameOfDay:dayIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   630
    "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
   631
     of the day.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   632
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   633
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   634
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   635
    ^ (self dayAbbrevsForLanguage:lang) at:dayIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   636
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   637
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   638
     Date abbreviatedNameOfDay:4 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   639
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   640
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   641
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   642
abbreviatedNameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   643
    "given a month index (1..12), return the abbreviated name
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   644
     of the month"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   645
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   646
    ^ self abbreviatedNameOfMonth:monthIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   647
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   649
     Date abbreviatedNameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   650
     Date abbreviatedNameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   651
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   652
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   653
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   654
abbreviatedNameOfMonth:monthIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   655
    "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
   656
     of the month.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   657
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   658
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   659
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   660
    ^ (self monthAbbrevsForLanguage:lang) at:monthIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   661
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   662
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   663
     Date abbreviatedNameOfMonth:11 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   664
     Date abbreviatedNameOfMonth:12 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   665
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   666
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   667
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   668
dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   669
    "return an array containing the date and time of now"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   670
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   671
    ^ Time dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   672
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   673
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   674
     Date dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   675
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   676
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   677
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   678
dayOfFirstWeekInYear:aYear
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   679
    "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
   680
     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
   681
     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
   682
     (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
   683
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   684
    |day dayInWeekOf1stJan firstThursday firstDayInWeek|
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   685
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   686
    "/ find the first thursday ...
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   687
    day := Timestamp newDay:1 year:aYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   688
    dayInWeekOf1stJan := day dayInWeek.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   689
    dayInWeekOf1stJan > 4 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   690
        firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   691
    ] ifFalse:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   692
        firstThursday := day addDays:(4 - dayInWeekOf1stJan).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   693
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   694
    "/ back to the preceeding monday
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   695
    firstDayInWeek := firstThursday subtractDays:3.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   696
    ^ firstDayInWeek
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   697
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   698
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   699
     Date dayOfFirstWeekInYear:1998   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   700
     Date dayOfFirstWeekInYear:1999    
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   701
     Date dayOfFirstWeekInYear:2000  
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   702
     Date dayOfFirstWeekInYear:2001   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   703
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   704
!
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
   705
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   706
dayOfWeek:dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   707
    "given the name of a day (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   708
     return the day-index (1 for monday; 7 for sunday).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   709
     Return 0 for invalid day name"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   710
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   711
    ^ self dayOfWeek:dayName language:nil
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   712
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   713
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   714
     Date dayOfWeek:'wednesday' 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   715
     Date dayOfWeek:'Wednesday' 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   716
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   717
!
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   718
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   719
dayOfWeek:dayName language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   720
    "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
   721
     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
   722
     Return 0 for invalid day name.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   723
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   724
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   725
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   726
    |idx langDayNames|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   727
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   728
    langDayNames := self dayNamesForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   729
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   730
    idx := langDayNames indexOf:dayName.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   731
    idx == 0 ifTrue:[
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   732
        idx := langDayNames indexOf:dayName asLowercase.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   733
    ].
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
   734
    ^ idx
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   735
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   736
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   737
     Date dayOfWeek:'wednesday' language:'en'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   738
     Date dayOfWeek:'Wednesday' language:'en'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   739
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   740
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   741
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   742
daysInMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   743
    "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
   744
     of days this month has (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   745
     return 0 if the month name was invalid.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   746
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   747
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   748
    |monthIndex "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   749
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   750
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   751
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   752
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   753
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   754
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   755
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   756
    ^ self daysInMonthIndex:monthIndex forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   757
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   758
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   759
     Date daysInMonth:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   760
     Date daysInMonth:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   761
     Date daysInMonth:'feb' forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   762
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   763
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   764
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   765
daysInYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   766
    "return the number of days in a year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   767
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   768
    (self leapYear:yearInteger) ifTrue:[^ 366].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   769
    ^ 365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   770
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   771
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   772
     Date daysInYear:1900  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   773
     Date daysInYear:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   774
     Date daysInYear:1904 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   775
     Date daysInYear:1980 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   776
     Date daysInYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   777
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   778
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   779
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   780
daysUntilMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   781
    "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
   782
     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
   783
     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
   784
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   785
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   786
    |monthIndex "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   787
     sumDays    "{ Class: SmallInteger }" |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   788
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   789
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   790
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   791
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   792
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   793
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   794
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   795
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   796
    sumDays := 0.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   797
    1 to:monthIndex-1 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   798
	sumDays := sumDays + (self daysInMonthIndex:m forYear:yearInteger)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   799
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   800
    ^ sumDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   801
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   802
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   803
     Date daysUntilMonth:'feb' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   804
     Date daysUntilMonth:'jan' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   805
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   806
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   807
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   808
defaultFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   809
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   810
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   811
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   812
    ^ DefaultFormats at:Language ifAbsent:(DefaultFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   813
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   814
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   815
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   816
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   817
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   818
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   819
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   820
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   821
firstDayOfYear:inYear
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   822
    "return the weekDay-index of the 1st-january of the given year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   823
     1->monday, 2->tuesday, ... 7->sunday"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   824
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   825
    | t d |
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   826
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   827
    ((inYear < 1) or:[ inYear > 9999]) ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   828
        ^ 0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   829
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   830
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   831
    "/ normal Gregorian calendar: one extra day per four years 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   832
    t := 4 + inYear + ((inYear + 3) // 4).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   833
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   834
    inYear > 1800 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   835
        "/ Julian calendar: regular Gregorian less 3 days per 400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   836
        t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   837
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   838
    inYear > 1752 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   839
        "/ calendar changeover
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   840
        t := t + 3.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   841
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   842
    d := t \\ 7.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   843
    "/ convert from 0 (sunday) .. 6 (saturday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   844
    "/ to 1 (munday) .. 7 (sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   845
    d == 0 ifTrue:[^ 7].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   846
    ^ d
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   847
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   848
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   849
     self firstDayOfYear:2000           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   850
     (Date newDay:1 year:2000) dayInWeek 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   851
     self firstDayOfYear:1999      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   852
     (Date newDay:1 year:1999) dayInWeek
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   853
     self firstDayOfYear:1998      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   854
     (Date newDay:1 year:1998) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   855
     self firstDayOfYear:2001           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   856
     (Date newDay:1 year:2001) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   857
     self firstDayOfYear:2002           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   858
     (Date newDay:1 year:2002) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   859
     self firstDayOfYear:2006           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   860
     (Date newDay:1 year:2006) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   861
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   862
     self firstDayOfYear:1800           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   863
     (Date newDay:1 year:1800) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   864
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   865
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
   866
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   867
indexOfMonth:aMonthString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   868
    "given the name of a month (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   869
     return the month-index (1 for jan; 12 for december).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   870
     The given string may be a full or abbreviated name,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   871
     case is ignored.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   872
     Return 0 for invalid month name."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   873
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   874
    ^ self indexOfMonth:aMonthString language:nil
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   875
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   876
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   877
     Date indexOfMonth:'jan'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   878
     Date indexOfMonth:'Jan'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   879
     Date indexOfMonth:'December'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   880
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   881
!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   882
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   883
indexOfMonth:aMonthString language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   884
    "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
   885
     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
   886
     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
   887
     case is ignored.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   888
     Return 0 for invalid month name.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   889
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   890
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   891
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   892
    |idx name langMonthNames langMonthAbbrevs|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   893
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   894
    langMonthNames := self monthNamesForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   895
    langMonthAbbrevs := self monthAbbrevsForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   896
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   897
    name := aMonthString asLowercase.
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   898
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   899
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   900
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   901
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   903
    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
   904
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   905
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   906
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   907
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   908
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   909
    ^ idx
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   910
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   911
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   912
     Date indexOfMonth:'jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   913
     Date indexOfMonth:'Jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   914
     Date indexOfMonth:'December' language:#en 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   915
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   916
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   917
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   918
isLeapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   919
    "Return true, if a year is a leap year.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   920
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   921
	 Please use the ST-80 compatible #leapYear for new programs, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   922
	 since this method will vanish."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   923
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   924
    ^ self leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   925
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   926
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   927
leapYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   928
    "return true, if yearInteger is a leap year."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   929
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   930
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   931
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   932
    y := yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   933
    (y \\ 4 == 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   934
	(y \\ 100 ~~ 0) ifTrue:[^ true].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   935
	(y \\ 400 == 0) ifTrue:[^ true]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   936
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   937
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   938
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   939
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   940
     Date leapYear:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   941
     Date leapYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   942
     Date leapYear:1900
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   943
     Date leapYear:2000
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   944
    "
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
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   947
longFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   948
    (LongFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   949
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
   950
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   951
    ^ LongFormats at:Language ifAbsent:(LongFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   952
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   953
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   954
     Date today printStringFormat:(Date defaultFormatString). 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   955
     Date today printStringFormat:(Date longFormatString).    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   956
     Date today printStringFormat:(Date shortFormatString).   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   957
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   958
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
   959
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   960
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   961
    "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
   962
     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
   963
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   964
    |restDays daysInMonth|
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
    restDays := aDayInYear.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   967
    restDays < 1 ifTrue:[^ nil].
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
    1 to:12 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   970
	daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   971
	restDays <= daysInMonth ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   972
	    ^ Array with:m with:restDays
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
	restDays := restDays - daysInMonth 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   975
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   976
    restDays > daysInMonth ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   977
    ^ Array with:12 with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   978
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   979
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   980
     Date monthAndDayFromDayInYear:66 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   981
     Date monthAndDayFromDayInYear:66 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   982
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   983
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   984
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   985
nameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   986
    "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
   987
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   988
    ^ self nameOfDay:dayIndex language:nil
699
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   991
     Date nameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   992
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   993
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   994
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   995
nameOfDay:dayIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   996
    "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
   997
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   998
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
   999
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1000
    ^ (self dayNamesForLanguage:lang) at:dayIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1001
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1002
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1003
     Date nameOfDay:4 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1004
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1005
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1006
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1007
nameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1008
    "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
  1009
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1010
    ^ self nameOfMonth:monthIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1011
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1012
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1013
     Date nameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1014
     Date nameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1015
     Date nameOfMonth:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1016
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1017
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1018
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1019
nameOfMonth:monthIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1020
    "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
  1021
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1022
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1023
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1024
    ^ (self monthNamesForLanguage:lang) at:monthIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1025
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1026
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1027
     Date nameOfMonth:11 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1028
     Date nameOfMonth:12 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1029
     Date nameOfMonth:4  language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1030
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1031
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1032
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1033
shortFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1034
    (ShortFormats isNil or:[EnvironmentChange]) ifTrue:[
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1035
	self initNames
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1036
    ].
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1037
    ^ ShortFormats at:Language ifAbsent:(ShortFormats at:#en).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1038
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1039
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1040
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1041
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1042
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1043
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1044
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1045
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1046
weekInYearOf:aDateOrTimestamp
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1047
    "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
  1048
     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
  1049
     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
  1050
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1051
    |dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1052
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1053
    dayInYear := aDateOrTimestamp dayInYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1054
    dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1055
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1056
    numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1057
    "/ 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
  1058
    numDays < 0 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1059
        "/ not in a week here ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1060
        "/ can be either 52 or 53, depending on the previous year.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1061
        ^ self weekInYearOf:(Date day:31 month:12 year:aDateOrTimestamp year - 1)
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1062
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1063
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1064
    "/ compute the week 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1065
    week := numDays // 7 + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1066
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1067
    "/ 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
  1068
    week == 53 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1069
        dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1070
        aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1071
            ^ 1
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1072
        ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1073
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1074
    ^ week
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1075
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1076
    "
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1077
     Timestamp now weekInYear    
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1078
     Date weekInYearOf:(Date day: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
  1079
     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
  1080
     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
  1081
     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
  1082
     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
  1083
     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
  1084
     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
  1085
     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
  1086
     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
  1087
     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
  1088
     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
  1089
     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
  1090
     Date weekInYearOf:(Timestamp newDay:17 year:2000)   was a monday -> W03
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1091
     Date weekInYearOf:(Date day:1 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1092
     Date weekInYearOf:(Date day:2 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1093
     Date weekInYearOf:(Date day:3 month:1 year:2001)     
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1094
     Date weekInYearOf:(Date day:24 month:12 year:2001)   -> W52
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1095
     Date weekInYearOf:(Date day:30 month:12 year:2001)   -> W52
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1096
     Date weekInYearOf:(Date day:31 month:12 year:2001)   -> W01
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1097
     Date weekInYearOf:(Date day:1 month:1 year:2002)    
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1098
     Date weekInYearOf:(Date day:2 month:1 year:2002)      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1099
     Date weekInYearOf:(Date day:7 month:1 year:2002)      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1100
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1101
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1102
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1103
yearAsDays: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1104
    "Returns the number of days since Jan 1, 1901. (GNU)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1105
     to the first Jan of the year, yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1106
     For 1901 this is zero, for 1902 its 365.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1107
     Defined for years >= 1901"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1108
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1109
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1110
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1111
    y := yearInteger - 1900.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1112
    y := y - 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1113
    ^ (y * 365)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1114
	+ (y // 4)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1115
	- (y // 100)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1116
	+ ((y + 300) // 400)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1117
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1118
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1119
     Date yearAsDays:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1120
     Date yearAsDays:1902   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1121
     Date yearAsDays:1903   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1122
     Date yearAsDays:1904    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1123
     Date yearAsDays:1905     
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1124
     Date yearAsDays:1994   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1125
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1126
    "
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
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1129
!Date class methodsFor:'handling language changes'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1130
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1131
update:something with:aParameter from:changedObject
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1132
    ((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1133
        "just remember change for next access"
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1134
        EnvironmentChange := true
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1135
    ]
1468
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1136
cb156455b046 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1137
    "Created: 15.6.1996 / 15:19:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1138
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1139
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1140
!Date class methodsFor:'obsolete instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1141
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1142
day:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1143
    "return a new Date, given the day, month and year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1144
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1145
	use newDay:month:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1146
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1147
    ^ self newDay:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1148
!
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1149
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1150
day:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1151
    "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
  1152
     Obsolete:
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1153
	use newDay:year: for ST-80 compatibility"
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1154
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1155
    ^ self newDay:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1156
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1157
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1158
!Date class methodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1159
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1160
dayAbbrevsForLanguage:language
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1161
    |langDayAbbrevs|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1162
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1163
    (DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1164
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1165
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1166
    langDayAbbrevs := DayAbbrevs at:(language ? Smalltalk language) ifAbsent:nil.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1167
    langDayAbbrevs isNil ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1168
        langDayAbbrevs := DayAbbrevs at:#en.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1169
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1170
    ^ langDayAbbrevs
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1171
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1172
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1173
dayNamesForLanguage:language
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1174
    |langDayNames|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1175
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1176
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1177
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1178
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1179
    langDayNames := DayNames at:(language ? Smalltalk language) ifAbsent:nil.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1180
    langDayNames isNil ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1181
        langDayNames := DayNames at:#en.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1182
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1183
    ^ langDayNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1184
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1185
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1186
daysInMonthIndex: monthIndex forYear: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1187
    "return the number of days in month monthIndex of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1188
     year yearInteger (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1189
     Return 0 for invalid month index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1190
     This is the internal version of daysInMonth:forYear:"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1191
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1192
    |days|
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
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1195
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1196
    days := #(31 28 31           "Jan Feb Mar"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1197
	      30 31 30           "Apr May Jun"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1198
	      31 31 30           "Jul Aug Sep"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1199
	      31 30 31           "Oct Nov Dec"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1200
	     ) at: monthIndex.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1201
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1202
    (monthIndex == 2) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1203
	(self leapYear:yearInteger) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1204
	    ^ days + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1205
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1206
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1207
    ^ days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1208
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1209
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1210
     Date daysInMonthIndex:2 forYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1211
     Date daysInMonthIndex:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1212
     Date daysInMonthIndex:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1213
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1214
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1215
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1216
monthAbbrevsForLanguage:language
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1217
    |langMonthAbbrevs|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1218
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1219
    (MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1220
        self initNames
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1221
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1222
    langMonthAbbrevs := MonthAbbrevs at:(language ? Smalltalk language) ifAbsent:nil.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1223
    langMonthAbbrevs isNil ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1224
        langMonthAbbrevs := MonthAbbrevs at:#en.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1225
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1226
    ^ langMonthAbbrevs
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1227
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1228
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1229
monthNamesForLanguage:language
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1230
    |langMonthNames|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1231
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1232
    (MonthNames isNil or:[EnvironmentChange]) ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1233
        self initNames
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
    langMonthNames := MonthNames at:(language ? Smalltalk language) ifAbsent:nil.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1236
    langMonthNames isNil ifTrue:[
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1237
        langMonthNames := MonthNames at:#en.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1238
    ].
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1239
    ^ langMonthNames
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1240
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1241
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  1242
!Date class methodsFor:'private-encoding'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1243
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1244
encodeYear:y month:m day:d
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1245
    "the internal encoding is stricktly private, 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1246
     and should not be used outside."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1247
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1248
    ^ (((y * 100) + m) * 100) + d
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1249
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1250
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  1251
!Date class methodsFor:'private-instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1252
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1253
fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1254
    "return a date, representing the date given by the operatingSystem time.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1255
     This somewhat clumsy implementation hides the OS's date representation
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1256
     (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
  1257
     Dont use this method, the osTime representation is totally unportable."
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1258
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1259
    ^ self basicNew fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1260
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1261
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1262
     Date fromOSTime:#(0 0)      -> on UNIX: this should return 1st Jan 1970
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1263
				    thats where Unix time starts
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1264
				    On other systems, it may be something different.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1265
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1266
     Date fromOSTime:#(86400 0)  -> on UNIX: the day after
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1267
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1268
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1269
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1270
!Date methodsFor:'Compatibility-ANSI'!
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1271
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1272
dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1273
    "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
  1274
     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
  1275
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1276
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1277
    |d|
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1278
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1279
    d := self dayInWeek.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1280
    d == 7 ifTrue:[
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1281
        ^ 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1282
    ].
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1283
    ^ d + 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1284
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1285
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1286
     Date today dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1287
     Date today dayInWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1288
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1289
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1290
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1291
dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1292
    "return the short week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1293
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1294
     Expect things like 'mon', 'tue' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1295
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1296
    ^ self abbreviatedDayName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1297
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1298
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1299
     Date today dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1300
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1301
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1302
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1303
dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1304
    "return the week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1305
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1306
     Expect things like 'monday', 'tuesday' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1307
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1308
    ^ self weekday
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1309
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1310
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1311
     Date today dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1312
     Date today dayOfWeekAbbreviation 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1313
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1314
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1315
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1316
dayOfYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1317
    "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
  1318
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1319
    ^ self dayInYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1320
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1321
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1322
     Date today dayOfYear 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1323
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1324
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1325
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1326
isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1327
    "return true, if the receivers year is a leap year"
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1328
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1329
    ^ self leap
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1330
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1331
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1332
     Date today isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1333
     (Date day:1 month:1 year:1992) isLeapYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1334
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1335
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1336
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1337
monthAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1338
    "return the month of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1339
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1340
     Expect things like 'jan', 'feb' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1341
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1342
    ^ self abbreviatedMonthName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1343
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1344
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1345
     Date today monthAbbreviation  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1346
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1347
! !
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  1348
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1349
!Date methodsFor:'Compatibility-ST80'!
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1350
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1351
previous:dayName 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1352
    "Return the previous date whose weekday name is dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1353
     Caveat; dayName is expected to be in the current language"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1354
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1355
    ^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1)
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1356
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1357
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1358
     Date today                 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1359
     Date today previous:#Monday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1360
     Date today previous:#Friday 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1361
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1362
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1363
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1364
printFormat:aFormatArray
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1365
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1366
     Return a string containing a printed representation of the receiver.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1367
     The formatArray argument consists of 6 or 7 integers which control
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1368
     the resulting string. The entries are:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1369
     1   day position (1, 2 or 3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1370
     2   month position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1371
     3   year position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1372
     4   asciiValue of separator character or separator character
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1373
         or collection of 2 separator characters
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1374
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1375
         4: abbreviated uppercase 5: full uppercase)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1376
     6   year format (1 include century; 2 exclude century)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1377
     7  (optional) true/false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1378
         if true, print numbers in 2-digit format
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1379
         (i.e. with leading zeros); 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1380
         Taken as false, if ommited
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1381
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1382
     Day and monthnames are in the currently active language.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1383
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1384
     This method supports more options than the ST-80 version; month formats 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1385
     4 and 5, non-numeric separators and the optional 7th parameter are not 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1386
     supported by ST-80. Be aware of this for compatibility reasons.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1387
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1388
     Notice that not all formats can be scanned (correctly) by #readFrom:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1389
     This is an ST-80 compatibility method - I would have choosen another
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1390
     (less cryptic) formatString ...
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1391
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1392
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1393
    ^ self printFormat:aFormatArray forLanguage:nil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1394
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1395
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1396
     Date today printFormat:#(1 2 3 '' 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1397
     Date today printFormat:#(1 2 3 $- 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1398
     Date today printFormat:#(1 2 3 $. 1 2 true)     
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1399
     Date today printFormat:#(2 1 3 32 3 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1400
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1401
     Date today printFormat:#(1 2 3 $- 2 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1402
     Date today printFormat:#(1 2 3 $- 4 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1403
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1404
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1405
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1406
printFormat:aFormatArray forLanguage:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1407
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1408
     Return a string containing a printed representation of the receiver.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1409
     The formatArray argument consists of 6 or 7 integers which control
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1410
     the resulting string. The entries are:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1411
     1   day position (1, 2 or 3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1412
     2   month position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1413
     3   year position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1414
     4   asciiValue of separator character or separator character
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1415
         or collection of 2 separator characters
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1416
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1417
         4: abbreviated uppercase 5: full uppercase)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1418
     6   year format (1 include century; 2 exclude century)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1419
     7  (optional) true/false.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1420
         if true, print numbers in 2-digit format
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1421
         (i.e. with leading zeros); 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1422
         Taken as false, if ommited
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1423
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1424
     Day and monthnames are in the currently active language.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1425
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1426
     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
  1427
     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
  1428
     supported by ST-80. Be aware of this for compatibility reasons.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1429
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1430
     Notice that not all formats can be scanned (correctly) by #readFrom:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1431
     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
  1432
     (less cryptic) formatString ...
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1433
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1434
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1435
    |mf upperCase day month year components sep1 sep2 leadingZeros|
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1436
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1437
    aFormatArray size > 6 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1438
        leadingZeros := aFormatArray at:7
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1439
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1440
        leadingZeros := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1441
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1442
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1443
    components := Array new:3.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1444
    day := self day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1445
    leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1446
        day := day printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1447
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1448
        day := day printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1449
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1450
    components at:(aFormatArray at:1) put:day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1451
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1452
    upperCase := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1453
    mf := aFormatArray at:5.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1454
    (mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1455
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1456
    mf == 1 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1457
        month := self month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1458
        leadingZeros ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1459
            month := month printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1460
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1461
            month := month printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1462
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1463
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1464
        mf == 2 ifTrue:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1465
            month := self abbreviatedMonthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1466
        ] ifFalse:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1467
            month := self monthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1468
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1469
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1470
    upperCase ifTrue:[month := month asUppercase].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1471
    components at:(aFormatArray at:2) put:month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1472
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1473
    year := self year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1474
    (aFormatArray at:6) == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1475
        year := year \\ 100.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1476
        year := year printStringLeftPaddedTo:2 with:$0 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1477
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1478
    year := year printString.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1479
    components at:(aFormatArray at:3) put:year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1480
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1481
    sep1 := sep2 := (aFormatArray at:4).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1482
    sep1 isString ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1483
        sep1 isCollection ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1484
            sep2 := (sep1 at:2).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1485
            sep1 := (sep1 at:1).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1486
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1487
            sep1 := sep2 := sep1 asCharacter
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1488
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1489
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1490
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1491
    ^ (components at:1)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1492
      , sep1 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1493
      , (components at:2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1494
      , sep2 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1495
      , (components at:3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1496
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1497
    "
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1498
     Date today printFormat:#(1 2 3 '' 1 2)         
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1499
     Date today printFormat:#(1 2 3 $- 1 2)         
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1500
     Date today printFormat:#(1 2 3 $. 1 2 true)     
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1501
     Date today printFormat:#(2 1 3 32 3 1)          
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1502
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1503
     Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en           
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1504
     Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1505
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1506
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1507
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1508
printFormat:aFormatArray forLanguage:languageOrNil on:aStream
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1509
    "Obsolete, backward ST-80 compatible formatted printing - see comment
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1510
     in printFormat:.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1511
     Append a printed representation of the receiver to aStream.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1512
     The argument, aFormatString controls the format, as described
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1513
     in the #printFormat: method.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1514
     Notice that not all formats can be scanned (correctly) by #readFrom:"
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1515
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1516
    aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1517
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1518
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1519
    "european formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1520
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1521
     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
  1522
     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
  1523
     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
  1524
     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
  1525
     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
  1526
     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
  1527
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1528
     US formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1529
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1530
     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
  1531
     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
  1532
     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
  1533
     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
  1534
     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
  1535
     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
  1536
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1537
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1538
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1539
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1540
printFormat:aFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1541
    "Obsolete, backward ST-80 compatible formatted printing - see comment
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1542
     in printFormat:.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1543
     Append a printed representation of the receiver to aStream.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1544
     The argument, aFormatString controls the format, as described
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1545
     in the #printFormat: method.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1546
     Notice that not all formats can be scanned (correctly) by #readFrom:"
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1547
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1548
    aStream nextPutAll:(self printFormat:aFormatArray)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1549
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1550
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1551
    "european formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1552
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1553
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1554
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1555
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1556
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1557
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1558
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1559
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1560
     US formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1561
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1562
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1563
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1564
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1565
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1566
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1567
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1568
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1569
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1570
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  1571
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1572
shortPrintString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1573
    "dummy - for now"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1574
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1575
    ^ self printString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1576
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1577
    "Created: 20.6.1997 / 17:16:48 / cg"
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1578
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1579
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1580
weekdayIndex
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1581
    "Return the day index; Monday=1, ... , Sunday=7"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1582
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1583
    ^ (self asDays + 1) \\ 7 + 1  "1 January 1901 was a Tuesday"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1584
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1585
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1586
     Date today dayName
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1587
     Date today weekdayIndex      
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1588
    "
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1589
! !
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  1590
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1591
!Date methodsFor:'Compatibility-Squeak'!
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1592
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1593
mmddyyyy
4462
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1594
    "return a printed representation of the receiver in the
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1595
     form mmddyyyy.
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1596
     The receiver can be reconstructed with: 
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1597
        Date readMMDDYYYYFrom:aStringOrStream onError:[...]"
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1598
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1599
    ^ (self month printStringLeftPaddedTo:2 with:$0)
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1600
       , (self day printStringLeftPaddedTo:2 with:$0) 
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1601
       , (self year printStringLeftPaddedTo:4 with:$0)
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1602
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1603
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1604
     Date today mmddyyyy
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1605
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1606
! !
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  1607
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1608
!Date methodsFor:'accessing'!
241
6f30be88e314 *** empty log message ***
claus
parents: 202
diff changeset
  1609
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1610
abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1611
    "return the short week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1612
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1613
     Expect things like 'mon', 'tue' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1614
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1615
    ^ self class abbreviatedNameOfDay:(self dayInWeek)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1616
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1617
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1618
     Date today abbreviatedDayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1619
     (Date day:15 month:4 year:1959) abbreviatedDayName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1620
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1621
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1622
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1623
abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1624
    "return the month of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1625
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1626
     Expect things like 'jan', 'feb' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  1627
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1628
    ^ self class abbreviatedNameOfMonth:(self month)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1629
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1630
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1631
     Date today abbreviatedMonthName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1632
     (Date day:15 month:4 year:1959) abbreviatedMonthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1633
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1634
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1635
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1636
abbreviatedMonthNameForLanguage:lang
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1637
    "return the month of the receiver as a string.
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1638
     The returned string depends on the language setting.
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1639
     Expect things like 'jan', 'feb' ..."
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1640
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1641
    ^ self class abbreviatedNameOfMonth:(self month) language:lang
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1642
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1643
    "
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1644
     Date today abbreviatedMonthNameForLanguage:#en 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1645
     Date today abbreviatedMonthNameForLanguage:#de 
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1646
    "
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1647
!
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  1648
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1649
asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1650
    "return the number of days elapsed since 01-Jan-1901
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1651
     and the receiver's day; starts with 0 for 1-1-1901.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1652
     Date>>fromDays: is the reverse operation.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1653
     For ST-80 compatibility."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1654
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1655
    |yr|
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1656
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1657
    yr := self year.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1658
    ^ (self class yearAsDays:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1659
      + (self class daysUntilMonth:self month forYear:yr)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1660
      + self day
85
claus
parents: 77
diff changeset
  1661
      - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1662
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1663
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1664
     (Date day: 5 month: 8 year: 1962) asDays  -> should be 22496
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1665
     (Date day: 1 month: 1 year: 1901) asDays  -> 0
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1666
     Date today asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1667
     Date fromDays:(Date today asDays + 7)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1668
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1669
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1670
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1671
asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1672
    "return the seconds between 1.jan.1901 and the same time in the receivers 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1673
     day. (i.e. midnight to midnight).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1674
     This does not include any leapSeconds ... strictly speaking, this is incorrect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1675
     ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1676
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1677
    ^ 60*60*24 * self asDays
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1678
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1679
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1680
     (Date day: 5 month: 8 year: 1962) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1681
     (Date day: 1 month: 1 year: 1901) asSeconds
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1682
     (Date today addDays:7) asSeconds - Date today asSeconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1683
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1684
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1685
    "Modified: 1.7.1996 / 14:19:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1686
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1687
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1688
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1689
    "return the day (1..31) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1690
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1691
    ^ dateEncoding \\ 100
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1692
8626
ae1fcb227a45 example
penk
parents: 8480
diff changeset
  1693
    "example:
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1694
     Date today day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1695
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1696
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1697
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1698
dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1699
    "return the number of days since 1st. Jan. 1901;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1700
     starting with 0 for this date.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1701
     Date>>fromDays: is the reverse operation.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1702
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1703
	 please use asDays for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1704
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1705
    ^ self asDays.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1706
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1707
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1708
     (Date day:1 month:1 year:1901) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1709
     Date fromDays:(Date day:1 month:1 year:1994) dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1710
     Date today dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1711
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1712
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1713
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1714
dayInWeek
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1715
    "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
  1716
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1717
     WARNING: does not care for pre-julian dates 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1718
        (i.e. do not use this for dates before 1752)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1719
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1720
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1721
    |wday|
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1722
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1723
    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
  1724
            + self asDays) \\ 7 + 1.
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1725
    wday < 1 ifTrue:[
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1726
        wday := wday + 7
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1727
    ].
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1728
    ^ wday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1729
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1730
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1731
     Date today dayInWeek      
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1732
     Date tomorrow dayInWeek 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1733
     Date yesterday dayInWeek 
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1734
     (Date today subtractDays:2) dayInWeek 
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1735
     Date today weekday 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1736
     Date tomorrow weekday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1737
     Date yesterday weekday 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1738
     (Date day:15 month:4 year:1959) dayInWeek 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1739
     (Date day:1 month:1 year:1901) dayInWeek 
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1740
     (Date day:31 month:12 year:1899) dayInWeek 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1741
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  1742
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1743
    "Modified: / 1.2.1998 / 14:10:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1744
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1745
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1746
dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1747
    "return the day-nr within the year of the receiver - 1 .. 365/366"
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1748
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1749
    ^ self asTimestamp dayInYear
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1750
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1751
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1752
     Date today dayInYear 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1753
     (Date newDay:1 year:1999) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1754
     (Date newDay:1 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1755
     (Date newDay:2 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1756
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1757
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1758
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1759
dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1760
    "return the week-day of the receiver as a string.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1761
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1762
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1763
     Obsolete:
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1764
	use #weekday for ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1765
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1766
    ^ self weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1767
!
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1768
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1769
dayOfMonth
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1770
    "Answer the day of the month represented by me.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1771
     Same as day; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1772
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1773
    ^ self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1774
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1775
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1776
     Date today dayOfMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1777
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1778
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1779
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1780
daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1781
    "return the number of days in the month of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1782
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1783
    ^ Date daysInMonth:(self month) forYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1784
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1785
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1786
     Date today daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1787
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1788
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1789
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1790
daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1791
    "return the number of days in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1792
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1793
    ^ Date daysInYear:(self year)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1794
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1795
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1796
     Date today daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1797
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1798
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1799
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1800
daysLeftInMonth
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1801
    "return the number of days left in the month of the receiver"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1802
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1803
    ^ self daysInMonth - self day
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1804
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1805
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1806
     Date today daysLeftInMonth             
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1807
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1808
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1809
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1810
daysLeftInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1811
    "return the number of days left in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1812
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1813
    ^ (Date daysInYear:(self year)) - self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1814
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1815
    "
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  1816
     Date today daysLeftInYear             
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1817
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1818
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1819
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1820
leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1821
    "return true, if the receivers year is a leap year"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1822
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1823
    ^ Date leapYear:(self year)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1824
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1825
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1826
     Date today leap
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1827
     (Date day:1 month:1 year:1992) leap
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1828
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1829
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1830
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1831
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1832
    "return the month (1..12) of the receiver"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1833
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1834
    ^ (dateEncoding // 100) \\ 100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1835
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1836
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1837
     Date today month
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1838
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1839
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1840
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1841
monthIndex
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1842
    "return the index of the month (e.g. Feb.=2).
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1843
     Same as month; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1844
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1845
    ^ self month  
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1846
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1847
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1848
monthName
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1849
    "return the month of the receiver as a string.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1850
     The returned string depends on the language setting.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1851
     Expect things like 'january', 'february' ..."
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1852
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1853
    ^ self class nameOfMonth:(self month)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1854
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1855
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1856
     Date today monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1857
     (Date day:15 month:4 year:1959) monthName
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1858
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1859
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1860
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1861
monthNameForLanguage:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1862
    "return the month of the receiver as a string.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1863
     The returned string depends on the language setting.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1864
     Expect things like 'january', 'february' ..."
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1865
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1866
    ^ self class nameOfMonth:(self month) language:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1867
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
     Date today monthName
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1870
     Date today monthNameForLanguage:#en
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1871
    "
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
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1874
weekInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1875
    "return the week number of the receiver - 1 for Jan, 1st.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1876
     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
  1877
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1878
    ^ self class weekInYearOf:self
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1879
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1880
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1881
     Date today weekInYear    
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1882
     (Date newDay:1 year:2000) weekInYear   was a saturday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1883
     (Date newDay:2 year:2000) weekInYear   was a sunday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1884
     (Date newDay:3 year:2000) weekInYear   was a monday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1885
     (Date newDay:4 year:2000) weekInYear   was a tuesday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1886
     (Date newDay:5 year:2000) weekInYear   was a wed
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1887
     (Date newDay:6 year:2000) weekInYear   was a thursday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1888
     (Date newDay:7 year:2000) weekInYear   was a fri
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1889
     (Date newDay:8 year:2000) weekInYear   was a sat
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1890
     (Date newDay:9 year:2000) weekInYear   was a sun
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1891
     (Date newDay:10 year:2000) weekInYear  was a monday
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1892
     (Date day:3 month:1 year:2001) weekInYear 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1893
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1894
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1895
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1896
weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1897
    "return the week-day of the receiver as a string.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1898
     The returned string depends on the language setting.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1899
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1900
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1902
    ^ self class nameOfDay:(self dayInWeek)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1904
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1905
     Date today weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1906
     (Date day:15 month:4 year:1959) weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1907
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1908
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1909
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1910
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1911
    "return the year (1..12) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1912
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1913
    ^ dateEncoding // (100*100)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1914
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1915
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1916
     Date today year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1917
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1918
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1919
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1920
!Date methodsFor:'arithmetic'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1921
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1922
+ days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1923
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1924
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1925
     This is the same as #addDays."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1926
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1927
    ^ self class fromDays:(self asDays + days)
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1928
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1929
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1930
     Date today + 7.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1931
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1932
     Date today to:(Date today + 28) by:7 do:[:date|
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1933
        Transcript show:date weekday; show:', '; showCr:date
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1934
     ].
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1935
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1936
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1937
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1938
- aDateOrNumberOfDays
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1939
    "return the delta in days (anInteger) between 2 dates or 
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1940
     subtract a number of days from a date returning a Date"
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1941
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1942
    aDateOrNumberOfDays class == self class ifTrue:[
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1943
        ^ self asDays - aDateOrNumberOfDays asDays
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1944
    ].
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1945
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1946
    ^ self class fromDays:(self asDays - aDateOrNumberOfDays asInteger)
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1947
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1948
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1949
        Date today - Date yesterday
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1950
        Date today - 3
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1951
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1952
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1953
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1954
addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1955
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1956
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1957
     For ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1958
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1959
    ^ self class fromDays:(self asDays + days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1960
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1961
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1962
     Date today addDays:7
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1963
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1964
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1965
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1966
daysUntil:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1967
    "return the number of days between the receiver and the argument,
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1968
     aDate, which should be some kind of date"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1969
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1970
    ^ aDate asDays - self asDays
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1971
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1972
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1973
     (Date day:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1974
     (Date day:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1975
     (Date day:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1976
    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1977
     |delta|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1978
     delta := Date today
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1979
                daysUntil:(Date day:25 month:12 year:Date today year).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1980
     Transcript show:'still ';
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1981
                show:delta ;
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  1982
                showCR:' days till xmas'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1983
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1984
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1985
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1986
subtractDate:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1987
    "return the number of days between the receiver and aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1988
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1989
    ^ self asDays - aDate asDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1990
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1991
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1992
    (Date day:1 month:1 year:1995) subtractDate:(Date day:24 month:12 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1993
    (Date day:1 month:3 year:1992) subtractDate:(Date day:1 month:2 year:1992)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1994
    (Date day:1 month:3 year:1994) subtractDate:(Date day:1 month:2 year:1994)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1995
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1996
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1997
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1998
subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1999
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2000
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2001
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2002
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2003
    ^ self class fromDays:(self asDays - days)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2004
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2005
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2006
     Date today subtractDays:7
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2007
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2008
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2009
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2010
!Date methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2011
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2012
< aDate
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2013
    "return true, if the date represented by the receiver
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2014
     is before the argument, aDate"
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2015
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2016
    (aDate isMemberOf:Date) ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2017
	^ dateEncoding < aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2018
    ].
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2019
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2020
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2021
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2022
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2023
    ^ dateEncoding < (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2024
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2025
				  day:aDate day)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2026
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2027
    "Date today < (Date day:24 month:12 year:2000)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2028
    "Date today < (Date day:24 month:12 year:1900)"
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  2029
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2030
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2031
= aDate
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2032
    "return true, if the date represented by the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2033
     is the same as the one represented by argument, aDate"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2034
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2035
    (aDate isMemberOf:Date) ifFalse:[^ false].
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2036
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2037
    ^ dateEncoding = aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2038
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2039
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2040
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2041
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2042
"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2043
    ^ dateEncoding = (Date encodeYear:aDate year
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2044
				month:aDate month
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2045
				  day:aDate day)
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  2046
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2047
    "Date today = ((Date today plusDays:7) minusDays:7)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2048
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2049
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2050
> aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2051
    "return true, if the date represented by the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2052
     is after the argument, aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2053
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2054
    (aDate isMemberOf:Date) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2055
	^ dateEncoding > aDate dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2056
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2057
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2058
    "the argument must understand year, month and day to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2059
     comparable, whatever it is"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2060
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2061
    ^ dateEncoding > (Date encodeYear:aDate year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2062
				month:aDate month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2063
				  day:aDate day)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2064
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2065
    "Date today > (Date day:24 month:12 year:2000)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2066
    "Date today > (Date day:24 month:12 year:1900)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2067
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2068
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2069
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2070
    "return an integer useful for hashing on dates"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2071
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2072
    ^ dateEncoding
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2073
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2074
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2075
!Date methodsFor:'converting'!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2076
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2077
asAbsoluteTime
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2078
    "deprecated, use #asTimestamp"
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2079
    <resource:#obsolete>
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2080
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2081
    ^ self asTimestamp
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  2082
!
4408
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2083
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2084
asDate
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2085
    "return the receiver"
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2086
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2087
    ^ self
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2088
!
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2089
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2090
asTimestamp
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2091
    "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
  2092
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2093
    ^ Timestamp year:(self year) month:(self month) day:(self day)  
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2094
                   hour:0 minute:0 second:0 millisecond:0
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2095
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2096
    "
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2097
     Date today asTimestamp
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  2098
    "
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  2099
! !
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2100
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2101
!Date methodsFor:'obsolete'!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2102
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2103
minusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2104
    "return a new date representing 'days' before the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2105
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2106
     Obsolete:
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2107
         Please dont use this method since it will vanish.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2108
         Use #subtractDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2109
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2110
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2111
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2112
    self obsoleteMethodWarning:'use #substractDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2113
    ^ self subtractDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2114
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2115
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2116
plusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2117
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2118
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2119
     Obsolete:
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2120
         Please dont use this method since it will vanish.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2121
         Use #addDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2122
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2123
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2124
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2125
    self obsoleteMethodWarning:'use #addDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2126
    ^ self addDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2127
! !
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  2128
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2129
!Date methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2130
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2131
addPrintBindingsTo:aDictionary
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2132
    "private print support: add bindings for printing to aDictionary.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2133
     valid format items are:
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2134
        %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
  2135
        %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
  2136
        %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
  2137
        %y              - year, full                     i.e. 1999, 2004
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2138
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2139
     special:
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2140
        %D              - day - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2141
        %M              - month - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2142
        %W              - week in year - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2143
        %Y              - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug)                     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2144
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2145
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2146
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2147
        %dayName        - full day name     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2148
        %DayName        - full day name, first character uppercase      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2149
        %DAYNAME        - full day name, all uppercase       
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2150
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2151
        %monthName      - full month name     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2152
        %MonthName      - full month name, first character uppercase      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2153
        %MONTHNAME      - full month name, all uppercase       
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2154
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2155
        %shortDayName   - short (abbreviated) day name     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2156
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2157
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2158
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2159
        %shortMonthName - short (abbreviated) month name     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2160
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2161
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2162
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2163
        %nth            - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2164
        %weekDayNth     - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2165
        %weekNth        - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')"     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2166
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2167
    self addPrintBindingsTo:aDictionary language:nil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2168
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2169
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2170
addPrintBindingsTo:aDictionary language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2171
    "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
  2172
     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
  2173
     valid format items are:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2174
        %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
  2175
        %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
  2176
        %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
  2177
        %y              - year, full                     i.e. 1999, 2004
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2178
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2179
     special:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2180
        %D              - day - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2181
        %M              - month - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2182
        %W              - week in year - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2183
        %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
  2184
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2185
        %weekDay        - day in week (1->monday, 2->tuesday, ... ,7->sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2186
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2187
        %dayName        - full day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2188
        %DayName        - full day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2189
        %DAYNAME        - full day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2190
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2191
        %monthName      - full month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2192
        %MonthName      - full month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2193
        %MONTHNAME      - full month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2194
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2195
        %shortDayName   - short (abbreviated) day name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2196
        %ShortDayName   - short (abbreviated) day name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2197
        %SHORTDAYNAME   - short (abbreviated) day name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2198
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2199
        %shortMonthName - short (abbreviated) month name     
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2200
        %ShortMonthName - short (abbreviated) month name, first character uppercase      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2201
        %SHORTMONTHNAME - short (abbreviated) month name, all uppercase       
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2202
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2203
        %nth            - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2204
        %weekDayNth     - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2205
        %weekNth        - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')"     
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2206
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2207
    |day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2208
     year weekInYear monthName shortMonthName 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2209
     dayInWeek dayOfWeek dayName shortDayName ws wsPadded0|
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2210
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2211
    day := self day.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2212
    ds := day printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2213
    dsPaddedB := day printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2214
    dsPadded0 := day printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2215
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2216
    month := self month.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2217
    ms := month printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2218
    msPaddedB := month printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2219
    msPadded0 := month printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2220
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2221
    year := self year.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2222
    weekInYear := self weekInYear.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2223
    ws := weekInYear printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2224
    wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2225
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2226
    dayInWeek := self dayInWeek.   "/ 1 .. 7
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2227
    dayOfWeek := self dayOfWeek.   "/ 0 .. 6
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2228
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2229
    monthName := self class nameOfMonth:(self month) language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2230
    dayName := self class nameOfDay:dayInWeek language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2231
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2232
    aDictionary at:#day put:dsPadded0.          "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2233
    aDictionary at:#daypadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2234
    aDictionary at:#dayPadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2235
    aDictionary at:#Day put:ds.                 "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2236
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2237
    aDictionary at:#month put:msPadded0.        "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2238
    aDictionary at:#monthPadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2239
    aDictionary at:#monthpadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2240
    aDictionary at:#Month put:ms.               "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2241
    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
  2242
    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
  2243
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2244
    aDictionary at:#year put:year.              "/ padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2245
    aDictionary at:#week put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2246
    aDictionary at:#Week put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2247
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2248
    year ~~ Date today year ifTrue:[
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2249
        aDictionary at:#yearOrTime put:(' ' , year printString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2250
    ].
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2251
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2252
    aDictionary at:$d put:dsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2253
    aDictionary at:$D put:ds.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2254
    aDictionary at:$m put:msPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2255
    aDictionary at:$M put:ms.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2256
    aDictionary at:$y put:year.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2257
    aDictionary at:$Y put:((year \\ 100)printStringLeftPaddedTo:2 with:$0).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2258
    aDictionary at:$w put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2259
    aDictionary at:$W put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2260
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2261
    aDictionary at:#monthName put:monthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2262
    aDictionary at:#monthname put:monthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2263
    aDictionary at:#MonthName put:monthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2264
    aDictionary at:#MONTHNAME put:monthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2265
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2266
    aDictionary at:#dayName put:dayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2267
    aDictionary at:#dayname put:dayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2268
    aDictionary at:#DayName put:dayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2269
    aDictionary at:#DAYNAME put:dayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2270
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2271
    aDictionary at:#weekDay put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2272
    aDictionary at:#weekday put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2273
    aDictionary at:#weekDayUS put:dayOfWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2274
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2275
    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
  2276
    aDictionary at:#shortdayname put:shortDayName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2277
    aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2278
    aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2279
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2280
    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
  2281
    aDictionary at:#shortmonthname put:shortMonthName.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2282
    aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2283
    aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2284
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2285
    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
  2286
                                     "/ 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
  2287
    aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:dayOfWeek-1 \\ 10 + 1). 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2288
                                     "/ 0   1    2    3    4    5    6      
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2289
    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
  2290
                                     "/ 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
  2291
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2292
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2293
printOn:aStream
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2294
    "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
  2295
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2296
    aStream nextPutAll:(self printStringFormat:(self class defaultFormatString) language:nil).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2297
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2298
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2299
     Date today printOn:Transcript. Transcript cr.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2300
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2301
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2302
    "Modified: 27.8.1995 / 01:01:49 / claus"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2303
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2304
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2305
printOn:aStream format:aFormatStringOrSqueakFormatArray
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2306
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2307
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2308
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2309
    aFormatStringOrSqueakFormatArray isArray ifTrue:[
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2310
        "/ backward compatibility: a squeak/st80 format array
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2311
        ^ self printFormat:aFormatStringOrSqueakFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2312
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2313
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2314
    aStream nextPutAll:(self printStringFormat:aFormatStringOrSqueakFormatArray language:nil)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2315
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2316
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2317
     Date today printOn:Transcript format:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2318
     Date today printOn:Transcript format:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2319
     Date today printOn:Transcript format:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2320
     Date today printOn:Transcript format:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2321
     Date today printOn:Transcript format:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2322
     Date today printOn:Transcript format:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2323
     Date today printOn:Transcript format:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2324
     Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2325
     Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2326
     Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2327
     Date today printOn:Transcript format:'%d%m%Y'                                      (millenium bug format - danger)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2328
     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
  2329
    "
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2330
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2331
     String streamContents:[:s |
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2332
        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
  2333
     ]    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2334
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2335
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2336
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2337
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2338
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2339
     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
  2340
     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
  2341
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2342
    aStream nextPutAll:(self printStringFormat:aFormatStringOrSqueakFormatArray language:languageOrNil)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2343
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2344
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2345
     Date today 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2346
        printOn:Transcript 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2347
        format:'%y%m%d'                             
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2348
        language:#en                             
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2349
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2350
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2351
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2352
printOn:aStream language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2353
    "append a printed representation of the receiver to aStream.
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2354
     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
  2355
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2356
    |format|
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2357
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2358
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
  2359
        self class initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2360
    ].
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2361
    format := DefaultFormats at:(languageOrNil ? Language) ifAbsent:[DefaultFormats at:#en].
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2362
    self printOn:aStream format:format language:languageOrNil.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2363
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2364
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2365
     Date today printOn:Transcript language:#en
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2366
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2367
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2368
    "Modified: / 27-08-1995 / 01:01:49 / claus"
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2369
    "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
  2370
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2371
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2372
printStringFormat:aFormatStringOrArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2373
    "print using a format string;
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2374
     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
  2375
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2376
    ^ self printStringFormat:aFormatStringOrArray language:nil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2377
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2378
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2379
     Date today printStringFormat:'%y%m%d'                                      (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2380
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2381
     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
  2382
     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
  2383
     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
  2384
     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
  2385
     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
  2386
     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
  2387
     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
  2388
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2389
     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
  2390
     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
  2391
     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
  2392
     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
  2393
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2394
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2395
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2396
printStringFormat:aFormatStringOrArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2397
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2398
     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
  2399
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2401
    |dict|
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2402
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2403
    dict := IdentityDictionary new.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  2404
    self addPrintBindingsTo:dict language:languageOrNil.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2405
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2406
    ^ (aFormatStringOrArray expandPlaceholdersWith:dict)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2407
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2408
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2409
     Date today printStringFormat:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2410
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2411
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2412
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2413
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2414
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2415
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2416
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2417
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2418
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2419
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2420
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2421
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  2422
     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
  2423
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2424
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2425
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2426
storeOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2427
    "append a representation to aStream, from which the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2428
     can be reconstructed"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2429
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2430
    aStream nextPutAll:'('; nextPutAll:'Date day:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2431
    self day printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2432
    aStream nextPutAll:' month:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2433
    self month printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2434
    aStream nextPutAll:' year:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2435
    self year printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2436
    aStream nextPutAll:')'
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2437
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2438
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2439
     Date today storeOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2440
     Date today storeString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2441
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2442
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2443
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  2444
!Date methodsFor:'private-accessing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2445
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2446
dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2447
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2448
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2449
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2450
    ^ dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2451
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2452
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2453
dateEncoding:anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2454
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2455
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2456
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2457
    dateEncoding := anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2458
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2459
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2460
fromOSTime:osTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2461
    "set my dateEncoding from an OS time.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2462
     This somewhat clumsy implementation hides the OS's date representation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2463
     (i.e. makes this class independent of what the OS starts its time values with).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2464
     Dont use this method, the osTime representation is totally unportable."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2465
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  2466
    |v y m d|
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  2467
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  2468
    v := OperatingSystem computeTimeAndDateFrom:osTime.
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  2469
    y := v year.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  2470
    m := v month.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  2471
    d := v day.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  2472
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  2473
    dateEncoding := (((y * 100) + m) * 100) + d
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2474
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2475
    "Modified: 1.7.1996 / 15:23:12 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2476
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2477
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  2478
!Date class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2479
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2480
version
8626
ae1fcb227a45 example
penk
parents: 8480
diff changeset
  2481
    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.94 2004-11-09 12:21:41 penk Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2482
! !
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  2483
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2484
Date initialize!