Timestamp.st
author Claus Gittinger <cg@exept.de>
Mon, 04 Mar 2013 13:43:31 +0100
changeset 14828 c0624563b69a
parent 14713 eb944b3267e6
child 14969 13470ec6f8c8
child 18017 7fef9e17913f
permissions -rw-r--r--
automatically generated by browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     1
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
     3
              All Rights Reserved
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     4
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    11
"
5376
c2ef7d5e25ca oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents: 5292
diff changeset
    12
"{ Package: 'stx:libbasic' }"
c2ef7d5e25ca oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents: 5292
diff changeset
    13
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    14
AbstractTime subclass:#Timestamp
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    15
	instanceVariableNames:'osTime'
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    16
	classVariableNames:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    17
	poolDictionaries:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    18
	category:'Magnitude-Time'
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    19
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    20
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    21
Object subclass:#TimestampBuilderAbstract
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    22
	instanceVariableNames:'year month day hour minute second millisecond isUtcTime'
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    23
	classVariableNames:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    24
	poolDictionaries:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    25
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    26
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    27
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    28
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    29
	instanceVariableNames:'stream'
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    30
	classVariableNames:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    31
	poolDictionaries:''
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
    32
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    33
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    34
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    35
!Timestamp class methodsFor:'documentation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    36
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    37
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    39
 COPYRIGHT (c) 1989 by Claus Gittinger
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    40
              All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    41
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    42
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    43
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    44
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    45
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    46
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    47
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    48
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    49
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    50
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    51
documentation
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    52
"
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    53
    This class represents time values in milliSeconds starting some
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    54
    time in the past. When printing an accessing values like #hour, the timestamp will be
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    55
    interpreted in the local timezone.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    56
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    57
    (The internal representation, osTime, will typically start with 1970-01-01 0:00, 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    58
     as used in the Unix operating system, but other systems may bias the time differently.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    59
     Actually, the implementation does not depend or even know which time/date 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    60
     the OperatingSystem bases its time upon - it is simply keeping the value(s)
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    61
     as returned from the OS.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    62
     For conversion, these values are given back to the OS, which will know
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    63
     how to convert these times. This has the advantage, that timestamps on files 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    64
     (such as last-access-time or last-modification-time) can be handled transparently - 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    65
     especially when performing comparisons).
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    66
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    67
    You should not interpret the osTime instance variable directly, instead
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    68
    (if at all), ask the OS to convert.
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    69
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    70
    The implementation of this class is not the same as in ST-80 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    71
    (which represents the time as seconds from Jan 1., 1901).
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    72
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    73
    This class should not be confused with Time (which only represents the
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    74
    time within one day). Time instances cannot be used to compare times across midnight; 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    75
    instances of Timestamp can.
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    76
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    77
    Notice: this class was once called AbsoluteTime. Einstein told us in 1905, that talking
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    78
    about a absolute time is not a good idea (at least in our universe). So the class
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    79
    has been renamed to Timestamp which makes us more compatible to other ST dialects (e.g. VW)
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    80
    AbsoluteTime is still kept as an alias for backward compatibility.
3479
9ca6229713f4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3122
diff changeset
    81
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    82
    [author:]
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    83
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    84
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    85
    [See also:]
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
    86
        UtcTimestamp Time Date
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    87
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    88
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    89
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    90
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    91
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    92
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    93
initialize
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    94
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    95
    AbsoluteTime := self.       "backward compatibility"
13606
e32a7d20543a changed: #initialize
Claus Gittinger <cg@exept.de>
parents: 13604
diff changeset
    96
    DateAndTime isNil ifTrue:[
e32a7d20543a changed: #initialize
Claus Gittinger <cg@exept.de>
parents: 13604
diff changeset
    97
        DateAndTime := self
e32a7d20543a changed: #initialize
Claus Gittinger <cg@exept.de>
parents: 13604
diff changeset
    98
    ].
e32a7d20543a changed: #initialize
Claus Gittinger <cg@exept.de>
parents: 13604
diff changeset
    99
e32a7d20543a changed: #initialize
Claus Gittinger <cg@exept.de>
parents: 13604
diff changeset
   100
    "Modified: / 20-08-2011 / 18:43:51 / cg"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   101
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   102
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   103
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   104
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   105
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   106
    "return an instance of the receiver, given individual components,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   107
     interpreted in the UTC timezone."
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   108
423
claus
parents: 392
diff changeset
   109
    ^ self basicNew 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   110
        fromOSTime:(OperatingSystem 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   111
                        computeOSTimeFromUTCYear:y month:m day:d 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   112
                                         hour:h minute:min second:s
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   113
                                         millisecond:millis)
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   114
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   115
    "
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
   116
     Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   117
     Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   118
     Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   119
     Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   120
     Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   121
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   122
     UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   123
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   124
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   125
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   126
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   127
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   128
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   129
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   130
decodeFromLiteralArray:anArray
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   131
    "decode an Timestamp literalArray.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   132
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   133
     anArray may be:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   134
        #(Timestamp '200004182000.123')
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   135
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   136
     or the deprecated old format, that is not portable between different architectures.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   137
     We parse this for backward compatibility (will be eventually removed).
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   138
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   139
        #(Timestamp #osTime: 12345678)     
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   140
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   141
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   142
    (anArray at:2) == #osTime: ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   143
        ^ self new osTime:(anArray at:3).
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   144
    ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   145
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   146
    ^ self 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   147
        readGeneralizedFrom:(anArray at:2) 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   148
        onError:[ self conversionErrorSignal 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   149
                    raiseErrorString:'literal array decoding' ]
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   150
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   151
    "
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   152
     Timestamp
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   153
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')      
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   154
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   155
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   156
423
claus
parents: 392
diff changeset
   157
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   158
    "return an instance of the receiver, initialized from a time and a date
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   159
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   160
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   161
     from my superclass."
423
claus
parents: 392
diff changeset
   162
claus
parents: 392
diff changeset
   163
    ^ self 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   164
        year:aDate year 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   165
        month:aDate month 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   166
        day:aDate day 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   167
        hour:aTime hours 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   168
        minute:aTime minutes 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   169
        second:aTime seconds 
12830
f6935e0c07a3 comment/format in:
Stefan Vogel <sv@exept.de>
parents: 12819
diff changeset
   170
        millisecond:0
423
claus
parents: 392
diff changeset
   171
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   172
     Timestamp fromDate:(Date today) andTime:(Time now)  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   173
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   174
     Timestamp now 
423
claus
parents: 392
diff changeset
   175
    "
claus
parents: 392
diff changeset
   176
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   177
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   178
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   179
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   180
!
claus
parents: 392
diff changeset
   181
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   182
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   183
    "return a new Timestamp, given the year and the day-in-year (starting at 1).
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   184
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   185
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   186
    ^ (Date newDay:dayInYear year:year) asTimestamp
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   187
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   188
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   189
     Timestamp newDay:183 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   190
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   191
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   192
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   193
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   194
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   195
secondsSince1970:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   196
    "set time from elapsed seconds since 1-1-1970, 0:0:0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   197
     This is the format used in the UNIX world"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   198
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   199
    ^ self basicNew setSeconds:secs.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   200
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   201
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   202
     Timestamp secondsSince1970:0      
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   203
     Timestamp secondsSince1970:3600
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   204
     Timestamp secondsSince1970:3600*24
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   205
     (Timestamp year:2010 month:7 day:1 hour:0 minute:0 second:0)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   206
       =
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   207
     (Timestamp secondsSince1970:1277935200)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   208
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   209
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   210
    "Created: / 21-10-1996 / 17:48:30 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   211
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   212
    "Modified: / 08-01-2011 / 16:06:28 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   213
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   214
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   215
utcMillisecondsSince1970:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   216
    "set time from elapsed milliseconds since 1-1-1970, 0:0:0."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   217
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   218
    ^ self basicNew setMilliseconds:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   219
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   220
    "Created: / 08-01-2011 / 16:09:32 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   221
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   222
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   223
utcNow
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   224
    ^ UtcTimestamp now
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   225
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   226
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   227
        Timestamp now
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   228
        Timestamp utcNow
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   229
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   230
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   231
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   232
utcSecondsSince1970:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   233
    "set time from elapsed seconds since 1-1-1970, 0:0:0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   234
     This is the format used in the UNIX world"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   235
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   236
    ^ self secondsSince1970:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   237
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   238
"/    |divMod|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   239
"/
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   240
"/    divMod := secs divMod:3600.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   241
"/    ^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2) millisecond:0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   242
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   243
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   244
     Timestamp secondsSince1970:0      
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   245
     Timestamp secondsSince1970:3600    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   246
     Timestamp secondsSince1970:3600*24  
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   247
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   248
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   249
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   250
    "Created: / 08-01-2011 / 16:05:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   251
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   252
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   253
year:y month:m day:d hour:h minute:min second:s
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   254
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   255
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   256
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   257
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   258
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:0
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   259
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   260
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   261
     Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   262
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   263
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   264
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   265
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   266
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   267
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   268
    "Created: / 13.7.1999 / 12:06:39 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   269
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   270
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   271
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   272
year:y month:m day:d hour:h minute:min second:s millisecond:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   273
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   274
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   275
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   276
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   277
    ^ self basicNew 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   278
            year:y month:m day:d hour:h minute:min second:s millisecond:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   279
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   280
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   281
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   282
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   283
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   284
     UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   285
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   286
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   287
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   288
    "Created: / 13.7.1999 / 12:28:44 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   289
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   290
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   291
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   292
!Timestamp class methodsFor:'Compatibility-Squeak'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   293
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   294
current
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   295
    ^ self now
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   296
!
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   297
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   298
fromString: aString
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   299
    "Answer a new instance for the value given by aString"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   300
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   301
    ^ self readFrom: (ReadStream on: aString).
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   302
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   303
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   304
     Timestamp fromString: '1-10-2000 11:55:00 am'. 
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   305
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   306
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   307
    "Modified (format): / 20-08-2011 / 16:51:53 / cg"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   308
!
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   309
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   310
readFrom:aStringOrStream
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   311
    "Answer a new instance for the value given by aStringOrStream"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   312
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   313
    ^ self 
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   314
        readFrom:aStringOrStream 
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   315
        onError:[ ConversionError raiseRequestErrorString:'conversion error']
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   316
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   317
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   318
     self readFrom:'23-jun-2000 15:00'
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   319
     self readFrom:'23-jun-2000 '
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   320
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   321
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   322
    "Modified (comment): / 20-08-2011 / 16:52:10 / cg"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   323
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   324
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   325
!Timestamp class methodsFor:'format strings'!
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   326
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   327
defaultFormatString
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   328
    ^ '%(year)-%(month)-%(day) %h:%m:%s.%i'
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   329
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   330
    "Created: / 16-01-2011 / 11:23:36 / cg"
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   331
! !
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   332
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   333
!Timestamp class methodsFor:'obsolete'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   334
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   335
day:d month:m year:y hour:h minutes:min seconds:s
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   336
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   337
    "This is obsolete. User #year:month:day:hour:minute:second:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   338
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   339
    ^ self 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   340
        year:y month:m day:d hour:h 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   341
        minute:min second:s millisecond:0
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   342
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   343
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   344
    "Modified: / 1.7.1996 / 15:22:26 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   345
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   346
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   347
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   348
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   349
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   350
    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   351
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   352
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   353
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   354
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   355
     Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   356
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   357
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   358
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   359
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   360
    "Created: / 1.7.1996 / 14:46:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   361
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   362
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   363
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   364
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   365
!Timestamp class methodsFor:'private'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   366
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   367
basicReadFrom:aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   368
    "return a new Timestamp, reading a printed representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   369
     The string is interpreted as 24 hour format, as printed.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   370
     Notice, that this is not the storeString format and 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   371
     is different from the format expected by readFrom:.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   372
     KLUDGE: 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   373
        us and non-us format have different ordering of day and month;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   374
        The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   375
        or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   376
     On error, raise an exception"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   377
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   378
    |firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   379
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   380
    firstNumber := Integer readFrom:aStream onError:[TimeConversionError raiseErrorString:' - integer expected'].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   381
    firstNumber > 31 ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   382
        "/ assume iso8601 format;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   383
        ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   384
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   385
    aStream skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   386
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   387
    "/ consider this a kludge
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   388
    usFormat := (aStream peek == $/ ).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   389
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   390
    [aStream peek isLetterOrDigit] whileFalse:[aStream next].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   391
    aStream peek isDigit ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   392
        secondNumber := Integer readFrom:aStream onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   393
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   394
        usFormat ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   395
            month := firstNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   396
            day := secondNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   397
        ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   398
            month := secondNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   399
            day := firstNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   400
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   401
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   402
    ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   403
        possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   404
        month := Date indexOfMonth:possibeMonthName asLowercase.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   405
        day := firstNumber.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   406
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   407
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   408
    (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   409
    (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   410
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   411
    [aStream peek isDigit] whileFalse:[aStream next].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   412
    year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   413
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   414
    aStream atEnd ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   415
        hour := min := sec := millis := 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   416
    ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   417
        [aStream peek isDigit] whileFalse:[aStream next].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   418
        hour := Integer readFrom:aStream onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   419
        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   420
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   421
        [aStream peek isDigit] whileFalse:[aStream next].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   422
        min := Integer readFrom:aStream onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   423
        (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   424
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   425
        aStream atEnd ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   426
            sec := millis := 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   427
        ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   428
            [aStream peek isDigit] whileFalse:[aStream next].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   429
            sec := Integer readFrom:aStream onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   430
            (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   431
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   432
            aStream peek = $. ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   433
                aStream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   434
                millis := Integer readFrom:aStream onError:0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   435
                millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   436
            ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   437
                millis := 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   438
            ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   439
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   440
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   441
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   442
    "special check - only 24:00:00 is allowed;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   443
     every time after that must wrap"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   444
    hour == 24 ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   445
        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   446
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   447
    ^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   448
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   449
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   450
     Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   451
     Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   452
     (Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   453
     (Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   454
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream       
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   455
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   456
     Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream  
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   457
     Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   458
     Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   459
     Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   460
     Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   461
     Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   462
     Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream   
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   463
     Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   464
     Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   465
     Timestamp basicReadFrom:'foo' readStream                    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   466
     Timestamp basicReadFrom:(Timestamp now printString readStream)                  
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   467
     Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   468
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   469
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   470
     UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   471
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   472
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   473
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   474
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   475
    "common helper for read methods.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   476
     Return a new Timestamp, reading an iso8601 representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   477
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   478
     If the time ends with a 'Z' it is the UTC (or zulu) time,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   479
     othrwise it is local time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   480
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   481
     Missing month/day values are replaced with 1; i.e. 1999T24:00
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   482
     is the same as 1999-01-01T24:00:00.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   483
     Missing minute, second and ms values are replaced with 0;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   484
     i.e. 1999T12 is the same as 1999-01-01T12:00:00.000.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   485
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   486
     On error, raise an exception.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   487
     Please use this format for all external representations - its the standard."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   488
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   489
    |str day month year hour min sec millis fraction isUtcTime peekChar|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   490
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   491
    str := aStringOrStream readStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   492
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   493
    month := day := 1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   494
    hour := min := sec := millis := 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   495
    isUtcTime := false.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   496
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   497
    yearOrNil notNil ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   498
        year := yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   499
    ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   500
        year := Integer readFrom:str onError:nil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   501
        year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   502
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   503
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   504
    str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   505
    str peek == $- ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   506
        str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   507
        "/ month follows.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   508
        month := Integer readFrom:str.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   509
        (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   510
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   511
        str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   512
        str peek == $- ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   513
            str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   514
            "/ day follows.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   515
            day := Integer readFrom:str.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   516
            (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   517
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   518
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   519
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   520
    str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   521
    str atEnd ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   522
        "time follows"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   523
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   524
        str peek == $T ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   525
            "we treat the T as optional here"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   526
            str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   527
            str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   528
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   529
        hour := Integer readFrom:str onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   530
        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   531
        str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   532
        str peekOrNil == $: ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   533
            str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   534
            "/ minutes follow.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   535
            min := Integer readFrom:str onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   536
            (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   537
            str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   538
            str peekOrNil == $: ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   539
                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   540
                "/ seconds follow.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   541
                sec := Integer readFrom:str onError:-1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   542
                (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   543
                str skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   544
                str peekOrNil == $. ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   545
                    str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   546
                    "/ millis follow.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   547
                    fraction := Number readMantissaFrom:str radix:10.    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   548
                    millis := (1000 * fraction) rounded.  "/ mhmh - should it be truncated ?
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   549
                ]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   550
            ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   551
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   552
        
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   553
        peekChar := str peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   554
        peekChar notNil ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   555
            peekChar == $Z ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   556
                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   557
                isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   558
            ]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   559
"/ Todo
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   560
"/            ifFalse:[peekChar == $+ ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   561
"/                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   562
"/                isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   563
"/            ] ifFalse:[peekChar == $- ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   564
"/                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   565
"/                isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   566
"/            ]]]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   567
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   568
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   569
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   570
    "special check - only 24:00:00 is allowed;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   571
     every time after that must wrap"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   572
    hour == 24 ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   573
        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   574
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   575
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   576
    isUtcTime ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   577
        ^ self 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   578
            UTCYear:year month:month day:day 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   579
            hour:hour minute:min second:sec millisecond:millis.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   580
    ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   581
        ^ self 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   582
            year:year month:month day:day 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   583
            hour:hour minute:min second:sec millisecond:millis.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   584
    ]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   585
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   586
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   587
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   588
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   589
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   590
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   591
     Timestamp readIso8601FormatFrom:'1995T13:11'           
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   592
     Timestamp readIso8601FormatFrom:'1995T13'              
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   593
     Timestamp readIso8601FormatFrom:'1995'              
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   594
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   595
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   596
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   597
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   598
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   599
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   600
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   601
   24 is allowed with ISO, and is 00:00 of the next day:
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   602
     Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00'    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   603
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   604
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   605
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   606
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   607
    "common helper for read methods."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   608
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   609
    |retVal|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   610
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   611
    ConversionError handle:[:ex |
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   612
        retVal := exceptionValue value
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   613
    ] do:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   614
        retVal := self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   615
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   616
    ^ retVal
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   617
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   618
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   619
!Timestamp class methodsFor:'reading'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   620
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   621
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   622
    "return a new Timestamp, reading a printed representation from aStream using a formatString.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   623
     The formatString is similar to the one used when printing.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   624
     On error, exceptionalValue is returned. If exceptionalValue is a one-arg block, an error message is
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   625
     passed as argument.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   626
     format:
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   627
        %h      hours, 00..23 (i.e. european)  0-padded to length 2
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   628
        %u      hours, 00..12 (i.e. us)        0-padded to length 2
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   629
        %m      minutes, 00..59                0-padded to length 2
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   630
        %s      seconds, 00..59                0-padded to length 2
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   631
        %i      milliseconds, 000..999         0-padded to length 3
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   632
        %a      am/pm
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   633
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   634
        %d             - day          
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   635
        %D             - day          
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   636
        %(day)         - day          
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   637
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   638
        %m             - month                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   639
        %M             - month                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   640
        %(month)       - month                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   641
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   642
        %(monthName)   - monthName                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   643
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   644
        %(year)        - year, full 4 digits
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   645
        %Y             - year, last 2 digits only, 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   646
                         0..71 map to 2000..2071; 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   647
                         72..99 map to 1972..1999; 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   648
        %Y1900          - year, last 2 digits only, map to 1900..1999 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   649
        %Y2000          - year, last 2 digits only, map to 2000..2099 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   650
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   651
    an optional length after the % gives a field length;
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   652
        i.e. %2h%2m%2s parses 123557 as 12:35:37
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   653
"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   654
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   655
    |day month year
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   656
     hour minute second millisecond
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   657
     utcOffset inStream formatStream error fChar format itemHandler 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   658
     len now s|
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   659
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   660
    error := [:msg | 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   661
                exceptionalValue isBlock ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   662
                    ^ exceptionalValue valueWithOptionalArgument:'format error; space expcected'
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   663
                ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   664
                    ^ exceptionalValue value
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   665
                ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   666
             ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   667
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   668
    itemHandler := [:format |
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   669
        |input|
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   670
        input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   671
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   672
        ( #('d' 'D' 'day' ) includes:format ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   673
            day := Integer readFrom:input onError:[ error value:'invalid day' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   674
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   675
        ] ifFalse:[ ( format = 'month' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   676
            month := Integer readFrom:input onError:[ error value:'invalid month' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   677
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   678
        ] ifFalse:[ ( format = 'year' or:[ format = 'y' ]) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   679
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   680
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   681
        ] ifFalse:[ ( format = 'Y' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   682
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   683
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   684
            (year between:0 and:71) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   685
                year := year + 1900
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   686
            ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   687
                year := year + 2000
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   688
            ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   689
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   690
        ] ifFalse:[ (format = 'monthName') ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   691
            s := input nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetter].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   692
            month := Date indexOfMonth:s asLowercase language:languageOrNil
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   693
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   694
        ] ifFalse:[ ( format = 'Y1900' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   695
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   696
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   697
            year := year + 1900
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   698
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   699
        ] ifFalse:[ ( format = 'Y2000' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   700
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   701
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   702
            year := year + 2000
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   703
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   704
        ] ifFalse:[ ( format = 'h' or:[ format = 'H' ]) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   705
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   706
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   707
        ] ifFalse:[ ( format = 'u'  or:[ format = 'U']) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   708
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   709
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   710
        ] ifFalse:[ ( format = 'm'  or:[ format = 'M' ]) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   711
            minute := Integer readFrom:input onError:[ error value:'invalid minute' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   712
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   713
        ] ifFalse:[ ( format = 's'  or:[ format = 'S' ]) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   714
            second := Integer readFrom:input onError:[ error value:'invalid second' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   715
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   716
        ] ifFalse:[ ( format = 'i'  or:[ format = 'I' ]) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   717
            millisecond := Integer readFrom:input onError:[ error value:'invalid month' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   718
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   719
        ] ifFalse:[ ( format = 'tz' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   720
            utcOffset := self utcOffsetFrom:input.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   721
            utcOffset isNil ifTrue:[ error value:'invalid timezone' ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   722
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   723
        ] ifFalse:[ ( format = 'a' ) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   724
            s := (input next:2) asLowercase.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   725
            s = 'am' ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   726
                (hour between:0 and:12) ifFalse:[ error value:'invalid hour' ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   727
            ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   728
                s = 'pm' ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   729
                    (hour between:1 and:12) ifFalse:[ error value:'invalid hour' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   730
                    hour := hour + 12.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   731
                ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   732
                    error value:'invalid am/pm' 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   733
                ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   734
            ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   735
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   736
        ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   737
            error value:'unhandled format:',format
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   738
        ]]]]]]]]]]]]]]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   739
   ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   740
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   741
    hour := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   742
    minute := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   743
    second := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   744
    millisecond := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   745
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   746
    inStream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   747
    formatStream := formatString readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   748
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   749
    [formatStream atEnd] whileFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   750
        fChar := formatStream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   751
        fChar = Character space ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   752
            inStream peek isSeparator ifFalse:[ error value: 'format error; space expcected' ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   753
            inStream skipSeparators.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   754
        ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   755
            fChar == $% ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   756
                len := nil.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   757
                (formatStream peek isDigit) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   758
                    len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   759
                ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   760
                (formatStream peek == $() ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   761
                    formatStream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   762
                    format := formatStream upTo:$).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   763
                ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   764
                    (formatStream peek == ${) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   765
                        formatStream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   766
                        format := formatStream upTo:$}.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   767
                    ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   768
                        (formatStream peek isLetter) ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   769
                            format := formatStream nextAlphaNumericWord.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   770
                        ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   771
                            error value:'unhandled format:',formatStream peek
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   772
                        ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   773
                    ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   774
                ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   775
                itemHandler value:format.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   776
            ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   777
                inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected'].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   778
                inStream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   779
            ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   780
        ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   781
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   782
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   783
    year isNil ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   784
        year := (now := Timestamp now) year
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   785
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   786
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   787
    ^ (self year:year month:month day:day hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) - utcOffset
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   788
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   789
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   790
     Timestamp readFrom:'20-2-1995 13:11:06' format:'%day-%month-%year %h:%m:%s' language:nil onError:[self halt]   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   791
     Timestamp readFrom:'20021995131106' format:'%2d%2month%4y%2h%2m%2s' language:nil onError:[self halt]   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   792
     Timestamp readFrom:'March 7 2009 7:30pm EST' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   793
     Timestamp readFrom:'March 7 2009 7:30pm UTC' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt]  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   794
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   795
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   796
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   797
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   798
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   799
     The string is interpreted as 24 hour format, as printed.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   800
     Notice, that this is not the storeString format and 
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   801
     is different from the format expected by readFrom:.
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   802
     The format read here is dd-mm-yyyy hh:mm:ss.iii"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   803
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   804
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   805
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   806
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   807
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
   808
    Error handle:[:ex |
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   809
        newTime := super readFrom:stream onError:exceptionBlock 
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   810
    ] do:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   811
        newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   812
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   813
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   814
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   815
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   816
     Timestamp readFrom:'20-2-1995 13:11:06'                            
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   817
     Timestamp readFrom:'20-2-1995 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   818
     Timestamp readFrom:'20-2-2001 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   819
     Timestamp readFrom:'20-2-1995 13:11:06.100'                        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   820
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   821
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'      
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   822
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   823
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   824
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   825
     Timestamp readFrom:'foo' onError:'wrong'                           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   826
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'                     
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   827
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   828
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   829
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   830
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   831
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   832
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   833
readGeneralizedFrom:aStringOrStream 
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   834
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   835
     The format read here is either
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   836
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   837
     or:
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   838
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   839
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   840
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   841
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   842
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   843
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   844
     Notice, that this is not the storeString format and 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   845
     is different from the format expected by readFrom:.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   846
    "
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   847
    ^ self 
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   848
        readGeneralizedFrom:aStringOrStream
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   849
        short:false
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   850
        onError:[
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   851
            self conversionErrorSignal raiseErrorString:'Timestamp format error' 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   852
        ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   853
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   854
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   855
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   856
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   857
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   858
    "return a new Timestamp, reading a printed representation from aStream.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   859
     The format read here is either
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   860
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   861
     or:
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   862
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   863
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   864
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   865
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   866
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   867
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   868
     Notice, that this is not the storeString format and 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   869
     is different from the format expected by readFrom:.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   870
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   871
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   872
    ^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   873
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   874
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   875
     |s|
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   876
     s := '' writeStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   877
     Timestamp now printGeneralizedOn:s.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   878
     Timestamp readGeneralizedFrom:s contents onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   879
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   880
 Daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   881
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   882
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   883
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   884
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   885
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   886
 No daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   887
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   888
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   889
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   890
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   891
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   892
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]   
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   893
     Timestamp readGeneralizedFrom:'199502201311' onError:[]    
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   894
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]    
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   895
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'    
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   896
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'    
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   897
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'                     
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   898
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   899
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]   
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   900
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   901
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   902
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   903
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   904
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   905
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   906
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   907
    "Modified: / 22-08-2006 / 12:30:11 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   908
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   909
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   910
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   911
    "return a new Timestamp, reading a printed representation from aStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   912
     The long format read here is either
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   913
            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   914
        or:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   915
            yyyy-mm-dd HH:MM:SS.iii +uuuu.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   916
     The (not recommended) short forms are:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   917
            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   918
        or:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   919
            yy-mm-dd HH:MM:SS.iii +uuuu.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   920
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   921
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   922
     This format is used for BER specification of the ASN.1 GeneralizedTime and
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   923
     UTCTime as defined in X.208 Sec. 33, so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   924
     The short form is no longer recommended.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   925
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   926
     Notice, that this is not the storeString format and 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   927
     is different from the format expected by readFrom:.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   928
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   929
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   930
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   931
    ^ [
12183
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
   932
        |newTime str day month year hour min sec millis c|
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
   933
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   934
        sec := millis := 0.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   935
        str := aStringOrStream readStream.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   936
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   937
        shortFormat ifTrue:[
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   938
            year := Integer readFrom:(str next:2).
12183
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
   939
            year < 50 ifTrue:[
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
   940
                year := year + 2000.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   941
            ] ifFalse:[
12183
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
   942
                year := year + 1900.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   943
            ].
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   944
        ] ifFalse:[
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   945
            year := Integer readFrom:(str next:4).
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
   946
        ].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   947
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   948
        month := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   949
        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   950
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   951
        day := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   952
        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   953
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   954
        str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   955
        hour:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   956
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   957
        str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   958
        min:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   959
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   960
        str atEnd ifFalse:[
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   961
            str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   962
            sec := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   963
            (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   964
            str atEnd ifFalse:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   965
                str peek == $. ifTrue:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   966
                    str next.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   967
                    millis := Integer readFrom:str.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   968
                ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   969
                str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   970
            ].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   971
        ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   972
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   973
        str atEnd ifTrue:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   974
            "/ this is local time
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   975
            newTime := self year:year month:month day:day 
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   976
                            hour:hour minute:min second:sec millisecond:millis.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   977
        ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   978
            c := str next.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   979
            c ~~ $Z ifTrue:[ 
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   980
                |tzh tzmin|
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   981
                tzh := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   982
                tzmin := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   983
                c == $+ ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   984
                    "the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   985
                    hour := hour - tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   986
                    min := min - tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   987
                ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   988
                    c ~~ $- ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   989
                        ^ exceptionBlock value.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   990
                    ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   991
                    "the timezone is behind of UTC or WEST from Greenwich: add hours and minutes"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   992
                    hour := hour + tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   993
                    min := min + tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   994
                ].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   995
            ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   996
            "this is UTC time"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   997
            newTime := self UTCYear:year month:month day:day 
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   998
                              hour:hour minute:min second:sec millisecond:millis.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   999
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1000
        newTime
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1001
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1002
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1003
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1004
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1005
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1006
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1007
     Timestamp readGeneralizedFrom:s contents onError:[]
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1008
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1009
     Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[] 
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1010
     Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[]    
12183
0d17b2d9a339 changed: #readGeneralizedFrom:short:onError:
Stefan Vogel <sv@exept.de>
parents: 12173
diff changeset
  1011
     Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[]    
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1012
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1013
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1014
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1015
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1016
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1017
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1018
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1019
 No daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1020
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1021
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1022
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1023
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1024
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1025
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]   
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1026
     Timestamp readGeneralizedFrom:'199502201311' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1027
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1028
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1029
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1030
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'                     
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1031
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1032
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]   
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1033
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1034
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] 
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1035
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1036
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] 
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1037
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1038
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1039
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1040
    "Modified: / 22-08-2006 / 12:30:11 / cg"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1041
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1042
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1043
readISO8601From: stringOrStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1044
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1045
    ^ TimestampISO8601Builder read:stringOrStream withClass:self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1046
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1047
    "Created: / 16-06-2005 / 16:13:36 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1048
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1049
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1050
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1051
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1052
     Missing month/day values are replaced with 1; i.e. 1999T24:00
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1053
     is the same as 1999-01-01T24:00:00.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1054
     Missing minute, second and ms values are replaced with 0;
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1055
     i.e. 1999T12 is the same as 1999-01-01T12:00:00.000.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1056
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1057
     On error, raise an exception.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1058
     Please use this format for all external representations - its the standard."
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1059
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1060
    ^ self
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1061
        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1062
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1063
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1064
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1065
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1066
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1067
     Timestamp readIso8601FormatFrom:'1995T13:11'           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1068
     Timestamp readIso8601FormatFrom:'1995T13'              
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1069
     Timestamp readIso8601FormatFrom:'1995'              
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1070
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1071
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1072
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1073
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1074
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1075
   24 is allowed with ISO, and is 00:00 of the next day:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1076
     Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1077
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1078
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1079
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1080
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1081
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1082
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1083
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1084
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1085
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1086
     i.e. 1999T12 is the same as 1999-01-01T12:00:00.000.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1087
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1088
     On error, raise an exception.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1089
     Please use this format for all external representations - its the standard."
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1090
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1091
    ^ self
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1092
        readIso8601FormatFrom:aStringOrStream 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1093
        yearAlreadyRead:nil 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1094
        onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1095
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1096
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1097
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1098
"/    All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), 
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1099
"/    also known as Greenwich Mean Time (GMT), without exception. 
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1100
"/    This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, 
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1101
"/    and should be assumed when reading the asctime format.
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1102
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1103
"/    HTTP-date      = rfc1123-date | rfc850-date | asctime-date
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1104
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1105
"/    rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1106
"/    rfc850-date    = weekday "," SP date2 SP time SP "GMT"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1107
"/    asctime-date   = wkday SP date3 SP time SP 4DIGIT
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1108
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1109
"/    date1          = 2DIGIT SP month SP 4DIGIT
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1110
"/                     ; day month year (e.g., 02 Jun 1982)
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1111
"/    date2          = 2DIGIT "-" month "-" 2DIGIT
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1112
"/                     ; day-month-year (e.g., 02-Jun-82)
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1113
"/    date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1114
"/                     ; month day (e.g., Jun  2)
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1115
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1116
"/    time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1117
"/                     ; 00:00:00 - 23:59:59
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1118
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1119
"/    wkday          = "Mon" | "Tue" | "Wed"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1120
"/                   | "Thu" | "Fri" | "Sat" | "Sun"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1121
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1122
"/    weekday        = "Monday" | "Tuesday" | "Wednesday"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1123
"/                   | "Thursday" | "Friday" | "Saturday" | "Sunday"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1124
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1125
"/    month          = "Jan" | "Feb" | "Mar" | "Apr"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1126
"/                   | "May" | "Jun" | "Jul" | "Aug"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1127
"/                   | "Sep" | "Oct" | "Nov" | "Dec"
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1128
"/
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1129
"/    Mon, 17 Aug 2009 11:11:15 GMT
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1130
"/
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1131
"/ however, occasionally, someone presents us with non-UTC strings which include a timezone;
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1132
"/ thus, this also supports:
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1133
"/    Mon, 17 Aug 2009 11:11:15 +xxxx
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1134
"/    Mon, 17 Aug 2009 11:11:15 -xxxx
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1135
"/ and:
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1136
"/    Mon, 17 Aug 2009 11:11:15 PST
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1137
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1138
    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1139
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1140
    rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1141
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1142
    parts := rfc1123String subStrings:Character space.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1143
    parts size == 6 ifTrue:[
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1144
        indexModifier := 0.
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1145
    ] ifFalse:[
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1146
        parts size == 5 ifTrue:[
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1147
            indexModifier := -1.
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1148
        ] ifFalse:[
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1149
            ^ exceptionBlock value
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1150
        ].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1151
    ].
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1152
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1153
    utcOffsetString := (parts at:6 + indexModifier).
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1154
    utcOffset := (self utcOffsetFrom:utcOffsetString) ? 0.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1155
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1156
    day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1157
    year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1158
    time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1159
    monthName := parts at:3 + indexModifier.
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1160
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1161
    month := (1 to:12) asOrderedCollection detect:[:i | 
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1162
        (Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName 
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1163
    ] ifNone:[^ exceptionBlock].    
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1164
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1165
    ^ (self 
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1166
        fromDate:(Date newDay:day monthIndex:month year:year) 
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1167
        andTime:time) - utcOffset
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1168
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1169
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1170
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PST' onError:nil        
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1171
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PDT' onError:nil        
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1172
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 UTC' onError:nil        
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1173
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 +0100' onError:nil        
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1174
    "
13085
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1175
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1176
    "Modified: / 05-10-2010 / 16:05:32 / cg"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1177
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1178
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1179
utcOffsetFrom:aStringOrStream
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1180
    "return the utcOffset (in seconds) for a given time-zone name.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1181
     Returns nil for invalid formats"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1182
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1183
    |table i offset stream tzName sign|
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1184
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1185
    table :=
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1186
        #(
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1187
            'GMT'   0                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1188
            'UTC'   0                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1189
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1190
            "/ US
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1191
            'AST'   -4                 "/ atlantic
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1192
            'ADT'   -3                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1193
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1194
            'AKST'   -8                "/ alaska
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1195
            'AKDT'   -9      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1196
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1197
            'CST'   -6                 "/ central
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1198
            'CDT'   -5      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1199
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1200
            'EST'   -5                 "/ eastern
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1201
            'EDT'   -4      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1202
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1203
            'EGST'   0                 "/ east greenland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1204
            'EGT'   -1      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1205
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1206
            'HADT'   -9                "/ hawaii
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1207
            'HAST'   -10      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1208
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1209
            'MST'   -7                 "/ mountain
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1210
            'MDT'   -6      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1211
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1212
            'NST'   -3.5                 "/ new foundland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1213
            'NDT'   -2.5      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1214
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1215
            'PST'   -8                 "/ pacific
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1216
            'PDT'   -7      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1217
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1218
            'PMST'  -3                 "/ pierre & miquelon
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1219
            'PMDT'  -2      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1220
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1221
            'WGST'  -2                 "/ west greenland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1222
            'WGT'   -3      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1223
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1224
            "/ europe
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1225
            'CET'   1                 "/ central european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1226
            'CEST'  2                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1227
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1228
            'EET'   2                 "/ east european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1229
            'EEST'  3              
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1230
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1231
            'WET'   0                  "/ west european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1232
            'WEST'  1                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1233
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1234
            'MSK'   4                  "/ moscow european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1235
            'MSD'   4         
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1236
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1237
            "/ pacific
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1238
            'NZST' 12                 "/ new zealand
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1239
            'NZDT' 13                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1240
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1241
            "/ south america
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1242
            'ART'   -3                 "/ argentina
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1243
            'BOT'   -4                 "/ bolivia
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1244
            'BRT'   -3                 "/ brasilia
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1245
            'BRST'  -2                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1246
            'CLT'   -4                 "/ chile
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1247
            'CLST'  -3                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1248
            'ECT'   -5                 "/ equador
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1249
            'PET'   -5                 "/ peru
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1250
            'PYT'   -4                 "/ paraguay
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1251
            'UYT'   -3                 "/ uruguay
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1252
            'VET'   -4.5               "/ venezuela
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1253
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1254
            "/ africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1255
            'CAT'   2                 "/ central africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1256
            'EAT'   3                 "/ east africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1257
            'SAST'  2                 "/ south africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1258
            'WAT'   1                 "/ west africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1259
            'WAST'  2                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1260
            'WT'    0                  "/ west sahara
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1261
            'WST'   1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1262
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1263
            'HKT'   8                 "/ hongkong           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1264
            'IST'   5.5                "/ india           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1265
            'JST'   9                 "/ japan           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1266
            'KST'   9                 "/ korea           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1267
            'SGT'   8                 "/ singapore
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1268
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1269
            "/ military
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1270
            'A'     1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1271
            'B'     2                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1272
            'C'     3                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1273
            'D'     4                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1274
            'E'     5                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1275
            'F'     6                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1276
            'G'     7                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1277
            'H'     8                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1278
            'I'     9                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1279
            'K'     10                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1280
            'L'     11                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1281
            'M'     12                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1282
            'N'     -1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1283
            'O'     -2                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1284
            'P'     -3                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1285
            'Q'     -4                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1286
            'R'     -5                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1287
            'S'     -6                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1288
            'T'     -7                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1289
            'U'     -8                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1290
            'V'     -9                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1291
            'W'     -10                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1292
            'X'     -11                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1293
            'Y'     -12                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1294
        ).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1295
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1296
    stream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1297
    stream skipSeparators.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1298
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1299
    stream peek isLetter ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1300
        tzName := stream upToMatching:[:ch | ch isLetter not].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1301
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1302
        i := table indexOf:tzName.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1303
        i ~~ 0 ifTrue:[ 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1304
            ^ (table at:i+1) * 60 * 60 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1305
        ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1306
    ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1307
        sign := 1.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1308
        stream peek == $- ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1309
            sign := -1.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1310
            stream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1311
        ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1312
            stream peek == $+ ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1313
                sign := 1.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1314
                stream next.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1315
            ] ifFalse:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1316
                stream skipSeparators
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1317
            ]
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1318
        ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1319
        offset := ((stream next:2) asNumber * 60 * 60).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1320
        offset := offset + ((stream next:2) asNumber * 60).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1321
        ^  offset * sign
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1322
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1323
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1324
    ^ nil
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1325
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1326
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1327
     self utcOffsetFrom:'UTC'  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1328
     self utcOffsetFrom:'PST'  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1329
     self utcOffsetFrom:'EST'
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1330
     self utcOffsetFrom:'+0130'  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1331
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1332
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1333
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1334
utcOffsetFromString:aString
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1335
    "return the utcOffset (in seconds) for a given time-zone name.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1336
     Returns nil for invalid formats"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1337
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1338
    |table i offset|
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1339
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1340
    table :=
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1341
        #(
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1342
            'GMT'   0                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1343
            'UTC'   0                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1344
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1345
            "/ US
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1346
            'AST'   -4                 "/ atlantic
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1347
            'ADT'   -3                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1348
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1349
            'AKST'   -8                "/ alaska
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1350
            'AKDT'   -9      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1351
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1352
            'CST'   -6                 "/ central
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1353
            'CDT'   -5      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1354
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1355
            'EST'   -5                 "/ eastern
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1356
            'EDT'   -4      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1357
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1358
            'EGST'   0                 "/ east greenland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1359
            'EGT'   -1      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1360
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1361
            'HADT'   -9                "/ hawaii
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1362
            'HAST'   -10      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1363
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1364
            'MST'   -7                 "/ mountain
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1365
            'MDT'   -6      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1366
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1367
            'NST'   -3.5                 "/ new foundland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1368
            'NDT'   -2.5      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1369
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1370
            'PST'   -8                 "/ pacific
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1371
            'PDT'   -7      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1372
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1373
            'PMST'  -3                 "/ pierre & miquelon
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1374
            'PMDT'  -2      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1375
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1376
            'WGST'  -2                 "/ west greenland
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1377
            'WGT'   -3      
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1378
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1379
            "/ europe
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1380
            'CET'   1                 "/ central european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1381
            'CEST'  2                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1382
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1383
            'EET'   2                 "/ east european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1384
            'EEST'  3              
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1385
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1386
            'WET'   0                  "/ west european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1387
            'WEST'  1                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1388
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1389
            'MSK'   4                  "/ moscow european
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1390
            'MSD'   4         
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1391
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1392
            "/ pacific
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1393
            'NZST' 12                 "/ new zealand
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1394
            'NZDT' 13                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1395
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1396
            "/ south america
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1397
            'ART'   -3                 "/ argentina
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1398
            'BOT'   -4                 "/ bolivia
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1399
            'BRT'   -3                 "/ brasilia
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1400
            'BRST'  -2                 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1401
            'CLT'   -4                 "/ chile
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1402
            'CLST'  -3                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1403
            'ECT'   -5                 "/ equador
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1404
            'PET'   -5                 "/ peru
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1405
            'PYT'   -4                 "/ paraguay
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1406
            'UYT'   -3                 "/ uruguay
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1407
            'VET'   -4.5               "/ venezuela
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1408
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1409
            "/ africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1410
            'CAT'   2                 "/ central africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1411
            'EAT'   3                 "/ east africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1412
            'SAST'  2                 "/ south africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1413
            'WAT'   1                 "/ west africa
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1414
            'WAST'  2                
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1415
            'WT'    0                  "/ west sahara
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1416
            'WST'   1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1417
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1418
            'HKT'   8                 "/ hongkong           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1419
            'IST'   5.5                "/ india           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1420
            'JST'   9                 "/ japan           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1421
            'KST'   9                 "/ korea           
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1422
            'SGT'   8                 "/ singapore
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1423
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1424
            "/ military
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1425
            'A'     1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1426
            'B'     2                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1427
            'C'     3                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1428
            'D'     4                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1429
            'E'     5                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1430
            'F'     6                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1431
            'G'     7                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1432
            'H'     8                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1433
            'I'     9                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1434
            'K'     10                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1435
            'L'     11                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1436
            'M'     12                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1437
            'N'     -1                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1438
            'O'     -2                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1439
            'P'     -3                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1440
            'Q'     -4                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1441
            'R'     -5                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1442
            'S'     -6                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1443
            'T'     -7                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1444
            'U'     -8                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1445
            'V'     -9                   
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1446
            'W'     -10                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1447
            'X'     -11                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1448
            'Y'     -12                  
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1449
        ).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1450
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1451
    i := table indexOf:aString.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1452
    i ~~ 0 ifTrue:[ ^ (table at:i+1) * 60 * 60 ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1453
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1454
    aString size == 5 ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1455
        offset := (aString copyFrom:4 to:5) asNumber * 60.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1456
        offset := offset + ((offset copyFrom:2 to:3) asNumber * 60 * 60).
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1457
        (aString at:1) == $- ifTrue:[
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1458
            offset := offset negated.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1459
        ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1460
        ^  offset
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1461
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1462
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1463
    ^ nil
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1464
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1465
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1466
     self utcOffsetFrom:'UTC' 
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1467
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1468
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1469
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1470
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1471
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1472
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1473
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1474
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1475
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1476
    ^ self timeInfo day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1477
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1478
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1479
     Timestamp now day 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1480
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1481
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1482
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1483
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1484
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1485
dayInWeek
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
  1486
    "return the week-day of the receiver - 1 for monday, 7 for sunday
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
  1487
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
  1488
     WARNING: does not care for pre-julian dates 
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
  1489
        (i.e. do not use this for dates before 1752)"
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1490
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1491
    ^ self timeInfo dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1492
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1493
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1494
     Timestamp now dayInWeek 
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1495
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1496
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1497
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1498
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1499
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1500
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1501
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1502
    "return the year-day of the receiver - 1 for Jan, 1st."
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1503
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1504
    ^ self timeInfo dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1505
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1506
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1507
     Timestamp now dayInYear 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1508
     Timestamp newDay:184 year:1996  
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1509
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1510
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1511
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1512
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1513
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1514
dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1515
    "Answer the day of the month represented by me.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1516
     Same as day; for ST-80 compatibility."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1517
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1518
    ^ self asDate dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1519
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1520
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1521
     Timestamp now dayOfMonth 
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1522
     (Timestamp newDay:184 year:1996) dayOfMonth  
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1523
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1524
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1525
    "Created: / 20-01-2011 / 12:26:54 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1526
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1527
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1528
dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1529
    "return the week-day of the receiver as a string.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1530
     The returned string depends on the language setting.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1531
     Expect things like 'monday', 'tuesday' ..."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1532
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1533
    ^ self asDate dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1534
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1535
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1536
     Timestamp now dayOfWeekName 
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1537
     (Timestamp newDay:184 year:1996) dayOfWeekName  
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1538
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1539
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1540
    "Created: / 20-01-2011 / 12:28:46 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1541
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1542
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1543
hour
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1544
    "return the hour (0..23).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1545
     ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1546
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1547
    ^ self hours
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1548
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1549
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1550
    "Modified: 1.7.1996 / 15:15:32 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1551
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1552
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1553
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1554
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1555
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1556
    ^ self timeInfo hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1557
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1558
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1559
     Timestamp now hours  
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1560
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1561
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1562
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1563
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1564
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1565
millisecond
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1566
    "return the millisecond (0..999).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1567
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1568
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1569
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1570
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1571
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1572
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1573
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1574
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1575
milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1576
    "return the milliseconds (0..999)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1577
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1578
    ^ self timeInfo milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1579
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1580
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1581
     Timestamp now milliseconds   
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1582
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1583
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1584
    "Created: 1.7.1996 / 15:15:02 / cg"
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1585
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1586
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1587
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1588
minute
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1589
    "return the minute (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1590
     ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1591
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1592
    ^ self minutes
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1593
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1594
    "Created: 1.7.1996 / 15:14:29 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1595
    "Modified: 1.7.1996 / 15:15:37 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1596
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1597
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1598
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1599
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1600
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1601
    ^ self timeInfo minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1602
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1603
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1604
     Timestamp now minutes 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1605
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1606
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1607
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1608
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1609
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1610
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1611
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1612
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1613
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1614
    ^ self timeInfo month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1615
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1616
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1617
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1618
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1619
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1620
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1621
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1622
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1623
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1624
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1625
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1626
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1627
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1628
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1629
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1630
osTime:aTime
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1631
    "set the internal representation of the time"
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1632
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1633
    osTime := aTime.
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1634
!
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1635
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1636
second
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1637
    "return the second (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1638
     ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1639
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1640
    ^ self seconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1641
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1642
    "Created: 1.7.1996 / 15:14:19 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1643
    "Modified: 1.7.1996 / 15:15:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1644
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1645
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1646
seconds
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1647
    "return the seconds (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1648
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1649
    ^ self timeInfo seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1650
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1651
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1652
     Timestamp now seconds 
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1653
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1654
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1655
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1656
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1657
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1658
timeInfo
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1659
    ^ OperatingSystem computeTimeAndDateFrom:osTime
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1660
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1661
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1662
timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1663
    "answer the number of minutes between local time and utc time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1664
     Delta is positive if local time is ahead of utc, negative if behind utc."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1665
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1666
    ^ self utcOffset negated // 60
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1667
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1668
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1669
     Timestamp now timeZoneDeltaInMinutes 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1670
     (Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1671
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1672
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1673
    "Modified: 20.12.1995 / 17:28:49 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1674
    "Modified: 1.7.1996 / 15:21:29 / cg"
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1675
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1676
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1677
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1678
    "return the difference between UTC (Greenwich Mean Time) and the local time in seconds.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1679
     If daylight saving time applies to ourself, take that into account.
8888
4171ed260947 Fix #utcSecondsSince1970 and #utcSecondsSince1901 (wrong direction of utcOffset)
Stefan Vogel <sv@exept.de>
parents: 8886
diff changeset
  1680
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1681
     Add utcOffset to convert from local time to UTC time.
8888
4171ed260947 Fix #utcSecondsSince1970 and #utcSecondsSince1901 (wrong direction of utcOffset)
Stefan Vogel <sv@exept.de>
parents: 8886
diff changeset
  1682
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1683
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1684
     If utcOffset is negative, the local timezone is east of Greenwich.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1685
     If utcOffset is positive, the local timezone is west of Greenwich."
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1686
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1687
    ^ self timeInfo utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1688
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1689
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1690
     Timestamp now utcOffset 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1691
     (Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1692
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1693
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1694
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1695
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1696
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1697
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1698
weekInYear
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1699
    "return the week number of the receiver - 1 for Jan, 1st."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1700
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1701
    ^ Date weekInYearOf:self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1702
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1703
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1704
     (Timestamp newDay:1 year:2000) weekInYear    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1705
     (Timestamp newDay:2 year:2000) weekInYear    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1706
     (Timestamp newDay:3 year:2000) weekInYear    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1707
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1708
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1709
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1710
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1711
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1712
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1713
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1714
    ^ self timeInfo year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1715
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1716
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1717
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1718
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1719
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1720
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1721
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1722
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1723
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1724
13199
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1725
ceilingSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1726
    "return a timestamp which represents the next full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1727
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1728
    |offs|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1729
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1730
    offs := (self milliseconds / 1000) ceiling.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1731
    ^ self class basicNew setSeconds:(self getSeconds + offs).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1732
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1733
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1734
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1735
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1736
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1737
     t2 := t1 ceilingSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1738
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1739
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1740
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1741
    "Created: / 08-01-2011 / 16:23:03 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1742
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1743
10736
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1744
deltaFrom:aTimestamp
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1745
    "return the delta as a timeDuration between 2 timeStamps.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1746
     The argument is supposed to be BEFORE the receiver,
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1747
        computes self - aTimestamp"
10736
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1748
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1749
    ^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds))
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1750
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1751
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1752
     |t1 t2|
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1753
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1754
     t1 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1755
     Delay waitForSeconds:0.5.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1756
     t2 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1757
     t2 deltaFrom:t1   
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1758
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1759
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1760
    "Created: / 04-10-2007 / 13:34:28 / cg"
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1761
    "Modified: / 10-07-2010 / 09:37:01 / cg"
10736
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1762
!
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1763
13199
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1764
floorSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1765
    "return a timestamp truncated to the last full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1766
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1767
    ^ self class basicNew setSeconds:(self getSeconds).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1768
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1769
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1770
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1771
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1772
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1773
     t2 := t1 floorSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1774
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1775
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1776
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1777
    "Created: / 08-01-2011 / 16:20:55 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1778
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  1779
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1780
millisecondDeltaFrom:aTimestamp
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
  1781
    "return the delta in milliseconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1782
     The argument is supposed to be BEFORE the receiver,
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1783
        computes self - aTimestamp"
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1784
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1785
    ^ self getMilliseconds - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1786
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1787
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1788
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1789
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1790
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1791
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1792
     t2 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1793
     t2 millisecondDeltaFrom:t1   
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1794
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1795
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1796
    "Modified: / 10-07-2010 / 09:37:18 / cg"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1797
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1798
13200
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1799
roundedToSecond
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1800
    "return a timestamp which represents the time rounded to the nearest full second"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1801
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1802
    |offs|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1803
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1804
    offs := (self milliseconds / 1000) rounded.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1805
    ^ self class basicNew setSeconds:(self getSeconds + offs).
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1806
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1807
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1808
     |t1 t2|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1809
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1810
     t1 := Timestamp now.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1811
     t2 := t1 roundedToSecond.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1812
     self halt
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1813
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1814
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1815
    "Created: / 08-01-2011 / 16:24:12 / cg"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1816
!
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  1817
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1818
secondDeltaFrom:aTimestamp
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1819
    "return the delta in seconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1820
     The argument is supposed to be BEFORE the receiver,
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1821
        computes self - aTimestamp"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1822
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1823
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1824
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1825
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1826
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1827
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1828
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1829
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1830
     t2 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1831
     t2 secondDeltaFrom:t1   
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1832
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1833
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  1834
    "Modified: / 10-07-2010 / 09:37:24 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1835
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1836
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1837
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1838
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1839
= aTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1840
    "return true if the argument, aTime represents the same time"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1841
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1842
    aTime isTimestamp ifFalse:[^ false].
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1843
    ^ (self getMilliseconds = aTime getMilliseconds)
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1844
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1845
    "Modified: 3.7.1996 / 13:10:24 / cg"
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1848
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1849
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1850
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1851
    ^ osTime // 1000
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1852
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1853
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1854
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1855
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1856
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1857
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1858
asAbsoluteTime
8254
73b6109ab982 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8246
diff changeset
  1859
    "deprecated, use #asTimestamp"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1860
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1861
    <resource:#obsolete>
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1862
9061
20af48b9b295 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9056
diff changeset
  1863
    self obsoleteMethodWarning:'use #asTimestamp'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1864
    ^ self
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1865
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1866
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1867
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1868
    "return a Date object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1869
     The returned date will only represent the day - not the timeOfDay."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1870
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1871
    ^ self timeInfo asDate 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1872
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1873
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1874
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1875
     Timestamp now asDate
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1876
     (Timestamp now addTime:3600) asDate 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1877
     (Timestamp now addTime:3600) asTime 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1878
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1879
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1880
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1881
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1882
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1883
asLocalTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1884
    "represent myself as a timestamp in the local timezone"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1885
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1886
    ^ self
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1887
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1888
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1889
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1890
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1891
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1892
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1893
7466
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1894
asMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1895
    "return the number of milliSeconds elapsed since whatever time the
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1896
     OperatingSystem bases its time upon. Since this is totally
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1897
     OS-dependent, do not interpret the value returned by this method.
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1898
     You can use it to add/subtract milliSeconds or get time deltas, though."
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1899
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1900
    ^ self getMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1901
!
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1902
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1903
asSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1904
    "return the number of seconds elapsed since whatever time the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1905
     OperatingSystem bases its time upon. Since this is totally
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1906
     OS-dependent, do not interpret the value returned by this method.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1907
     You can use it to add/subtract seconds or get time deltas, though."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1908
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1909
    ^ self getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1910
7004
6cd2080ea0a3 added asUTCSecondsSince1901
penk
parents: 6955
diff changeset
  1911
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1912
     Timestamp now asSeconds
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1913
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1914
     Time hour:23 minutes:33 seconds:0         
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1915
     Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1916
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1917
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1918
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1919
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1920
    "return a Time object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1921
     The returned time will only represent the timeOfDay - not the day."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1922
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1923
    ^ self timeInfo asTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1924
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1925
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1926
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1927
     Timestamp now asTime
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1928
     UtcTimestamp now asTime
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1929
     (Timestamp now addTime:3600) asTime 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1930
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1931
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1932
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1933
asTimestamp
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1934
    "return an Timestamp object from the receiver - thats the receiver."
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1935
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1936
    ^ self 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1937
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1938
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1939
asUtcTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1940
    "represent myself as a timestamp in the UTC timezone"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1941
    
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1942
    ^ UtcTimestamp fromOSTime:osTime
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1943
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1944
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1945
     Timestamp now asUtcTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1946
     Timestamp now asUtcTimestamp asLocalTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1947
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1948
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1949
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1950
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1951
    "encode myself as an array, from which a copy of the receiver
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1952
     can be reconstructed with #decodeAsLiteralArray.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1953
     The encoding is: 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1954
        (#Timestamp YYYYMMDDhhmmss.iii)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1955
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1956
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1957
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1958
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1959
    s := WriteStream on:(String new:18).
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1960
    self printGeneralizedOn:s isLocal:true.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1961
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1962
    ^ Array
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1963
        with:self class name
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1964
        with:s contents
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1965
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1966
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1967
      Timestamp now literalArrayEncoding
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1968
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1969
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1970
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1971
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1972
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1973
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1974
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1975
"   
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1976
    secondsBetween1901and1970 := 
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1977
        ((Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901))
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1978
        *  (24 * 60 * 60)
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1979
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1980
9449
6ba774be6aa1 stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents: 9433
diff changeset
  1981
    ^ self utcSecondsSince1970 + 2177452800.  
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1982
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1983
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1984
     Timestamp now utcSecondsSince1901 
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1985
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1986
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1987
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1988
!Timestamp methodsFor:'double dispatching'!
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1989
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1990
differenceFromTimestamp:aTimestamp
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1991
    "/ the correct thing to do (and I will, in the future) is to
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1992
    "/ return a TimeDuration:
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1993
    "/
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1994
    "/ ^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds))
13542
a3ffef26b8ef comment/format in: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13541
diff changeset
  1995
    "/ which is the same as: deltaFrom:aTimestamp
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1996
    "/
14428
cb61ee2ba157 comment/format in: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13700
diff changeset
  1997
    "/ however, there might be old code around, which is not be prepared for
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1998
    "/ getting a non-number (the seconds). Therefore, for the meantime,
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  1999
    "/ we return:
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2000
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2001
    ^ aTimestamp getSeconds - self getSeconds
13542
a3ffef26b8ef comment/format in: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13541
diff changeset
  2002
    "/ which is the same as: secondDeltaFrom:aTimestamp
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2003
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2004
    "/ be prepared for a change here.
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2005
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2006
    "Created: / 01-08-2011 / 16:38:10 / cg"
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2007
! !
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2008
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2009
!Timestamp methodsFor:'initialization'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2010
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2011
year:y month:m day:d hour:h minute:min second:s millisecond:millis 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2012
    osTime := OperatingSystem 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2013
                computeOSTimeFromYear:y
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2014
                month:m
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2015
                day:d
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2016
                hour:h
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2017
                minute:min
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2018
                seconds:s
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2019
                millis:millis
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2020
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2021
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2022
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2023
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2024
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2025
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2026
    "private print support: add bindings for printing to aDictionary
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2027
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  2028
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2029
    self asDate addPrintBindingsTo:dict language:languageOrNil.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2030
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2031
    self year == Date today year ifTrue:[
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2032
        dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m').
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2033
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2034
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2035
    super addPrintBindingsTo:dict language:languageOrNil.
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2036
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2037
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2038
printGeneralizedOn:aStream 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2039
    "append a representation of the receiver to aStream in a general format,
9385
f46f04a13052 comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
  2040
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2041
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2042
     This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2043
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2044
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2045
    ^ self printGeneralizedOn:aStream isLocal:false short:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2046
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2047
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2048
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2049
    "append a representation of the receiver to aStream in a general format,
11177
f5faa6cb49ed fix typo in comment
Stefan Vogel <sv@exept.de>
parents: 11140
diff changeset
  2050
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2051
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2052
     This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2053
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2054
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2055
     If isLocal is true, represent as local time, otherwise add UTC time offset."
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2056
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2057
    self printGeneralizedOn:aStream isLocal:isLocal short:false
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2058
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2059
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2060
    "Modified: / 1.7.1996 / 15:20:59 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2061
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2062
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2063
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2064
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2065
    "append a representation of the receiver to aStream in a general format,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2066
     top-down, without separators;
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2067
        long format:  'yyyymmddHHMMSS.mmm+0100'
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2068
        short format: 'yymmddHHMMSS.mmm+0100'
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2069
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2070
     This format is used for the ASN.1 GeneralizedTime and UTCTime
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2071
     as defined in X.208 Sec. 33, so read this before changing the output format.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2072
     The short format is no longer recommended.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2073
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2074
     If isLocal is true, represent as local time, otherwise add UTC time offset."
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2075
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2076
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2077
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2078
    isLocal ifTrue:[
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2079
        t := self timeInfo.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2080
    ] ifFalse:[
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2081
        t := self asUtcTimestamp timeInfo.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2082
    ].
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2083
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2084
    shortFormat ifTrue:[
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2085
        self assert:(t year between:1951 and:2049).
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2086
        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2087
    ] ifFalse:[
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2088
        t year    printOn:aStream leftPaddedTo:4 with:$0.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2089
    ].
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2090
    t month   printOn:aStream leftPaddedTo:2 with:$0.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2091
    t day     printOn:aStream leftPaddedTo:2 with:$0.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2092
    t hours   printOn:aStream leftPaddedTo:2 with:$0. 
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2093
    t minutes printOn:aStream leftPaddedTo:2 with:$0.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2094
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2095
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2096
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2097
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2098
    isLocal ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2099
        "/ this should be printed as non-local-time
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2100
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2101
        off := t utcOffset.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2102
        (self isUtcTimestamp or:[off == 0]) ifTrue:[
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2103
            aStream nextPut:$Z.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2104
        ] ifFalse:[ |min|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2105
            off < 0 ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2106
                aStream nextPut:$+.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2107
                off := off negated.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2108
            ] ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2109
                aStream nextPut:$-.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2110
            ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2111
            min := off // 60.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2112
            min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2113
            min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2114
        ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2115
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2116
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2117
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2118
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2119
     Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr. 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2120
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2121
     Time now printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2122
     Date today printOn:Transcript. Transcript cr.        
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2123
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2124
     Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. 
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2125
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2126
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2127
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2128
     Date today printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2129
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2130
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2131
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2132
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2133
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2134
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2135
printISO8601
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2136
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2137
    ^ TimestampISO8601Builder print: self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2138
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2139
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2140
     Timestamp now printISO8601           
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2141
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2142
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2143
    "Created: / 16-06-2005 / 16:11:15 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2144
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2145
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2146
printISO8601Compressed
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2147
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2148
    ^ TimestampISO8601Builder printCompressed: self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2149
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2150
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2151
     Timestamp now printISO8601Compressed           
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2152
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2153
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2154
    "Created: / 16-06-2005 / 16:11:31 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2155
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2156
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2157
printISO8601CompressedOn: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2158
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2159
    TimestampISO8601Builder printCompressed: self on: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2160
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2161
    "Created: / 16-06-2005 / 16:11:50 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2162
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2163
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2164
printISO8601On: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2165
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2166
    TimestampISO8601Builder print: self on: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2167
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2168
    "Created: / 16-06-2005 / 16:11:07 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2169
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2170
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2171
printIso8601FormatOn:aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2172
    "append the iso8601 representation of the receiver to aStream.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2173
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2174
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2175
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2176
        1999-01-01
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2177
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2178
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2179
     No timezone information (eg. Z or +0100) is added, so the reader will read as local time."
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2180
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2181
    |format|
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2182
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2183
    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2184
    self milliseconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2185
        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2186
        self seconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2187
            format := '%(year)-%(month)-%(day)T%h:%m'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2188
            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2189
                format := '%(year)-%(month)-%(day)'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2190
            ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2191
        ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2192
    ].
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2193
    self printOn:aStream format:format 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2194
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2195
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2196
     Timestamp now printIso8601FormatOn:Transcript   
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2197
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2198
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2199
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2200
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2201
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2202
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2203
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2204
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  2205
    "/ now, use ISO format...
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  2206
    self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'  
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  2207
"/    self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'  
5678
5e1e70d18067 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5677
diff changeset
  2208
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'  
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2209
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2210
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2211
     Timestamp now printOn:Transcript. Transcript cr. 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2212
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2213
     Time now printOn:Transcript. Transcript cr.           
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2214
     Date today printOn:Transcript. Transcript cr.        
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2215
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2216
     Time now asTimestamp printOn:Transcript. Transcript cr.           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2217
     Timestamp now printOn:Transcript. Transcript cr. 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2218
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2219
     Date today asTimestamp printOn:Transcript. Transcript cr.           
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2220
     Date today printOn:Transcript. Transcript cr.           
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2221
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2222
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2223
    "Modified: 1.7.1996 / 15:20:59 / cg"
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2224
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2225
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2226
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2227
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2228
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2229
        'Fri, 04 Jul 2003 15:56:11 GMT'
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2230
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2231
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2232
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2233
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2234
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2235
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2236
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2237
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2238
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2239
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2240
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2241
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2242
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2243
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2244
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2245
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2246
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2247
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2248
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2249
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2250
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2251
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2252
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2253
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2254
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2255
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2256
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2257
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2258
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2259
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2260
    timeInfo := self asUtcTimestamp timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2261
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2262
    aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek);
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2263
            nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2264
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2265
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2266
    aStream nextPutAll:(#('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') at:timeInfo month).
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2267
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2268
"/ the following is too slow for heavy use    
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2269
"/    timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT' language:#en. 
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2270
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2271
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2272
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2273
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2274
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2275
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2276
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2277
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2278
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2279
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2280
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2281
    "
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2282
     String streamContents:[:s| Timestamp now printRFC1123FormatOn:s]   
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2283
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2284
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2285
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2286
printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2287
    "return the Iso8601 representation of the receiver.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2288
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2289
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2290
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2291
        1999-01-01
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2292
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2293
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2294
    ^ String streamContents:[:s | self printIso8601FormatOn:s]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2295
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2296
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2297
     Timestamp now printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2298
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2299
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2300
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2301
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2302
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2303
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2304
        'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2305
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2306
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2307
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2308
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2309
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2310
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2311
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2312
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2313
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2314
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2315
    "store the receiver in a format suitable for reconstruction of the
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2316
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2317
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2318
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2319
    aStream nextPut:$(; 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2320
            nextPutAll:self class name; 
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2321
            nextPutAll:' readIso8601FormatFrom:'''.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2322
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2323
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  2324
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2325
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2326
     Timestamp now storeString 
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2327
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2328
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2329
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2330
    "
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2331
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2332
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2333
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2334
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2335
fromOSTime:anUninterpretedOSTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2336
    "strictly private: set the seconds from an OS time (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2337
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2338
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2339
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2340
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2341
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2342
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2343
getMilliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2344
    "strictly private: return the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2345
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2346
    ^ osTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2347
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2348
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2349
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2350
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2351
getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2352
    "strictly private: return the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2353
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2354
    ^ osTime // 1000
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2355
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2356
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2357
setMilliseconds:millis
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2358
    "strictly private: set the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2359
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2360
    osTime := millis.
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2361
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2362
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2363
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2364
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2365
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2366
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2367
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2368
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2369
    osTime := secs * 1000.
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  2370
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  2371
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2372
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2373
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2374
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2375
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2376
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2377
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  2378
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2379
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2380
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2381
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  2382
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2383
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2384
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2385
!Timestamp methodsFor:'testing'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2386
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2387
isTimestamp
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2388
    ^ true
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2389
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2390
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2391
isUtcTimestamp
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2392
    ^ false
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2393
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2394
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2395
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2397
acceptVisitor:aVisitor with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2398
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2399
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  2400
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2401
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2402
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2403
malformed:aString
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2404
    TimeConversionError raiseErrorString:(' - ', aString)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2405
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2406
    "Created: / 15-06-2005 / 15:54:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2407
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2408
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2409
!Timestamp::TimestampBuilderAbstract methodsFor:'support'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2410
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2411
addHoursAndMinutes: arrayWithHoursAndMinutes
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2412
    "Add the given number of hours and minutes to the current timestamp state. If the time
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2413
    is to be subtracted, both numbers in the array must be negated. When the are not the same
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2414
    sign, the behavior may be strange. It's intended only for time zone corrections, where
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2415
    not more than 12 (in fact, 23) hours is added or subtracted (ie. date can be modified only
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2416
    one day forward or backward)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2417
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2418
    | hours minutes |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2419
    hours := arrayWithHoursAndMinutes first.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2420
    minutes := arrayWithHoursAndMinutes second.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2421
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2422
    minutes isZero ifFalse: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2423
        minute := minute + minutes.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2424
        minute >= 60 ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2425
            hours := hours + minute // 60.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2426
            minute := minute \\ 60.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2427
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2428
        minute < 0 ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2429
            hours := hours + minute // 60.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2430
            minute := (minute \\ 60) negated
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2431
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2432
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2433
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2434
    "Hours may get zero by time zone specification or by minutes modifications above."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2435
    hours isZero ifTrue: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2436
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2437
    "Add or subtract the hour and make date corrections if necessary."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2438
    hour := hour + hours.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2439
    hour < 0 ifTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2440
        "Oops, got to previous day, must adjust even the date."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2441
        hour := 24 - ((hour negated) \\ 24).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2442
        day := day - 1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2443
        day <= 0 ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2444
            "Got to previous month..."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2445
            month := month - 1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2446
            month <= 0 ifTrue: [year := year - 1. month := 12].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2447
            day := self lastDayInMonth: month]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2448
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2449
    hour >= 24 ifTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2450
        hour := hour \\ 24.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2451
        day := day + 1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2452
        day > (self lastDayInMonth: month) ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2453
            month := month + 1.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2454
            month > 12 ifTrue: [year := year + 1. month := 1].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2455
            day := 1]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2456
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2457
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2458
    "Created: / 15-06-2005 / 16:45:49 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2459
    "Modified: / 16-06-2005 / 15:04:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2460
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2461
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2462
dateFromDayNumber: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2463
    "Set month and day from an absolute number of the day in the year. 1.1. is day number one."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2464
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2465
    | leap |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2466
    leap := self isLeapYear: year.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2467
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2468
    (anInteger between: 1 and: 365) ifFalse: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2469
        (leap and: [anInteger = 366])
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2470
            ifFalse: [self malformed: 'Bad day number: ' , anInteger printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2471
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2472
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2473
    self shouldImplement
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2474
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2475
    "Created: / 15-06-2005 / 11:27:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2476
    "Modified: / 16-06-2005 / 12:31:37 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2477
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2478
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2479
dateFromWeek: weekInteger andWeekday: dayInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2480
    "Compute the month and day. Find the first day (weekday) in the year, maybe even
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2481
    adjust the year. Both week and day are 1-based, the first week in a year is the one
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2482
    with thursday (or the one containing 4.1.)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2483
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2484
    "Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2485
    (dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2486
    (weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2487
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2488
    self shouldImplement
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2489
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2490
    "Created: / 15-06-2005 / 11:29:42 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2491
    "Modified: / 15-06-2005 / 16:42:33 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2492
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2493
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2494
isAllowedDay: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2495
    "Answer whether the given day is allowed in the current month."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2496
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2497
    ^anInteger between: 1 and: (self lastDayInMonth: month)
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2498
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2499
    "Created: / 15-06-2005 / 16:22:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2500
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2501
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2502
isLeapYear: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2503
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2504
    ^(anInteger bitAnd: 3) = 0 and: [anInteger \\ 100 > 0 or: [anInteger \\ 400 = 0]]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2505
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2506
    "Created: / 15-06-2005 / 16:16:31 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2507
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2508
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2509
lastDayInMonth: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2510
    "Answer the number of the last day of the given month in the current year."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2511
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2512
    ^anInteger = 2
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2513
        ifTrue: [(self isLeapYear: year) ifTrue: [29] ifFalse: [28]]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2514
        ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2515
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2516
    "Created: / 15-06-2005 / 17:12:31 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2517
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2518
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2519
timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2520
    "Answer the timestamp as it has been parsed."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2521
    "Notes:
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2522
     - When reading, the time has either been adjusted to UTZ/zulu time,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2523
       or is a local time.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2524
     - On UNIX, timestamps can only hold dates between 1970-01-01T01:00:00Z and 2038-01-19T00:00:00Z"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2525
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2526
    isUtcTime ifTrue:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2527
        ^ timestampClass
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2528
            UTCYear: year month: month day: day
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2529
            hour: hour minute: minute second: second millisecond: millisecond
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2530
    ] ifFalse:[
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2531
        ^ timestampClass
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2532
            year: year month: month day: day
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2533
            hour: hour minute: minute second: second millisecond: millisecond
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2534
    ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2535
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2536
    "Created: / 15-06-2005 / 15:39:24 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2537
    "Modified: / 30-06-2005 / 16:48:25 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2538
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2539
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2540
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2541
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2542
documentation
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2543
"
11994
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2544
    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. Also, class
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2545
    methods can be used to print but the main reading job is done in instance protocol. It has been
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2546
    written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2547
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2548
    It produces timestamps, ie. when the string (or stream) contains only a time, an error will result
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2549
    (it may also pass in some cases but with the time undestood as date). It survives incomplete dates,
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2550
    broken years, incomplete times and timezones. All times read with timezone difference are recomputed
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2551
    to UTC before the timestamp is created (even passing across new year boundary is handled correctly).
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2552
    Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2553
    All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2554
    possible. For an example of what the builder can read, see the examples method and ISO 8601 itself.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2555
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2556
    [author:]
11994
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2557
        Martin Dvorak (masca@volny.cz)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2558
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2559
    [instance variables:]
11994
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2560
        stream          A stream the builder operates on. Assigned on each call to instance method #read:,
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2561
                        so the builder instance can be reused (by at most one thread).
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2562
        year            Current timestamp year. No default value, date must be present.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2563
        month           Current timestamp month. May change during parsing. Defaults to 1.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2564
        day             Current timestamp day. Defaults to 1.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2565
        hour            Current timestamp hour. Defaults to 0.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2566
        minute          Current timestamp minute. Defaults to 0.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2567
        second          Current timestamp second. Defaults to 0.
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2568
        millisecond     Current timestamp millisecond. Defaults to 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2569
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2570
    [see also:]
11994
4665bdb0fd89 *** empty log message ***
fm
parents: 11993
diff changeset
  2571
        Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2572
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2573
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2574
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2575
examples
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2576
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2577
    See the testing protocol on instance protocol (should be turned into a TestCase).
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2578
    It covers the main features this builder has.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2579
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2580
    Just to introduce some coding examples, try:
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2581
        Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2582
        UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2583
        Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2584
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2585
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2586
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2587
history
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2588
    "Created: / 16-06-2005 / 16:28:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2589
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2590
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2591
!Timestamp::TimestampISO8601Builder class methodsFor:'parsing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2592
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2593
read: stringOrStream withClass:timestampClass
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2594
    ^ self new read:stringOrStream withClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2595
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2596
    "Created: / 15-06-2005 / 17:52:03 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2597
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2598
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2599
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2600
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2601
print: aTimestamp
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2602
    "Print the given timestamp in general ISO8601 format."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2603
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2604
    | stream |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2605
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2606
    self print: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2607
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2608
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2609
    "Created: / 15-06-2005 / 17:52:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2610
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2611
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2612
print: aTimestamp on: aStream
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2613
    "Print the given timestamp in general ISO8601 format."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2614
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2615
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2616
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2617
    timeInfo := aTimestamp asUtcTimestamp timeInfo.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2618
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2619
    aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2620
        nextPutAll: (timeInfo year printStringRadix: 10 size: 4 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2621
        nextPut: $-;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2622
        nextPutAll: (timeInfo month printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2623
        nextPut: $-;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2624
        nextPutAll: (timeInfo day printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2625
        nextPut: $T;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2626
        nextPutAll: (timeInfo hours printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2627
        nextPut: $:;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2628
        nextPutAll: (timeInfo minutes printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2629
        nextPut: $:;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2630
        nextPutAll: (timeInfo seconds printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2631
        nextPut: $Z
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2632
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2633
    "Created: / 15-06-2005 / 17:56:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2634
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2635
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2636
printCompressed: aTimestamp
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2637
    "Print in special compressed format for timestamp interchange with mobile devices."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2638
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2639
    | stream |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2640
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2641
    self printCompressed: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2642
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2643
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2644
    "Created: / 15-06-2005 / 17:52:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2645
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2646
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2647
printCompressed: aTimestamp on: aStream
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2648
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2649
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2650
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2651
    timeInfo := aTimestamp asUtcTimestamp timeInfo.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2652
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2653
    aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2654
        nextPutAll: (timeInfo year printStringRadix: 10 size: 4 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2655
        nextPutAll: (timeInfo month printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2656
        nextPutAll: (timeInfo day printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2657
        nextPut: $T;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2658
        nextPutAll: (timeInfo hours printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2659
        nextPutAll: (timeInfo minutes printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2660
        nextPutAll: (timeInfo seconds printStringRadix: 10 size: 2 fill: $0);
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2661
        nextPut: $Z
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2662
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2663
    "Created: / 15-06-2005 / 17:54:17 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2664
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2665
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2666
!Timestamp::TimestampISO8601Builder class methodsFor:'testing'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2667
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2668
test
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2669
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2670
    self test_date.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2671
    self test_time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2672
    self test_timezone.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2673
    self test_edge.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2674
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2675
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2676
        TimestampISO8601Builder test
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2677
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2678
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2679
    "Created: / 15-06-2005 / 17:51:16 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2680
    "Modified: / 16-06-2005 / 10:15:55 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2681
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2682
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2683
test_date
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2684
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2685
    | ts |
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2686
    ts := UtcTimestamp
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2687
         year: 2005 month: 6 day: 15
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2688
         hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2689
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2690
    "Test common dates"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2691
    self assert: ts = (self read: '20050615' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2692
    self assert: ts = (self read: '2005-06-15'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2693
    self assert: ts = (self read: '05-06-15'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2694
    self assert: ts = (self read: '05-0615'  withClass:Timestamp). "/ Is this correct?
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2695
    self assert: ts = (self read: ':50615'  withClass:Timestamp). "/ Should not happen and should not appear after 2009
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2696
    self assert: ts = (self read: '200506-15'  withClass:Timestamp). "/ Is this corect?
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2697
    self assert: ts = (self read: '105-06-15'  withClass:Timestamp). "/ Should not happen
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2698
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2699
    "Test week numbers"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2700
    "/self assert: ts = (self read: '05W243'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2701
    "/self assert: ts = (self read: '2005W24-3'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2702
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2703
    "Test day numbers"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2704
    "self assert: ts = (self read: '2005-166'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2705
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2706
    ts := Timestamp year: 2004 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2707
    self assert: ts = (self read: '2004-366'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2708
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2709
    ts := Timestamp year: 2005 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2710
    self assert: ts = (self read: '2004-365'  withClass:Timestamp)."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2711
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2712
    "Test february"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2713
    ts := UtcTimestamp year: 2000 month: 2 day: 28 hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2714
    self assert: ts = (self read: '20000228'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2715
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2716
    ts := UtcTimestamp year: 2000 month: 2 day: 29 hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2717
    self assert: ts = (self read: '20000229'  withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2718
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2719
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2720
        TimestampISO8601Builder new test_date
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2721
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2722
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2723
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2724
    "Created: / 15-06-2005 / 17:21:56 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2725
    "Modified: / 16-06-2005 / 11:50:04 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2726
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2727
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2728
test_edge
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2729
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2730
    | ts |
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2731
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2732
    self test_mustFail: [self read: '20050229' withClass:Timestamp].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2733
    self test_mustFail: [self read: '20050029' withClass:Timestamp].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2734
    self test_mustFail: [self read: '20050332' withClass:Timestamp].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2735
    self test_mustFail: [self read: '2005-366' withClass:Timestamp].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2736
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2737
    ts := UtcTimestamp year: 2005 month: 1 day: 1 hour: 0 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2738
    self assert: ts = (self read: '20041231T22-0200' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2739
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2740
    ts := UtcTimestamp year: 2004 month: 12 day: 31 hour: 22 minute: 0 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2741
    self assert: ts = (self read: '20050101T0000+0200' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2742
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2743
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2744
        TimestampISO8601Builder new test_edge
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2745
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2746
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2747
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2748
    "Created: / 16-06-2005 / 09:44:34 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2749
    "Modified: / 16-06-2005 / 11:48:59 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2750
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2751
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2752
test_mustFail: aBlock
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2753
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2754
    TimeConversionError
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2755
        handle: [:ex | ex return]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2756
        do: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2757
            aBlock value.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2758
            self error: 'Assertion failed'
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2759
        ]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2760
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2761
    "Created: / 16-06-2005 / 09:43:37 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2762
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2763
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2764
test_time
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2765
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2766
    | ts |
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2767
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2768
    ts := UtcTimestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2769
    self assert: ts = (self read: '2005-06-15 17:37' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2770
    self assert: ts = (self read: '20050615T1737' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2771
    self assert: ts = (self read: '05-0615T17:3700' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2772
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2773
    ts := UtcTimestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 30.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2774
    self assert: ts = (self read: '05-0615T17:3700.03' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2775
    self assert: ts = (self read: '2005-06-15T17:37:00.0305486-00:00' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2776
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2777
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2778
        TimestampISO8601Builder new test_time
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2779
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2780
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2781
    "Created: / 15-06-2005 / 17:39:26 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2782
    "Modified: / 16-06-2005 / 11:54:30 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2783
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2784
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2785
test_timezone
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2786
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2787
    | ts |
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2788
    ts := UtcTimestamp
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2789
         year: 2005 month: 6 day: 15
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2790
         hour: 17 minute: 37 second: 0 millisecond: 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2791
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2792
    self assert: ts = (self read: '2005-06-15T17:37Z' withClass:UtcTimestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2793
    self assert: ts = (self read: '2005-06-15T17:37+0000' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2794
    self assert: ts = (self read: '2005-06-15T17:37-00:00' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2795
    self assert: ts = (self read: '2005-06-15T15:37:00-0200' withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2796
    self assert: ts = (self read: '2005-06-15T19:37:00+0200'withClass:Timestamp).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2797
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2798
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2799
        TimestampISO8601Builder new test_timezone
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2800
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2801
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2802
    "Created: / 15-06-2005 / 17:40:23 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2803
    "Modified: / 16-06-2005 / 10:17:57 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2804
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2805
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2806
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2807
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2808
nextDigit
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2809
    | char |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2810
    char := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2811
    char isNil ifTrue: [^-1].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2812
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2813
    ^char isDigit
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2814
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2815
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2816
            char codePoint - $0 codePoint]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2817
        ifFalse: [-1]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2818
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2819
    "Created: / 14-06-2005 / 11:48:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2820
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2821
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2822
nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2823
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2824
    | digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2825
    digit := self nextDigit.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2826
    ^ digit < 0
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2827
        ifTrue: [self malformed: 'No digit found']
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2828
        ifFalse: [digit]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2829
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2830
    "Created: / 15-06-2005 / 10:57:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2831
    "Modified: / 15-06-2005 / 17:22:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2832
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2833
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2834
nextDigits: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2835
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2836
    | char number |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2837
    number := 0.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2838
    anInteger timesRepeat: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2839
        char := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2840
        char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits'].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2841
        char isDigit
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2842
            ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2843
                stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2844
                number := number * 10 + char codePoint - $0 codePoint]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2845
            ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2846
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2847
    ^ number
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2848
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2849
    "Created: / 14-06-2005 / 11:57:22 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2850
    "Modified: / 15-06-2005 / 15:54:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2851
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2852
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2853
!Timestamp::TimestampISO8601Builder methodsFor:'processing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2854
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2855
read:stringOrStream withClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2856
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2857
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2858
    stream := stringOrStream readStream.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2859
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2860
    month := day := 1.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2861
    hour := minute := second := millisecond := 0.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2862
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2863
    "Read the year. This will read and swallow up to four year digits."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2864
    self readYear.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2865
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2866
    "Check if date has been read, ie. T or space necountered. If yes, read the time.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2867
    There is possible inconsistency - a dash may be read followed by T, which is not
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2868
    valid. But don't mind that, timestamps will be well-formatted in most cases."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2869
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2870
    peek ifNil: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2871
        "End of stream, only year has been read."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2872
        ^self timestampWithClass:timestampClass].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2873
    peek = $- ifTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2874
        "Skip the dash after year, if present."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2875
        stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2876
        peek := stream peekOrNil].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2877
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2878
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2879
    (peek = $T or: [peek = Character space])
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2880
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2881
            "Got time signature. Skip the signature, read time and answer the timestamp."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2882
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2883
            self readTime.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2884
            self readTimezone.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2885
            ^ self timestampWithClass:timestampClass]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2886
        ifFalse: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2887
            "Date not read completely yet, expecting month/day or week/day or day"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2888
            peek = $W
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2889
                ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2890
                    "Parse week number and (possibly) day number."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2891
                    stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2892
                    self readWeekNumber]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2893
                ifFalse: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2894
                    "Got digit, read month number followed by day or day number."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2895
                    self readMonthOrDay]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2896
        ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2897
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2898
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2899
    peek ifNil: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2900
        "End of stream, only year has been read."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2901
        ^ self timestampWithClass:timestampClass].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2902
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2903
    (peek asUppercase = $T or: [peek = Character space])
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2904
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2905
            "Got time signature, expecting time follows. Otherwise only date was in the stream."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2906
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2907
            self readTime.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2908
            self readTimezone].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2909
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2910
    ^ self timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2911
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2912
    "Created: / 14-06-2005 / 11:45:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2913
    "Modified: / 16-06-2005 / 10:15:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2914
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2915
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2916
!Timestamp::TimestampISO8601Builder methodsFor:'reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2917
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2918
readMilliseconds
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2919
    "Read an arbitrary number of digits representing milliseconds. As the timestamp can
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2920
    hold only integer amounts of milliseconds, don't mind the rest of the digits."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2921
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2922
    | digit factor |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2923
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2924
    factor := 100.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2925
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2926
    [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2927
        digit := self nextDigit.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2928
        digit >= 0
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2929
    ] whileTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2930
        factor > 0 ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2931
            "Factor still > 0, did not read all three digits of mantissa."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2932
            millisecond := digit * factor + millisecond.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2933
            factor := (factor / 10) integerPart
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2934
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2935
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2936
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2937
    factor = 100 ifTrue: [self malformed: 'No digits after millisecond separator']
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2938
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2939
    "Created: / 15-06-2005 / 15:25:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2940
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2941
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2942
readMonthOrDay
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2943
    "Read month number, optionally followed by day, or absolute day number (three digit)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2944
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2945
    | dayDigit1 dayDigit2 |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2946
    month := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2947
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2948
    stream peekOrNil = $-
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2949
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2950
            "Got dash. Day number must follow."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2951
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2952
            day := self nextDigits: 2.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2953
            (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2954
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2955
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2956
    dayDigit1 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2957
    dayDigit1 < 0 ifTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2958
        "No more digits than month, leave day unspecified."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2959
        (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2960
        ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2961
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2962
    dayDigit2 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2963
    dayDigit2 < 0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2964
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2965
            "Read only three digits, this is absolute day number in a year."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2966
            self dateFromDayNumber: month * 10 + dayDigit1]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2967
        ifFalse: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2968
            "Read four digits. So there's month and day."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2969
            (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2970
            day := dayDigit1 * 10 + dayDigit2.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2971
            (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2972
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2973
    "Created: / 15-06-2005 / 11:12:02 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2974
    "Modified: / 16-06-2005 / 11:47:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2975
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2976
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2977
readTime
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2978
    "Date read, don't mind it. Read only the time value."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2979
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2980
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2981
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2982
    hour := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2983
    (hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2984
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2985
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2986
    peek = $:
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2987
        ifTrue: [stream next]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2988
        ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2989
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2990
    minute := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2991
    (minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2992
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2993
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2994
    peek = $:
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2995
        ifTrue: [stream next]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2996
        ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2997
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2998
    second := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2999
    (second between: 0 and: 59) ifFalse: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3000
        "Seconds are usually in this range, do a special check for leap seconds."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3001
        second <= 61
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3002
            ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3003
                "Leap seconds can occur only on midnight on 31.12. or 30.6. Dont' check year
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3004
                as it's not deterministic."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3005
                (minute = 59 and: [hour = 23 and: [(month = 12 and: [day = 31]) or: [month = 6 and: [day = 30]]]])
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3006
                    ifFalse: [self malformed: 'Bad leap second']]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3007
            ifFalse: [self malformed: 'Bad second: ' , second printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3008
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3009
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3010
    "Hour, minute and second read. Read appendices."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3011
    stream peekOrNil = $.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3012
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3013
            "Read dot. Skip it and read milliseconds."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3014
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3015
            self readMilliseconds].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3016
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3017
    hour = 24 ifTrue: [
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3018
        (minute = 0 and: [second = 0 and: [millisecond = 0]])
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3019
            ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3020
                "On 24 hour, advance to the next day."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3021
                "hour := 0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3022
                self addMinutes: 1440"]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3023
            ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3024
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3025
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3026
    "Created: / 14-06-2005 / 17:27:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3027
    "Modified: / 30-06-2005 / 11:34:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3028
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3029
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3030
readTimezone
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3031
    "Read time zone information. There are three possibilities of what can occur.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3032
    If there is nothing more to read, the offset is unknown - this is treated as
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3033
    Zulu time as this may not be true."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3034
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3035
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3036
    peek := stream peek.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3037
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3038
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3039
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3040
    "If the time is in Zulu, don't modify the timestamp. This makes the machine
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3041
    run in Zulu time zone, maybe some corrections would be nice."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3042
    peek = $Z
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3043
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3044
            "Time read, skip Zulu signature and exit."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3045
            isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3046
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3047
            ^ self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3048
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3049
    peek = $+
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3050
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3051
            "Read a plus, expect a negative time zone difference."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3052
            isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3053
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3054
            self addHoursAndMinutes: (self readTimezoneOffset collect: [:e | e negated]).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3055
            ^ self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3056
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3057
    peek = $-
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3058
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3059
            "Read a minus, expect positive time zone difference or unknown offset."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3060
            isUtcTime := true.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3061
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3062
            self addHoursAndMinutes: self readTimezoneOffset.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3063
            ^ self].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3064
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3065
    "This is local time"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3066
    isUtcTime := false.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3067
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3068
    "Created: / 16-06-2005 / 09:54:21 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3069
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3070
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3071
readTimezoneOffset
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3072
    "Read time zone offset as a number minutes. Generally, there should be hours only
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3073
    but as the format introduces minutes in offsets, we must accept them."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3074
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3075
    | hours digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3076
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3077
    "Read hours."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3078
    hours := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3079
    (hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3080
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3081
    stream peekOrNil = $:
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3082
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3083
            "Colon read, minutes must follow."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3084
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3085
            digit := self nextDigits: 2.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3086
            (digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3087
            ^Array with: hours with: digit].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3088
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3089
    "Read next digit and check whether minutes follow. If not, return only with hours. If yes,
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3090
     check boundaries."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3091
    digit := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3092
    digit < 0 ifTrue: [^Array with: hours with: 0].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3093
    digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3094
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3095
    "Read the last digit of offset, it must be present."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3096
    ^Array with: hours with: digit * 10 + self nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3097
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3098
    "Created: / 15-06-2005 / 15:35:41 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3099
    "Modified: / 15-06-2005 / 17:45:58 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3100
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3101
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3102
readWeekNumber
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3103
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3104
    | week day digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3105
    "Read week number. It is always two digits long."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3106
    week := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3107
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3108
    stream peekOrNil = $-
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3109
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3110
            "Got dash, day number must follow."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3111
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3112
            digit := self nextDigit.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3113
            digit < 0 ifTrue: [self malformed: 'Bad weekday number'].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3114
            self dateFromWeek: week andWeekday: digit.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3115
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3116
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3117
    "Read day number that follows the week. If the number is not given, consider it monday."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3118
    day := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3119
    day <= 0 ifTrue: [day := 1].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3120
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3121
    self dateFromWeek: week andWeekday: day
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3122
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3123
    "Created: / 14-06-2005 / 12:06:47 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3124
    "Modified: / 15-06-2005 / 15:53:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3125
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3126
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3127
readYear
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3128
    "Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3129
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3130
    | read peek |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3131
    stream peekOrNil = $:
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3132
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3133
            "Broken two digit year > 1999 follows."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3134
            stream next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3135
            year := self nextDigitOrError + 2000.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3136
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3137
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3138
    "Expecting two-, three- or four-digit year"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3139
    "Read the first two digits. They must be there."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3140
    read := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3141
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3142
    "Check if there's a dash, this can help us deciding whether the year ends."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3143
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3144
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3145
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3146
    year := peek = $-
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3147
        ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3148
            "OK, got two digits. These are expected to be the year after 1970."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3149
            read < 70
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3150
                ifTrue: [read + 2000]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3151
                ifFalse: [read + 1900]]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3152
        ifFalse: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3153
            "Read the next digit for the case of three-digit year after 1900 (ie. year > 1999)."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3154
             read := read * 10 + self nextDigitOrError.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3155
             peek := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3156
             (peek isNil or: [peek = $-])
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3157
                ifTrue: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3158
                    "Read three digit year, return it."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3159
                    read + 1900]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3160
                ifFalse: [
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3161
                    "Read the fourth digit of the year. These can be month digits but the
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3162
                    two-digit year format is deprecated anyway."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3163
                    read := read * 10 + self nextDigitOrError]
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3164
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3165
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3166
    "Created: / 14-06-2005 / 12:01:11 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3167
    "Modified: / 15-06-2005 / 17:31:56 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3168
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3169
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3170
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3171
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3172
version
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  3173
    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.143 2013-01-25 13:34:35 cg Exp $'
12164
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  3174
!
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  3175
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  3176
version_CVS
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  3177
    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.143 2013-01-25 13:34:35 cg Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3178
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3179
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  3180
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3181
Timestamp initialize!