Date.st
author Claus Gittinger <cg@exept.de>
Sat, 25 May 2019 23:48:34 +0200
changeset 24149 e5e20aba8e1f
parent 24116 ef0506792fc5
child 24161 cfa3f53b41d9
permissions -rw-r--r--
#DOCUMENTATION by cg class: FileStream comment/format in: #copy:into:bufferSize:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17194
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
     1
"{ Encoding: utf8 }"
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    14
"{ Package: 'stx:libbasic' }"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
    15
17419
664ffe1aa68e class: Date
Claus Gittinger <cg@exept.de>
parents: 17196
diff changeset
    16
"{ NameSpace: Smalltalk }"
664ffe1aa68e class: Date
Claus Gittinger <cg@exept.de>
parents: 17196
diff changeset
    17
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    18
Magnitude subclass:#Date
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    19
	instanceVariableNames:'dateEncoding'
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    20
	classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs DefaultFormats
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
    21
		ShortFormats LongFormats EnvironmentChange'
972
76cd3ca837e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    22
	poolDictionaries:''
7673
1e802ebb66ea Category change
Stefan Vogel <sv@exept.de>
parents: 7651
diff changeset
    23
	category:'Magnitude-Time'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    26
!Date class methodsFor:'documentation'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    27
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    31
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    42
documentation
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    43
"
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    44
    Instances of Date represent dates as year, month and day encoded in the
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    45
    (private & hidden) instance dateEncoding. The value found there is
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    46
    year*100*100 + month*100 + day
17640
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    47
    This makes magnitude-like comparison of dates easy, and the main components
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    48
    d,m,y are easily reconstructed (assuming, that this is the stuff most used).
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    49
    Do not depend on the internal representation -
17640
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    50
    it is private and not guaranteed for future versions.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    51
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    52
    The old representation used days since 1st Jan. 1901 internally -
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    53
    with the new implementation, it is possible to reasonably represent almost
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    54
    any Date.
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    55
    (which insurance companies will like,
17640
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    56
     since they can now represent even very old people's birthday :-)
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    57
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    58
    Notice:
16971
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
    59
        no correction for pre-Gregorian dates (< 1583) is done.
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    60
        For dates before 1582 (when calendars were changed from Julian to Gregorian),
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    61
        the so called 'proleptic gregorian calendar' is used.
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    62
        This assumes leap years to continue in the past as if a gregorian calendar was used.
17640
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    63
        Thus, 0000 is considered a leap year.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    64
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    65
    The printed representation of dates is controlled by resource definitions -
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    66
    thus national variants are already supported (see file 'resources/Date.rs').
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    67
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    68
    Compatibility notice:
17640
4a5db495ac4b class: Date
Claus Gittinger <cg@exept.de>
parents: 17466
diff changeset
    69
        due to historic reasons, there are some methods found twice
21698
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    70
        with different names in this class. The old ST/X methods will vanish
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    71
        over time, but kept for a while to support existing applications
d5a110704c12 #OTHER by mawalch
mawalch
parents: 21486
diff changeset
    72
        (the info on how these methods should be named
20776
e3fc290ab88d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20409
diff changeset
    73
         came somewhat late from the testers...).
e3fc290ab88d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20409
diff changeset
    74
e3fc290ab88d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20409
diff changeset
    75
        Please do not use methods marked as obsolete.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    76
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    77
    Most useful methods:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    78
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    79
        Date today
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    80
        (Date today) addDays:
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1227
diff changeset
    81
        (Date today) subtractDays:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    82
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    83
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    84
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    85
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    86
    [see also:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    87
        Time AbstractTime
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    88
        Filename
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    89
        OperatingSystem
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    90
"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    91
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
    92
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    93
!Date class methodsFor:'initialization'!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    94
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    95
initDefaultNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    96
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    97
19558
2636649cfaab #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19453
diff changeset
    98
    |enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs|
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
    99
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   100
    DayNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   101
    DayAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   102
    MonthNames := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   103
    MonthAbbrevs := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   104
    DefaultFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   105
    LongFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   106
    ShortFormats := Dictionary new.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   107
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   108
    enDayNames := #('monday'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   109
                    'tuesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   110
                    'wednesday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   111
                    'thursday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   112
                    'friday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   113
                    'saturday'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   114
                    'sunday').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   115
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   116
    enDayAbbrevs := #('mon' 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   117
                      'tue' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   118
                      'wed'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   119
                      'thu' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   120
                      'fri' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   121
                      'sat' 
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   122
                      'sun').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   123
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   124
    enMonthNames := #('january'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   125
                      'february'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   126
                      'march'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   127
                      'april'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   128
                      'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   129
                      'june'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   130
                      'july'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   131
                      'august'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   132
                      'september'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   133
                      'october'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   134
                      'november'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   135
                      'december').
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   136
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   137
    enMonthAbbrevs := #('jan'
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   138
                        'feb'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   139
                        'mar'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   140
                        'apr'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   141
                        'may'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   142
                        'jun'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   143
                        'jul'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   144
                        'aug'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   145
                        'sep'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   146
                        'oct'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   147
                        'nov'
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   148
                        'dec').
8145
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
    DayNames at:#'en' put:enDayNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   151
    DayAbbrevs at:#'en' put:enDayAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   152
    MonthNames at:#'en' put:enMonthNames.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   153
    MonthAbbrevs at:#'en' put:enMonthAbbrevs.
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   154
19558
2636649cfaab #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19453
diff changeset
   155
    DefaultFormats at:#'en' put:('%d-%m-%y').
2636649cfaab #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19453
diff changeset
   156
    ShortFormats at:#'en' put:('%d-%m-%y').
2636649cfaab #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19453
diff changeset
   157
    LongFormats at:#'en' put:('%(dayName), %d-%m-%y').
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   158
12105
cf33361e1ff2 changed:7 methods
Claus Gittinger <cg@exept.de>
parents: 12097
diff changeset
   159
    "/ take the "master" language here, for the caching
cf33361e1ff2 changed:7 methods
Claus Gittinger <cg@exept.de>
parents: 12097
diff changeset
   160
    EnvironmentChange := (Smalltalk language asSymbol ~~ #'en').
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
    "
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   163
     Date initDefaultNames
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   164
    "
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   165
!
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   166
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   167
initNames
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   168
    "read the language specific names."
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   169
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   170
    |lang|
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   171
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   172
    DayNames isNil ifTrue:[
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   173
        self initDefaultNames.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   174
    ].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   175
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   176
    lang := Smalltalk language asSymbol.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   177
    lang ~~ #'en' ifTrue:[
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   178
        self initNamesForLanguage: lang.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   179
    ].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   180
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   181
    EnvironmentChange := false
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   182
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   183
    "
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   184
     Date initNames
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   185
    "
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   186
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   187
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   188
initNamesForLanguage:language
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   189
    "read the language specific names."
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   190
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   191
    |resources lang 
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   192
     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
   193
     enDefaultFormat enLongFormat enShortFormat may|
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   194
8943
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   195
    DayNames isNil ifTrue:[
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   196
        self initDefaultNames.
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   197
    ].
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   198
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   199
    lang := language asSymbol.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   200
    lang ~~ #'en' ifTrue:[
14624
58ad30334e84 care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents: 14498
diff changeset
   201
	ResourcePack notNil ifTrue:[ "/ guard for tinytalk (no libview)
58ad30334e84 care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents: 14498
diff changeset
   202
            resources := ResourcePack forPackage:'stx:libbasic' resourceFileName:(language,'.rs') cached:false.
58ad30334e84 care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents: 14498
diff changeset
   203
	].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   204
        resources notNil ifTrue:[
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   205
            enDayNames := DayNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   206
            enDayAbbrevs := DayAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   207
            enMonthNames := MonthNames at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   208
            enMonthAbbrevs := MonthAbbrevs at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   209
            monthAbbrevKeys := enMonthAbbrevs copy.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   210
            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
   211
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   212
            enDefaultFormat := DefaultFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   213
            enShortFormat := ShortFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   214
            enLongFormat := LongFormats at:#'en'.
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   215
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   216
            DefaultFormats at:lang put:(resources at:'DATEFORMAT' default:enDefaultFormat).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   217
            ShortFormats at:lang put:(resources at:'SHORTDATEFORMAT' default:enShortFormat).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   218
            LongFormats at:lang put:(resources at:'LONGDATEFORMAT' default:enLongFormat).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   219
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   220
            DayNames at:lang put:(resources array:enDayNames).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   221
            DayAbbrevs at:lang put:(resources array:enDayAbbrevs).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   222
            MonthNames at:lang put:(resources array:enMonthNames).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   223
            MonthAbbrevs at:lang put:(resources array:monthAbbrevKeys).
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   224
            "/ may needs special care (same key for long and short name)
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   225
            may := resources string:'MAY_ABBREV' default:nil.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   226
            may isNil ifTrue:[
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   227
                may := resources string:'may'.
8196
3b3407d69207 special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents: 8179
diff changeset
   228
            ].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   229
            (MonthAbbrevs at:lang) at:5 put:may.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   230
        ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   231
    ].
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   232
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   233
    "
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   234
     Date initNamesForLanguage:#de.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   235
     Date initNamesForLanguage:#fr.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   236
     Date initNamesForLanguage:#es.
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   237
    "
13736
599f4686a493 comment/format in: #initNamesForLanguage:
Claus Gittinger <cg@exept.de>
parents: 13509
diff changeset
   238
599f4686a493 comment/format in: #initNamesForLanguage:
Claus Gittinger <cg@exept.de>
parents: 13509
diff changeset
   239
    "Modified (format): / 28-09-2011 / 15:56:41 / cg"
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   240
!
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   241
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   242
initialize
8943
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   243
    DayNames isNil ifTrue:[
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   244
        self initDefaultNames.
eff0b1c83c65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8878
diff changeset
   245
    ].
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   246
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   247
    Smalltalk addDependent:self.
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
   248
    Smalltalk language ~= 'en' ifTrue:[
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   249
        EnvironmentChange := true
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   250
    ]
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   251
! !
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
   252
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   253
!Date class methodsFor:'instance creation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   254
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   255
fromDays:dayCount
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   256
    "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
   257
     (i.e. 'Date fromDays:0' returns 1st Jan. 1901).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   258
     Date asDays is the reverse operation.
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   259
     Notice, that this is not able to represent dates before 1901!!.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   260
     Added for GNU/ST-80 compatibility"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   261
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   262
    |year rest d yearIncrement yearAsDays|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   264
    "approx. year"
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   265
    year := (dayCount // 366) + 1901.
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   266
    yearAsDays := (self yearAsDays:year).
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   267
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   268
    dayCount < 0 ifTrue:[
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   269
        rest := dayCount negated - yearAsDays + 1. "+1 for ST-80 compatibility"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   270
        yearIncrement := -1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   271
    ] ifFalse:[
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   272
        rest := dayCount - yearAsDays + 1. "+1 for ST-80 compatibility"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   273
        yearIncrement := 1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   274
    ].
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   275
    rest > 365 ifTrue:[
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   276
        [d := self daysInYear:year. rest > d] whileTrue:[
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   277
            "adjust"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   278
            year := year + yearIncrement.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   279
            rest := rest - d.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   280
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   281
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   282
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   283
    ^ self newDay:rest year:year
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   284
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   285
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   286
     Date fromDays:0     -> 1 jan 1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   287
     Date fromDays:365   -> 1 jan 1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   288
     Date fromDays:730   -> 1 jan 1903
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   289
     Date fromDays:1095  -> 1 jan 1904
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   290
     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
   291
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   292
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   293
    "Modified: 1.7.1996 / 14:24:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   295
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   296
fromDaysFrom0:dayCount
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   297
    "return a new Date, given the day-number starting with 0 at 1.Jan 0;
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   298
     (i.e. 'Date fromDaysSince0:0' returns 1st Jan. 0).
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   299
     Date asDaysSince0 is the reverse operation.
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   300
     Notice, that this is a private interface.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   301
     Also notice: does not care for Gregorian/Julisn calendar change"
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   302
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   303
    |year rest d yearIncrement yearAsDaysFrom0|
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   304
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   305
    "approx. year"
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   306
    year := (dayCount // 366).
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   307
    yearAsDaysFrom0 := (self yearAsDaysFrom0:year).
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   308
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   309
    dayCount < 0 ifTrue:[
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   310
        rest := dayCount negated - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility"
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   311
        yearIncrement := -1.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   312
    ] ifFalse:[
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   313
        rest := dayCount - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility"
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   314
        yearIncrement := 1.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   315
    ].
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   316
    rest > 365 ifTrue:[
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   317
        [d := self daysInYear:year. rest > d] whileTrue:[
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   318
            "adjust"
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   319
            year := year + yearIncrement.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   320
            rest := rest - d.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   321
        ].
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   322
    ].
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   323
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   324
    ^ self newDay:rest year:year
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   325
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   326
    "
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   327
     Date fromDaysFrom0:0     -> 1 jan 0
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
   328
     Date fromDaysFrom0:366   -> 1 jan 1
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   329
    "
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   330
!
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
   331
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
newDay:dayInYear year:year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
    "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
   334
     See also: Date today / Time now / Timestamp now.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   335
     ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   336
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   337
    |monthAndDay|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   338
19896
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   339
    ((dayInYear between:1 and:365) 
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   340
     or:[dayInYear == 366 and:[self leapYear:year]]) ifFalse:[
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   341
        "
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   342
         this error is triggered, when you try to create a
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   343
         day from an invalid day-in-year; 
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   344
         for example, 366 in a non-leap year.
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   345
         I don't know, if ST-80 wraps to the next year(s) in this case.
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   346
        "
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   347
        ^ self conversionErrorSignal raiseErrorString:' - Date: invalid day in year'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   349
    monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   350
    ^ self basicNew year:year month:(monthAndDay at:1) day:(monthAndDay at:2)  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   352
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   353
     Date newDay:150 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   354
     Date newDay:1 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   355
     Date newDay:1 year:1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   356
     Date newDay:1 year:1902
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   357
     Date newDay:365 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   358
     Date newDay:366 year:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
     Date newDay:365 year:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
     Date newDay:366 year:1994
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
   361
     Date newDay:0 year:1994
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   362
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   363
     Date newDay:271 year:2008
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   364
     Date newDay:270 year:2008
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   365
     Date newDay:271 year:2007
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   366
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   367
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   368
    "Modified: 1.7.1996 / 14:22:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   369
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   370
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   371
newDayInWeek:dayInWeek week:week year:yearArg
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   372
    "return a new Date, given the year, the week (1..) and the day in week (1..7).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   373
     See http://en.wikipedia.org/wiki/ISO_week_date"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   374
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   375
    |weekDayOfJan4 dayInYear year|
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   376
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   377
    year := yearArg.
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   378
    weekDayOfJan4 := (self year:year month:1 day:4) dayInWeek.
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   379
    dayInYear := (week * 7) + dayInWeek - (weekDayOfJan4 + 3).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   380
    dayInYear < 1 ifTrue:[
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   381
        dayInYear := dayInYear + (self daysInYear:year-1).
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   382
        year := year - 1.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   383
    ].
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   384
    dayInYear > (self daysInYear:year) ifTrue:[
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   385
        dayInYear := dayInYear - (self daysInYear:year).
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   386
        year := year + 1.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   387
    ].
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   388
    ^ self newDay:dayInYear year:year.
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   389
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   390
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   391
     Date newDayInWeek:6 week:39 year:2008     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   392
     Date newDayInWeek:1 week:40 year:2014     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   393
     Date newDayInWeek:1 week:44 year:2014     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   394
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   395
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
   396
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   397
readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   398
    "return a new Date, reading a printed representation from aStream.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   399
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   400
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   401
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   402
         3   year position (1..3)
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   403
     or a formatString (see printing instance protocol)."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
   404
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   405
    ^ self 
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   406
        readFrom:aStringOrStream
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   407
        format:aSqueakFormatArrayOrFormatString 
19896
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   408
        onError:[ self conversionErrorSignal raiseWith:aStringOrStream errorString:' - invalid Date' ]
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   409
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   410
    "
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   411
     Date readFrom:'19:11:1999' format:#( 1 2 3 )
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   412
     Date readFrom:'19-nov-1999' format:#( 1 2 3 )
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   413
     Date readFrom:'19:11:1999' format:#( 2 1 3 )  -> exception: wrong month
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   414
     Date readFrom:'5:12:1999' format:#( 2 1 3 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   415
     Date readFrom:'may-12-1999' format:#( 2 1 3 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   416
     Date readFrom:'1999 may 12' format:#( 3 2 1 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   417
     Date readFrom:'12/31/2001' format:#( 2 1 3 ) 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   418
     Date readFrom:' 31.08.2001' format:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   419
     Date readFrom:' 31.dec.2001' format:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   420
     Date readFrom:' 31.Dec.2001' format:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   421
     Date readFrom:' 31.dez.2001' format:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   422
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   423
     Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   424
     Date readFrom:'12/01' format:'%m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   425
     Date readFrom:'01' format:'%y' onError:'fail'        
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   426
     Date readFrom:'30.01' format:'%d %m' onError:'fail'       
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   427
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   428
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   429
    "Created: 16.11.1995 / 22:50:17 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   430
    "Modified: 8.10.1996 / 19:25:39 / cg"
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   431
!
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   432
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   433
readFrom:aStringOrStream format:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   434
    "return a new Date, reading a printed representation from aStream.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   435
     aFormatStringOrSqueakFormatArray may either be a Squeak formatArray:
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   436
         1   day position (1, 2 or 3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   437
         2   month position (1..3)
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   438
         3   year position (1..3)
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   439
     or an ST/X formatString (see printing instance protocol).
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   440
     For now %d, %m, %monthName, %shortMonthName, %y, %Y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString.
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   441
     y1900 converts 2-digit year YY into 19YY, 
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   442
     y2000 into 20YY.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   443
     y1950, y1980, y1970 and Y are special; 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   444
     if the year is below 50/80/70/70, it is converted to 20YY, otherwise to 19YY. 
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   445
     The formatString can have any of these characters '-.:,;/' as separator.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   446
     The format may be preceeded by a single numeric length (as in %2d) to specify how many
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   447
     characters to read.
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   448
     The formatString can also use a space as separator (for  ex. '%d %m %y') and any separator will be allowed.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   449
     However, when a character separator is defined, only that separator will be expected.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   450
     TODO: make this a general feature of all DateAndTime classes.
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   451
    "
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   452
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   453
    |str|
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   454
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   455
    str := aStringOrStream readStream.
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   456
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   457
    ^ [
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   458
        |day month year dayOfYear monthAndDay|
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   459
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   460
        aFormatStringOrSqueakFormatArray isString ifTrue:[
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   461
            |formatStream fc c sel somePartAssoc len lStr|
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   462
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   463
            formatStream := aFormatStringOrSqueakFormatArray readStream.
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   464
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   465
            [formatStream atEnd] whileFalse:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   466
                fc := formatStream next.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   467
                fc == $% ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   468
                    sel := ''.
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   469
                    len := nil.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   470
                    (fc := formatStream peekOrNil) notNil ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   471
                        fc isDigit ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   472
                            len := fc digitValue.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   473
                            formatStream next.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   474
                        ]
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   475
                    ].    
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   476
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   477
                    (fc := formatStream peekOrNil) notNil ifTrue:[
17466
52ceef24f430 class: Date
Claus Gittinger <cg@exept.de>
parents: 17419
diff changeset
   478
                        fc == $( ifTrue:[
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   479
                            formatStream next.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   480
                            sel := formatStream upTo:$)
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   481
                        ] ifFalse:[
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   482
                            sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter])
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   483
                        ]
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   484
                    ].
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   485
                    len notNil ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   486
                        lStr := str next:len.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   487
                        somePartAssoc := self readDatePartFrom:lStr readStream format:sel language:languageOrNil.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   488
                    ] ifFalse:[    
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   489
                        somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   490
                    ].
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   491
                    somePartAssoc key == #day ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   492
                        day := somePartAssoc value.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   493
                    ] ifFalse:[somePartAssoc key == #month ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   494
                        month := somePartAssoc value.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   495
                    ] ifFalse:[somePartAssoc key == #year ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   496
                        year := somePartAssoc value.
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   497
                    ] ifFalse:[somePartAssoc key == #dayOfYear ifTrue:[
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   498
                        dayOfYear := somePartAssoc value.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   499
                    ] ifFalse:[
19896
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   500
                        self conversionErrorSignal raiseWith:aStringOrStream errorString:' - unexpected date part'
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   501
                    ]]]].
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   502
                ] ifFalse:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   503
                    fc == Character space ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   504
                        "/ Skip most possible separator characters 
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   505
                        "/ (if not enough, should check for isNationalAlphaNumeric instead)
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   506
                        [(c := str peek) isSeparator 
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   507
                         or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c]] whileTrue:[str next].    
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   508
                    ] ifFalse:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   509
                        str skipSeparators.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   510
                        str next ~= fc ifTrue:[^ exceptionBlock value].
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   511
                        str skipSeparators.
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   512
                    ]
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   513
                ]
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   514
            ].
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   515
        ] ifFalse:[
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   516
            |arg|
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   517
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   518
            arg := Array new:3.
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   519
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   520
            1 to:3 do:[:i|
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   521
                |v|
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   522
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   523
                [str peek isLetterOrDigit] whileFalse:[str next].
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   524
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   525
                v := (str peek isDigit) ifTrue:[Integer readFrom:str]
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   526
                                       ifFalse:[str nextAlphaNumericWord].
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   527
                arg at:i put:v
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   528
            ].
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   529
            year := arg at:(aFormatStringOrSqueakFormatArray at:3).
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   530
            day := arg at:(aFormatStringOrSqueakFormatArray at:1).
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   531
            month := arg at:(aFormatStringOrSqueakFormatArray at:2).
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   532
        ].
7649
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   533
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   534
        dayOfYear notNil ifTrue:[
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   535
            monthAndDay := self monthAndDayFromDayInYear:dayOfYear forYear:year.
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   536
            month := monthAndDay at:1.
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   537
            day := monthAndDay at:2.  
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   538
        ].
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   539
        
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   540
        day isNil ifTrue:[ day := 1 ].
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   541
        month isNil ifTrue:[ month := 1 ].
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   542
        year isNil ifTrue:[ year := self today year ].
16835
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   543
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   544
        (year between:0 and:99) ifTrue:[
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   545
            year := UserPreferences current twoDigitDateHandler value:year.
08f60ee0a4ed class: Date
Stefan Vogel <sv@exept.de>
parents: 16834
diff changeset
   546
        ].
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   547
        self  year:year month:month day:day.
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   548
    ] on:Error do:[:ex| 
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   549
        exceptionBlock value
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   550
    ].
4997
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   551
9104a31610cf checkin from browser
tm
parents: 4462
diff changeset
   552
    "
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6419
diff changeset
   553
     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
   554
     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
   555
     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
   556
     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
   557
     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
   558
     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
   559
     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
   560
     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
   561
     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
   562
     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
   563
     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
   564
     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
   565
a6704f70a3cf conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents: 6872
diff changeset
   566
     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
   567
     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
   568
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   569
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   570
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
1e907123a5c2 readFrom with formatString.
Claus Gittinger <cg@exept.de>
parents: 7648
diff changeset
   571
     Date readFrom:'01' printFormat:'%y' onError:'fail'       
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   572
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'     
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   573
     Date readFrom:'300180' printFormat:'%2d%2m%2y' onError:'fail' 
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   574
     
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   575
     Date readFrom:'300170' printFormat:'%2d%2m%2y' onError:'fail'      - gives 2070 as year
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   576
     Date readFrom:'300170' printFormat:'%2d%2m%2Y' onError:'fail'      - gives 1970 as year
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   577
     Date readFrom:'300169' printFormat:'%2d%2m%2y' onError:'fail'      - gives 2069 as year
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   578
     Date readFrom:'300169' printFormat:'%2d%2m%2Y' onError:'fail'      - gives 2069 as year
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   579
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   580
     Date readFrom:'300170' printFormat:'%2d%2m%2(y1950)' onError:'fail'  - gives 1970 as year   
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   581
     Date readFrom:'300170' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 2070 as year   
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   582
     Date readFrom:'300181' printFormat:'%2d%2m%2(y1980)' onError:'fail'  - gives 1981 as year   
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   583
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   584
     Date readFrom:'2015103' printFormat:'%4y%3(dayOfYear)' onError:'fail'   
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
   585
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   586
     Date readFrom:'2018-12-03' printFormat:'%y %m %d' language: #de onError:'fail'          
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   587
     Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail'          
17194
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
   588
     Date readFrom:'3-März-1995' printFormat:'%d %monthName %y' language: #de onError:'fail'          
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
   589
     Date readFrom:'3-mär-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'   
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
   590
     Date readFrom:'3/mär/1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'  
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
   591
     Date readFrom:'3/mär/1995' printFormat:'%d-%shortMonthName-%y' language: #de onError:'fail'          
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   592
     Date readFrom:'3-dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'          
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   593
     Date readFrom:'3-Dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail'          
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   594
     Date readFrom:'3-Dezember-1995' printFormat:'%d %monthName %y' language: #de onError:'fail'          
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
   595
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   596
    "
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   597
23550
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   598
    "Created: / 16-11-1995 / 22:50:17 / cg"
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   599
    "Modified: / 08-10-1996 / 19:25:39 / cg"
52d7b15396e8 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23236
diff changeset
   600
    "Modified (comment): / 03-12-2018 / 10:37:22 / Stefan Vogel"
4421
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   601
!
9ecd9ba9faa4 added inverse to mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
   602
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   603
readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString onError:exceptionBlock
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   604
    "return a new Date, reading a printed representation from aStream.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   605
     aSqueakFormatArrayOrFormatString may either be a Squeak formatArray:
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   606
         1   day position (1, 2 or 3)
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   607
         2   month position (1..3)
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   608
         3   year position (1..3)
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
   609
     or an ST/X formatString (see printing instance protocol).
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   610
     All of the %-formats as in the printString are supported here.
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   611
     (i.e. %d, %m and %y, %shortMonthName and %monthName)
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   612
     In addition, %Y, %y1900, %y2000, %y1950 and %y1980 are supported:
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
   613
     y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
   614
     y1950, y1980 and Y are special; if the year is below 50/80/70, it is converted to 20YY, otherwise to 19YY. 
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   615
     TODO: make this a general feature of all DateAndTime classes.
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   616
    "
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   617
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   618
    ^ self
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   619
        readFrom:aStringOrStream 
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   620
        format:aSqueakFormatArrayOrFormatString 
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   621
        language:nil 
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   622
        onError:exceptionBlock
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   623
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   624
    "
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   625
     Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   626
     Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail'  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   627
     Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   628
     Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   629
     Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   630
     Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date'  -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   631
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail'        -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   632
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   633
     Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   634
     Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   635
     Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   636
     Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date']  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   637
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   638
     Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   639
     Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   640
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   641
     Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   642
     Date readFrom:'12/01' format:'%m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   643
     Date readFrom:'01' format:'%y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   644
     Date readFrom:'30.01' format:'%d %m' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   645
     Date readFrom:'311201' format:'%2d%2m%2y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   646
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   647
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   648
    "Created: 16.11.1995 / 22:50:17 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   649
    "Modified: 8.10.1996 / 19:25:39 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   650
!
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   651
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   652
readFrom:aStringOrStream onError:exceptionBlock
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   653
    "return a new Date, reading a printed representation from aStream.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   654
     Notice, that this is not the storeString format and 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   655
     is different from the format expected by readFrom:.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   656
     
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   657
     BUG:
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   658
       For Smalltalk compatibility, this method handles american format 
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   659
       (i.e. month/day/year),
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   660
       the common format with letter month in the middle (10 December 2007)
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   661
       and ISO formats (yyyy-mm-dd) - as long as yyyy is > 12.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   662
       It also handles yyyymmdd and yymmdd.               
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   663
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   664
       It also handles short years (i.e. 2 digits), by evaluating the
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   665
       UserPreferences current twoDigitDateHandler
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   666
       By default, that one will convert late 90's days to 19xx, and all others to 20xx.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   667
       
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   668
       It does NOT handle the german/french and other dd-mm-yyyy formats.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   669
       use readFrom:printFormat:onError: for this."
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   670
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   671
    ^ [
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   672
        |str pos items first second third month day year
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   673
         yearString monthString dayString|
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   674
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   675
        str := aStringOrStream readStream.
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   676
        pos := str position.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   677
        items := 
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   678
            3 timesCollect:[:idx|
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   679
                str peek isNil ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   680
                    nil
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   681
                ] ifFalse:[        
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   682
                    [str peek isLetterOrDigit] whileFalse:[str next].
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   683
                    (str peek isDigit) ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   684
                        Integer readFrom:str
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   685
                    ] ifFalse:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   686
                        str nextAlphaNumericWord
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   687
                    ].
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   688
                ].
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   689
            ].
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   690
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   691
        first := items at:1.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   692
        second := items at:2.
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   693
        third := items at:3.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   694
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   695
        second isNil ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   696
            "/ mh - only one number???
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   697
            "/ assume yyyymmdd or yymmdd formats
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   698
            str position:pos.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   699
            yearString := str next:4.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   700
            monthString := str next:2.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   701
            str atEnd ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   702
                dayString := monthString.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   703
                monthString := yearString copyFrom:3.                
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   704
                yearString := yearString copyTo:2.                
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   705
            ] ifFalse:[
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   706
                dayString := str next:2.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   707
            ].        
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   708
            day := Integer readFrom:dayString.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   709
            month := Integer readFrom:monthString.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   710
            year := Integer readFrom:yearString.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   711
        ] ifFalse:[        
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   712
            (first isInteger and:[second isInteger and:[first > 12]]) ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   713
                "ISO Date: yyyy-mm-dd"
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   714
                year := first.
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   715
                month := second.
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   716
                day := third.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   717
            ] ifFalse:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   718
                year := third.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   719
                second isInteger ifTrue:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   720
                    "must be an american date mm/dd/yy"
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   721
                    month := first.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   722
                    day := second.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   723
                ] ifFalse:[
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   724
                    "3 Dec 2007"
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   725
                    day := first.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   726
                    month := second.
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   727
                ].
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   728
            ].
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   729
        ].
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   730
        (year between:0 and:99) ifTrue:[
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   731
            year := UserPreferences current twoDigitDateHandler value:year.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   732
        ].
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   733
        self  year:year month:month day:day.
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   734
    ] on:Error do:exceptionBlock.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   735
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   736
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   737
     Date readFromString:'31 December 1992'  
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   738
     Date readFrom:'19:11:1999'                 onError:'wrong date'.  
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   739
     Date readFrom:'2007-12-31'                 onError:'wrong date'.  
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   740
     Date readFromString:'December, 5 1992'  
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   741
     Date readFromString:'12/31/1992'           
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   742
     Date readFromString:'01/02/1992'           
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   743
     Date readFromString:'3-jan-95'           
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   744
     Date readFromString:'3-jan-01'           
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   745
     Date readFromString:'12/31/01'        
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   746
     Date readFromString:'15.4.1992'         -> german; leads to an error
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   747
     Date readFromString:'10.4.1992'         -> german; leads to a wrong date
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   748
     Date readFromString:'10.4.1992' onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
   749
     Date readFromString:'32.4.1992' onError:['wrong date']
23595
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   750
     Date readFromString:'fooBar'    onError:['wrong date']
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   751
     Date readFromString:'10.4'      onError:['wrong date']
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   752
     Date readFromString:'10041999'  onError:['wrong date']  
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   753
     Date readFromString:'20140111'  onError:['wrong date']  
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   754
     Date readFrom:'20140111'
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   755
     Date readFrom:'140111' 
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   756
     Date readFrom:'990111' 
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   757
    "
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   758
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   759
    "Created: / 16-11-1995 / 22:50:17 / cg"
3e25773eaf65 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23550
diff changeset
   760
    "Modified: / 08-10-1996 / 19:25:39 / cg"
23597
72e6a6ce055f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23596
diff changeset
   761
    "Modified (comment): / 09-01-2019 / 18:25:32 / Claus Gittinger"
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   762
!
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
   763
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   764
today
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   765
    "return a date, representing today.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   766
     See also: Time now / Timestamp now."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   767
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   768
    ^ self fromOSTime:(OperatingSystem getOSTime)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   769
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
     Date today
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   772
    "
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
   773
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
   774
    "Modified: 1.7.1996 / 15:20:16 / cg"
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   775
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   776
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   777
tomorrow
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   778
    "return a date, representing tomorrow.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   779
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   780
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   781
    ^ self today addDays:1
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   782
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   783
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   784
     Date tomorrow 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   785
     Date tomorrow dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   786
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   787
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   788
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   789
utcToday
17135
c900676dae27 class: Date
Claus Gittinger <cg@exept.de>
parents: 17080
diff changeset
   790
    "return a date, representing today in UTC.
c900676dae27 class: Date
Claus Gittinger <cg@exept.de>
parents: 17080
diff changeset
   791
     That is, the current date in London without any daylight saving adjustments.
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   792
     See also: Time now / Timestamp now."
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   793
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   794
    ^ self new fromUtcOSTime:(OperatingSystem getOSTime)
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   795
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   796
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   797
     Date today
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   798
     Date utcToday
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   799
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   800
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   801
    "Modified: 1.7.1996 / 15:20:16 / cg"
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   802
!
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
   803
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   804
year:year month:month day:day
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   805
    "return a new Date, given the day, month and year.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   806
     For your convenience, month may be either an integer 
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   807
     or the month's name as a string. 
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   808
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   809
     WARNING: semantics changed: 0..99 is no longer treated as 1900..1999,
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   810
              but as 0..99 now.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   811
              Any such adjustments must be made by the caller of this method now
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   812
              (see those, for example readFrom:onError:)"
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   813
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   814
    |monthIndex ok|
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   815
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   816
    (year < 100 and:[year > 0]) ifTrue:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   817
        'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   818
    ].
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   819
    year class ~= SmallInteger ifTrue:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   820
        "we support a lot of future, but LargeInteger years fail in #isLeapYear"
19896
32e62e396575 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19789
diff changeset
   821
        self conversionErrorSignal raiseWith:year errorString:' - invalid year in Date (way too large)'.
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   822
    ].    
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   823
    month isInteger ifTrue:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   824
        monthIndex := month
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   825
    ] ifFalse:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   826
        monthIndex := self indexOfMonth:month
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   827
    ].
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   828
    (monthIndex == 2 and:[day == 29]) ifTrue:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   829
        ok := self leapYear:year
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   830
    ] ifFalse:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   831
        ok := day <= (self daysInMonth:month forYear:year)
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   832
    ].
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   833
    ((day > 0) and:[ok]) ifTrue:[
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   834
        ^ self basicNew year:year month:monthIndex day:day.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   835
    ].
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   836
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   837
    "this error is triggered if you try to create a date from an
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   838
     invalid year/month/day combination;
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   839
     Such as 29-feb-year, where year is no leap year
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   840
    "
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   841
    self conversionErrorSignal raiseErrorString:' - invalid date'.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   842
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   843
    "
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   844
     Date year:1993  month:'may' day:8
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   845
     Date year:1993  month:5     day:8
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   846
     Date year:2004 month:'feb' day:29
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   847
     Date year:2003 month:'feb' day:29
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   848
     Date year:5 month:'feb' day:28   
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   849
     Date year:95 month:'feb' day:28  
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   850
    "
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   851
!
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   852
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   853
yesterday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   854
    "return a date, representing yesterday.
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
   855
     See also: Time now / Timestamp now."
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   856
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
   857
    ^ self today subtractDays:1
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   858
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   859
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   860
     Date yesterday 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   861
     Date yesterday dayInWeek
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
   862
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   863
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   864
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   865
!Date class methodsFor:'Compatibility-Dolphin'!
6872
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   866
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   867
newDay:day monthIndex:month year:year
17419
664ffe1aa68e class: Date
Claus Gittinger <cg@exept.de>
parents: 17196
diff changeset
   868
    "Dolphin compatibility - same as newDay:month:year"
664ffe1aa68e class: Date
Claus Gittinger <cg@exept.de>
parents: 17196
diff changeset
   869
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   870
    ^ self year:year month:month day:day 
6872
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   871
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   872
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   873
     Date newDay:8 monthIndex:5 year:1993
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   874
    "
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   875
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   876
    "Modified: 19.4.1996 / 15:28:15 / cg"
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   877
! !
c6e1e2bce9e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
   878
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   879
!Date class methodsFor:'Compatibility-ST80'!
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   880
7648
61b7826a9a0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7646
diff changeset
   881
newDay:day monthNumber:monthIndex year:year
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   882
    "ST80 compatibility"
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   883
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   884
    ^ self year:year month:monthIndex day:day
7646
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   885
! !
94ae479eedbb compatibility
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
   886
7299
ae1b90fe7c4f category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   887
!Date class methodsFor:'Compatibility-Squeak'!
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   888
11815
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   889
current
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   890
    "return the current date"
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   891
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   892
    ^ self today
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   893
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   894
    "
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   895
     Date current
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   896
    "
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   897
!
b9fce735fa98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11787
diff changeset
   898
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   899
fromSeconds:seconds
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   900
    "Answer an instance of me which is 'seconds' seconds after January 1, 1901."
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   901
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   902
    | secondsInDay |
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   903
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   904
    secondsInDay := 24 * 60 * 60.
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   905
    ^self fromDays: seconds // secondsInDay
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   906
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   907
    "
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   908
     Date fromSeconds:0
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   909
     Date fromSeconds:(24 * 60 * 60 * 365)
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
   910
    "
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   911
!
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   912
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   913
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   914
    "return a new Date, reading a printed representation from aStream.
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   915
     Notice, that this is not the storeString format and 
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   916
     is different from the format expected by readFrom:"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   917
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   918
    ^ [
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   919
        |str monthString month dayString day year yearString|
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   920
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   921
        str := aStringOrStream readStream.
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   922
        monthString := str next:2.
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   923
        [str peek isDigit] whileFalse:[str next].
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   924
        dayString := str next:2.
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   925
        [str peek isDigit] whileFalse:[str next].
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   926
        yearString := str next:4.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   927
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   928
        year := Integer readFrom:yearString.
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
   929
        month := Integer readFrom:monthString.
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   930
        day := Integer readFrom:dayString.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   931
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
   932
        self  year:year month:month day:day.
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   933
    ] on:Error do:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   934
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   935
    "
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   936
     Date readMMDDYYYYFrom:'10041999' onError:['wrong date']  
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   937
     Date readMMDDYYYYFrom:'100419' onError:['wrong date']  
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   938
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
   939
     Date readMMDDYYYYFrom:'10040001' onError:['wrong date']  
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   940
     Date readMMDDYYYYFrom:'10-04-2001' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   941
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   942
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   943
    "Created: / 16-11-1995 / 22:50:17 / cg"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   944
    "Modified: / 08-10-1996 / 19:25:39 / cg"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   945
    "Modified (comment): / 09-01-2019 / 18:20:37 / Claus Gittinger"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   946
!
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   947
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   948
readYYMMDDFrom:aStringOrStream onError:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   949
    "return a new Date, reading a printed representation from aStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   950
     Notice, that this is not the storeString format and 
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   951
     is different from the format expected by readFrom:"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   952
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   953
    ^ [
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   954
        |str monthString month dayString day yearString year|
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   955
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   956
        str := aStringOrStream readStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   957
        yearString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   958
        [str peek isDigit] whileFalse:[str next].
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   959
        monthString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   960
        [str peek isDigit] whileFalse:[str next].
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   961
        dayString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   962
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   963
        day := Integer readFrom:dayString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   964
        month := Integer readFrom:monthString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   965
        year := Integer readFrom:yearString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   966
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   967
        year := UserPreferences current twoDigitDateHandler value:year.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   968
        self year:year month:month day:day
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   969
    ] on:Error do:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   970
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   971
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   972
     Date readYYMMDDFrom:'991004' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   973
     Date readYYMMDDFrom:'211004' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   974
     Date readYYMMDDFrom:'21-10-04' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   975
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   976
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   977
    "Created: / 09-01-2019 / 18:16:24 / Claus Gittinger"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   978
!
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   979
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   980
readYYMMFrom:aStringOrStream onError:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   981
    "return a new Date, reading a printed representation from aStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   982
     Notice, that this is not the storeString format and 
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   983
     is different from the format expected by readFrom:"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   984
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   985
    ^ [
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   986
        |str monthString month dayString day yearString year|
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   987
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   988
        str := aStringOrStream readStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   989
        yearString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   990
        [str peek isDigit] whileFalse:[str next].
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   991
        monthString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   992
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   993
        day := 1.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   994
        month := Integer readFrom:monthString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   995
        year := Integer readFrom:yearString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   996
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   997
        year := UserPreferences current twoDigitDateHandler value:year.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   998
        self  year:year month:month day:day
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
   999
    ] on:Error do:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1000
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1001
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1002
     Date readYYMMFrom:'9910' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1003
     Date readYYMMFrom:'2010' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1004
     Date readYYMMFrom:'20-10' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1005
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1006
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1007
    "Created: / 09-01-2019 / 18:18:24 / Claus Gittinger"
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1008
!
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1009
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1010
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1011
    "return a new Date, reading a printed representation from aStream.
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1012
     Notice, that this is not the storeString format and 
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1013
     is different from the format expected by readFrom:"
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1014
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1015
    ^ [
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1016
        |str monthString month dayString day yearString year|
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1017
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1018
        str := aStringOrStream readStream.
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1019
        yearString := str next:4.
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1020
        [str peek isDigit] whileFalse:[str next].
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1021
        monthString := str next:2.
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1022
        [str peek isDigit] whileFalse:[str next].
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1023
        dayString := str next:2.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1024
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1025
        day := Integer readFrom:dayString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1026
        month := Integer readFrom:monthString.
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1027
        year := Integer readFrom:yearString.
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1028
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1029
        self  year:year month:month day:day
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1030
    ] on:Error do:exceptionBlock
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1031
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1032
    "
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1033
     Date readYYYYMMDDFrom:'19991004' onError:['wrong date']  
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1034
     Date readYYYYMMDDFrom:'1999-10-04' onError:['wrong date']  
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  1035
     Date readYYYYMMDDFrom:'911004' onError:['wrong date']  
11181
591c81b496c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11176
diff changeset
  1036
    "
23596
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1037
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1038
    "Modified (comment): / 09-01-2019 / 18:21:05 / Claus Gittinger"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1039
!
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1040
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1041
readYYYYMMFrom:aStringOrStream onError:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1042
    "return a new Date, reading a printed representation from aStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1043
     Notice, that this is not the storeString format and 
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1044
     is different from the format expected by readFrom:"
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1045
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1046
    ^ [
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1047
        |str monthString month dayString day yearString year|
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1048
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1049
        str := aStringOrStream readStream.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1050
        yearString := str next:4.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1051
        [str peek isDigit] whileFalse:[str next].
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1052
        monthString := str next:2.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1053
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1054
        day := 1.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1055
        month := Integer readFrom:monthString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1056
        year := Integer readFrom:yearString.
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1057
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1058
        self  year:year month:month day:day
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1059
    ] on:Error do:exceptionBlock
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1060
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1061
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1062
     Date readYYYYMMFrom:'199910' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1063
     Date readYYYYMMFrom:'1999-10' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1064
     Date readYYYYMMFrom:'9110' onError:['wrong date']  
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1065
    "
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1066
84be05fbe375 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23595
diff changeset
  1067
    "Created: / 09-01-2019 / 18:17:28 / Claus Gittinger"
7005
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
  1068
! !
e8392cfd4341 added fromSeconds
penk
parents: 6976
diff changeset
  1069
11553
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1070
!Date class methodsFor:'change & update'!
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1071
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1072
update:something with:aParameter from:changedObject
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1073
    ((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1074
        "just remember change for next access"
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1075
        EnvironmentChange := true
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1076
    ]
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1077
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1078
    "Created: 15.6.1996 / 15:19:25 / cg"
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1079
! !
5f6a4bccb7e7 category
Claus Gittinger <cg@exept.de>
parents: 11350
diff changeset
  1080
11127
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1081
!Date class methodsFor:'error handling'!
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1082
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1083
conversionErrorSignal
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1084
    "return the signal used for conversion error handling"
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1085
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1086
    ^ DateConversionError
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1087
! !
c90d2486fe26 onversion errors
Claus Gittinger <cg@exept.de>
parents: 11079
diff changeset
  1088
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1089
!Date class methodsFor:'general queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1090
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1091
abbreviatedDayNamesForLanguage:languageOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1092
    "return a collection of short month-names for a given language or the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1093
     current language if nil is given.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1094
     The returned strings depend on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1095
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1096
     If not, english names are returned"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1097
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1098
    |langDayAbbrevs lang|
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1099
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1100
    (DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1101
        self initNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1102
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1103
    lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1104
    langDayAbbrevs := DayAbbrevs at:lang ifAbsent:nil.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1105
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1106
    "/ If language is not found, try to initialize it from the resources and try again
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1107
    langDayAbbrevs isNil ifTrue:[ 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1108
        self initNamesForLanguage: lang.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1109
        "/ If language initialization failed, take english dayAbbrevs
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1110
        langDayAbbrevs := DayAbbrevs at:lang ifAbsent:[DayAbbrevs at:#en.].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1111
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1112
    ^ langDayAbbrevs
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1113
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1114
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1115
     self abbreviatedDayNamesForLanguage:#en   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1116
     self abbreviatedDayNamesForLanguage:#de   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1117
     self abbreviatedDayNamesForLanguage:#fr   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1118
     self abbreviatedDayNamesForLanguage:#es   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1119
     self abbreviatedDayNamesForLanguage:#zulu 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1120
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1121
     self abbreviatedDayNamesForLanguage:nil   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1122
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1123
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1124
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1125
abbreviatedMonthNamesForLanguage:languageOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1126
    "return a collection of short month-names for a given language or the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1127
     current language if nil is given.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1128
     The returned strings depend on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1129
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1130
     If not, english names are returned"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1131
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1132
    |langMonthAbbrevs lang|
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1133
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1134
    (MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1135
        self initNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1136
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1137
    lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1138
    langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:nil.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1139
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1140
    "/ If language is not found, try to initialize it from the resources and try again
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1141
    langMonthAbbrevs isNil ifTrue:[ 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1142
        self initNamesForLanguage: lang.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1143
        "/ If language initialization failed, take english monthAbbrevs
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1144
        langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:[MonthAbbrevs at:#en.].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1145
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1146
    ^ langMonthAbbrevs
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1147
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1148
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1149
     self abbreviatedMonthNamesForLanguage:#en
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1150
     self abbreviatedMonthNamesForLanguage:#de
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1151
     self abbreviatedMonthNamesForLanguage:#fr
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1152
     self abbreviatedMonthNamesForLanguage:#es
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1153
     self abbreviatedMonthNamesForLanguage:#zulu
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1154
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1155
     self abbreviatedMonthNamesForLanguage:nil
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1156
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1157
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1158
    "Modified (format): / 18-07-2011 / 09:34:20 / cg"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1159
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1160
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1161
abbreviatedNameOfDay:dayIndex
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1162
    "given a day index (1..7), 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1163
     return the abbreviated name of the day 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1164
     for the current language setting"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1165
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1166
    ^ self abbreviatedNameOfDay:dayIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1167
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1168
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1169
     Date abbreviatedNameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1170
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1171
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1172
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1173
abbreviatedNameOfDay:dayIndex language:langOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1174
    "given a day index (1..7), 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1175
     return the abbreviated name of the day.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1176
     For nil, the current default language us used.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1177
     For unknown languages, english is used." 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1178
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1179
    ^ (self abbreviatedDayNamesForLanguage:langOrNilForDefault) at:dayIndex
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1180
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1181
    "
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1182
     Date abbreviatedNameOfDay:4 language:#en    
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1183
     Date abbreviatedNameOfDay:4 language:#de    
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1184
     Date abbreviatedNameOfDay:4 language:#zulu  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1185
     Date abbreviatedNameOfDay:4 language:nil    
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1186
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1187
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1188
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1189
abbreviatedNameOfMonth:monthIndex
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1190
    "given a month index (1..12), 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1191
     return the abbreviated name of the month
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1192
     for the current language setting"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1193
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1194
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1195
    ^ self abbreviatedNameOfMonth:monthIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1196
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1197
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1198
     Date abbreviatedNameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1199
     Date abbreviatedNameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1200
    "
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
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1203
abbreviatedNameOfMonth:monthIndex language:langOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1204
    "given a month index (1..12), 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1205
     return the abbreviated name of the month.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1206
     For nil, the current default language us used.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1207
     For unknown languages, english is used." 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1208
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1209
    ^ (self abbreviatedMonthNamesForLanguage:langOrNilForDefault) at:monthIndex
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1210
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1211
    "
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1212
     Date abbreviatedNameOfMonth:11 language:#en     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1213
     Date abbreviatedNameOfMonth:12 language:#en     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1214
     Date abbreviatedNameOfMonth:12 language:#de     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1215
     Date abbreviatedNameOfMonth:12 language:#fr     
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1216
     Date abbreviatedNameOfMonth:12 language:#zulu   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1217
     Date abbreviatedNameOfMonth:12 language:nil     
7793
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
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1220
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1221
dateAndTimeNow
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1222
    "return an array containing the date and time of now.
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1223
     As these provide no timezone info, this should be only used for user interface purposes."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1224
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1225
    ^ Time dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1226
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1227
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1228
     Date dateAndTimeNow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1229
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1230
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1231
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1232
dayNamesForLanguage:languageOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1233
    "return a collection of day-names for a given language or the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1234
     current language if nil is given.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1235
     The returned strings depend on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1236
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1237
     If not, english names are returned"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1238
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1239
    |langDayNames lang|
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1240
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1241
    (DayNames isNil or:[EnvironmentChange]) ifTrue:[
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1242
        self initNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1243
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1244
    lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1245
    langDayNames := DayNames at:lang ifAbsent:nil.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1246
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1247
    "/ If language is not found, try to initialize it from the resources and try again
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1248
    langDayNames isNil ifTrue:[ 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1249
        self initNamesForLanguage: lang.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1250
        "/ If language initialization failed, take english dayNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1251
        langDayNames := DayNames at:lang ifAbsent:[DayNames at:#en].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1252
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1253
    ^ langDayNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1254
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1255
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1256
     self dayNamesForLanguage:#en
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1257
     self dayNamesForLanguage:#de
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1258
     self dayNamesForLanguage:#fr   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1259
     self dayNamesForLanguage:#es   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1260
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1261
     self dayNamesForLanguage:#zulu 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1262
     self dayNamesForLanguage:nil   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1263
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1264
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1265
    "Modified (format): / 18-07-2011 / 09:34:08 / cg"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1266
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1267
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1268
dayOfFirstWeekInYear:aYear
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1269
    "for a given year, return the day corresponding to that year's monday of week-01.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1270
     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
  1271
     and the 1st day of that week is the preceeding monday 
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1272
     (that means: that the returned day might be a day of the previous year!!)"
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1273
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1274
    |day dayInWeekOf1stJan firstThursday firstDayInWeek|
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1275
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1276
    "/ find the first thursday ...
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  1277
    day := self newDay:1 year:aYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1278
    dayInWeekOf1stJan := day dayInWeek.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1279
    dayInWeekOf1stJan > 4 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1280
        firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1281
    ] ifFalse:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1282
        firstThursday := day addDays:(4 - dayInWeekOf1stJan).
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1283
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1284
    "/ back to the preceeding monday
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1285
    firstDayInWeek := firstThursday subtractDays:3.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1286
    ^ firstDayInWeek
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1287
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1288
    "
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1289
     Date newDay:1 year:1900  
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1290
     Date dayOfFirstWeekInYear:1900  
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1291
     Date dayOfFirstWeekInYear:1998   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1292
     Date dayOfFirstWeekInYear:1999    
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1293
     Date dayOfFirstWeekInYear:2000  
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1294
     Date dayOfFirstWeekInYear:2001   
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1295
    "
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1296
!
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1297
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1298
dayOfWeek:dayName
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1299
    "given the name of a day (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1300
     return the day-index (1 for monday; 7 for sunday).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1301
     Return 0 for invalid day name"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1302
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1303
    |d|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1304
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1305
    d := self dayOfWeek:dayName language:nil.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1306
    d == 0 ifTrue:[
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1307
        d := self dayOfWeek:dayName language:'en'.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1308
    ].
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1309
    ^ d
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1310
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1311
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1312
     Date dayOfWeek:'wednesday' 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1313
     Date dayOfWeek:'Wednesday' 
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  1314
     Date dayOfWeek:'Mittwoch' 
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1315
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1316
!
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1317
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1318
dayOfWeek:dayName language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1319
    "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
  1320
     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
  1321
     Return 0 for invalid day name.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1322
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1323
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1324
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1325
    |idx langDayNames|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1326
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1327
    langDayNames := self dayNamesForLanguage:lang.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1328
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1329
    idx := langDayNames indexOf:dayName.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1330
    idx == 0 ifTrue:[
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1331
        idx := langDayNames indexOf:dayName asLowercase.
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1332
    ].
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  1333
    ^ idx
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1334
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1336
     Date dayOfWeek:'wednesday' language:'en'
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1337
     Date dayOfWeek:'Wednesday' language:'en'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1338
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1339
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1340
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1341
daysInMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1342
    "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
  1343
     of days this month has (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1344
     return 0 if the month name was invalid.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1345
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1346
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1347
    |monthIndex "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1348
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1349
    month isInteger ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1350
	monthIndex := month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1351
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1352
	monthIndex := self indexOfMonth:month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1353
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1354
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1355
    ^ self daysInMonthIndex:monthIndex forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1356
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1357
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1358
     Date daysInMonth:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1359
     Date daysInMonth:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1360
     Date daysInMonth:'feb' forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1361
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1362
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1363
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1364
daysInYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1365
    "return the number of days in a year"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1366
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1367
    (self leapYear:yearInteger) ifTrue:[^ 366].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1368
    ^ 365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1369
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1370
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1371
     Date daysInYear:1900  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1372
     Date daysInYear:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1373
     Date daysInYear:1904 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1374
     Date daysInYear:1980 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1375
     Date daysInYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1376
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1377
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1378
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1379
daysUntilMonth:month forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1380
    "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
  1381
     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
  1382
     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
  1383
     For your convenience, month maybe an integer or name-string."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1384
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1385
    |monthIndex|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1386
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1387
    month isInteger ifTrue:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1388
        monthIndex := month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1389
    ] ifFalse:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1390
        monthIndex := self indexOfMonth:month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1391
    ].
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1392
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  1393
    ^ self daysUntilMonthIndex:monthIndex forYear:yearInteger
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1394
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1395
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1396
     Date daysUntilMonth:'feb' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1397
     Date daysUntilMonth:'jan' forYear:1993
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1398
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1399
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1400
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1401
defaultFormatString
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1402
    "a language specific format string to present dates in user interfaces.
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1403
     Do not use this to store/retrieve dates (use ISO8601 for that)"
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1404
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1405
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1406
        self initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1407
    ].
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  1408
    ^ DefaultFormats at:Smalltalk language ifAbsent:(DefaultFormats at:#en).
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1409
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1410
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1411
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1412
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1413
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1414
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1415
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1416
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1417
firstDayOfYear:inYear
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1418
    "return the weekDay-index of the 1st-january of the given year.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1419
     1->monday, 2->tuesday, ... 7->sunday"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1420
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1421
    | t d |
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1422
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1423
    ((inYear < 1) or:[ inYear > 9999]) ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1424
        ^ 0.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1425
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1426
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1427
    "/ normal Gregorian calendar: one extra day per four years 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1428
    t := 4 + inYear + ((inYear + 3) // 4).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1429
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1430
    inYear > 1800 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1431
        "/ Julian calendar: regular Gregorian less 3 days per 400
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1432
        t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400).
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1433
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1434
    inYear > 1752 ifTrue:[
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1435
        "/ calendar changeover
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1436
        t := t + 3.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1437
    ].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1438
    d := t \\ 7.
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1439
    "/ convert from 0 (sunday) .. 6 (saturday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1440
    "/ to 1 (munday) .. 7 (sunday)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1441
    d == 0 ifTrue:[^ 7].
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1442
    ^ d
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1443
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1444
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1445
     self firstDayOfYear:2000           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1446
     (Date newDay:1 year:2000) dayInWeek 
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1447
     self firstDayOfYear:1999      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1448
     (Date newDay:1 year:1999) dayInWeek
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1449
     self firstDayOfYear:1998      
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1450
     (Date newDay:1 year:1998) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1451
     self firstDayOfYear:2001           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1452
     (Date newDay:1 year:2001) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1453
     self firstDayOfYear:2002           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1454
     (Date newDay:1 year:2002) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1455
     self firstDayOfYear:2006           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1456
     (Date newDay:1 year:2006) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1457
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1458
     self firstDayOfYear:1800           
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1459
     (Date newDay:1 year:1800) dayInWeek    
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1460
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1461
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  1462
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1463
indexOfMonth:aMonthString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1464
    "given the name of a month (either string or symbol),
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1465
     return the month-index (1 for jan; 12 for december).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1466
     The given string may be a full or abbreviated name,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1467
     case is ignored.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1468
     Return 0 for invalid month name."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1469
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1470
    |monthIndex|
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1471
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1472
    monthIndex := self indexOfMonth:aMonthString language:nil.
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1473
    "/ if not found, retry in english
17080
cc02d25252ed class: Date
Stefan Vogel <sv@exept.de>
parents: 17053
diff changeset
  1474
    (monthIndex == 0 and:[ Smalltalk language ~= #en ])
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1475
    ifTrue:[
17080
cc02d25252ed class: Date
Stefan Vogel <sv@exept.de>
parents: 17053
diff changeset
  1476
        monthIndex := self indexOfMonth:aMonthString language:#en.
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1477
    ].
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1478
    ^ monthIndex
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1479
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1480
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1481
     Date indexOfMonth:'jan'
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1482
     Date indexOfMonth:'Jan'  
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1483
     Date indexOfMonth:'December'
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1484
     Date indexOfMonth:'Dezember' 
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1485
     Date indexOfMonth:'december' 
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1486
     Date indexOfMonth:'dezember' 
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1487
    "
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1488
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1489
    "Modified: / 08-10-2006 / 14:22:06 / cg"
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1490
!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1491
14714
cebd5cc86824 class: Date
Claus Gittinger <cg@exept.de>
parents: 14624
diff changeset
  1492
indexOfMonth:aMonthString language:languageOrNil
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1493
    "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
  1494
     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
  1495
     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
  1496
     case is ignored.
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1497
     Return 0 for invalid month name.
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1498
     For nil, Smalltalk language (i.e. the current language setting) is used,
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1499
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1500
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1501
    |idx name langMonthNames langMonthAbbrevs|
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1502
14714
cebd5cc86824 class: Date
Claus Gittinger <cg@exept.de>
parents: 14624
diff changeset
  1503
    langMonthNames := self monthNamesForLanguage:languageOrNil.
16839
7e3621d2361b class: Date
Stefan Vogel <sv@exept.de>
parents: 16838
diff changeset
  1504
    langMonthAbbrevs := self abbreviatedMonthNamesForLanguage:languageOrNil.
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1505
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1506
    name := aMonthString asLowercase.
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1507
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1508
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1509
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1510
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1511
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1512
    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
  1513
    idx := langMonthAbbrevs indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1514
    idx ~~ 0 ifTrue:[^ idx].
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1515
    idx := langMonthNames indexOf:name.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1516
    idx ~~ 0 ifTrue:[^ idx].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1517
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1518
    ^ idx
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1519
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1520
    "
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1521
     Date indexOfMonth:'jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1522
     Date indexOfMonth:'Jan'      language:#en 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1523
     Date indexOfMonth:'December' language:#en 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1524
    "
10056
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1525
3c8e8c867a13 indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents: 9262
diff changeset
  1526
    "Modified: / 08-10-2006 / 14:20:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1527
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1528
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1529
leapYear:yearInteger
16971
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1530
    "return true, if yearInteger is a leap year.
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1531
     For years before 1583, the proleptic calendar is used 
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1532
     (i.e. assuming there was a gregorian calendar in effect)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1533
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1534
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1535
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1536
    y := yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1537
    (y \\ 4 == 0) ifTrue:[
16971
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1538
        (y \\ 100 ~~ 0) ifTrue:[^ true].
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1539
        (y \\ 400 == 0) ifTrue:[^ true]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1540
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1541
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1542
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1543
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1544
     Date leapYear:1992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1545
     Date leapYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1546
     Date leapYear:1900
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1547
     Date leapYear:2000
16971
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1548
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1549
     Date leapYear:0
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1550
     Date leapYear:-1
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1551
     Date leapYear:-2
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1552
     Date leapYear:-3
78a1846a2bfe class: Date
Claus Gittinger <cg@exept.de>
parents: 16927
diff changeset
  1553
     Date leapYear:-4
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1554
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1555
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1556
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1557
longFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1558
    (LongFormats isNil or:[EnvironmentChange]) ifTrue:[
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  1559
        self initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1560
    ].
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  1561
    ^ LongFormats at:Smalltalk language ifAbsent:(LongFormats at:#en).
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1562
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1563
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1564
     Date today printStringFormat:(Date defaultFormatString). 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1565
     Date today printStringFormat:(Date longFormatString).    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1566
     Date today printStringFormat:(Date shortFormatString).   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1567
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1568
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1569
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1570
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1571
    "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
  1572
     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
  1573
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1574
    |restDays daysInMonth|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1575
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1576
    restDays := aDayInYear.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1577
    restDays < 1 ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1578
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1579
    1 to:12 do:[:m |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1580
	daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1581
	restDays <= daysInMonth ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1582
	    ^ Array with:m with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1583
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1584
	restDays := restDays - daysInMonth 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1585
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1586
    restDays > daysInMonth ifTrue:[^ nil].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1587
    ^ Array with:12 with:restDays
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1588
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1589
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1590
     Date monthAndDayFromDayInYear:66 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1591
     Date monthAndDayFromDayInYear:66 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1592
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1593
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1594
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1595
monthNamesForLanguage:languageOrNilForDefault
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1596
    "return a collection of month-names for a given language or the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1597
     current language if nil is given.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1598
     The returned strings depend on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1599
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1600
     If not, english names are returned"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1601
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1602
    |langMonthNames lang|
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1603
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1604
    (MonthNames isNil or:[EnvironmentChange]) ifTrue:[
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1605
        self initNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1606
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1607
    lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1608
    langMonthNames := MonthNames at:lang ifAbsent:nil.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1609
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1610
    "/ If language is not found, try to initialize it from the resources and try again
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1611
    langMonthNames isNil ifTrue:[ 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1612
        self initNamesForLanguage: lang.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1613
        "/ If language initialization failed, take english monthNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1614
        langMonthNames := MonthNames at:lang ifAbsent:[MonthNames at:#en.].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1615
    ].
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1616
    ^ langMonthNames
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1617
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1618
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1619
     self monthNamesForLanguage:#en  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1620
     self monthNamesForLanguage:#de  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1621
     self monthNamesForLanguage:#fr   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1622
     self monthNamesForLanguage:#es   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1623
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1624
     self monthNamesForLanguage:#zulu 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1625
     self monthNamesForLanguage:nil   
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1626
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1627
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1628
    "Modified: / 18-07-2011 / 09:34:32 / cg"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1629
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1630
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1631
nameOfDay:dayIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1632
    "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
  1633
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1634
    ^ self nameOfDay:dayIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1635
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1636
    "
8795
7fc3fbba3b63 comment
Claus Gittinger <cg@exept.de>
parents: 8626
diff changeset
  1637
     Date nameOfDay:1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1638
     Date nameOfDay:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1639
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1640
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1641
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1642
nameOfDay:dayIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1643
    "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
  1644
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1645
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1646
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1647
    ^ (self dayNamesForLanguage:lang) at:dayIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1648
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1649
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1650
     Date nameOfDay:4 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1651
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1652
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1653
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1654
nameOfMonth:monthIndex
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1655
    "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
  1656
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1657
    ^ self nameOfMonth:monthIndex language:nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1658
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1659
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1660
     Date nameOfMonth:11
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1661
     Date nameOfMonth:12
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1662
     Date nameOfMonth:4
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1663
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1664
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1665
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1666
nameOfMonth:monthIndex language:lang
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1667
    "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
  1668
     For nil, Smalltalk language is used,
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1669
     for unknown languages, english is used." 
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1670
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1671
    ^ (self monthNamesForLanguage:lang) at:monthIndex
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1672
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1673
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1674
     Date nameOfMonth:11 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1675
     Date nameOfMonth:12 language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1676
     Date nameOfMonth:4  language:#en
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1677
    "
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1678
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  1679
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1680
shortFormatString
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1681
    (ShortFormats isNil or:[EnvironmentChange]) ifTrue:[
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  1682
        self initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1683
    ].
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  1684
    ^ ShortFormats at:Smalltalk language ifAbsent:(ShortFormats at:#en).
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1685
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1686
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1687
     Date today printStringFormat:(Date defaultFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1688
     Date today printStringFormat:(Date longFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1689
     Date today printStringFormat:(Date shortFormatString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1690
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1691
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  1692
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1693
weekInYearOf:aDateOrTimestamp
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1694
    "for a given date or timeStamp, return the week-number.
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1695
     The returned week number starts with 1 for the first week which has a thursday in it.
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1696
     (see DIN 1355-1/ISO 8601)
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1697
     The rule is:
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1698
        every monday (and only monday), a new week begins   
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1699
        the first week is the one which has at least 4 days of the new year in it
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1700
        
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1701
     Be prepared: this 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
  1702
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1703
    |date dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1704
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1705
    date := aDateOrTimestamp asDate.
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1706
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1707
    dayInYear := date dayInYear.
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1708
    dayOfFirstWeekInYear := self dayOfFirstWeekInYear:date year.
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1709
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1710
    numDays := date subtractDate:dayOfFirstWeekInYear.
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1711
    "/ 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
  1712
    numDays < 0 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1713
        "/ not in a week here ...
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1714
        "/ can be either 52 or 53, depending on the previous year.
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  1715
        ^ self weekInYearOf:(self year:date year - 1  month:12 day:31) 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1716
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1717
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1718
    "/ compute the week 
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1719
    week := numDays // 7 + 1.
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1720
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1721
    "/ 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
  1722
    week == 53 ifTrue:[
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1723
        dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1.
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  1724
        date >= dayOfFirstWeekInNextYear ifTrue:[
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1725
            ^ 1
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1726
        ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1727
    ].
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  1728
    ^ week
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1729
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1730
    "
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1731
     Timestamp now weekInYear    
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1732
     Date weekInYearOf:(Date newDay:31 month:12 year:1999)     was a friday; 
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  1733
     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
  1734
     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
  1735
     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
  1736
     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
  1737
     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
  1738
     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
  1739
     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
  1740
     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
  1741
     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
  1742
     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
  1743
     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
  1744
     Date weekInYearOf:(Timestamp newDay:17 year:2000)   was a monday -> W03
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1745
     Date weekInYearOf:(Date newDay:1 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1746
     Date weekInYearOf:(Date newDay:2 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1747
     Date weekInYearOf:(Date newDay:3 month:1 year:2001)     
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1748
     Date weekInYearOf:(Date newDay:24 month:12 year:2001)   -> W52
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1749
     Date weekInYearOf:(Date newDay:30 month:12 year:2001)   -> W52
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1750
     Date weekInYearOf:(Date newDay:31 month:12 year:2001)   -> W01
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1751
     Date weekInYearOf:(Date newDay:1 month:1 year:2002)    
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1752
     Date weekInYearOf:(Date newDay:2 month:1 year:2002)      
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1753
     Date weekInYearOf:(Date newDay:7 month:1 year:2002)      
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1754
     Date weekInYearOf:(Date newDay:26 month:9 year:2008) 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1755
     Date weekInYearOf:(Date newDay:27 month:9 year:2008)
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1756
     Date weekInYearOf:(Date newDay:4 month:1 year:2008)
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1757
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1758
     Date weekInYearOf:(Date newDay:1 month:1 year:2010) 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1759
     Date weekInYearOf:(Date newDay:2 month:1 year:2010) 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1760
     Date weekInYearOf:(Date newDay:3 month:1 year:2010) 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  1761
     Date weekInYearOf:(Date newDay:4 month:1 year:2010) 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1762
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1763
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  1764
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1765
yearAsDays: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1766
    "Returns the number of days since Jan 1, 1901. (GNU)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1767
     to the first Jan of the year, yearInteger.
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1768
     For 1901 this is zero, for 1902 it's 365.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1769
     Defined for years >= 1901"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1770
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1771
    |y "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1772
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1773
    y := yearInteger - 1900.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1774
    y := y - 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1775
    ^ (y * 365)
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1776
        + (y // 4)
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1777
        - (y // 100)
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1778
        + ((y + 300) // 400)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1779
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1780
    "
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  1781
     Date yearAsDays:5 
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  1782
     Date yearAsDays:1900 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1783
     Date yearAsDays:1901 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1784
     Date yearAsDays:1902   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1785
     Date yearAsDays:1903   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1786
     Date yearAsDays:1904    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1787
     Date yearAsDays:1905     
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1788
     Date yearAsDays:1994   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1789
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1790
    "
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1791
!
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1792
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1793
yearAsDaysFrom0: yearInteger
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1794
    "Returns the number of days since Jan 1, 0 to Jan 1, yearInteger
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1795
     without caring for gregorian calendar change
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1796
     (i.e. as if there was a gregorian for all time).
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1797
     Also assuming that the leapYear rules were present in pre-gregorian times also.
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1798
     Used internally to compute date differences.
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1799
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1800
     In previous versions, dates were counted relative to 1.1.1901.
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1801
     This is no longer done; however, for backward compatibility, the old yearAsDays
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1802
     and Date fromDays is still supported.
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1803
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1804
     For years >= 1901 it must hold that:
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1805
        yearAsDaysFrom0(d1) - yearAsDaysFrom0(d2)
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1806
     is the same as
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1807
        yearAsDays(d1) - yearAsDays(d2)
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1808
    "
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1809
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1810
    |y "{ Class: SmallInteger }"|
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1811
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1812
    yearInteger == 0 ifTrue:[^ 0].
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1813
    y := yearInteger - 1.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1814
    ^ 366             "/ 0 would have been a leap year
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1815
        + (y * 365)
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1816
        + (y // 4)    "/ every 4th year is a leap year
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1817
        - (y // 100)  "/ but not evey 100th
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1818
        + (y // 400)  "/ but evey 400th is
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1819
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1820
    "
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1821
     Date yearAsDaysFrom0:1900 
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1822
     Date yearAsDaysFrom0:1901 
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1823
     Date yearAsDaysFrom0:1902   
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1824
     Date yearAsDaysFrom0:1903   
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1825
     Date yearAsDaysFrom0:1904    
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1826
     Date yearAsDaysFrom0:1905     
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1827
     Date yearAsDaysFrom0:1994 
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1828
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1829
     (Date yearAsDays:2001) - (Date yearAsDays:2000)   
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1830
     (Date yearAsDaysFrom0:2001) - (Date yearAsDaysFrom0:2000)   
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1831
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1832
     (Date yearAsDays:2002) - (Date yearAsDays:2001)           
16983
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1833
     (Date yearAsDaysFrom0:2002) - (Date yearAsDaysFrom0:2001)   
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1834
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1835
     Date yearAsDaysFrom0:-4     -1461  -- -4 was a leap year
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1836
     Date yearAsDaysFrom0:-3     -1095
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1837
     Date yearAsDaysFrom0:-2     -730
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1838
     Date yearAsDaysFrom0:-1     -365
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1839
     Date yearAsDaysFrom0:0      0
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1840
     Date yearAsDaysFrom0:1      366     -- 0 was a leap year
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1841
     Date yearAsDaysFrom0:2      731
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1842
     Date yearAsDaysFrom0:3      1096
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1843
     Date yearAsDaysFrom0:4      1461
ef0d2f381125 class: Date
Claus Gittinger <cg@exept.de>
parents: 16974
diff changeset
  1844
     Date yearAsDaysFrom0:5      1827    -- 0 and 4 are leap years
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  1845
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1846
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1847
17690
569c4ccfd790 class: Date
Claus Gittinger <cg@exept.de>
parents: 17640
diff changeset
  1848
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1849
!Date class methodsFor:'obsolete'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1850
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1851
day:day month:month year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1852
    "return a new Date, given the day, month and year.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1853
     Obsolete:
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1854
        use newDay:month:year: for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1855
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1856
    <resource: #obsolete>
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1857
18585
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1858
    "sr: #storeString has this format,
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1859
     you really want to remove this method somewhen???
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1860
     if yes, please change #storeString also to #newDay:"
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1861
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1862
    self obsoleteMethodWarning:'use #year:month:day: (2014-09)'.
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1863
    ^ self year:year month:month day:day
18585
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1864
bf88a46eb50c class: Date
sr
parents: 18568
diff changeset
  1865
    "Modified (comment): / 16-07-2015 / 15:32:14 / sr"
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1866
!
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1867
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1868
day:dayInYear year:year
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1869
    "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
  1870
     Obsolete:
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1871
        use newDay:year: for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1872
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1873
    <resource: #obsolete>
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1874
16838
a5de52c9d329 class: Date
Stefan Vogel <sv@exept.de>
parents: 16835
diff changeset
  1875
    self obsoleteMethodWarning:'use #newDay:year: (2014-09)'.
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  1876
    ^ self newDay:dayInYear year:year
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1877
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1878
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1879
isLeapYear:yearInteger
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1880
    "Return true, if a year is a leap year.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1881
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1882
         Please use the ST-80 compatible #leapYear for new programs, 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1883
         since this method will vanish."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1884
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1885
16838
a5de52c9d329 class: Date
Stefan Vogel <sv@exept.de>
parents: 16835
diff changeset
  1886
    self obsoleteMethodWarning:'use #leapYear: (2014-09)'.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  1887
    ^ self leapYear:yearInteger
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1888
!
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1889
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1890
newDay:day month:month year:year
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1891
    "backward compatibility"
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1892
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1893
    ^ self year:year month:month day:day
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1894
!
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  1895
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1896
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1897
    "OBSOLETE: kept for backward compatibility.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1898
     return a new Date, reading a printed representation from aStream.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1899
     aSqueakFormatArrayOrFormatString may either be a squeak formatArray
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1900
         1   day position (1, 2 or 3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1901
         2   month position (1..3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1902
         3   year position (1..3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1903
     or a formatString (see printing instance protocol)."
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1904
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1905
    ^ self 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1906
        readFrom:aStringOrStream
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1907
        format:aSqueakFormatArrayOrFormatString 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1908
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1909
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1910
     Date readFrom:'19:11:1999' printFormat:#( 1 2 3 )
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1911
     Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 )
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1912
     Date readFrom:'19:11:1999' printFormat:#( 2 1 3 )  -> exception: wrong month
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1913
     Date readFrom:'5:12:1999' printFormat:#( 2 1 3 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1914
     Date readFrom:'may-12-1999' printFormat:#( 2 1 3 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1915
     Date readFrom:'1999 may 12' printFormat:#( 3 2 1 )  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1916
     Date readFrom:'12/31/2001' printFormat:#( 2 1 3 ) 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1917
     Date readFrom:' 31.08.2001' printFormat:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1918
     Date readFrom:' 31.dec.2001' printFormat:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1919
     Date readFrom:' 31.Dec.2001' printFormat:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1920
     Date readFrom:' 31.dez.2001' printFormat:#( 1 2 3 )    
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1921
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1922
     Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1923
     Date readFrom:'12/01' printFormat:'%m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1924
     Date readFrom:'01' printFormat:'%y' onError:'fail'        
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1925
     Date readFrom:'30.01' printFormat:'%d %m' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1926
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1927
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1928
    "Created: 16.11.1995 / 22:50:17 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1929
    "Modified: 8.10.1996 / 19:25:39 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1930
!
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1931
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1932
readFrom:aStringOrStream printFormat:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1933
    "OBSOLETE: kept for backward compatibility
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1934
     return a new Date, reading a printed representation from aStream.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  1935
     aFormatStringOrSqueakFormatArray may either be a Squeak formatArray
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1936
         1   day position (1, 2 or 3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1937
         2   month position (1..3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1938
         3   year position (1..3)
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  1939
     or an ST/X formatString (see printing instance protocol).
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1940
     For now %d, %m, %monthName, %shortMonthName, %y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1941
     y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1942
     y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1943
     The formatString can have any of these characters '-.:,;/' as separator.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1944
     The format may be preceeded by a single numeric length (as in %2d) to specify how many
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1945
     characters to read.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1946
     The formatString can also use a space as separator (for  ex. '%d %m %y') and any separator will be allowed.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1947
     However, when a character separator is defined, only that separator will be expected.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1948
     TODO: make this a general feature of all DateAndTime classes.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1949
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1950
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1951
    ^ self readFrom:aStringOrStream format:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1952
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1953
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1954
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1955
     Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1956
     Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail'  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1957
     Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1958
     Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1959
     Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1960
     Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date'  -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1961
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail'        -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1962
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1963
     Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1964
     Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1965
     Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1966
     Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date']  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1967
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1968
     Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1969
     Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1970
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1971
     Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1972
     Date readFrom:'12/01' format:'%m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1973
     Date readFrom:'01' format:'%y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1974
     Date readFrom:'30.01' format:'%d %m' onError:'fail'     
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1975
     Date readFrom:'300180' format:'%2d%2m%2y' onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1976
     
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1977
     Date readFrom:'300170' format:'%2d%2m%2y' onError:'fail'      - gives 2070 as year
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1978
     Date readFrom:'300170' format:'%2d%2m%2(y1950)' onError:'fail'  - gives 1970 as year   
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1979
     Date readFrom:'300170' format:'%2d%2m%2(y1980)' onError:'fail'  - gives 2070 as year   
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1980
     Date readFrom:'300181' format:'%2d%2m%2(y1980)' onError:'fail'  - gives 1981 as year   
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1981
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1982
     Date readFrom:'3-3-1995' format:'%d %m %y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1983
     Date readFrom:'3-März-1995' format:'%d %monthName %y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1984
     Date readFrom:'3-mär-1995' format:'%d %shortMonthName %y' language: #de onError:'fail'   
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1985
     Date readFrom:'3/mär/1995' format:'%d %shortMonthName %y' language: #de onError:'fail'  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1986
     Date readFrom:'3/mär/1995' format:'%d-%shortMonthName-%y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1987
     Date readFrom:'3-dez-1995' format:'%d %shortMonthName %y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1988
     Date readFrom:'3-Dez-1995' format:'%d %shortMonthName %y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1989
     Date readFrom:'3-Dezember-1995' format:'%d %monthName %y' language: #de onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1990
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1991
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1992
    "Created: 16.11.1995 / 22:50:17 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1993
    "Modified: 8.10.1996 / 19:25:39 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1994
!
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1995
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1996
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1997
    "return a new Date, reading a printed representation from aStream.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  1998
     aSqueakFormatArrayOrFormatString may either be a Squeak formatArray
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  1999
         1   day position (1, 2 or 3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2000
         2   month position (1..3)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2001
         3   year position (1..3)
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2002
     or an ST/X formatString (see printing instance protocol).
18444
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2003
     All of the %-formats as in the printString are supported here.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2004
     (i.e. %d, %m and %y, %shortMonthName and %monthName)
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2005
     In addition, %y1900, %y2000, %y1950 and %y1980 are supported:
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2006
     y1900 converts 2-digit year YY into 19YY, y2000 into 20YY.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2007
     y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2008
     TODO: make this a general feature of all DateAndTime classes.
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2009
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2010
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2011
    ^ self readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString onError:exceptionBlock
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2012
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2013
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2014
     Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2015
     Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail'  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2016
     Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' 
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2017
     Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail'          
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2018
     Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2019
     Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date'  -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2020
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail'        -> german
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2021
     Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2022
     Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2023
     Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2024
     Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date']
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2025
     Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date']  
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2026
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2027
     Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2028
     Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2029
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2030
     Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2031
     Date readFrom:'12/01' format:'%m %y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2032
     Date readFrom:'01' format:'%y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2033
     Date readFrom:'30.01' format:'%d %m' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2034
     Date readFrom:'311201' format:'%2d%2m%2y' onError:'fail'       
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2035
    "
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2036
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2037
    "Created: 16.11.1995 / 22:50:17 / cg"
f70da4b43b10 class: Date
Claus Gittinger <cg@exept.de>
parents: 18443
diff changeset
  2038
    "Modified: 8.10.1996 / 19:25:39 / cg"
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2039
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2040
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  2041
!Date class methodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2042
13509
771552bde287 changed:
Claus Gittinger <cg@exept.de>
parents: 13234
diff changeset
  2043
dayAbbrevsForLanguage:languageOrNilForDefault
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2044
    <resource: #obsolete>
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2045
    "return a collection of short day-names for a given language or the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2046
     current language if nil is given.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2047
     The returned strings depend on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2048
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2049
     If not, english names are returned"
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2050
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2051
    ^ self abbreviatedDayNamesForLanguage:languageOrNilForDefault
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2052
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2053
    "
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2054
     self dayAbbrevsForLanguage:#en
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2055
     self dayAbbrevsForLanguage:#de
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2056
     self dayAbbrevsForLanguage:#fr
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2057
     self dayAbbrevsForLanguage:#es
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2058
     self dayAbbrevsForLanguage:nil
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2059
     self dayAbbrevsForLanguage:#zulu
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2060
    "
13509
771552bde287 changed:
Claus Gittinger <cg@exept.de>
parents: 13234
diff changeset
  2061
771552bde287 changed:
Claus Gittinger <cg@exept.de>
parents: 13234
diff changeset
  2062
    "Modified (format): / 18-07-2011 / 09:34:14 / cg"
7793
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  2063
!
8abaefe33259 keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents: 7673
diff changeset
  2064
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2065
daysInMonthIndex: monthIndex forYear: yearInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2066
    "return the number of days in month monthIndex of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2067
     year yearInteger (modified GNU).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2068
     Return 0 for invalid month index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2069
     This is the internal version of daysInMonth:forYear:"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2070
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2071
    |days|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2072
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2073
    (monthIndex between:1 and:12) ifFalse:[^ 0].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2074
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2075
    days := #(31 28 31           "Jan Feb Mar"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2076
	      30 31 30           "Apr May Jun"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2077
	      31 31 30           "Jul Aug Sep"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2078
	      31 30 31           "Oct Nov Dec"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2079
	     ) at: monthIndex.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2080
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2081
    (monthIndex == 2) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2082
	(self leapYear:yearInteger) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2083
	    ^ days + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2084
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2085
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2086
    ^ days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2087
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2088
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2089
     Date daysInMonthIndex:2 forYear:1994
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2090
     Date daysInMonthIndex:2 forYear:1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2091
     Date daysInMonthIndex:2 forYear:1981
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2092
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2093
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2094
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2095
daysUntilMonthIndex: monthIndex forYear: yearInteger
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2096
    "return the number of days from 1st January up to month monthIndex of
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2097
     year yearInteger (modified GNU).
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2098
     Return 0 for invalid month index.
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2099
     This is the internal version of dayInMonth:forYear:"
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2100
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2101
    |days|
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2102
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2103
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2104
       |sum|
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2105
       sum := 0.
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2106
       #(31 28 31          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2107
         30 31 30          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2108
         31 31 30          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2109
         31 30 31          
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2110
        ) collect:[:each | |first| first:= sum. sum := sum + each. first]
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2111
                #(0 31 59 90 120 151 181 212 243 273 304 334)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2112
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2113
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2114
    (monthIndex between:1 and:12) ifFalse:[^ 0].
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2115
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2116
    days := #(0 31 59 90 120 151 181 212 243 273 304 334) at: monthIndex.
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2117
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2118
    (monthIndex > 2) ifTrue:[
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2119
        (self leapYear:yearInteger) ifTrue:[
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2120
            ^ days + 1
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2121
        ]
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2122
    ].
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2123
    ^ days
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2124
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2125
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2126
     Date daysUntilMonthIndex:3 forYear:1994
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2127
     Date daysUntilMonthIndex:3 forYear:1980
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2128
     Date daysUntilMonthIndex:3 forYear:1981
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2129
    "
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2130
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2131
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2132
!Date class methodsFor:'private-encoding/decoding'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2133
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2134
encodeYear:y month:m day:d
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2135
    "the internal encoding is strictly private, 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2136
     and should not be used outside."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2137
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2138
    "this encoding was chosen to be easily readable...
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2139
     and also sortable"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2140
    ^ (((y * 100) + m) * 100) + d
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2141
!
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2142
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2143
readDatePartFrom:str format:fmt language:languageOrNil
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2144
    "read a single component (such as %shortName) from str"
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2145
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2146
    |dayName monthName day month year format string dayOfYear|
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2147
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2148
    format := fmt.
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2149
    string := str throughAnyForWhich:[:ch | ch isNationalAlphaNumeric].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2150
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2151
    ((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2152
        "/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2153
        dayName := string.
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2154
        ^ nil.
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2155
    ].
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2156
    ((format sameAs:'d') or:[format sameAs:'day']) ifTrue:[
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2157
        day := Integer readFrom:string.
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2158
        ^ #day -> day
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2159
    ].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2160
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2161
    ((format sameAs:'m') or:[format sameAs:'month']) ifTrue:[
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2162
        month := Integer readFrom:string.      
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2163
        ^ #month -> month
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2164
    ].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2165
    (format sameAs:'monthName') ifTrue:[
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2166
        monthName := string.
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2167
        month := (self monthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2168
"/        month == 0 ifTrue:[self error:'invalid month name'].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2169
        ^ #month -> month
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2170
    ].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2171
    (format sameAs:'shortMonthName') ifTrue:[
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2172
        monthName := string.
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2173
        month := (self abbreviatedMonthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m].
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2174
"/        month == 0 ifTrue:[self error:'invalid month name'].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2175
        ^ #month -> month
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2176
    ].
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2177
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2178
    (format sameAs: 'y1900') ifTrue:[
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2179
        year := Integer readFrom:string.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2180
        year < 100 ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2181
            ^ #year -> (year + 1900)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2182
        ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2183
        ^ #year -> year
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2184
    ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2185
    
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2186
    (format sameAs: 'y1950') ifTrue:[
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2187
        "shift YY into 1950..2049; for 2k support of old date strings" 
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2188
        year := Integer readFrom:string.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2189
        year < 100 ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2190
            year < 50 ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2191
                ^ #year -> (year + 2000)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2192
            ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2193
            ^ #year -> (year + 1900)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2194
        ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2195
        ^ #year -> year
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2196
    ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2197
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2198
    (format sameAs: 'y1980') ifTrue:[
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2199
        "shift YY into 1980..2079; for 2k support of old date strings" 
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2200
        year := Integer readFrom:string.
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2201
        year < 100 ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2202
            year < 80 ifTrue:[
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2203
                ^ #year -> (year + 2000)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2204
            ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2205
            ^ #year -> (year + 1900)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2206
        ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2207
        ^ #year -> year
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2208
    ].
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2209
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2210
    (format sameAs: 'y1970') ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2211
        "shift YY into 1970..2069; for 2k support of old date strings" 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2212
        year := Integer readFrom:string.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2213
        year < 100 ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2214
            year < 70 ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2215
                ^ #year -> (year + 2000)
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2216
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2217
            ^ #year -> (year + 1900)
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2218
        ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2219
        ^ #year -> year
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2220
    ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  2221
18446
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2222
    (format = 'Y') ifTrue:[
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2223
        "shift YY into 1970..2069; for 2k support of old date strings" 
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2224
        year := Integer readFrom:string.
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2225
        year < 100 ifTrue:[
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2226
            year < 70 ifTrue:[
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2227
                ^ #year -> (year + 2000)
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2228
            ].
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2229
            ^ #year -> (year + 1900)
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2230
        ].
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2231
        ^ #year -> year
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2232
    ].
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2233
    
621525712675 class: Date
Claus Gittinger <cg@exept.de>
parents: 18444
diff changeset
  2234
    ((format = 'y') or:[format sameAs:'year']) ifTrue:[
12812
4ca9c8addc9f added: #initNamesForLanguage:
fm
parents: 12796
diff changeset
  2235
        year := Integer readFrom:string.
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2236
        year < 100 ifTrue:[
11787
917164680a0f *** empty log message ***
fm
parents: 11786
diff changeset
  2237
            ^ #year -> (year + 2000)
11786
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2238
        ].
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2239
        ^ #year -> year
4173f6139f15 enhacements for #readFrom:printFormat:onError:
fm
parents: 11742
diff changeset
  2240
    ].
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2241
    
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2242
    (format sameAs:'dayOfYear') ifTrue:[
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2243
        dayOfYear := Integer readFrom:string.      
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2244
        ^ #dayOfYear -> dayOfYear
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2245
    ].
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  2246
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  2247
    self error:'unknown format specifier: ',format
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2248
! !
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2249
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  2250
!Date class methodsFor:'private-instance creation'!
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2251
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2252
fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2253
    "return a date, representing the date given by the operatingSystem time.
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2254
     This somewhat clumsy implementation hides the OS's date representation
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2255
     (i.e. makes this class independent of what the OS starts its time values with).
20794
cad768b79b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20776
diff changeset
  2256
     Don't use this method, the osTime representation is totally unportable."
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2257
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2258
    ^ self basicNew fromOSTime:osTime
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2259
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2260
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2261
     Date fromOSTime:0              -> on UNIX: this should return 1st Jan 1970
20409
795098692ba7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19896
diff changeset
  2262
                                       that's where Unix time starts
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2263
                                       On other systems, it may be something different.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2264
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2265
     Date fromOSTime:(24*60*60*1000) -> on UNIX: the day after
1227
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2266
    "
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2267
! !
e89b39909085 commentary & category changes
Claus Gittinger <cg@exept.de>
parents: 972
diff changeset
  2268
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2269
!Date methodsFor:'Compatibility-ANSI'!
6419
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2270
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2271
dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2272
    "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
  2273
     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
  2274
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2275
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2276
    |d|
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2277
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2278
    d := self dayInWeek.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2279
    d == 7 ifTrue:[
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2280
        ^ 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2281
    ].
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2282
    ^ d + 1
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2283
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2284
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2285
     Date today dayOfWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2286
     Date today dayInWeek
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2287
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2288
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2289
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2290
dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2291
    "return the short week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2292
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2293
     Expect things like 'mon', 'tue' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2294
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2295
    ^ self abbreviatedDayName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2296
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2297
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2298
     Date today dayOfWeekAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2299
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2300
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2301
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2302
dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2303
    "return the week-day of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2304
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2305
     Expect things like 'monday', 'tuesday' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2306
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2307
    ^ self weekday
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2308
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2309
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2310
     Date today dayOfWeekName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2311
     Date today dayOfWeekAbbreviation 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2312
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2313
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2314
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2315
dayOfYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2316
    "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
  2317
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2318
    ^ self dayInYear
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2319
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2320
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2321
     Date today dayOfYear 
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2322
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2323
!
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2324
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2325
monthAbbreviation
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2326
    "return the month of the receiver as a string.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2327
     The returned string depends on the language setting.
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2328
     Expect things like 'jan', 'feb' ..."
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2329
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2330
    ^ self abbreviatedMonthName
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2331
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2332
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2333
     Date today monthAbbreviation  
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2334
    "
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2335
! !
5cf00f5e656d more ANSI compatibility
Claus Gittinger <cg@exept.de>
parents: 5858
diff changeset
  2336
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2337
!Date methodsFor:'Compatibility-ST80'!
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2338
11740
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2339
firstDayInMonth
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2340
    "Return the first day in the month of the receiver"
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2341
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2342
    ^ self subtractDays:(self dayOfMonth - 1)
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2343
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2344
    "
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2345
     Date today               
11895
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2346
     Date today firstDayInMonth    
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2347
     Date today firstDayInMonth subtractDays:1   
11740
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2348
     (Date today subtractDays:30) firstDayInMonth   
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2349
     (Date today subtractDays:122) firstDayInMonth   
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2350
     (Date today subtractDays:154) firstDayInMonth
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2351
    "
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2352
!
8adadac9799e +firstDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11665
diff changeset
  2353
11895
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2354
lastDayInMonth 
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2355
    "Return the last day in the month in which the receiver is."
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2356
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2357
    ^ self addDays:(self daysInMonth - self day).
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2358
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2359
    "
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2360
     Date today       
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2361
     Date today lastDayInMonth        
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2362
     Date today lastDayInMonth addDays:1  
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2363
    "
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2364
!
cb8b4f7949f4 +lastDayInMonth
Claus Gittinger <cg@exept.de>
parents: 11815
diff changeset
  2365
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2366
next:dayName 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2367
    "Return the next date whose weekday name is dayName.
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2368
     Caveat; dayName is expected to be in the current language"
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2369
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2370
    |ti ni|
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2371
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2372
    ti := self weekdayIndex.
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2373
    ni := (self class dayOfWeek:dayName).
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2374
    ^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ])
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2375
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2376
    "
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2377
     Date today              
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2378
     Date today next:#Friday
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2379
     Date today next:#Sunday 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2380
     Date today next:#Monday 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2381
     Date today next:#Thursday
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2382
     Date today next:#WednesDay
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2383
    "
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2384
!
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2385
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2386
nextDayWithIndex:dayIndex 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2387
    "Return the next date whose weekday name is dayName.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2388
     dayIndex is Monday=1, ... , Sunday=7"
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2389
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2390
    |ti|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2391
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2392
    self assert:(dayIndex between:1 and:7).
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2393
    ti := self weekdayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2394
    ^ self addDays:(dayIndex > ti ifTrue:[ dayIndex-ti ] ifFalse:[ 7+dayIndex-ti ])
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2395
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2396
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2397
     Date today              
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2398
     Date today nextDayWithIndex:5 - next Friday
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2399
     Date today nextDayWithIndex:7  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2400
     Date today nextDayWithIndex:1  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2401
     Date today nextDayWithIndex:4  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2402
     Date today nextDayWithIndex:3  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2403
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2404
!
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2405
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2406
previous:dayName 
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2407
    "Return the previous date whose weekday name is dayName.
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2408
     Caveat; dayName is expected to be in the current language"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2409
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2410
    ^ self previousDayWithIndex:(self class dayOfWeek:dayName).
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2411
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2412
    "
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2413
     Date today                    
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2414
     Date today previous:#Montag 
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2415
     Date today previous:#Monday 
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2416
11664
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2417
     Date today previous:#Friday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2418
     Date today previous:#Sunday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2419
     Date today previous:#Monday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2420
     Date today previous:#Thursday  
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2421
     Date today previous:#WednesDay 
Claus Gittinger <cg@exept.de>
parents: 11652
diff changeset
  2422
     Date today previous:#TuesDay  
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2423
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2424
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2425
11665
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2426
previousDayWithIndex:dayIndex
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2427
    "Return the previous date whose weekday name is dayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2428
     dayIndex is Monday=1, ... , Sunday=7"
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2429
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2430
    |ti|
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2431
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2432
    self assert:(dayIndex between:1 and:7).
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2433
    ti := self weekdayIndex.
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2434
    ^ self subtractDays:(((ti - dayIndex - 1) \\ 7) + 1)
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2435
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2436
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2437
     Date today                    
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2438
     Date today previousDayWithIndex:1 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2439
     Date today previousDayWithIndex:5  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2440
     Date today previousDayWithIndex:7  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2441
     Date today previousDayWithIndex:4  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2442
     Date today previousDayWithIndex:3 
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2443
     Date today previousDayWithIndex:2  
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2444
    "
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2445
!
352825372305 +nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents: 11664
diff changeset
  2446
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2447
printFormat:aFormatArray
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2448
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2449
     Return a string containing a printed representation of the receiver.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2450
     The formatArray argument consists of 6 or 7 integers which control
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2451
     the resulting string. The entries are:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2452
     1   day position (1, 2 or 3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2453
     2   month position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2454
     3   year position (1..3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2455
     4   asciiValue of separator character or separator character
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2456
         or collection of 2 separator characters
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2457
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2458
         4: abbreviated uppercase 5: full uppercase)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2459
     6   year format (1 include century; 2 exclude century)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2460
     7  (optional) true/false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2461
         if true, print numbers in 2-digit format
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2462
         (i.e. with leading zeros); 
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2463
         Taken as false, if omited
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2464
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2465
     Day and monthnames are in the currently active language.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2466
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2467
     This method supports more options than the ST-80 version; month formats 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2468
     4 and 5, non-numeric separators and the optional 7th parameter are not 
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2469
     supported by ST-80. Be aware of this for compatibility reasons.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2470
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2471
     Notice that not all formats can be scanned (correctly) by #readFrom:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2472
     This is an ST-80 compatibility method - I would have choosen another
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2473
     (less cryptic) formatString ...
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2474
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2475
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2476
    ^ self printFormat:aFormatArray forLanguage:nil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2477
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2478
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2479
     Date today printFormat:#(1 2 3 '' 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2480
     Date today printFormat:#(1 2 3 $- 1 2)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2481
     Date today printFormat:#(1 2 3 $. 1 2 true)     
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2482
     Date today printFormat:#(2 1 3 32 3 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2483
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)  
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2484
     Date today printFormat:#(1 2 3 $- 2 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2485
     Date today printFormat:#(1 2 3 $- 4 1)          
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2486
    "
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2487
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2488
    "Modified (comment): / 17-05-2017 / 16:16:05 / mawalch"
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2489
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2490
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2491
printFormat:aFormatArray forLanguage:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2492
    "Obsolete, backward ST-80 compatible formatted printing - see printStringFormat:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2493
     Return a string containing a printed representation of the receiver.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2494
     The formatArray argument consists of 6 or 7 integers which control
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2495
     the resulting string. The entries are:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2496
     1   day position (1, 2 or 3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2497
     2   month position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2498
     3   year position (1..3)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2499
     4   asciiValue of separator character or separator character
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2500
         or collection of 2 separator characters
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2501
     5   month format (1: numeric; 2: abbreviated name; 3: fullname
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2502
         4: abbreviated uppercase 5: full uppercase)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2503
     6   year format (1 include century; 2 exclude century)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2504
     7  (optional) true/false.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2505
         if true, print numbers in 2-digit format
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2506
         (i.e. with leading zeros);
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2507
         Taken as false, if omited
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2508
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2509
     Day and monthnames are in the currently active language.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2510
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2511
     This method supports more options than the ST-80 version; month formats
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2512
     4 and 5, non-numeric separators and the optional 7th parameter are not
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2513
     supported by ST-80. Be aware of this for compatibility reasons.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2514
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2515
     Notice that not all formats can be scanned (correctly) by #readFrom:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2516
     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
  2517
     (less cryptic) formatString ...
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2518
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2519
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2520
    |mf upperCase day month year components sep1 sep2 leadingZeros|
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2521
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2522
    aFormatArray size > 6 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2523
        leadingZeros := aFormatArray at:7
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2524
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2525
        leadingZeros := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2526
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2527
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2528
    components := Array new:3.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2529
    day := self day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2530
    leadingZeros ifTrue:[
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2531
        day := day printStringLeftPaddedTo:2 with:$0
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2532
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2533
        day := day printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2534
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2535
    components at:(aFormatArray at:1) put:day.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2536
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2537
    upperCase := false.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2538
    mf := aFormatArray at:5.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2539
    (mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2540
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2541
    mf == 1 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2542
        month := self month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2543
        leadingZeros ifTrue:[
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2544
            month := month printStringLeftPaddedTo:2 with:$0
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2545
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2546
            month := month printString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2547
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2548
    ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2549
        mf == 2 ifTrue:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2550
            month := self abbreviatedMonthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2551
        ] ifFalse:[
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2552
            month := self monthNameForLanguage:languageOrNil
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2553
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2554
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2555
    upperCase ifTrue:[month := month asUppercase].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2556
    components at:(aFormatArray at:2) put:month.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2557
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2558
    year := self year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2559
    (aFormatArray at:6) == 2 ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2560
        year := year \\ 100.
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2561
        year := year printStringLeftPaddedTo:2 with:$0
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2562
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2563
    year := year printString.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2564
    components at:(aFormatArray at:3) put:year.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2565
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2566
    sep1 := sep2 := (aFormatArray at:4).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2567
    sep1 isString ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2568
        sep1 isCollection ifTrue:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2569
            sep2 := (sep1 at:2).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2570
            sep1 := (sep1 at:1).
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2571
        ] ifFalse:[
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2572
            sep1 := sep2 := sep1 asCharacter
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2573
        ]
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2574
    ].
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2575
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2576
    ^ (components at:1)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2577
      , sep1 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2578
      , (components at:2)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2579
      , sep2 asString
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2580
      , (components at:3)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2581
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2582
    "
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2583
     Date today printFormat:#(1 2 3 '' 1 2)
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2584
     Date today printFormat:#(1 2 3 $- 1 2)
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2585
     Date today printFormat:#(1 2 3 $. 1 2 true)
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2586
     Date today printFormat:#(2 1 3 32 3 1)
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2587
     Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2588
     Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2589
     Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2590
    "
21758
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2591
6ee7cb66af99 #OTHER by mawalch
mawalch
parents: 21698
diff changeset
  2592
    "Modified (comment): / 17-05-2017 / 16:18:55 / mawalch"
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2593
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2594
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2595
printFormat:aFormatArray forLanguage:languageOrNil on:aStream
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2596
    "Obsolete, backward ST-80 compatible formatted printing - see comment
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2597
     in printFormat:.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2598
     Append a printed representation of the receiver to aStream.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2599
     The argument, aFormatString controls the format, as described
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2600
     in the #printFormat: method.
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2601
     Notice that not all formats can be scanned (correctly) by #readFrom:"
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2602
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2603
    aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil)
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2604
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2605
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2606
    "european formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2607
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2608
     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
  2609
     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
  2610
     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
  2611
     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
  2612
     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
  2613
     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
  2614
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2615
     US formats:
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2616
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2617
     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
  2618
     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
  2619
     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
  2620
     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
  2621
     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
  2622
     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
  2623
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2624
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2625
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2626
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2627
printFormat:aFormatArray on:aStream
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2628
    "Obsolete, backward ST-80 compatible formatted printing - see comment
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2629
     in printFormat:.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2630
     Append a printed representation of the receiver to aStream.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2631
     The argument, aFormatString controls the format, as described
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2632
     in the #printFormat: method.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2633
     Notice that not all formats can be scanned (correctly) by #readFrom:"
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2634
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2635
    aStream nextPutAll:(self printFormat:aFormatArray)
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2636
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2637
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2638
    "european formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2639
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2640
     Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2641
     Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2642
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2643
     Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2644
     Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2645
     Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2646
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2647
     US formats:
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2648
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2649
     Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2650
     Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2651
     Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2652
     Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2653
     Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2654
     Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2655
     Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2656
    "
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2657
!
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  2658
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2659
shortPrintString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2660
    "dummy - for now"
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2661
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2662
    ^ self printString
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2663
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2664
    "Created: 20.6.1997 / 17:16:48 / cg"
6976
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2665
!
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2666
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2667
weekdayIndex
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2668
    "Return the day index; Monday=1, ... , Sunday=7"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2669
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2670
    ^ (self asDays + 1) \\ 7 + 1  "1 January 1901 was a Tuesday"
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2671
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2672
    "
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2673
     Date today dayName
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2674
     Date today weekdayIndex      
4529a6fafa92 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6952
diff changeset
  2675
    "
5515
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2676
! !
4adb4b3a7475 category only
Claus Gittinger <cg@exept.de>
parents: 5282
diff changeset
  2677
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2678
!Date methodsFor:'Compatibility-Squeak'!
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2679
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2680
mmddyyyy
4462
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2681
    "return a printed representation of the receiver in the
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2682
     form mmddyyyy.
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2683
     The receiver can be reconstructed with: 
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2684
        Date readMMDDYYYYFrom:aStringOrStream onError:[...]"
9ede4d534b8f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2685
11182
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2686
    ^ self printStringFormat:'%m%d%y'
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2687
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2688
"/    ^ (self month printStringLeftPaddedTo:2 with:$0)
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2689
"/       , (self day printStringLeftPaddedTo:2 with:$0) 
849a5a70d2d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11181
diff changeset
  2690
"/       , (self year printStringLeftPaddedTo:4 with:$0)
4407
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2691
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2692
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2693
     Date today mmddyyyy
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2694
    "
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2695
! !
413565318bec added mmddyyyy
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  2696
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2697
!Date methodsFor:'accessing'!
241
6f30be88e314 *** empty log message ***
claus
parents: 202
diff changeset
  2698
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2699
abbreviatedDayName
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2700
    "return the short week-day-name of the receiver as a string.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2701
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2702
     Expect things like 'mon', 'tue' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2703
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2704
    ^ self class abbreviatedNameOfDay:(self dayInWeek)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2705
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2706
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2707
     Date today abbreviatedDayName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2708
     (Date newDay:15 month:4 year:1959) abbreviatedDayName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2709
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2710
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2711
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2712
abbreviatedDayNameForLanguage:lang
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2713
    "return the short week-day-name of the receiver as a string.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2714
     The returned string depends on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2715
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2716
     If not, the english name is returned.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2717
     Expect things like 'mon', 'tue' ..."
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2718
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2719
    ^ self class abbreviatedNameOfDay:(self dayInWeek) language:lang
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2720
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2721
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2722
     Date today abbreviatedDayNameForLanguage:#en      
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2723
     Date today abbreviatedDayNameForLanguage:#de      
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2724
     Date today abbreviatedDayNameForLanguage:#zulu 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2725
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2726
     (Date newDay:15 month:4 year:1959) abbreviatedDayName
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2727
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2728
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2729
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2730
abbreviatedMonthName
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2731
    "return the short month name of the receiver as a string.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2732
     The returned string depends on the language setting.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2733
     Expect things like 'jan', 'feb' ..."
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  2734
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2735
    ^ self class abbreviatedNameOfMonth:(self month)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2736
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2737
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2738
     Date today abbreviatedMonthName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2739
     (Date newDay:15 month:4 year:1959) abbreviatedMonthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2740
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2741
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2742
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2743
abbreviatedMonthNameForLanguage:lang
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2744
    "return the short month-name of the receiver as a string in a given language.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2745
     The returned string depends on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2746
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2747
     If not, the english name is returned.
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2748
     Expect things like 'jan', 'feb' ..."
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2749
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2750
    ^ self class abbreviatedNameOfMonth:(self month) language:lang
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2751
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2752
    "
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2753
     Date today abbreviatedMonthNameForLanguage:#en 
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2754
     Date today abbreviatedMonthNameForLanguage:#de 
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2755
     Date today abbreviatedMonthNameForLanguage:#zulu 
7794
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2756
    "
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2757
!
7f1901b11541 accessor for language specific abbreviated month name
penk
parents: 7793
diff changeset
  2758
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2759
additionalPicoseconds
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2760
    "for protocol compatibility"
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2761
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2762
    ^ 0
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2763
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2764
    "
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2765
     Date today > Timestamp now
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2766
     Timestamp now > Date today
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2767
    "
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2768
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2769
    "Created: / 04-06-2018 / 09:58:11 / Claus Gittinger"
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2770
!
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  2771
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2772
asDays
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2773
    "return the number of days elapsed since 01-Jan-1901
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2774
     and the receiver's day; starts with 0 for 1-1-1901.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2775
     Date>>fromDays: is the reverse operation.
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  2776
     Notice, 
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  2777
        that this represents dates before 1901 as negative values!!
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2778
     For GNU/ST-80 compatibility."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2779
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2780
    |yr|
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2781
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2782
    yr := self year.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2783
    ^ (self class yearAsDays:yr)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  2784
      + (self class daysUntilMonthIndex:self month forYear:yr)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2785
      + self day
85
claus
parents: 77
diff changeset
  2786
      - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2787
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2788
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2789
     (Date newDay: 5 month: 8 year: 1962) asDays  -> should be 22496
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2790
     (Date newDay: 1 month: 1 year: 1901) asDays  -> 0
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2791
     (Date newDay: 31 month: 12 year: 1900) asDays -> -1
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2792
     (Date newDay: 1 month: 1 year: 1800) asDays  -> -36889
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2793
     Date today asDays    
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  2794
     Date fromDays:(Date today asDays + 7) 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2795
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2796
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2797
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2798
asDaysFrom0
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2799
    "return the number of days elapsed since 01-Jan-0
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2800
     and the receiver's day; starts with 0 for 1-1-0.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2801
     Date>>fromDaysFrom0: is the reverse operation.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2802
     Notice, that this is not able to represent dates before 0!!."
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2803
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2804
    |yr|
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2805
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2806
    yr := self year.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2807
    ^ (self class yearAsDaysFrom0:yr)
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2808
      + (self class daysUntilMonthIndex:self month forYear:yr)
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2809
      + self day
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2810
      - 1
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2811
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2812
    "
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2813
     (Date newDay: 1 month: 1 year: 0) asDaysFrom0  -> should be 0
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2814
     (Date newDay: 1 month: 1 year: 1) asDaysFrom0  -> should be 366
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2815
     Date fromDaysFrom0:(Date today asDaysFrom0 + 7) 
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2816
    "
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2817
!
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2818
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2819
asSeconds
19453
0b5b292b5437 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19209
diff changeset
  2820
    "return the seconds between 1.jan.1901 and the same time in the receiver's 
17690
569c4ccfd790 class: Date
Claus Gittinger <cg@exept.de>
parents: 17640
diff changeset
  2821
     day. (i.e. midnight to midnight). The returned number may be negative for dates before 1901.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2822
     This does not include any leapSeconds ... strictly speaking, this is incorrect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2823
     ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2824
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2825
    ^ 60*60*24 * self asDays
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2826
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2827
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2828
     (Date newDay: 5 month: 8 year: 1962) asSeconds
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2829
     (Date newDay: 1 month: 1 year: 1901) asSeconds
17690
569c4ccfd790 class: Date
Claus Gittinger <cg@exept.de>
parents: 17640
diff changeset
  2830
     (Date newDay: 1 month: 1 year: 1700) asSeconds
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2831
     (Date today addDays:7) asSeconds - Date today asSeconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2832
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2833
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2834
    "Modified: 1.7.1996 / 14:19:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2835
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2836
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2837
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2838
    "return the day (1..31) of the receiver"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2839
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2840
    ^ dateEncoding \\ 100
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2841
8626
ae1fcb227a45 example
penk
parents: 8480
diff changeset
  2842
    "example:
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2843
     Date today day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2844
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2845
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2846
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2847
dayInWeek
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2848
    "return the week-day of the receiver - 1 for monday, 7 for sunday.
22816
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2849
     WARNING: different from (american) dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2850
     WARNING: does not care for pre-gregorian dates 
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2851
        (i.e. do not use this for dates before 1583)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2852
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2853
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2854
    |wday|
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2855
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2856
    wday := self asDaysFrom0 \\ 7 - 1.
22816
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2857
    "/    wday := (1 "knowing, that 1st Jan 1901 was a tuesday"
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2858
    "/            + self asDays) \\ 7 + 1.
3256
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2859
    wday < 1 ifTrue:[
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2860
        wday := wday + 7
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2861
    ].
637d16a0c83b care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  2862
    ^ wday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2863
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2864
    "
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2865
     Date today dayInWeek    
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2866
     Date tomorrow dayInWeek
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2867
     Date yesterday dayInWeek 
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2868
     (Date today subtractDays:2) dayInWeek   
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2869
     Date today weekday                      
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2870
     Date tomorrow weekday                   
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2871
     Date yesterday weekday                  
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2872
     (Date newDay:15 month:4 year:1959) dayInWeek 
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  2873
     (Date newDay:1 month:1 year:1901) dayInWeek   
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2874
     (Date newDay:31 month:12 year:1900) dayInWeek 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  2875
     (Date newDay:31 month:12 year:1899) dayInWeek 
22816
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2876
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2877
     Date today dayInWeek    
9f4e5ef4d361 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21758
diff changeset
  2878
     Date today dayOfWeek    
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2879
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  2880
3257
db002a9bf071 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2881
    "Modified: / 1.2.1998 / 14:10:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2882
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2883
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2884
dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2885
    "return the day-nr within the year of the receiver - 1 .. 365/366"
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2886
    
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2887
    "
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2888
        |daysSoFar|
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2889
        daysSoFar := 0.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2890
        #(0 31 28 31 30 31 30 31 31 30 31 30) collect:[:i| daysSoFar := daysSoFar + i]
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2891
    "
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2892
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2893
    |days month|
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2894
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2895
    month := self month.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2896
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2897
    days := #(0 31 59 90 120 151 181 212 243 273 304 334) at:month.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2898
    days := days + self day.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2899
    (month > 2 and:[self class leapYear:self year]) ifTrue:[
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2900
        days := days + 1.
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2901
    ].
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2902
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2903
    ^ days
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2904
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2905
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2906
     Date today dayInYear 
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2907
     (Date newDay:1 year:1999) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2908
     (Date newDay:1 year:2000) dayInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2909
     (Date newDay:2 year:2000) dayInYear
11349
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2910
     (Date newDay:59 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2911
     (Date newDay:60 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2912
     (Date newDay:61 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2913
     (Date newDay:366 year:2004) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2914
     (Date newDay:59 year:2005) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2915
     (Date newDay:60 year:2005) dayInYear
8ce689609977 Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents: 11182
diff changeset
  2916
     (Date newDay:365 year:2005) dayInYear
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2917
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2918
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  2919
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2920
dayOfMonth
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2921
    "Answer the day of the month represented by me.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2922
     Same as day; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2923
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2924
    ^ self day
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2925
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2926
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2927
     Date today dayOfMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2928
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2929
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2930
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2931
daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2932
    "return the number of days in the month of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2933
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2934
    ^ self class daysInMonth:(self month) forYear:(self year)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2935
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2936
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2937
     Date today daysInMonth
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2938
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2939
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2940
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2941
daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2942
    "return the number of days in the year of the receiver"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2943
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2944
    ^ self class daysInYear:(self year)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2945
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2946
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2947
     Date today daysInYear
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2948
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2949
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2950
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2951
daysLeftInMonth
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2952
    "return the number of days left in the month of the receiver"
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2953
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2954
    ^ self daysInMonth - self day
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2955
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2956
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2957
     Date today daysLeftInMonth             
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2958
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2959
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  2960
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2961
daysLeftInYear
11079
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2962
    "return the number of days left in the year of the receiver.
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2963
     Today is excluded from the count (i.e. in a non-leap-year,
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2964
     the first january will return 364)"
cd8abd9e87a7 oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents: 10912
diff changeset
  2965
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2966
    ^ (self class daysInYear:(self year)) - self dayOfYear
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2967
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2968
    "
5282
d38c5238399c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5186
diff changeset
  2969
     Date today daysLeftInYear             
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2970
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2971
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2972
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  2973
isLeapYear
17053
c654249389f9 class: Date
Claus Gittinger <cg@exept.de>
parents: 16983
diff changeset
  2974
    "return true, if the receiver's year is a leap year"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2975
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  2976
    ^ self class leapYear:self year
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2977
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2978
    "
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  2979
     Date today isLeapYear
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  2980
     (Date newDay:1 month:1 year:1992) isLeapYear
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2981
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2982
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2983
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2984
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2985
    "return the month (1..12) of the receiver"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2986
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2987
    ^ (dateEncoding // 100) \\ 100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2988
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2989
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2990
     Date today month
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2991
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2992
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2993
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2994
monthIndex
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2995
    "return the index of the month (e.g. Feb.=2).
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2996
     Same as month; for ST-80 compatibility."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2997
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2998
    ^ self month  
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2999
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3000
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3001
monthName
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3002
    "return the month of the receiver as a string.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3003
     The returned string depends on the language setting.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3004
     Expect things like 'january', 'february' ..."
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3005
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3006
    ^ self class nameOfMonth:(self month)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3007
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3008
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3009
     Date today monthName
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3010
     (Date newDay:15 month:4 year:1959) monthName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3011
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3012
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3013
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3014
monthNameForLanguage:languageOrNil
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3015
    "return the month-name of the receiver as a string in a given language.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3016
     The returned string depends on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3017
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3018
     If not, the english name is returned.
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3019
     Expect things like 'january', 'february' ..."
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3020
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3021
    ^ self class nameOfMonth:(self month) language:languageOrNil
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3022
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3023
    "
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3024
     Date today monthName                 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3025
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3026
     Date today monthNameForLanguage:#en  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3027
     Date today monthNameForLanguage:#de  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3028
     Date today monthNameForLanguage:#zulu
7961
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3029
    "
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3030
!
a3d9da2b9a49 english print strings
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3031
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3032
weekInYear
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3033
    "return the week number of the receiver - 1 for Jan, 1st.
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3034
     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
  3035
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3036
    ^ self class weekInYearOf:self
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3037
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3038
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3039
     Date today weekInYear    
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3040
     (Date newDay:1 year:2000) weekInYear   was a saturday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3041
     (Date newDay:2 year:2000) weekInYear   was a sunday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3042
     (Date newDay:3 year:2000) weekInYear   was a monday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3043
     (Date newDay:4 year:2000) weekInYear   was a tuesday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3044
     (Date newDay:5 year:2000) weekInYear   was a wed
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3045
     (Date newDay:6 year:2000) weekInYear   was a thursday
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3046
     (Date newDay:7 year:2000) weekInYear   was a fri
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3047
     (Date newDay:8 year:2000) weekInYear   was a sat
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3048
     (Date newDay:9 year:2000) weekInYear   was a sun
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3049
     (Date newDay:10 year:2000) weekInYear  was a monday
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3050
     (Date newDay:3 month:1 year:2001) weekInYear 
5548
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3051
    "
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3052
!
eead51e4752e added #weekInYear query
Claus Gittinger <cg@exept.de>
parents: 5515
diff changeset
  3053
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3054
weekday
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3055
    "return the week-day of the receiver as a string.
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3056
     The returned string depends on the current language setting.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3057
     Expect things like 'monday', 'tuesday' ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3058
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3059
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3060
    ^ self class nameOfDay:(self dayInWeek)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3061
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3062
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3063
     Date today weekday
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3064
     (Date newDay:15 month:4 year:1959) weekday
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3065
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3066
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3067
16913
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3068
weekdayForLanguage:lang
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3069
    "return the week-day-name of the receiver as a string in a given language.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3070
     The returned string depends on the resource translation file to be present for the 
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3071
     given language (i.e. libbasic/resources(<lang>.rs).
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3072
     If not, the english name is returned.
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3073
     Expect things like 'monday', 'tuesday'..."
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3074
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3075
    ^ self class nameOfDay:(self dayInWeek) language:lang
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3076
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3077
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3078
     Date today weekdayForLanguage:#de      -> Mittwoch
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3079
     Date today weekdayForLanguage:#en      -> wednesday
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3080
     Date today weekdayForLanguage:#zulu    -> wednesday       
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3081
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3082
     (Date newDay:15 month:4 year:1959) weekdayForLanguage:#de  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3083
     (Date newDay:15 month:4 year:1959) weekdayForLanguage:#en  
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3084
     (Date newDay:15 month:4 year:1959) weekdayForLanguage:#zulu
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3085
    "
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3086
!
d504bc963add class: Date
Claus Gittinger <cg@exept.de>
parents: 16839
diff changeset
  3087
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3088
year
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3089
    "return the year of the receiver"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3090
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3091
    ^ dateEncoding // (100*100)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3092
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3093
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3094
     Date today year
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3095
     Date today subtractDays:(1000 * 365)
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3096
     Date today addDays:(1000 * 365)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3097
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3098
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3099
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3100
year:year month:month day:day
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3101
    dateEncoding := self class encodeYear:year month:month day:day
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3102
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3103
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3104
!Date methodsFor:'arithmetic'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3105
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3106
+ days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3107
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3108
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3109
     This is the same as #addDays."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3110
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3111
    ^ self class fromDaysFrom0:(self asDaysFrom0 + days)
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3112
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3113
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3114
     Date today + 7.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3115
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3116
     Date today to:(Date today + 28) by:7 do:[:date|
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3117
        Transcript show:date weekday; show:', '; showCr:date
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3118
     ].
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3119
    "
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3120
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3121
24116
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3122
- aDateOrNumberOfDaysOrTimeDuration
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3123
    "return the delta in days (anInteger) between 2 dates or 
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3124
     subtract a number of days from a date returning a Date"
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3125
24116
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3126
    aDateOrNumberOfDaysOrTimeDuration class == self class ifTrue:[
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3127
        ^ self asDaysFrom0 - aDateOrNumberOfDaysOrTimeDuration asDaysFrom0
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3128
    ].
24116
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3129
    aDateOrNumberOfDaysOrTimeDuration isTimeDuration ifTrue:[
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3130
        ^ self asTimestamp - aDateOrNumberOfDaysOrTimeDuration 
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3131
    ].    
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3132
    ^ self class fromDaysFrom0:(self asDaysFrom0 - aDateOrNumberOfDaysOrTimeDuration asInteger)
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3133
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3134
    "
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3135
     Date today - Date yesterday  
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3136
     Date today - 3               
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3137
     Date today + 3               
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3138
    "
24116
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3139
ef0506792fc5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23712
diff changeset
  3140
    "Modified: / 08-05-2019 / 12:01:47 / Claus Gittinger"
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3141
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3142
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3143
addDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3144
    "return a new date representing 'days' after the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3145
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3146
     For ST-80 compatibility."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3147
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3148
    ^ self class fromDaysFrom0:(self asDaysFrom0 + days)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3149
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3150
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3151
     Date today addDays:7
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3152
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3153
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3154
14331
sr
parents: 13736
diff changeset
  3155
addMonths:numberOfMonths
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3156
    "Return a new instance which added numberOfMonths to self months. 
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3157
     Keep the day of month if possible.
14331
sr
parents: 13736
diff changeset
  3158
     If the month of the new instance has fewer days than self dayOfMonth set the day to the last
sr
parents: 13736
diff changeset
  3159
     day of the new instance's month.
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3160
     Does (probably) not work correct for resulting dates before calendar reform."
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3161
14331
sr
parents: 13736
diff changeset
  3162
    |yearToAdd years monthsInYear tempDate newMonth newMonthAsDate|
sr
parents: 13736
diff changeset
  3163
sr
parents: 13736
diff changeset
  3164
    yearToAdd := 0.
sr
parents: 13736
diff changeset
  3165
    years := numberOfMonths // 12.
sr
parents: 13736
diff changeset
  3166
    monthsInYear := numberOfMonths \\ 12.
sr
parents: 13736
diff changeset
  3167
    tempDate := self addYears:years.  
sr
parents: 13736
diff changeset
  3168
sr
parents: 13736
diff changeset
  3169
    newMonth := tempDate month + monthsInYear.
sr
parents: 13736
diff changeset
  3170
    (newMonth between:1 and:12) ifFalse:[
sr
parents: 13736
diff changeset
  3171
        newMonth := newMonth \\ 12.
sr
parents: 13736
diff changeset
  3172
        yearToAdd := 1.
sr
parents: 13736
diff changeset
  3173
    ].
sr
parents: 13736
diff changeset
  3174
sr
parents: 13736
diff changeset
  3175
    newMonthAsDate := self class 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3176
                        year:(tempDate year + yearToAdd)
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3177
                        month:newMonth 
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3178
                        day:1.
14331
sr
parents: 13736
diff changeset
  3179
sr
parents: 13736
diff changeset
  3180
    ^ self class 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3181
        year:(tempDate year + yearToAdd)
14331
sr
parents: 13736
diff changeset
  3182
        month:newMonth 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3183
        day:(newMonthAsDate daysInMonth min:tempDate day)
14331
sr
parents: 13736
diff changeset
  3184
sr
parents: 13736
diff changeset
  3185
    "Created: / 23-08-2012 / 11:04:17 / sr"
sr
parents: 13736
diff changeset
  3186
    "Created: / 24-08-2012 / 12:14:52 / anwild"
sr
parents: 13736
diff changeset
  3187
!
sr
parents: 13736
diff changeset
  3188
sr
parents: 13736
diff changeset
  3189
addMonthsUsingEncoding:numberOfMonths
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3190
    "Return a new instance which added numberOfMonths to self months. 
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3191
     Keep the day of month if possible.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3192
     If the month of the new instance has fewer days than self dayOfMonth,
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3193
     set the day to the last day of the new instance's month.                                                           
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3194
     Does (probably) not work correct for resulting dates before calendar reform."
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3195
14331
sr
parents: 13736
diff changeset
  3196
    | newEncoding |
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3197
14331
sr
parents: 13736
diff changeset
  3198
    newEncoding := dateEncoding 
sr
parents: 13736
diff changeset
  3199
                    + ((numberOfMonths + self month) // 12 * 10000)    "the new year"
sr
parents: 13736
diff changeset
  3200
                    + ((((numberOfMonths \\ 12) + self month) \\ 12) * 100)  "the new month"
sr
parents: 13736
diff changeset
  3201
                    - (self month * 100) "in the line above the new month is already completely calculated. So subtract the current month"
sr
parents: 13736
diff changeset
  3202
                    - self day  "in the line below the new day is already completely calculated. So subtract the current day"
sr
parents: 13736
diff changeset
  3203
                    + (self day min: self daysInMonth). "the new day considering the maximum number of days in the new month."
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  3204
    ^ self class 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3205
        year: newEncoding // 10000
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3206
        month: (newEncoding // 100 \\ 100) 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3207
        day: newEncoding \\ 100. 
14331
sr
parents: 13736
diff changeset
  3208
sr
parents: 13736
diff changeset
  3209
    "Created: / 24-08-2012 / 15:18:44 / anwild"
sr
parents: 13736
diff changeset
  3210
!
sr
parents: 13736
diff changeset
  3211
sr
parents: 13736
diff changeset
  3212
addYears:numberOfYears
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3213
    "Return a new instance which is the same date, but numberOfYears ahead of self. 
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3214
     Cares about leap years.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3215
     I.e. goes from a leap year's 29.feb to a non-leap year's 28.feb."
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3216
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3217
    |newYear newDay newMonth|
14331
sr
parents: 13736
diff changeset
  3218
sr
parents: 13736
diff changeset
  3219
    newYear := self year + numberOfYears.
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3220
    newDay := self day.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3221
    newMonth := self month.
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3222
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3223
    "/ special care for the 29th of February in a leapYear
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3224
    (newDay = 29 and:[newMonth == 2]) ifTrue:[
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3225
        (self class leapYear:newYear) ifFalse: [
14331
sr
parents: 13736
diff changeset
  3226
            newDay := 28.
sr
parents: 13736
diff changeset
  3227
        ].
sr
parents: 13736
diff changeset
  3228
    ].
sr
parents: 13736
diff changeset
  3229
sr
parents: 13736
diff changeset
  3230
    ^ self class 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3231
        year:newYear
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3232
        month:newMonth 
19712
c675e9b89efd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19558
diff changeset
  3233
        day:newDay 
14331
sr
parents: 13736
diff changeset
  3234
sr
parents: 13736
diff changeset
  3235
    "Created: / 23-08-2012 / 11:05:04 / sr"
sr
parents: 13736
diff changeset
  3236
    "Created: / 24-08-2012 / 12:14:09 / anwild"
sr
parents: 13736
diff changeset
  3237
!
sr
parents: 13736
diff changeset
  3238
9262
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3239
daysSince:aDate
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3240
    "return the number of days between the receiver and the argument,
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3241
     aDate, which should be some kind of date"
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3242
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3243
    ^ self asDaysFrom0 - aDate asDaysFrom0
9262
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3244
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3245
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3246
     Date today daysSince:(Date newDay:1 month:1 year:1901) 
9262
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3247
    "
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3248
!
705366a61be2 +daysSince:
Claus Gittinger <cg@exept.de>
parents: 9220
diff changeset
  3249
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3250
daysUntil:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3251
    "return the number of days between the receiver and the argument,
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3252
     aDate, which should be some kind of date"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3253
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3254
    ^ aDate asDaysFrom0 - self asDaysFrom0
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3255
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3256
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3257
     (Date newDay:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3258
     (Date newDay:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3259
     (Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3260
    
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3261
     |delta|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3262
     delta := Date today
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3263
                daysUntil:(Date newDay:25 month:12 year:Date today year).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3264
     Transcript show:'still ';
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3265
                show:delta ;
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3266
                showCR:' days till xmas'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3267
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3268
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3269
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3270
firstDayInPreviousMonth:nMonths
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3271
    "Return the first day of a previous month (0=this month, 1=prev. month, etc.).
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3272
     CG: there are two such methods - which one is obsolete?"
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3273
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3274
    ^ self firstDayOfPreviousMonth:nMonths
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3275
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3276
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3277
     (Date newDay:3 month:6 year:2009) firstDayInMonth     
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3278
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:0    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3279
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:5    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3280
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:6    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3281
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:7    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3282
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:17    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3283
     (Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:18    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3284
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3285
!
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3286
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3287
firstDayOfPreviousMonth:nMonths
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3288
    "Return the first day of a previous month (0=this month).
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3289
     CG: there are two such methods - which one is obsolete? (see firstDayInPreviousMonth:)"
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3290
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3291
    |month year monthNegated|
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3292
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3293
    month := self month.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3294
    year := self year.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3295
    month := month - nMonths.
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3296
    month < 1 ifTrue:[
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3297
        monthNegated := month negated.
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3298
        year := year - 1 - (monthNegated // 12).
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3299
        month := (12 - (monthNegated \\ 12)).
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3300
    ].
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3301
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  3302
    ^ self class year:year month:month day:1.
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3303
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3304
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3305
     (Date newDay:3 month:6 year:2009) firstDayInMonth     
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3306
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0  
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3307
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3308
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3309
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7    
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3310
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17    
18357
05ec4f009e76 class: Date
Claus Gittinger <cg@exept.de>
parents: 18271
diff changeset
  3311
     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18  
11741
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3312
    "
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3313
!
0ff07acd680f category changes
Claus Gittinger <cg@exept.de>
parents: 11740
diff changeset
  3314
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3315
subtractDate:aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3316
    "return the number of days between the receiver and aDate"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3317
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3318
    ^ self asDaysFrom0 - aDate asDaysFrom0
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3319
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3320
    "
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3321
    (Date newDay:1 month:1 year:1995) subtractDate:(Date newDay:24 month:12 year:1994)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3322
    (Date newDay:1 month:3 year:1992) subtractDate:(Date newDay:1 month:2 year:1992)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3323
    (Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3324
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3325
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3326
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3327
subtractDays:days
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3328
    "return a new date representing 'days' before the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3329
     The argument should be some kind of integer.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3330
     For ST-80 compatibility"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3331
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3332
    ^ self class fromDaysFrom0:(self asDaysFrom0 - days)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3333
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3334
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3335
     Date today subtractDays:7
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3336
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3337
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3338
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3339
!Date methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3340
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  3341
< aDate
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  3342
    "return true, if the date represented by the receiver
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3343
     is before the argument, aDate.
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3344
     If compared against a timestamp, the receiver is treated like 00:00:00 midnight"
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  3345
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3346
    "/ quick check, if it is another Date; then we can tune this operation,
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3347
    "/ by not having to compute the osTime
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3348
    (aDate isMemberOf:Date) ifTrue:[
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3349
        ^ dateEncoding < aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3350
    ].
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  3351
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3352
    "/ the argument must understand year, month and day to be
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3353
    "/ comparable, whatever it is
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  3354
    ^ dateEncoding < (self class encodeYear:aDate year month:aDate month day:aDate day)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3355
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3356
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3357
        Date today < (Date day:24 month:12 year:2000)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3358
        Date today < (Date day:24 month:12 year:1900)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3359
        Date today < Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3360
        Date today-1 < Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3361
    "
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3362
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3363
    "Modified (comment): / 04-06-2018 / 09:58:51 / Claus Gittinger"
29
b6577a9f8cee *** empty log message ***
claus
parents: 10
diff changeset
  3364
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3365
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3366
= aDate
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3367
    "return true, if the date represented by the receiver
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3368
     is the same as the one represented by argument, aDate.
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3369
     If compared against a timestamp, the receiver is treated like 00:00:00 midnight"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3370
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3371
    "/ must have same class and same osTime
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  3372
    (aDate isMemberOf:Date) ifFalse:[^ false].
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  3373
    ^ dateEncoding = aDate dateEncoding
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3374
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3375
    "the argument must understand year, month and day to be
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3376
     comparable, whatever it is"
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3377
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  3378
"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3379
    ^ dateEncoding = (Date encodeYear:aDate year
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3380
                                month:aDate month
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3381
                                  day:aDate day)
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
  3382
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3383
    "Date today = ((Date today plusDays:7) minusDays:7)"
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3384
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3385
    "Modified (comment): / 04-06-2018 / 09:58:57 / Claus Gittinger"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3386
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3387
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3388
> aDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3389
    "return true, if the date represented by the receiver
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3390
     is after the argument, aDate.
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3391
     If compared against a timestamp, the receiver is treated like 00:00:00 midnight"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3392
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3393
    "/ quick check, if it is another Date; then we can tune this operation,
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3394
    "/ by not having to compute the osTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3395
    (aDate isMemberOf:Date) ifTrue:[
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3396
        ^ dateEncoding > aDate dateEncoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3397
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3398
19789
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3399
    "/ the argument must understand year, month and day,
c7d12ebf2ebd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19712
diff changeset
  3400
    "/ to be comparable, whatever it is
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  3401
    ^ dateEncoding > (self class encodeYear:aDate year month:aDate month day:aDate day)
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3402
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3403
    "
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3404
      Date today > (Date newDay:24 month:12 year:2099)
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3405
      Date today > (Date newDay:24 month:12 year:1900)
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3406
      Date today > Timestamp now
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  3407
      Date today+1 > Timestamp now
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3408
    "
23048
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3409
16322be3d286 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23022
diff changeset
  3410
    "Modified (comment): / 04-06-2018 / 09:59:02 / Claus Gittinger"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3411
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3412
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3413
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3414
    "return an integer useful for hashing on dates"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3415
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3416
    ^ dateEncoding
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3417
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3418
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  3419
!Date methodsFor:'converting'!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  3420
4408
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3421
asDate
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3422
    "return the receiver"
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3423
3d76920644f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3424
    ^ self
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3425
!
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3426
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3427
asLocalTimestamp
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3428
    "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
  3429
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3430
    ^ Timestamp 
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3431
        year:(self year) month:(self month) day:(self day)  
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3432
        hour:0 minute:0 second:0 millisecond:0
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3433
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3434
    "
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3435
     Date today asLocalTimestamp
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3436
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3437
!
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3438
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3439
asTimestamp
23236
345f2e8336bc #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23048
diff changeset
  3440
    "return an Timestamp instance, representing midnight of last night"
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3441
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3442
    ^ self asLocalTimestamp
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3443
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3444
    "
8247
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3445
     Date today asTimestamp
146e7e7dcf57 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8201
diff changeset
  3446
    "
23236
345f2e8336bc #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23048
diff changeset
  3447
345f2e8336bc #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23048
diff changeset
  3448
    "Modified (comment): / 27-07-2018 / 11:09:49 / Stefan Vogel"
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3449
!
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3450
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3451
asUtcTimestamp
16927
38c1c35a9892 class: Date
Claus Gittinger <cg@exept.de>
parents: 16913
diff changeset
  3452
    "return an UtcTimestamp instance, representing midnight of last night"
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3453
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3454
    ^ UtcTimestamp 
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3455
        year:(self year) month:(self month) day:(self day)  
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3456
        hour:0 minute:0 second:0 millisecond:0
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3457
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3458
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3459
     Date today asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3460
    "
5775
92b02a4a7e83 week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents: 5679
diff changeset
  3461
! !
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  3462
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3463
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3464
!Date methodsFor:'obsolete'!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3465
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3466
asAbsoluteTime
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3467
    "deprecated, use #asTimestamp"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3468
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3469
12001
75a4c5f8cdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11895
diff changeset
  3470
    self obsoleteMethodWarning:'use #asTimestamp'.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3471
    ^ self asTimestamp
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3472
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3473
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3474
dayCount
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3475
    "return the number of days since 1st. Jan. 1901;
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3476
     starting with 0 for this date.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3477
     Date>>fromDays: is the reverse operation.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3478
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3479
         please use asDays for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3480
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3481
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3482
    ^ self asDays.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3483
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3484
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3485
dayName
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3486
    "return the week-day of the receiver as a string.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3487
     The returned string depends on the language setting.
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3488
     Expect things like 'monday', 'tuesday' ...
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3489
     Obsolete:
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3490
        use #weekday for ST-80 compatibility"
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3491
    <resource:#obsolete>
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3492
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3493
    ^ self weekday
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3494
!
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  3495
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3496
leap
19453
0b5b292b5437 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19209
diff changeset
  3497
    "return true, if the receiver's year is a leap year"
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3498
    <resource: #obsolete>
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3499
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3500
    ^ self isLeapYear
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3501
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3502
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3503
     Date today leap
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3504
     (Date newDay:1 month:1 year:1992) leap
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3505
    "
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3506
!
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  3507
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3508
minusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3509
    "return a new date representing 'days' before the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3510
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3511
     Obsolete:
20794
cad768b79b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20776
diff changeset
  3512
         Please don't use this method since it will vanish.
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3513
         Use #subtractDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3514
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3515
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3516
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3517
    self obsoleteMethodWarning:'use #substractDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3518
    ^ self subtractDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3519
!
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3520
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3521
plusDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3522
    "return a new date representing 'days' after the receiver.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3523
     The argument should be some kind of integer.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3524
     Obsolete:
20794
cad768b79b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20776
diff changeset
  3525
         Please don't use this method since it will vanish.
8201
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3526
         Use #addDays: instead for ST-80 compatibility."
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3527
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3528
    <resource: #obsolete>
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3529
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3530
    self obsoleteMethodWarning:'use #addDays:'.
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3531
    ^ self addDays:days
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3532
! !
d8ae80af9651 More arithmethic.
Stefan Vogel <sv@exept.de>
parents: 8196
diff changeset
  3533
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 29
diff changeset
  3534
!Date methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3535
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3536
addPrintBindingsTo:aDictionary
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3537
    "see comment in addPrintBindingsTo:language:"
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3538
    
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3539
    self addPrintBindingsTo:aDictionary language:nil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3540
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3541
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3542
addPrintBindingsTo:aDictionary language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3543
    "private print support: add bindings for printing to aDictionary.
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3544
     languageOrNil can only be #en or nil for the current language setting (Smalltalk language).
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3545
     
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3546
     valid format items are:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3547
        %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
  3548
        %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
  3549
        %w              - week in year, 00..53           0-padded to length 2
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3550
        %y              - year, full                     i.e. '1999', '2004'
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3551
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3552
     special:
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3553
        %D              - day - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3554
        %M              - month - unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3555
        %W              - week in year - unpadded
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3556
        %Y              - year, last 2 digits only i.e. 1999->'99', 1904->'04', 2004->'04'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3557
                          (danger: year 2k bug)
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3558
                            makes any date a 2-digit value. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3559
                            Only use to process/generate old (backward compatible) datasets
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3560
                            which were generated way before y2k, and the old (bad) values need to
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3561
                            be regenerated.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3562
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3563
        %Y1900          - year, last 2 digits of 19YY i.e. 1999->'99', 1904->'04', 2004->error
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3564
                         (danger: year 2k bug)
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3565
                            raises an error, if the year is not in 1900..1999 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3566
                            Only use to process/generate old (backward compatible) datasets
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3567
                            which were generated way before y2k, and the old (bad) values need to
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3568
                            be regenerated. Same as above, but with error reporting
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3569
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3570
        %Y2000          - year, last 2 digits of 20YY only i.e. 2001->'01', 2004->'04' 2099->'99'
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3571
                          raises an error, if the year is not in 2000..2099    
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3572
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3573
        %Y1950          - year, last 2 digits of 19YY or 20YY only i.e. 2001->'01', 2049->'49', 1950->'50', 1999->'99'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3574
                          raises an error, if the year is not in 1950..2049.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3575
                            this is occasionally used to get old (pre y2k) data converted.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3576
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3577
        %Y1980          - year, last 2 digits of 19YY or 20YY only i.e. 2001->'01', 2079->'79, 1999->'99' 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3578
                          same as above, with boundary year at 1980
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3579
                          raises an error, if the year is not in 1980..2079    
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3580
                            this is occasionally used to get old (pre y2k) data converted.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3581
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3582
        %Y1970          - same as above, with boundary year at 1970.
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3583
                          raises an error, if the year is not in 1970..2069    
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3584
13174
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3585
        %(weekDay)      - day in week (1->monday, 2->tuesday, ... ,7->sunday)
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  3586
        %(dayOfYear)    - day in year (1..365/366)
13174
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3587
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3588
        %(dayName)      - full day name     
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3589
        %(DayName)      - full day name, first character uppercase      
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3590
        %(DAYNAME)      - full day name, all uppercase       
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3591
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3592
        %(monthName)    - full month name     
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3593
        %(MonthName)    - full month name, first character uppercase      
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3594
        %(MONTHNAME)    - full month name, all uppercase       
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3595
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3596
        %(shortDayName) - short (abbreviated) day name     
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3597
        %(ShortDayName) - short (abbreviated) day name, first character uppercase      
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3598
        %(SHORTDAYNAME) - short (abbreviated) day name, all uppercase       
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3599
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3600
        %(shortMonthName) - short (abbreviated) month name     
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3601
        %(ShortMonthName) - short (abbreviated) month name, first character uppercase      
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3602
        %(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase       
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3603
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3604
        %(nth)          - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3605
        %(weekDayNth)   - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
17193
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3606
        %(weekNth)      - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')     
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3607
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3608
        %(yearRoman)    - year, in roman letters                    
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3609
        %(monthRoman)   - month, in roman letters"                    
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3610
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3611
    |day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3612
     year weekInYear monthName shortMonthName 
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3613
     dayInWeek dayOfWeek dayName dayOfYear shortDayName ws wsPadded0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3614
     conv|
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3615
23022
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3616
    aDictionary at:#'iso8601'         put:[ self printStringIso8601 ].
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3617
    aDictionary at:#'iso8601_compact' put:[ self printStringIso8601Compressed ].
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3618
    
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3619
    day := self day.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3620
    ds := day printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3621
    dsPaddedB := day printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3622
    dsPadded0 := day printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3623
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3624
    month := self month.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3625
    ms := month printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3626
    msPaddedB := month printStringLeftPaddedTo:2.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3627
    msPadded0 := month printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3628
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3629
    year := self year.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3630
    weekInYear := self weekInYear.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3631
    ws := weekInYear printString.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3632
    wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3633
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3634
    dayInWeek := self dayInWeek.   "/ 1 .. 7
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3635
    dayOfWeek := self dayOfWeek.   "/ 0 .. 6
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  3636
    dayOfYear := self dayOfYear.   "/ 0 .. 6
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3637
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3638
    monthName := self class nameOfMonth:(self month) language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3639
    dayName := self class nameOfDay:dayInWeek language:languageOrNil.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3640
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3641
    aDictionary at:#day put:dsPadded0.          "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3642
    aDictionary at:#daypadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3643
    aDictionary at:#dayPadded put:dsPaddedB.    "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3644
    aDictionary at:#Day put:ds.                 "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3645
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3646
    aDictionary at:#month put:msPadded0.        "/ 0-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3647
    aDictionary at:#monthPadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3648
    aDictionary at:#monthpadded put:msPaddedB.  "/ Blank-padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3649
    aDictionary at:#Month put:ms.               "/ unpadded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3650
    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
  3651
    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
  3652
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3653
    aDictionary at:#year put:year.              "/ padded
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3654
    aDictionary at:#week put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3655
    aDictionary at:#Week put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3656
21217
33de3c28902a #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20794
diff changeset
  3657
    year ~~ self class today year ifTrue:[
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3658
        aDictionary at:#yearOrTime put:(' ' , year printString).
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3659
    ].
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3660
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3661
    aDictionary at:$d put:dsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3662
    aDictionary at:$D put:ds.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3663
    aDictionary at:$m put:msPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3664
    aDictionary at:$M put:ms.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3665
    aDictionary at:$y put:year.
22874
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3666
    aDictionary at:$Y put:[ (year \\ 100) printStringLeftPaddedTo:2 with:$0 ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3667
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3668
    conv := 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3669
        [ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3670
            (year between:1950 and:2049) ifFalse:[ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3671
                self error:'year cannot be represented'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3672
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3673
            (year between:1950 and:1999) ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3674
                (year - 1900) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3675
            ] ifFalse:[    
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3676
                (year - 2000) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3677
            ]
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3678
        ].        
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3679
    aDictionary at:#Y1950 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3680
    aDictionary at:#y1950 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3681
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3682
    conv := 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3683
        [ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3684
            (year between:1980 and:2079) ifFalse:[ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3685
                self error:'year cannot be represented'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3686
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3687
            (year between:1980 and:1999) ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3688
                (year - 1900) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3689
            ] ifFalse:[    
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3690
                (year - 2000) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3691
            ]
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3692
        ].        
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3693
    aDictionary at:#Y1980 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3694
    aDictionary at:#y1980 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3695
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3696
    conv := 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3697
        [ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3698
            (year between:1970 and:2069) ifFalse:[ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3699
                self error:'year cannot be represented'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3700
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3701
            (year between:1970 and:1999) ifTrue:[
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3702
                (year - 1900) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3703
            ] ifFalse:[    
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3704
                (year - 2000) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3705
            ]
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3706
        ].        
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3707
    aDictionary at:#Y1970 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3708
    aDictionary at:#y1970 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3709
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3710
    conv := 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3711
        [ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3712
            (year between:2000 and:2099) ifFalse:[ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3713
                self error:'year cannot be represented'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3714
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3715
            (year - 2000) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3716
        ].        
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3717
    aDictionary at:#Y2000 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3718
    aDictionary at:#y2000 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3719
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3720
    conv := 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3721
        [ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3722
            (year between:1900 and:1999) ifFalse:[ 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3723
                self error:'year cannot be represented'
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3724
            ].
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3725
            (year - 1900) printStringLeftPaddedTo:2 with:$0
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3726
        ].        
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3727
    aDictionary at:#Y1900 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3728
    aDictionary at:#y1900 put:conv. 
fbe961c2662c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22835
diff changeset
  3729
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3730
    aDictionary at:$w put:wsPadded0.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3731
    aDictionary at:$W put:ws.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3732
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3733
    aDictionary at:#monthName put:monthName.
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3734
    aDictionary at:#monthname put:monthName asLowercase.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3735
    aDictionary at:#MonthName put:monthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3736
    aDictionary at:#MONTHNAME put:monthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3737
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3738
    aDictionary at:#dayName put:dayName.
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3739
    aDictionary at:#dayname put:dayName asLowercase.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3740
    aDictionary at:#DayName put:dayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3741
    aDictionary at:#DAYNAME put:dayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3742
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3743
    aDictionary at:#weekDay put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3744
    aDictionary at:#weekday put:dayInWeek.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3745
    aDictionary at:#weekDayUS put:dayOfWeek.
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  3746
    aDictionary at:#dayOfYear put:dayOfYear.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3747
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3748
    aDictionary at:#shortDayName put:(shortDayName := self class abbreviatedNameOfDay:(self dayInWeek) language:languageOrNil).
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3749
    aDictionary at:#shortdayname put:shortDayName asLowercase.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3750
    aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3751
    aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3752
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3753
    aDictionary at:#shortMonthName put:(shortMonthName := self class abbreviatedNameOfMonth:(self month) language:languageOrNil).
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3754
    aDictionary at:#shortmonthname put:shortMonthName asLowercase.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3755
    aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3756
    aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3757
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3758
    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
  3759
                                     "/ 0   1    2    3    4    5    6    7    8    9
13174
2fe9eccdb8e4 comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents: 12814
diff changeset
  3760
    aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). 
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3761
                                     "/ 0   1    2    3    4    5    6      
14496
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3762
    aDictionary at:#weekDayUSNth put:(#('st' 'nd' 'rd' 'th' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). 
86af3ba4d272 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 14331
diff changeset
  3763
                                     "/ 0   1    2    3    4    5    6      
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3764
    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
  3765
                                     "/ 0   1    2    3    4    5    6    7    8    9     
17193
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3766
    aDictionary at:#yearRoman  put:[ year romanPrintString ].
d8f5450b6c5a class: Date
Claus Gittinger <cg@exept.de>
parents: 17135
diff changeset
  3767
    aDictionary at:#monthRoman  put:[ month romanPrintString ].
23022
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3768
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3769
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3770
     Date today printStringFormat:'%(weekDay)'
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3771
     Date today printStringFormat:'%(iso8601)'
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3772
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3773
    
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3774
    "Modified: / 25-05-2018 / 12:10:33 / Claus Gittinger"
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3775
!
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3776
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3777
printIso8601CompressedOn:aStream
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3778
    "append the compact iso8601 representation of the receiver to aStream.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3779
     This format looks like:
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3780
        19990101T240000
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3781
     or, for zero hr:min:sec,
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3782
        19990101
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3783
     Of course, a 24 hour clock is used.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3784
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3785
     No timezone information is added, so the reader will read as local time."
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3786
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3787
    self printOn:aStream format:'%y%m%d'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3788
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3789
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3790
     Timestamp now printStringIso8601Format -> '2018-05-09T12:17:32.646'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3791
     Date today printStringIso8601Format -> '2018-05-09'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3792
     Time now printStringIso8601Format -> '2018-05-09'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3793
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3794
     Timestamp now printStringIso8601Compressed -> '20180525T120446.266'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3795
     Date today printStringIso8601Compressed -> '2018-05-09'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3796
     Time now printStringIso8601Compressed -> '2018-05-09'.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3797
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3798
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3799
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3800
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3801
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3802
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3803
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3804
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3805
    "Created: / 25-05-2018 / 12:05:04 / Claus Gittinger"
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3806
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3807
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3808
printIso8601FormatOn:aStream
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3809
    "append the iso8601 representation of the receiver to aStream.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3810
     This format looks like:
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3811
        1999-01-01T24:00:00
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3812
     or, for zero hr:min:sec,
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3813
        1999-01-01
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3814
     Of course, a 24 hour clock is used.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3815
23022
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3816
     No timezone information is added, so the reader will read as local time."
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3817
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3818
    self printOn:aStream format:'%y-%m-%d'.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3819
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3820
    "
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3821
     Timestamp now printStringIso8601Format -> '2018-05-09T12:17:32.646+02'.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3822
     Date today printStringIso8601Format -> '2018-05-09'.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3823
     Time now printStringIso8601Format -> '2018-05-09'.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3824
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3825
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3826
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3827
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3828
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3829
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3830
    "
23022
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3831
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  3832
    "Modified (comment): / 25-05-2018 / 12:03:37 / Claus Gittinger"
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3833
!
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3834
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3835
printOn:aStream
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3836
    "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
  3837
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3838
    self printOn:aStream format:(self class defaultFormatString) language:nil.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3839
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3840
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3841
     Date today printOn:Transcript. Transcript cr.
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3842
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3843
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3844
    "Modified: 27.8.1995 / 01:01:49 / claus"
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3845
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3846
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3847
printOn:aStream format:aFormatStringOrSqueakFormatArray
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3848
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3849
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3850
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3851
    self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3852
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3853
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3854
     Date today printOn:Transcript format:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3855
     Date today printOn:Transcript format:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3856
     Date today printOn:Transcript format:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3857
     Date today printOn:Transcript format:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3858
     Date today printOn:Transcript format:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3859
     Date today printOn:Transcript format:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3860
     Date today printOn:Transcript format:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3861
     Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3862
     Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y'   
23712
301d6f68b150 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23597
diff changeset
  3863
     Date today printOn:Transcript format:'%(DayName), %(MonthName) %d, %y' language:#en  
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3864
     Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3865
     Date today printOn:Transcript format:'%d%m%Y'                                      (millenium bug format - danger)
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3866
     Date today printOn:Transcript format:'%d%m%(Y1950)'                                (millenium bug partial workaround format - danger)
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3867
     Date today printOn:Transcript format:'%d%m%(Y1980)'                                (millenium bug partial workaround format - danger)
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3868
     Date today printOn:Transcript format:'Today is the %(weekDay) day of the week'     
17196
c15e6ad5fcba class: Date
Claus Gittinger <cg@exept.de>
parents: 17194
diff changeset
  3869
     Date today printOn:Transcript format:'Today is %(year).%(monthRoman).%D'           (hungarian format)
c15e6ad5fcba class: Date
Claus Gittinger <cg@exept.de>
parents: 17194
diff changeset
  3870
     Date today printOn:Transcript format:'Today is %(D) %(monthRoman) %y'              (poland)
c15e6ad5fcba class: Date
Claus Gittinger <cg@exept.de>
parents: 17194
diff changeset
  3871
     Date today printOn:Transcript format:'Today is %(D)-%(monthRoman)-%y'              (romania)
c15e6ad5fcba class: Date
Claus Gittinger <cg@exept.de>
parents: 17194
diff changeset
  3872
     Date today printOn:Transcript format:'Today is %(D)/%(mon)-%Y'                     (sweden)
17194
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
  3873
     Date today printOn:Transcript format:'Anno domini %(yearRoman)'
73fb6e2decad class: Date
Claus Gittinger <cg@exept.de>
parents: 17193
diff changeset
  3874
     Date today printOn:Transcript format:'%y年%(mon)月%d日'                               (select a font, which can display those chars)
18448
47f63bccdee0 class: Date
Claus Gittinger <cg@exept.de>
parents: 18446
diff changeset
  3875
     Date today printOn:Transcript format:'%(dayOfYear)'                                      
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3876
    "
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3877
15200
64d7fa3c9c63 class: Date
Claus Gittinger <cg@exept.de>
parents: 14714
diff changeset
  3878
    "short form (as in blogs like www.stackoverflow, www.superuser etc.)
64d7fa3c9c63 class: Date
Claus Gittinger <cg@exept.de>
parents: 14714
diff changeset
  3879
     Date today printOn:Transcript format:'%(MonthName) %D ''%Y'     
64d7fa3c9c63 class: Date
Claus Gittinger <cg@exept.de>
parents: 14714
diff changeset
  3880
     Timestamp now printOn:Transcript format:'%(MonthName) %D ''%Y at %h:%m'     
64d7fa3c9c63 class: Date
Claus Gittinger <cg@exept.de>
parents: 14714
diff changeset
  3881
    "
18443
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3882
314b1142aefa class: Date
Claus Gittinger <cg@exept.de>
parents: 18357
diff changeset
  3883
    "Squeak format spec:
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  3884
     String streamContents:[:s |
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  3885
        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
  3886
     ]    
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3887
    "
23712
301d6f68b150 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23597
diff changeset
  3888
301d6f68b150 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23597
diff changeset
  3889
    "Modified (comment): / 10-02-2019 / 15:40:30 / Claus Gittinger"
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3890
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3891
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3892
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3893
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3894
     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
  3895
     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
  3896
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3897
    |dict|
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3898
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3899
    aFormatStringOrSqueakFormatArray isArray ifTrue:[
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3900
        "backward compatibility: a squeak/st80 format array"
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3901
        self printFormat:aFormatStringOrSqueakFormatArray on:aStream.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3902
        ^ self.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3903
    ].
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3904
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3905
    dict := IdentityDictionary new.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3906
    self addPrintBindingsTo:dict language:languageOrNil.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3907
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3908
    aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3909
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3910
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3911
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3912
     Date today 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3913
        printOn:Transcript 
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3914
        format:'%y%m%d'                             
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3915
        language:#en                             
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  3916
    "
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3917
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3918
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3919
printOn:aStream language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3920
    "append a printed representation of the receiver to aStream.
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  3921
     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
  3922
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  3923
    |format langUsed|
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3924
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  3925
    (DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[
8145
e24be75b5f5d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8118
diff changeset
  3926
        self class initNames
8118
efc99c0f68bc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  3927
    ].
18926
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  3928
    langUsed := languageOrNil notNil ifTrue:[languageOrNil] ifFalse:[Smalltalk language].    
559b7bad1dce #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18731
diff changeset
  3929
    format := DefaultFormats at:langUsed ifAbsent:[DefaultFormats at:#en].
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  3930
    self printOn:aStream format:format language:languageOrNil.
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3931
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3932
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3933
     Date today printOn:Transcript language:#en
13195
d3a5d03a1c1c comment/format in: #printOn:language:
Claus Gittinger <cg@exept.de>
parents: 13174
diff changeset
  3934
     Date today printOn:Transcript language:#de
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3935
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3936
8179
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  3937
    "Modified: / 27-08-1995 / 01:01:49 / claus"
eea4776d7848 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  3938
    "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
  3939
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3940
7023
6092f474bbba *** empty log message ***
penk
parents: 7005
diff changeset
  3941
printStringFormat:aFormatStringOrArray
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3942
    "print using a format string;
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3943
     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
  3944
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3945
    ^ self printStringFormat:aFormatStringOrArray language:nil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3946
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3947
    "
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3948
     Date today printStringFormat:'%y%m%d'                                      (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3949
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3950
     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
  3951
     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
  3952
     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
  3953
     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
  3954
     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
  3955
     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
  3956
     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
  3957
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3958
     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
  3959
     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
  3960
     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
  3961
     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
  3962
    "
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3963
!
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3964
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3965
printStringFormat:aFormatStringOrArray language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3966
    "print using a format string;
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7961
diff changeset
  3967
     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
  3968
     see #addPrintBindingsTo: for a list of valid format strings"
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3969
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3970
    |s|
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3971
18271
c64f4a0c035d class: Date
Stefan Vogel <sv@exept.de>
parents: 17690
diff changeset
  3972
    s := CharacterWriteStream new:20.
10908
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3973
    self printOn:s format:aFormatStringOrArray language:languageOrNil.
88b75a3ed4eb Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents: 10879
diff changeset
  3974
    ^ s contents.
5778
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3975
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3976
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3977
     Date today printStringFormat:'%y%m%d'                                      (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3978
     Date today printStringFormat:'%y-%m-%d'                                    (iso format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3979
     Date today printStringFormat:'%y-W%w'                                      (iso format - working week)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3980
     Date today printStringFormat:'%d-%m-%y'                                    (european trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3981
     Date today printStringFormat:'%m/%d/%y'                                    (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3982
     Date today printStringFormat:'%D-%(monthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3983
     Date today printStringFormat:'%D-%(MonthName)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3984
     Date today printStringFormat:'%D-%(MONTHNAME)-%y'                          (us trivia format)
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3985
     Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3986
     Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y'   
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3987
     Date today printStringFormat:'%d%m%Y'                                      (millenium bug format - danger)
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  3988
     Date today printStringFormat:'Today is day %(weekDay) of the week'              
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  3989
     Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week'     
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7299
diff changeset
  3990
     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
  3991
    "
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3992
!
f1dbbbf00aaf better printing
Claus Gittinger <cg@exept.de>
parents: 5775
diff changeset
  3993
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3994
printStringIso8601
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3995
    "return the Iso8601 representation of the receiver with local timezon information.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3996
     This format looks like:
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3997
        1999-01-01T24:00:00
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3998
     or, for zero hr:min:sec,
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  3999
        1999-01-01
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4000
     Of course, a 24 hour clock is used."
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4001
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4002
    ^ String streamContents:[:s | self printIso8601FormatOn:s]
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4003
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4004
    "
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4005
     Date today printStringIso8601
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4006
     Timestamp now printStringIso8601
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4007
     Time now printStringIso8601
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4008
    "
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4009
!
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4010
23022
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4011
printStringIso8601Compressed
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4012
    "return the Iso8601 representation of the receiver with local timezon information.
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4013
     This format looks like:
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4014
        19990101T240000
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4015
     or, for zero hr:min:sec (i.e. Date),
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4016
        19990101
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4017
     Of course, a 24 hour clock is used."
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4018
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4019
    ^ String streamContents:[:s | self printIso8601CompressedOn:s]
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4020
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4021
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4022
     Date today printStringIso8601
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4023
     Date today printStringIso8601Compressed
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4024
     Timestamp now printStringIso8601
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4025
     Timestamp now printStringIso8601Compressed
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4026
     Time now printStringIso8601
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4027
     Time now printStringIso8601Compressed
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4028
    "
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4029
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4030
    "Created: / 25-05-2018 / 12:05:46 / Claus Gittinger"
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4031
!
b50e8a99d04b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22874
diff changeset
  4032
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4033
storeOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4034
    "append a representation to aStream, from which the receiver
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4035
     can be reconstructed"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4036
21486
b2da9b8e6a8e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21217
diff changeset
  4037
    aStream nextPut:$(; nextPutAll:'Date newDay:'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4038
    self day printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4039
    aStream nextPutAll:' month:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4040
    self month printOn:aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4041
    aStream nextPutAll:' year:'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4042
    self year printOn:aStream.
21486
b2da9b8e6a8e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21217
diff changeset
  4043
    aStream nextPut:$)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4044
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4045
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4046
     Date today storeOn:Transcript
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4047
     Date today storeString
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4048
    "
21486
b2da9b8e6a8e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21217
diff changeset
  4049
b2da9b8e6a8e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21217
diff changeset
  4050
    "Modified: / 17-02-2017 / 10:57:34 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4051
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4052
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7023
diff changeset
  4053
!Date methodsFor:'private-accessing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4054
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4055
dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4056
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4057
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4058
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4059
    ^ dateEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4060
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4061
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4062
dateEncoding:anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4063
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4064
     and should not be used outside."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4065
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4066
    dateEncoding := anInteger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4067
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4068
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4069
fromOSTime:osTime
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4070
    "set my dateEncoding as date in the local timezone from an OS time.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4071
     This somewhat clumsy implementation hides the OS's date representation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4072
     (i.e. makes this class independent of what the OS starts its time values with).
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  4073
     Don't use this method, the osTime representation is totally unportable."
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  4074
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  4075
    |v|
5858
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  4076
df08a7ccbdb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5830
diff changeset
  4077
    v := OperatingSystem computeTimeAndDateFrom:osTime.
11350
68606ef82813 Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents: 11349
diff changeset
  4078
    dateEncoding := self class encodeYear:v year month:v month day:v day
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  4079
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1468
diff changeset
  4080
    "Modified: 1.7.1996 / 15:23:12 / cg"
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4081
!
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4082
13234
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4083
fromUtcOSTime:osTime
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4084
    "set my dateEncoding as UTC date from an OS time.
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4085
     This somewhat clumsy implementation hides the OS's date representation
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4086
     (i.e. makes this class independent of what the OS starts its time values with).
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4087
     Don't use this method, the osTime representation is totally unportable."
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4088
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4089
    |v|
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4090
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4091
    v := OperatingSystem computeUTCTimeAndDateFrom:osTime.
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4092
    dateEncoding := self class encodeYear:v year month:v month day:v day
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4093
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4094
    "Modified: 1.7.1996 / 15:23:12 / cg"
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4095
!
Stefan Vogel <sv@exept.de>
parents: 13195
diff changeset
  4096
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4097
getMilliseconds
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4098
    "protocol compatibility with Timestamp.
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4099
     Only use to get millisecond deltas between dates (if at all).
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4100
     Returns the number of milliseconds of midnight since the epoch (1.1.1970).
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4101
     Notice: 
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4102
        because Date does not include timezone info (in contrast to Timestamp),
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4103
        this returns the millis of the UTC date (see example below).
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4104
     Notice:
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4105
        beacuse of that, always use Timestamps for comparisons."
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4106
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4107
    "
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4108
     ((Timestamp epoch addDays:365) asDate asDays - 365)      -> 25202
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4109
    "
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4110
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4111
    ^ 1000 * 60*60*24 * (self asDays - 25202)
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4112
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4113
    "
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4114
     Date today asUtcTimestamp getMilliseconds
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4115
        -
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4116
     Date today getMilliseconds
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4117
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4118
     Date today asTimestamp getMilliseconds
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4119
        -
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4120
     Date today getMilliseconds
22835
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4121
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4122
     (Date year:1970 month:1 day:1) asTimestamp getMilliseconds     -- local time
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4123
     (Date year:1970 month:1 day:1) asUtcTimestamp getMilliseconds  -- utc time
157b20cb8547 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22816
diff changeset
  4124
     (Date year:1970 month:1 day:1) getMilliseconds                 -- utc time
11593
4d5d359f2008 Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents: 11553
diff changeset
  4125
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4126
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4127
11176
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4128
!Date methodsFor:'visiting'!
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4129
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4130
acceptVisitor:aVisitor with:aParameter
16725
e6c6ab52735e comment/format only
Claus Gittinger <cg@exept.de>
parents: 16191
diff changeset
  4131
    "dispatch for visitor pattern; send #visitDate:with: to aVisitor"
11176
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4132
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4133
    ^ aVisitor visitDate:self with:aParameter
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4134
! !
766eb30bb98a Add visitor method
Stefan Vogel <sv@exept.de>
parents: 11128
diff changeset
  4135
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  4136
!Date class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4137
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4138
version
18568
b29493dd47eb class: Date
Claus Gittinger <cg@exept.de>
parents: 18448
diff changeset
  4139
    ^ '$Header$'
12097
e83549637ebf changed:7 methods
Claus Gittinger <cg@exept.de>
parents: 12001
diff changeset
  4140
!
e83549637ebf changed:7 methods
Claus Gittinger <cg@exept.de>
parents: 12001
diff changeset
  4141
e83549637ebf changed:7 methods
Claus Gittinger <cg@exept.de>
parents: 12001
diff changeset
  4142
version_CVS
18568
b29493dd47eb class: Date
Claus Gittinger <cg@exept.de>
parents: 18448
diff changeset
  4143
    ^ '$Header$'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4144
! !
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6624
diff changeset
  4145
14714
cebd5cc86824 class: Date
Claus Gittinger <cg@exept.de>
parents: 14624
diff changeset
  4146
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4147
Date initialize!