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