Timestamp.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 13 Feb 2010 23:34:44 +0000
branchjv
changeset 17751 b2273fa8d59f
parent 17735 6a5bc05f696a
child 17757 73caeb68bf1f
permissions -rw-r--r--
Merged with /trunk
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
154
d4236ec280a6 *** empty log message ***
claus
parents: 92
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
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
    15
	instanceVariableNames:'osTime'
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
    16
	classVariableNames:''
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
    17
	poolDictionaries:''
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    18
	category:'Magnitude-Time'
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    19
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    20
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    21
Object subclass:#TimestampBuilderAbstract
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    22
	instanceVariableNames:'year month day hour minute second millisecond'
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    23
	classVariableNames:''
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    24
	poolDictionaries:''
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    25
	privateIn:Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    26
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    27
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    28
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    29
	instanceVariableNames:'stream'
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    30
	classVariableNames:''
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    31
	poolDictionaries:''
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    32
	privateIn:Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    33
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
    34
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    35
!Timestamp class methodsFor:'documentation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    36
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    37
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    39
 COPYRIGHT (c) 1989 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 92
diff changeset
    40
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    41
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    42
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    43
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    44
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    45
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    46
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    47
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    48
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    49
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    50
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    51
documentation
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    52
"
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    53
    This class represents time values in milliSeconds starting some
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    54
    time in the past. 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    55
    (typically, from 1st. Jan 1970, as used in the Unix operating system,
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    56
     but other systems may bias the time differently.
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    57
     Actually, the implementation does not depend or even know which time/date 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    58
     the OperatingSystem bases its time upon - it is simply keeping the value(s)
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    59
     as returned from the OS.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    60
     For conversion, these values are given back to the OS, which will know
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    61
     how to convert these times. This has the advantage, that timestamps on files 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    62
     (such as last-access-time or last-modification-time) can be handled transparently - 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    63
     especially when performing comparisons).
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    64
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    65
    You should not interpret the osTime instance variable directly, instead
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    66
    (if at all), ask the OS to convert.
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    67
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    68
    The implementation of this class is not the same as in ST-80 
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    69
    (which represents the time as seconds from Jan 1., 1901).
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    70
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    71
    This class should not be confused with Time (which only represents the
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    72
    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
    73
    instances of Timestamp can.
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    74
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    75
    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
    76
    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
    77
    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
    78
    AbsoluteTime is still kept as an alias for backward compatibility.
3479
9ca6229713f4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3122
diff changeset
    79
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    80
    [author:]
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    81
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    82
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    83
    [See also:]
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    84
        Time Date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    85
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    86
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    87
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    88
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    89
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    90
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    91
initialize
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    92
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    93
    AbsoluteTime := self.       "backward compatibility"
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    94
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    95
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    96
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    97
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
    98
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    99
    "return an instance of the receiver, given individual components.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   100
     See also `Timestamp now' and other protocol inherited
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   101
     from my superclass."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   102
423
claus
parents: 392
diff changeset
   103
    ^ self basicNew 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   104
        fromOSTime:(OperatingSystem 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   105
                        computeOSTimeFromUTCYear:y month:m day:d 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   106
                                         hour:h minute:min second:s
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   107
                                         millisecond:millis)
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   108
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   109
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   110
     Timestamp UTCYear:1970 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   111
     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
   112
     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
   113
     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
   114
     Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   115
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   116
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   117
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   118
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   119
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   120
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   121
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   122
day:d month:m year:y hour:h minutes:min seconds:s
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   123
    "This is obsolete. User #year:month:day:hour:minute:second:"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   124
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   125
    ^ self 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   126
        year:y month:m day:d hour:h 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   127
        minute:min second:s millisecond:0
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   128
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   129
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   130
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   131
     Timestamp day:8 month:1 year:1995 hour:0 minute:43 second:48 
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   132
    "
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   133
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   134
    "Modified: / 1.7.1996 / 15:22:26 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   135
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   136
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   137
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   138
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   139
    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   140
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   141
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   142
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   143
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   144
     Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   145
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   146
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   147
    "
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   148
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   149
    "Created: / 1.7.1996 / 14:46:09 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   150
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   151
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   152
!
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   153
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   154
decodeFromLiteralArray:anArray
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   155
    "decode an Timestamp literalArray.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   156
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   157
     anArray may be:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   158
        #(Timestamp '200004182000.123')
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   159
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   160
     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
   161
     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
   162
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   163
        #(Timestamp #osTime: 12345678)     
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   164
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   165
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   166
    (anArray at:2) == #osTime: ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   167
        ^ self new osTime:(anArray at:3).
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   168
    ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   169
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   170
    ^ self 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   171
        readGeneralizedFrom:(anArray at:2) 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   172
        onError:[ self conversionErrorSignal 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   173
                    raiseErrorString:'literal array decoding' ]
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   174
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   175
    "
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   176
     Timestamp
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   177
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')      
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   178
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   179
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   180
423
claus
parents: 392
diff changeset
   181
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   182
    "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
   183
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   184
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   185
     from my superclass."
423
claus
parents: 392
diff changeset
   186
claus
parents: 392
diff changeset
   187
    ^ self 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   188
        year:aDate year 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   189
        month:aDate month 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   190
        day:aDate day 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   191
        hour:aTime hours 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   192
        minute:aTime minutes 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   193
        second:aTime seconds 
423
claus
parents: 392
diff changeset
   194
claus
parents: 392
diff changeset
   195
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   196
     Timestamp fromDate:(Date today) andTime:(Time now)  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   197
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   198
     Timestamp now 
423
claus
parents: 392
diff changeset
   199
    "
claus
parents: 392
diff changeset
   200
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   201
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   202
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   203
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   204
!
claus
parents: 392
diff changeset
   205
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   206
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   207
    "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
   208
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   209
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   210
    ^ (Date newDay:dayInYear year:year) asTimestamp
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   211
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   212
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   213
     Timestamp newDay:183 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   214
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   215
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   216
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   217
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   218
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   219
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   220
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   221
     The string is interpreted as 24 hour format, as printed.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   222
     Notice, that this is not the storeString format and 
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   223
     is different from the format expected by readFrom:.
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   224
     The format read here is dd-mm-yyyy hh:mm:ss.iii"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   225
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   226
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   227
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   228
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   229
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
   230
    Error handle:[:ex |
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   231
        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
   232
    ] do:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   233
        newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   234
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   235
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   236
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   237
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   238
     Timestamp readFrom:'20-2-1995 13:11:06'                            
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   239
     Timestamp readFrom:'20-2-1995 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   240
     Timestamp readFrom:'20-2-2001 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   241
     Timestamp readFrom:'20-2-1995 13:11:06.100'                        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   242
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   243
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'      
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   244
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   245
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   246
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   247
     Timestamp readFrom:'foo' onError:'wrong'                           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   248
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'                     
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   249
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   250
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   251
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   252
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   253
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   254
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   255
readGeneralizedFrom:aStringOrStream 
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   256
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   257
     The format read here is either
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   258
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   259
     or:
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   260
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   261
     The string is interpreted as 24 hour format, as printed.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   262
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   263
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   264
     so read this before changing anything here.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   265
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   266
     Notice, that this is not the storeString format and 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   267
     is different from the format expected by readFrom:.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   268
    "
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   269
    ^ self 
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   270
        readGeneralizedFrom:aStringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   271
        short:false
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   272
        onError:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   273
            self conversionErrorSignal raiseErrorString:'Timestamp format error' 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   274
        ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   275
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   276
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   277
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   278
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   279
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   280
    "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
   281
     The format read here is either
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   282
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   283
     or:
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   284
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   285
     The string is interpreted as 24 hour format, as printed.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   286
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   287
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   288
     so read this before changing anything here.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   289
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   290
     Notice, that this is not the storeString format and 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   291
     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
   292
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   293
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   294
    ^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   295
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   296
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   297
     |s|
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   298
     s := '' writeStream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   299
     Timestamp now printGeneralizedOn:s.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   300
     Timestamp readGeneralizedFrom:s contents onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   301
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   302
 Daylight saving time:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   303
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   304
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   305
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   306
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   307
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   308
 No daylight saving time:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   309
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   310
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   311
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   312
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   313
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   314
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]   
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   315
     Timestamp readGeneralizedFrom:'199502201311' onError:[]    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   316
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   317
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   318
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   319
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'                     
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   320
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   321
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]   
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   322
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   323
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   324
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   325
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   326
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   327
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   328
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   329
    "Modified: / 22-08-2006 / 12:30:11 / cg"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   330
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   331
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   332
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   333
    "return a new Timestamp, reading a printed representation from aStream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   334
     The long format read here is either
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   335
            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   336
        or:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   337
            yyyy-mm-dd HH:MM:SS.iii +uuuu.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   338
     The (not recommended) short forms are:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   339
            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   340
        or:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   341
            yy-mm-dd HH:MM:SS.iii +uuuu.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   342
     The string is interpreted as 24 hour format, as printed.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   343
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   344
     This format is used for BER specification of the ASN.1 GeneralizedTime and
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   345
     UTCTime as defined in X.208 Sec. 33, so read this before changing anything here.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   346
     The short form is no longer recommended.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   347
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   348
     Notice, that this is not the storeString format and 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   349
     is different from the format expected by readFrom:.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   350
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   351
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   352
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   353
    ^ [
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   354
        |newTime str day month year hour min sec millis c|
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   355
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   356
        sec := millis := 0.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   357
        str := aStringOrStream readStream.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   358
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   359
        shortFormat ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   360
            year := Integer readFrom:(str next:2).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   361
            year < 50 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   362
                year := year + 2000.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   363
            ] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   364
                year := year + 1900.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   365
            ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   366
        ] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   367
            year := Integer readFrom:(str next:4).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   368
        ].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   369
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   370
        month := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   371
        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   372
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   373
        day := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   374
        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   375
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   376
        str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   377
        hour:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   378
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   379
        str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   380
        min:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   381
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   382
        str atEnd ifFalse:[
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   383
            str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   384
            sec := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   385
            (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   386
            str atEnd ifFalse:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   387
                str peek == $. ifTrue:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   388
                    str next.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   389
                    millis := Integer readFrom:str.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   390
                ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   391
                str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   392
            ].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   393
        ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   394
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   395
        str atEnd ifTrue:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   396
            "/ this is local time
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   397
            newTime := self year:year month:month day:day 
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   398
                            hour:hour minute:min second:sec millisecond:millis.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   399
        ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   400
            c := str next.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   401
            c ~~ $Z ifTrue:[ 
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   402
                |tzh tzmin|
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   403
                tzh := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   404
                tzmin := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   405
                c == $+ ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   406
                    "the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   407
                    hour := hour - tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   408
                    min := min - tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   409
                ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   410
                    c ~~ $- ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   411
                        ^ exceptionBlock value.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   412
                    ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   413
                    "the timezone is behind of UTC or WEST from Greenwich: add hours and minutes"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   414
                    hour := hour + tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   415
                    min := min + tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   416
                ].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   417
            ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   418
            "this is UTC time"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   419
            newTime := self UTCYear:year month:month day:day 
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   420
                              hour:hour minute:min second:sec millisecond:millis.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   421
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   422
        newTime
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   423
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   424
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   425
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
   426
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
   427
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   428
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   429
     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
   430
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   431
     Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[] 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   432
     Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[]    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   433
     Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[]    
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   434
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   435
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   436
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   437
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   438
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   439
     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
   440
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   441
 No daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   442
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   443
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   444
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   445
     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
   446
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   447
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]   
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   448
     Timestamp readGeneralizedFrom:'199502201311' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   449
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   450
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   451
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   452
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'                     
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   453
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   454
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]   
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   455
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   456
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] 
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   457
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   458
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] 
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   459
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   460
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   461
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   462
    "Modified: / 22-08-2006 / 12:30:11 / cg"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   463
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   464
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   465
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   466
    "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
   467
     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
   468
     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
   469
     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
   470
     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
   471
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   472
     On error, raise an exception.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   473
     Please use this format for all external representations - its the standard."
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   474
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   475
    ^ self
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   476
        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   477
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   478
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   479
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   480
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   481
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   482
     Timestamp readIso8601FormatFrom:'1995T13:11'           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   483
     Timestamp readIso8601FormatFrom:'1995T13'              
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   484
     Timestamp readIso8601FormatFrom:'1995'              
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   485
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   486
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   487
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   488
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   489
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   490
   24 is allowed with ISO, and is 00:00 of the next day:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   491
     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
   492
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   493
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   494
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   495
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   496
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   497
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   498
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   499
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   500
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   501
     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
   502
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   503
     On error, raise an exception.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   504
     Please use this format for all external representations - its the standard."
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   505
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   506
    ^ self
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   507
        readIso8601FormatFrom:aStringOrStream 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   508
        yearAlreadyRead:nil 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   509
        onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   510
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   511
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   512
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   513
    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   514
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   515
"/    All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   516
"/    also known as Greenwich Mean Time (GMT), without exception. 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   517
"/    This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   518
"/    and should be assumed when reading the asctime format.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   519
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   520
"/    HTTP-date      = rfc1123-date | rfc850-date | asctime-date
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   521
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   522
"/    rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   523
"/    rfc850-date    = weekday "," SP date2 SP time SP "GMT"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   524
"/    asctime-date   = wkday SP date3 SP time SP 4DIGIT
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   525
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   526
"/    date1          = 2DIGIT SP month SP 4DIGIT
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   527
"/                     ; day month year (e.g., 02 Jun 1982)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   528
"/    date2          = 2DIGIT "-" month "-" 2DIGIT
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   529
"/                     ; day-month-year (e.g., 02-Jun-82)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   530
"/    date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   531
"/                     ; month day (e.g., Jun  2)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   532
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   533
"/    time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   534
"/                     ; 00:00:00 - 23:59:59
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   535
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   536
"/    wkday          = "Mon" | "Tue" | "Wed"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   537
"/                   | "Thu" | "Fri" | "Sat" | "Sun"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   538
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   539
"/    weekday        = "Monday" | "Tuesday" | "Wednesday"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   540
"/                   | "Thursday" | "Friday" | "Saturday" | "Sunday"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   541
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   542
"/    month          = "Jan" | "Feb" | "Mar" | "Apr"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   543
"/                   | "May" | "Jun" | "Jul" | "Aug"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   544
"/                   | "Sep" | "Oct" | "Nov" | "Dec"
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   545
"/
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   546
"/    Mon, 17 Aug 2009 11:11:15 GMT
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   547
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   548
    rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   549
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   550
    parts := rfc1123String subStrings:Character space.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   551
    parts size == 6 ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   552
        indexModifier := 0.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   553
    ] ifFalse:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   554
        parts size == 5 ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   555
            indexModifier := -1.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   556
        ] ifFalse:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   557
            ^ exceptionBlock value
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   558
        ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   559
    ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   560
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   561
    utcOffsetString := (parts at:6 + indexModifier).
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   562
    ((utcOffsetString sameAs:'GMT') or:[utcOffsetString sameAs:'UTC']) ifFalse:[ 
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   563
        self assert:utcOffsetString size == 5.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   564
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   565
        utcOffset := (utcOffsetString from:4 to:5) asString asNumber * 60.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   566
        utcOffset := utcOffset + ((utcOffsetString from:2 to:3) asString asNumber * 60 * 60).
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   567
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   568
        (utcOffsetString at:1) asSymbol == #- ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   569
            utcOffset := -1 * utcOffset.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   570
        ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   571
    ].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   572
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   573
    day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   574
    year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   575
    time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   576
    monthName := parts at:3 + indexModifier.
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   577
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   578
    month := (1 to:12) asOrderedCollection detect:[:i | 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   579
        (Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   580
    ] ifNone:[^ exceptionBlock].    
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   581
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   582
    ^ (Timestamp 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   583
        fromDate:(Date newDay:day monthIndex:month year:year) 
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   584
        andTime:time) + utcOffset       
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   585
!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   586
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   587
secondsSince1970:sec
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   588
    "set time from elapsed seconds since 1-1-1970, 0:0:0.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   589
     This is the format used in the UNIX world"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   590
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   591
    |divMod|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   592
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   593
    divMod := sec divMod:3600.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   594
    ^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2) millisecond:0.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   595
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   596
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   597
     Timestamp secondsSince1970:0      
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   598
     Timestamp secondsSince1970:3600
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   599
     Timestamp secondsSince1970:3600*24
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   600
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   601
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   602
    "Created: / 21.10.1996 / 17:48:30 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   603
    "Modified: / 13.7.1999 / 12:31:22 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   604
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   605
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   606
year:y month:m day:d hour:h minute:min second:s
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   607
    "return an instance of the receiver, given individual components.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   608
     See also `Timestamp now' and other protocol inherited
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   609
     from my superclass."
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   610
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   611
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:0
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   612
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   613
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   614
     Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   615
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   616
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   617
     Timestamp year:2000 month:1 day:1 hour:1 minutes:0 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   618
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   619
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   620
    "Modified: / 1.7.1996 / 15:22:07 / cg"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   621
    "Created: / 13.7.1999 / 12:06:39 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   622
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   623
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   624
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   625
year:y month:m day:d hour:h minute:min second:s millisecond:millis
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   626
    "return an instance of the receiver, given individual components.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   627
     See also `Timestamp now' and other protocol inherited
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   628
     from my superclass."
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   629
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   630
    ^ self basicNew 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   631
        fromOSTime:(OperatingSystem 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   632
                        computeOSTimeFromYear:y month:m day:d 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   633
                                         hour:h minute:min seconds:s millis:millis)
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   634
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   635
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   636
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   637
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   638
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   639
     Timestamp year:2000 month:1 day:1 hour:1 minute:0 second:0 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   640
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   641
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   642
    "Modified: / 1.7.1996 / 15:22:07 / cg"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   643
    "Created: / 13.7.1999 / 12:28:44 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   644
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   645
! !
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   646
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   647
!Timestamp class methodsFor:'Compatibility-Squeak'!
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   648
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   649
current
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   650
    ^ self now
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   651
! !
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   652
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   653
!Timestamp class methodsFor:'private'!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   654
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   655
basicReadFrom:aStream
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   656
    "return a new Timestamp, reading a printed representation from aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   657
     The string is interpreted as 24 hour format, as printed.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   658
     Notice, that this is not the storeString format and 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   659
     is different from the format expected by readFrom:.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   660
     KLUDGE: 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   661
        us and non-us format have different ordering of day and month;
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   662
        The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   663
        or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   664
     On error, raise an exception"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   665
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   666
    |firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName|
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   667
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   668
    firstNumber := Integer readFrom:aStream onError:[ConversionError raiseErrorString:' - integer expected'].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   669
    firstNumber > 31 ifTrue:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   670
        "/ assume iso8601 format;
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   671
        ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   672
    ].
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   673
    aStream skipSeparators.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   674
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   675
    "/ consider this a kludge
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   676
    usFormat := (aStream peek == $/ ).
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   677
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   678
    [aStream peek isLetterOrDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   679
    aStream peek isDigit ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   680
        secondNumber := Integer readFrom:aStream onError:-1.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   681
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   682
        usFormat ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   683
            month := firstNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   684
            day := secondNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   685
        ] ifFalse:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   686
            month := secondNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   687
            day := firstNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   688
        ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   689
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   690
    ] ifFalse:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   691
        possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   692
        month := Date indexOfMonth:possibeMonthName asLowercase.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   693
        day := firstNumber.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   694
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   695
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   696
    (day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:' - bad day' ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   697
    (month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:' - bad month' ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   698
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   699
    [aStream peek isDigit] whileFalse:[aStream next].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   700
    year := Integer readFrom:aStream onError:[ ConversionError raiseErrorString:' - bad year' ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   701
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   702
    aStream atEnd ifTrue:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   703
        hour := min := sec := millis := 0.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   704
    ] ifFalse:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   705
        [aStream peek isDigit] whileFalse:[aStream next].
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   706
        hour := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   707
        (hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:' - bad hour' ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   708
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   709
        [aStream peek isDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   710
        min := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   711
        (min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad minute' ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   712
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   713
        aStream atEnd ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   714
            sec := millis := 0.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   715
        ] ifFalse:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   716
            [aStream peek isDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   717
            sec := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   718
            (sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad second' ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   719
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   720
            aStream peek = $. ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   721
                aStream next.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   722
                millis := Integer readFrom:aStream onError:0.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   723
                millis >= 1000 ifTrue:[ ConversionError raiseErrorString:' - bad millisecond' ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   724
            ] ifFalse:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   725
                millis := 0.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   726
            ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   727
        ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   728
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   729
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   730
    "special check - only 24:00:00 is allowed;
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   731
     every time after that must wrap"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   732
    hour == 24 ifTrue:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   733
        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ ConversionError raiseErrorString:' - bad hour' ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   734
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   735
    ^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   736
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   737
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   738
     Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   739
     Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   740
     (Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   741
     (Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   742
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream       
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   743
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream    
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   744
     Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream  
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   745
     Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   746
     Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   747
     Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   748
     Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   749
     Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   750
     Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream   
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   751
     Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   752
     Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   753
     Timestamp basicReadFrom:'foo' readStream                    
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   754
     Timestamp basicReadFrom:(Timestamp now printString readStream)                  
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   755
     Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   756
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   757
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   758
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   759
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   760
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   761
    "common helper for read methods.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   762
     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
   763
     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
   764
     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
   765
     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
   766
     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
   767
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   768
     On error, raise an exception.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   769
     Please use this format for all external representations - its the standard."
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   770
7008
e154492de5d8 Remove unused method vars
Stefan Vogel <sv@exept.de>
parents: 7006
diff changeset
   771
    |str day month year hour min sec millis fraction|
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   772
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   773
    str := aStringOrStream readStream.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   774
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   775
    month := day := 1.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   776
    hour := min := sec := millis := 0.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   777
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   778
    yearOrNil notNil ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   779
        year := yearOrNil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   780
    ] ifFalse:[
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   781
        year := Integer readFrom:str onError:nil.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   782
        year isNil ifTrue:[ ConversionError raiseErrorString:' - bad year' ]
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   783
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   784
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   785
    str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   786
    str peek == $- ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   787
        str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   788
        "/ month follows.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   789
        month := Integer readFrom:str.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   790
        (month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:' - bad month' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   791
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   792
        str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   793
        str peek == $- ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   794
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   795
            "/ day follows.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   796
            day := Integer readFrom:str.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   797
            (day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:' - bad day' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   798
        ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   799
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   800
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   801
    str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   802
    str atEnd ifFalse:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   803
        "time follows"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   804
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   805
        str peek == $T ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   806
            "we treat the T as optional here"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   807
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   808
            str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   809
        ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   810
        hour := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   811
        (hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:' - bad hour' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   812
        str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   813
        str peek == $: ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   814
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   815
            "/ minutes follow.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   816
            min := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   817
            (min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad minute' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   818
            str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   819
            str peek == $: ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   820
                str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   821
                "/ seconds follow.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   822
                sec := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   823
                (sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad seconds' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   824
                str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   825
                str peek == $. ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   826
                    str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   827
                    "/ millis follow.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   828
                    fraction := Number readMantissaFrom:str radix:10.    
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   829
                    millis := (1000 * fraction) rounded.  "/ mhmh - should it be truncated ?
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   830
                ]
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   831
            ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   832
        ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   833
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   834
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   835
    "special check - only 24:00:00 is allowed;
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   836
     every time after that must wrap"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   837
    hour == 24 ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   838
        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ ConversionError raiseErrorString:' - bad hour' ].
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   839
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   840
    ^ self 
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   841
        year:year month:month day:day 
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   842
        hour:hour minute:min second:sec millisecond:millis.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   843
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   844
    "
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   845
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'    
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   846
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   847
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   848
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   849
     Timestamp readIso8601FormatFrom:'1995T13:11'           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   850
     Timestamp readIso8601FormatFrom:'1995T13'              
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   851
     Timestamp readIso8601FormatFrom:'1995'              
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   852
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   853
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   854
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   855
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   856
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   857
   24 is allowed with ISO, and is 00:00 of the next day:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   858
     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
   859
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   860
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   861
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   862
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   863
    "common helper for read methods.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   864
     Return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   865
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   866
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   867
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   868
     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
   869
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   870
     On error, raise an exception.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   871
     Please use this format for all external representations - its the standard."
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   872
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   873
    |retVal|
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   874
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   875
    ConversionError handle:[:ex |
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   876
        retVal := exceptionValue value
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   877
    ] do:[
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   878
        retVal := self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   879
    ].
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   880
    ^ retVal
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   881
! !
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   882
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   883
!Timestamp class methodsFor:'reading'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   884
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   885
readISO8601From: stringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   886
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   887
    ^TimestampISO8601Builder read: stringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   888
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   889
    "Created: / 16-06-2005 / 16:13:36 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   890
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   891
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   892
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   893
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   894
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   895
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   896
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   897
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   898
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   899
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
   900
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   901
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   902
     Timestamp now day 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   903
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   904
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   905
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   906
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   907
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   908
dayInWeek
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   909
    "return the week-day of the receiver - 1 for monday, 7 for sunday
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   910
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   911
     WARNING: does not care for pre-julian dates 
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   912
        (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
   913
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   914
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   915
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   916
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   917
     Timestamp now dayInWeek 
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   918
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   919
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   920
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   921
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   922
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   923
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   924
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   925
    "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
   926
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   927
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   928
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   929
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   930
     Timestamp now dayInYear 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   931
     Timestamp newDay:184 year:1996  
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   932
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   933
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   934
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   935
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   936
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   937
hour
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   938
    "return the hour (0..23).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   939
     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
   940
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   941
    ^ self hours
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   942
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   943
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   944
    "Modified: 1.7.1996 / 15:15:32 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   945
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   946
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   947
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   948
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   949
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   950
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
   951
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   952
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   953
     Timestamp now hours  
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   954
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   955
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   956
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   957
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   958
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   959
millisecond
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   960
    "return the millisecond (0..999).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   961
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   962
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   963
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   964
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   965
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   966
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   967
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   968
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   969
milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   970
    "return the milliseconds (0..999)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   971
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   972
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   973
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   974
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   975
     Timestamp now milliseconds   
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   976
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   977
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   978
    "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
   979
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   980
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   981
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   982
minute
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   983
    "return the minute (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   984
     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
   985
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   986
    ^ self minutes
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   987
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   988
    "Created: 1.7.1996 / 15:14:29 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   989
    "Modified: 1.7.1996 / 15:15:37 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   990
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   991
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   992
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   993
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   994
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   995
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   996
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   997
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   998
     Timestamp now minutes 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   999
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1000
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1001
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1002
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1003
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1004
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1005
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1006
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1007
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1008
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1009
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1010
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1011
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1012
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1013
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1014
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1015
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1016
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1017
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1018
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1019
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1020
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1021
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1022
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1023
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1024
osTime:aTime
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1025
    "set the internal representation of the time"
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1026
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1027
    osTime := aTime.
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1028
!
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1029
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1030
second
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1031
    "return the second (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1032
     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
  1033
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1034
    ^ self seconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1035
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1036
    "Created: 1.7.1996 / 15:14:19 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1037
    "Modified: 1.7.1996 / 15:15:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1038
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1039
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1040
seconds
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1041
    "return the seconds (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1042
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1043
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1044
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1045
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1046
     Timestamp now seconds 
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1047
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1048
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1049
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1050
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1051
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1052
timeInfo
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1053
    ^ (OperatingSystem computeTimeAndDateFrom:osTime)
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1054
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1055
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1056
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1057
    "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
  1058
     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
  1059
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1060
     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
  1061
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1062
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1063
     If utcOffset is negative, the local timezone is east of Greenwich.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1064
     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
  1065
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1066
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1067
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1068
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1069
     Timestamp now utcOffset 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1070
     (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
  1071
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1072
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1073
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1074
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1075
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1076
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1077
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1078
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1079
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1080
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1081
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1082
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1083
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1084
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1085
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1086
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1087
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1088
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1089
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1090
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1091
10736
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1092
deltaFrom:aTimestamp
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1093
    "return the delta as a timeDuration between 2 timeStamps.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1094
     The argument is supposed to be BEFORE the receiver"
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1095
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1096
    ^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds))
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1097
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1098
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1099
     |t1 t2|
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1100
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1101
     t1 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1102
     Delay waitForSeconds:0.5.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1103
     t2 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1104
     t2 deltaFrom:t1   
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1105
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1106
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1107
    "Created: / 04-10-2007 / 13:34:28 / cg"
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1108
!
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
  1109
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1110
millisecondDeltaFrom:aTimestamp
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
  1111
    "return the delta in milliseconds between 2 absolute times.
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1112
     The argument is supposed to be BEFORE the receiver"
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1113
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1114
    ^ self getMilliseconds - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1115
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1116
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1117
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1118
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1119
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1120
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1121
     t2 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1122
     t2 millisecondDeltaFrom:t1   
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1123
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1124
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
  1125
    "Modified: / 5.6.1998 / 04:21:33 / cg"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1126
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1127
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1128
secondDeltaFrom:aTimestamp
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1129
    "return the delta in seconds between 2 absolute times.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1130
     The argument is supposed to be BEFORE the receiver"
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1131
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1132
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1133
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1134
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1135
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1136
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1137
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1138
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1139
     t2 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1140
     t2 secondDeltaFrom:t1   
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1141
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1142
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  1143
    "Modified: / 5.6.1998 / 04:21:33 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1144
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1145
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1146
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1147
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1148
= aTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1149
    "return true if the argument, aTime represents the same time"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1150
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1151
    (aTime species == self species) ifFalse:[^ false].
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1152
    ^ (self getMilliseconds = aTime getMilliseconds)
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1153
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1154
    "Modified: 3.7.1996 / 13:10:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1155
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1156
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1157
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1158
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1159
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1160
    ^ osTime // 1000
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1161
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  1162
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1163
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1164
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1165
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1166
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1167
asAbsoluteTime
8254
73b6109ab982 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8246
diff changeset
  1168
    "deprecated, use #asTimestamp"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1169
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1170
    <resource:#obsolete>
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1171
9061
20af48b9b295 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9056
diff changeset
  1172
    self obsoleteMethodWarning:'use #asTimestamp'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1173
    ^ self
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1174
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1175
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1176
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1177
    "return a Date object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1178
     The returned date will only represent the day - not the timeOfDay."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1179
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1180
    ^ Date fromOSTime:osTime 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1181
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1182
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1183
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1184
     Timestamp now asDate
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1185
     (Timestamp now addTime:3600) asDate 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1186
     (Timestamp now addTime:3600) asTime 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1187
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1188
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1189
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1190
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1191
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1192
asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1193
    "convert an utc timestamp to local time "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1194
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1195
    ^ self - self utcOffset
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1196
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1197
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1198
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1199
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1200
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1201
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1202
7466
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1203
asMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1204
    "return the number of milliSeconds elapsed since whatever time the
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1205
     OperatingSystem bases its time upon. Since this is totally
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1206
     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
  1207
     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
  1208
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1209
    ^ self getMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1210
!
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1211
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1212
asNative
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1213
	#swAdded.
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1214
	^self
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1215
!
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1216
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1217
asSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1218
    "return the number of seconds elapsed since whatever time the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1219
     OperatingSystem bases its time upon. Since this is totally
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1220
     OS-dependent, do not interpret the value returned by this method.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1221
     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
  1222
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1223
    ^ self getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1224
7004
6cd2080ea0a3 added asUTCSecondsSince1901
penk
parents: 6955
diff changeset
  1225
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1226
     Timestamp now asSeconds
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1227
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1228
     Time hour:23 minutes:33 seconds:0         
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1229
     Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1230
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1231
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1232
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1233
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1234
    "return a Time object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1235
     The returned time will only represent the timeOfDay - not the day."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1236
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1237
    ^ Time fromOSTime:osTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1238
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1239
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1240
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1241
     Timestamp now asTime
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1242
     (Timestamp now addTime:3600) asTime 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1243
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1244
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1245
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1246
asTimestamp
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1247
    "return an Timestamp object from the receiver - thats the receiver."
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1248
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1249
    ^ self 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1250
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1251
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1252
asUtcTimestamp
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1253
    "convert a local time timestamp to UTC"
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1254
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1255
    ^ self + self utcOffset
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1256
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1257
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1258
     Timestamp now asUtcTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1259
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1260
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1261
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1262
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1263
    "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
  1264
     can be reconstructed with #decodeAsLiteralArray.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1265
     The encoding is: 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1266
        (#Timestamp YYYYMMDDhhmmss.iii)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1267
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1268
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1269
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1270
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1271
    s := WriteStream on:(String new:18).
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1272
    self printGeneralizedOn:s isLocal:true.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1273
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1274
    ^ Array
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1275
        with:self class name
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1276
        with:s contents
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1277
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1278
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1279
      Timestamp now literalArrayEncoding
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1280
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1281
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1282
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1283
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1284
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1285
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1286
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1287
"   
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1288
    secondsBetween1901and1970 := 
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1289
        ((Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901))
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1290
        *  (24 * 60 * 60)
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1291
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1292
9449
6ba774be6aa1 stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents: 9433
diff changeset
  1293
    ^ self utcSecondsSince1970 + 2177452800.  
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1294
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1295
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1296
     Timestamp now utcSecondsSince1901 
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1297
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1298
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1299
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1300
!Timestamp methodsFor:'printing'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1301
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1302
printISO8601
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1303
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1304
    ^ TimestampISO8601Builder print: self
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1305
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1306
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1307
     Timestamp now printISO8601           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1308
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1309
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1310
    "Created: / 16-06-2005 / 16:11:15 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1311
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1312
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1313
printISO8601Compressed
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1314
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1315
    ^ TimestampISO8601Builder printCompressed: self
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1316
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1317
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1318
     Timestamp now printISO8601Compressed           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1319
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1320
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1321
    "Created: / 16-06-2005 / 16:11:31 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1322
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1323
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1324
printISO8601CompressedOn: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1325
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1326
    TimestampISO8601Builder printCompressed: self on: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1327
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1328
    "Created: / 16-06-2005 / 16:11:50 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1329
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1330
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1331
printISO8601On: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1332
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1333
    TimestampISO8601Builder print: self on: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1334
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1335
    "Created: / 16-06-2005 / 16:11:07 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1336
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1337
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1338
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1339
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1340
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1341
    "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
  1342
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1343
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1344
    self asDate addPrintBindingsTo:dict language:languageOrNil.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1345
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1346
    self year == Date today year ifTrue:[
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1347
        dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m').
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1348
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1349
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1350
    super addPrintBindingsTo:dict language:languageOrNil.
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  1351
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  1352
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1353
printGeneralizedOn:aStream 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1354
    "append a representation of the receiver to aStream in a general format,
9385
f46f04a13052 comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
  1355
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1356
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1357
     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
  1358
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1359
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1360
    ^ self printGeneralizedOn:aStream isLocal:false short:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1361
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1362
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1363
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1364
    "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
  1365
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1366
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1367
     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
  1368
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1369
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1370
     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
  1371
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1372
    self printGeneralizedOn:aStream isLocal:isLocal short:false
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1373
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1374
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1375
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1376
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1377
     Time now printOn:Transcript. Transcript cr.           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1378
     Date today printOn:Transcript. Transcript cr.        
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1379
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1380
     Time now asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1381
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1382
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1383
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1384
     Date today printOn:Transcript. Transcript cr.           
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1385
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1386
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1387
    "Modified: / 1.7.1996 / 15:20:59 / cg"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1388
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1389
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1390
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1391
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1392
    "append a representation of the receiver to aStream in a general format,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1393
     top-down, without separators;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1394
        long format:  'yyyymmddHHMMSS.mmm+0100'
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1395
        short format: 'yymmddHHMMSS.mmm+0100'
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1396
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1397
     This format is used for the ASN.1 GeneralizedTime and UTCTime
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1398
     as defined in X.208 Sec. 33, so read this before changing the output format.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1399
     The short format is no longer recommended.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1400
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1401
     If isLocal is true, represent as local time, otherwise add UTC time offset."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1402
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1403
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1404
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1405
    t := OperatingSystem computeTimeAndDateFrom:osTime.
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1406
    shortFormat ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1407
        self assert:(t year between:1951 and:2049).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1408
        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1409
    ] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1410
        t year    printOn:aStream leftPaddedTo:4 with:$0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1411
    ].
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1412
    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
  1413
    t day     printOn:aStream leftPaddedTo:2 with:$0.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1414
    t hours   printOn:aStream leftPaddedTo:2 with:$0. 
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1415
    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
  1416
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1417
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1418
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1419
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1420
    isLocal ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1421
        "/ this should be printed as non-local-time
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1422
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1423
        off := t utcOffset.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1424
        off == 0 ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1425
            aStream nextPut:$Z.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1426
        ] ifFalse:[ |min|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1427
            off < 0 ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1428
                aStream nextPut:$+.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1429
                off := off negated.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1430
            ] ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1431
                aStream nextPut:$-.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1432
            ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1433
            min := off // 60.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1434
            min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1435
            min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1436
        ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1437
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1438
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1439
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1440
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1441
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1442
     Time now printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1443
     Date today printOn:Transcript. Transcript cr.        
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1444
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1445
     Time now asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1446
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1447
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1448
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1449
     Date today printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1450
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1451
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1452
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1453
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1454
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1455
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1456
printIso8601FormatOn:aStream
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1457
    "append the iso8601 UTC representation of the receiver to aStream.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1458
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1459
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1460
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1461
        1999-01-01
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1462
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1463
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1464
    |format|
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1465
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1466
    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1467
    self milliseconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1468
        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1469
        self seconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1470
            format := '%(year)-%(month)-%(day)T%h:%m'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1471
            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1472
                format := '%(year)-%(month)-%(day)'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1473
            ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1474
        ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1475
    ].
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1476
    self printOn:aStream format:format 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1477
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1478
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1479
     Timestamp now printIso8601FormatOn:Transcript   
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1480
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1481
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1482
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1483
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1484
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1485
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1486
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1487
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1488
    "/ now, use ISO format...
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1489
    self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'  
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1490
"/    self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'  
5678
5e1e70d18067 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5677
diff changeset
  1491
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'  
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1492
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1493
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1494
     Timestamp now printOn:Transcript. Transcript cr. 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1495
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1496
     Time now printOn:Transcript. Transcript cr.           
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1497
     Date today printOn:Transcript. Transcript cr.        
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1498
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1499
     Time now asTimestamp printOn:Transcript. Transcript cr.           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1500
     Timestamp now printOn:Transcript. Transcript cr. 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1501
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1502
     Date today asTimestamp printOn:Transcript. Transcript cr.           
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1503
     Date today printOn:Transcript. Transcript cr.           
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1504
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1505
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  1506
    "Modified: 1.7.1996 / 15:20:59 / cg"
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  1507
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1508
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1509
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1510
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1511
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1512
        'Fri, 04 Jul 2003 15:56:11 GMT'
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1513
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1514
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1515
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1516
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1517
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1518
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1519
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1520
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1521
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1522
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1523
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1524
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1525
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1526
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1527
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1528
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1529
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1530
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1531
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1532
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1533
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1534
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1535
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1536
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1537
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1538
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1539
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1540
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1541
    |meUTC timeInfo|
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1542
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1543
    meUTC := self class fromSeconds:((self asSeconds) + (self utcOffset)).
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1544
    timeInfo := meUTC timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1545
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1546
    aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek);
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1547
            nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1548
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1549
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1550
    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
  1551
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1552
"/ The following line is wrong, because the names are printed in the current locale!!
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1553
"/    timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT'. 
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1554
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1555
"/ the following is too slow for heavy use    
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1556
"/    timeInfo printOn:aStream format:' %y %h:%m:%s GMT'. 
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1557
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1558
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1559
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1560
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1561
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1562
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1563
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1564
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1565
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1566
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1567
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1568
    "
8414
dca52c2725ef comment
ca
parents: 8396
diff changeset
  1569
     Timestamp now printRFC1123FormatOn:Transcript   
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1570
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1571
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1572
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1573
printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1574
    "return the Iso8601 representation of the receiver.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1575
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1576
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1577
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1578
        1999-01-01
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1579
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1580
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1581
    ^ String streamContents:[:s | self printIso8601FormatOn:s]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1582
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1583
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1584
     Timestamp now printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1585
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1586
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1587
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1588
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1589
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1590
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1591
        'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1592
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1593
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1594
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1595
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1596
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1597
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1598
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1599
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1600
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1601
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1602
    "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
  1603
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1604
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1605
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1606
    aStream nextPut:$(; 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1607
            nextPutAll:self class name; 
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1608
            nextPutAll:' readIso8601FormatFrom:'''.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1609
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1610
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1611
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1612
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1613
     Timestamp now storeString 
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1614
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1615
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1616
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1617
    "
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1618
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1619
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1620
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1621
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1622
fromOSTime:anUninterpretedOSTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1623
    "strictly private: set the seconds from an OS time (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1624
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1625
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1626
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1627
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1628
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1629
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1630
getMilliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1631
    "strictly private: return the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1632
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1633
    ^ osTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1634
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1635
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1636
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1637
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1638
getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1639
    "strictly private: return the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1640
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1641
    ^ osTime // 1000
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1642
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1643
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1644
setMilliseconds:millis
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1645
    "strictly private: set the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1646
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1647
    osTime := millis.
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1648
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1649
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1650
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1651
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1652
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1653
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1654
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1655
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1656
    osTime := secs * 1000.
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  1657
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  1658
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1659
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1660
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1661
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1662
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1663
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1664
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1665
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1666
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1667
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1668
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1669
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1670
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1671
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1672
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1673
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1674
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1675
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1676
acceptVisitor:aVisitor with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1677
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1678
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1679
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1680
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1681
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1682
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1683
malformed: aString
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1684
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1685
    ConversionError raiseErrorString: aString
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1686
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1687
    "Created: / 15-06-2005 / 15:54:04 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1688
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1689
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1690
!Timestamp::TimestampBuilderAbstract methodsFor:'support'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1691
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1692
addHoursAndMinutes: arrayWithHoursAndMinutes
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1693
    "Add the given number of hours and minutes to the current timestamp state. If the time
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1694
    is to be subtracted, both numbers in the array must be negated. When the are not the same
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1695
    sign, the behavior may be strange. It's intended only for time zone corrections, where
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1696
    not more than 12 (in fact, 23) hours is added or subtracted (ie. date can be modified only
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1697
    one day forward or backward)."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1698
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1699
    | hours minutes |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1700
    hours := arrayWithHoursAndMinutes first.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1701
    minutes := arrayWithHoursAndMinutes second.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1702
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1703
    minutes isZero ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1704
	minute := minute + minutes.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1705
	minute >= 60 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1706
	    hours := hours + minute // 60.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1707
	    minute := minute \\ 60.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1708
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1709
	minute < 0 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1710
	    hours := hours + minute // 60.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1711
	    minute := (minute \\ 60) negated
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1712
	]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1713
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1714
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1715
    "Hours may get zero by time zone specification or by minutes modifications above."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1716
    hours isZero ifTrue: [^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1717
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1718
    "Add or subtract the hour and make date corrections if necessary."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1719
    hour := hour + hours.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1720
    hour < 0 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1721
	"Oops, got to previous day, must adjust even the date."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1722
	hour := 24 - ((hour negated) \\ 24).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1723
	day := day - 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1724
	day <= 0 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1725
	    "Got to previous month..."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1726
	    month := month - 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1727
	    month <= 0 ifTrue: [year := year - 1. month := 12].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1728
	    day := self lastDayInMonth: month]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1729
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1730
    hour >= 24 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1731
	hour := hour \\ 24.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1732
	day := day + 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1733
	day > (self lastDayInMonth: month) ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1734
	    month := month + 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1735
	    month > 12 ifTrue: [year := year + 1. month := 1].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1736
	    day := 1]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1737
    ]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1738
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1739
    "Created: / 15-06-2005 / 16:45:49 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1740
    "Modified: / 16-06-2005 / 15:04:45 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1741
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1742
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1743
dateFromDayNumber: anInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1744
    "Set month and day from an absolute number of the day in the year. 1.1. is day number one."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1745
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1746
    | leap |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1747
    leap := self isLeapYear: year.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1748
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1749
    (anInteger between: 1 and: 365) ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1750
	(leap and: [anInteger = 366])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1751
	    ifFalse: [self malformed: 'Bad day number: ' , anInteger printString]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1752
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1753
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1754
    self shouldImplement
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1755
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1756
    "Created: / 15-06-2005 / 11:27:35 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1757
    "Modified: / 16-06-2005 / 12:31:37 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1758
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1759
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1760
dateFromWeek: weekInteger andWeekday: dayInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1761
    "Compute the month and day. Find the first day (weekday) in the year, maybe even
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1762
    adjust the year. Both week and day are 1-based, the first week in a year is the one
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1763
    with thursday (or the one containing 4.1.)."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1764
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1765
    "Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1766
    (dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1767
    (weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1768
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1769
    self shouldImplement
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1770
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1771
    "Created: / 15-06-2005 / 11:29:42 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1772
    "Modified: / 15-06-2005 / 16:42:33 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1773
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1774
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1775
isAllowedDay: anInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1776
    "Answer whether the given day is allowed in the current month."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1777
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1778
    ^anInteger between: 1 and: (self lastDayInMonth: month)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1779
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1780
    "Created: / 15-06-2005 / 16:22:51 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1781
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1782
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1783
isLeapYear: anInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1784
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1785
    ^(anInteger bitAnd: 3) = 0 and: [anInteger \\ 100 > 0 or: [anInteger \\ 400 = 0]]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1786
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1787
    "Created: / 15-06-2005 / 16:16:31 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1788
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1789
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1790
lastDayInMonth: anInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1791
    "Answer the number of the last day of the given month in the current year."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1792
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1793
    ^anInteger = 2
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1794
	ifTrue: [(self isLeapYear: year) ifTrue: [29] ifFalse: [28]]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1795
	ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1796
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1797
    "Created: / 15-06-2005 / 17:12:31 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1798
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1799
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1800
timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1801
    "Answer the timestamp as it has been parsed."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1802
    "Notes:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1803
     - Should use UTCYear:... here? This will produce timezone-dependent timestamp.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1804
     - On UNIX, timestamps can only hold dates between 1970-01-01T01:00:00Z and 2038-01-19T00:00:00Z"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1805
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1806
    ^Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1807
	year: year month: month day: day
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1808
	hour: hour minute: minute second: second millisecond: millisecond
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1809
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1810
    "Created: / 15-06-2005 / 15:39:24 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1811
    "Modified: / 30-06-2005 / 16:48:25 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1812
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1813
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1814
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1815
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1816
documentation
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1817
"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1818
    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. Also, class
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1819
    methods can be used to print but the main reading job is done in instance protocol. It has been
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1820
    written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1821
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1822
    It produces timestamps, ie. when the string (or stream) contains only a time, an error will result
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1823
    (it may also pass in some cases but with the time undestood as date). It survives incomplete dates,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1824
    broken years, incomplete times and timezones. All times read with timezone difference are recomputed
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1825
    to UTC before the timestamp is created (even passing across new year boundary is handled correctly).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1826
    Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1827
    All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1828
    possible. For an example of what the builder can read, see the examples method and ISO 8601 itself.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1829
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1830
    [author:]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1831
        Martin Dvorak (masca@volny.cz)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1832
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1833
    [instance variables:]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1834
        stream          A stream the builder operates on. Assigned on each call to instance method #read:,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1835
                        so the builder instance can be reused (by at most one thread).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1836
        year            Current timestamp year. No default value, date must be present.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1837
        month           Current timestamp month. May change during parsing. Defaults to 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1838
        day             Current timestamp day. Defaults to 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1839
        hour            Current timestamp hour. Defaults to 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1840
        minute          Current timestamp minute. Defaults to 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1841
        second          Current timestamp second. Defaults to 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1842
        millisecond     Current timestamp millisecond. Defaults to 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1843
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1844
    [see also:]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1845
        Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1846
"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1847
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1848
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1849
examples
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1850
"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1851
    See the testing protocol on instance protocol (should be turned into a TestCase).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1852
    It covers the main features this builder has.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1853
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1854
    Just to introduce some coding examples, try:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1855
        TimestampISO8601Builder read: (TimestampISO8601Builder print: Timestamp now)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1856
"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1857
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1858
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1859
history
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1860
    "Created: / 16-06-2005 / 16:28:38 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1861
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1862
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1863
!Timestamp::TimestampISO8601Builder class methodsFor:'parsing'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1864
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1865
read: stringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1866
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1867
    ^self new read: stringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1868
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1869
    "Created: / 15-06-2005 / 17:52:03 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1870
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1871
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1872
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1873
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1874
print: aTimestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1875
    "Print the given timestamp in general ISO8601 format."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1876
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1877
    | stream |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1878
    stream := String new writeStream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1879
    self print: aTimestamp on: stream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1880
    ^stream contents
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1881
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1882
    "Created: / 15-06-2005 / 17:52:29 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1883
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1884
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1885
print: aTimestamp on: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1886
    "Print the given timestamp in general ISO8601 format."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1887
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1888
    aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1889
	nextPutAll: (aTimestamp year printStringRadix: 10 size: 4 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1890
	nextPut: $-;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1891
	nextPutAll: (aTimestamp month printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1892
	nextPut: $-;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1893
	nextPutAll: (aTimestamp day printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1894
	nextPut: $T;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1895
	nextPutAll: (aTimestamp hour printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1896
	nextPut: $:;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1897
	nextPutAll: (aTimestamp minute printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1898
	nextPut: $:;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1899
	nextPutAll: (aTimestamp second printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1900
	nextPut: $Z
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1901
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1902
    "Created: / 15-06-2005 / 17:56:51 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1903
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1904
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1905
printCompressed: aTimestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1906
    "Print in special compressed format for timestamp interchange with mobile devices."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1907
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1908
    | stream |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1909
    stream := String new writeStream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1910
    self printCompressed: aTimestamp on: stream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1911
    ^stream contents
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1912
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1913
    "Created: / 15-06-2005 / 17:52:52 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1914
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1915
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1916
printCompressed: aTimestamp on: aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1917
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1918
    aStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1919
	nextPutAll: (aTimestamp year printStringRadix: 10 size: 4 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1920
	nextPutAll: (aTimestamp month printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1921
	nextPutAll: (aTimestamp day printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1922
	nextPut: $T;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1923
	nextPutAll: (aTimestamp hour printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1924
	nextPutAll: (aTimestamp minute printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1925
	nextPutAll: (aTimestamp second printStringRadix: 10 size: 2 fill: $0);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1926
	nextPut: $Z
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1927
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1928
    "Created: / 15-06-2005 / 17:54:17 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1929
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1930
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1931
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1932
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1933
nextDigit
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1934
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1935
    | char |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1936
    char := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1937
    char ifNil: [^-1].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1938
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1939
    ^char isDigit
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1940
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1941
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1942
	    char codePoint - $0 codePoint]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1943
	ifFalse: [-1]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1944
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1945
    "Created: / 14-06-2005 / 11:48:52 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1946
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1947
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1948
nextDigitOrError
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1949
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1950
    | digit |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1951
    digit := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1952
    ^digit < 0
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1953
	ifTrue: [self malformed: 'No digit found']
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1954
	ifFalse: [digit]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1955
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1956
    "Created: / 15-06-2005 / 10:57:00 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1957
    "Modified: / 15-06-2005 / 17:22:52 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1958
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1959
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1960
nextDigits: anInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1961
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1962
    | char number |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1963
    number := 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1964
    anInteger timesRepeat: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1965
	char := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1966
	char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1967
	char isDigit
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1968
	    ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1969
		stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1970
		number := number * 10 + char codePoint - $0 codePoint]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1971
	    ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found']
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1972
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1973
    ^number
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1974
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1975
    "Created: / 14-06-2005 / 11:57:22 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1976
    "Modified: / 15-06-2005 / 15:54:29 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1977
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1978
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1979
!Timestamp::TimestampISO8601Builder methodsFor:'processing'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1980
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1981
read: stringOrStream
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1982
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1983
    | peek |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1984
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1985
    stream := stringOrStream readStream.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1986
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1987
    month := day := 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1988
    hour := minute := second := millisecond := 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1989
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1990
    "Read the year. This will read and swallow up to four year digits."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1991
    self readYear.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1992
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1993
    "Check if date has been read, ie. T or space necountered. If yes, read the time.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1994
    There is possible inconsistency - a dash may be read followed by T, which is not
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1995
    valid. But don't mind that, timestamps will be well-formatted in most cases."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1996
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1997
    peek ifNil: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1998
	"End of stream, only year has been read."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  1999
	^self timestamp].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2000
    peek = $- ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2001
	"Skip the dash after year, if present."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2002
	stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2003
	peek := stream peek].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2004
    peek := peek asUppercase.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2005
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2006
    (peek = $T or: [peek = Character space])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2007
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2008
	    "Got time signature. Skip the signature, read time and answer the timestamp."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2009
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2010
	    self readTime.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2011
	    self readTimezone.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2012
	    ^self timestamp]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2013
	ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2014
	    "Date not read completely yet, expecting month/day or week/day or day"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2015
	    peek = $W
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2016
		ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2017
		    "Parse week number and (possibly) day number."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2018
		    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2019
		    self readWeekNumber]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2020
		ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2021
		    "Got digit, read month number followed by day or day number."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2022
		    self readMonthOrDay]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2023
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2024
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2025
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2026
    peek ifNil: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2027
	"End of stream, only year has been read."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2028
	^self timestamp].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2029
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2030
    (peek asUppercase = $T or: [peek = Character space])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2031
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2032
	    "Got time signature, expecting time follows. Otherwise only date was in the stream."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2033
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2034
	    self readTime.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2035
	    self readTimezone].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2036
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2037
    ^self timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2038
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2039
    "Created: / 14-06-2005 / 11:45:04 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2040
    "Modified: / 16-06-2005 / 10:15:35 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2041
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2042
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2043
!Timestamp::TimestampISO8601Builder methodsFor:'reading'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2044
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2045
readMilliseconds
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2046
    "Read an arbitrary number of digits representing milliseconds. As the timestamp can
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2047
    hold only integer amounts of milliseconds, don't mind the rest of the digits."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2048
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2049
    | digit factor |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2050
    factor := 100.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2051
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2052
    [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2053
	digit := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2054
	digit >= 0
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2055
    ] whileTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2056
	factor > 0 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2057
	    "Factor still > 0, did not read all three digits of mantissa."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2058
	    millisecond := digit * factor + millisecond.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2059
	    factor := (factor / 10) integerPart
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2060
	]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2061
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2062
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2063
    factor = 100 ifTrue: [self malformed: 'No digits after millisecond separator']
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2064
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2065
    "Created: / 15-06-2005 / 15:25:45 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2066
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2067
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2068
readMonthOrDay
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2069
    "Read month number, optionally followed by day, or absolute day number (three digit)."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2070
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2071
    | dayDigit1 dayDigit2 |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2072
    month := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2073
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2074
    stream peek = $-
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2075
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2076
	    "Got dash. Day number must follow."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2077
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2078
	    day := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2079
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2080
	    ^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2081
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2082
    dayDigit1 := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2083
    dayDigit1 < 0 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2084
	"No more digits than month, leave day unspecified."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2085
	(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2086
	^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2087
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2088
    dayDigit2 := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2089
    dayDigit2 < 0
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2090
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2091
	    "Read only three digits, this is absolute day number in a year."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2092
	    self dateFromDayNumber: month * 10 + dayDigit1]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2093
	ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2094
	    "Read four digits. So there's month and day."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2095
	    (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2096
	    day := dayDigit1 * 10 + dayDigit2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2097
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2098
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2099
    "Created: / 15-06-2005 / 11:12:02 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2100
    "Modified: / 16-06-2005 / 11:47:34 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2101
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2102
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2103
readTime
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2104
    "Date read, don't mind it. Read only the time value."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2105
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2106
    | peek |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2107
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2108
    hour := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2109
    (hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2110
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2111
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2112
    peek = $:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2113
	ifTrue: [stream next]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2114
	ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2115
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2116
    minute := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2117
    (minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2118
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2119
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2120
    peek = $:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2121
	ifTrue: [stream next]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2122
	ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2123
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2124
    second := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2125
    (second between: 0 and: 59) ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2126
	"Seconds are usually in this range, do a special check for leap seconds."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2127
	second <= 61
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2128
	    ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2129
		"Leap seconds can occur only on midnight on 31.12. or 30.6. Dont' check year
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2130
		as it's not deterministic."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2131
		(minute = 59 and: [hour = 23 and: [(month = 12 and: [day = 31]) or: [month = 6 and: [day = 30]]]])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2132
		    ifFalse: [self malformed: 'Bad leap second']]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2133
	    ifFalse: [self malformed: 'Bad second: ' , second printString]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2134
    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2135
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2136
    "Hour, minute and second read. Read appendices."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2137
    stream peek = $.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2138
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2139
	    "Read dot. Skip it and read milliseconds."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2140
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2141
	    self readMilliseconds].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2142
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2143
    hour = 24 ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2144
	(minute = 0 and: [second = 0 and: [millisecond = 0]])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2145
	    ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2146
		"On 24 hour, advance to the next day."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2147
		"hour := 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2148
		self addMinutes: 1440"]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2149
	    ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)']
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2150
    ]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2151
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2152
    "Created: / 14-06-2005 / 17:27:00 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2153
    "Modified: / 30-06-2005 / 11:34:38 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2154
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2155
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2156
readTimezone
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2157
    "Read time zone information. There are three possibilities of what can occur.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2158
    If there is nothing more to read, the offset is unknown - this is treated as
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2159
    Zulu time as this may not be true."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2160
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2161
    | peek |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2162
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2163
    peek ifNil: [^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2164
    peek := peek asUppercase.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2165
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2166
    "If the time is in Zulu, don't modify the timestamp. This makes the machine
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2167
    run in Zulu time zone, maybe some corrections would be nice."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2168
    peek = $Z
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2169
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2170
	    "Time read, skip Zulu signature and exit."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2171
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2172
	    ^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2173
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2174
    peek = $+
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2175
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2176
	    "Read a plus, expect a negative time zone difference."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2177
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2178
	    self addHoursAndMinutes: (self readTimezoneOffset collect: [:e | e negated]).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2179
	    ^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2180
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2181
    peek = $-
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2182
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2183
	    "Read a minus, expect positive time zone difference or unknown offset."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2184
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2185
	    self addHoursAndMinutes: self readTimezoneOffset.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2186
	    ^self]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2187
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2188
    "Created: / 16-06-2005 / 09:54:21 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2189
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2190
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2191
readTimezoneOffset
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2192
    "Read time zone offset as a number minutes. Generally, there should be hours only
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2193
    but as the format introduces minutes in offsets, we must accept them."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2194
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2195
    | hours digit |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2196
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2197
    "Read hours."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2198
    hours := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2199
    (hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2200
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2201
    stream peek = $:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2202
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2203
	    "Colon read, minutes must follow."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2204
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2205
	    digit := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2206
	    (digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2207
	    ^Array with: hours with: digit].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2208
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2209
    "Read next digit and check whether minutes follow. If not, return only with hours. If yes,
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2210
    check boundaries."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2211
    digit := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2212
    digit < 0 ifTrue: [^Array with: hours with: 0].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2213
    digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2214
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2215
    "Read the last digit of offset, it must be present."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2216
    ^Array with: hours with: digit * 10 + self nextDigitOrError
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2217
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2218
    "Created: / 15-06-2005 / 15:35:41 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2219
    "Modified: / 15-06-2005 / 17:45:58 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2220
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2221
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2222
readWeekNumber
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2223
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2224
    | week day digit |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2225
    "Read week number. It is always two digits long."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2226
    week := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2227
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2228
    stream peek = $-
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2229
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2230
	    "Got dash, day number must follow."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2231
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2232
	    digit := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2233
	    digit < 0 ifTrue: [self malformed: 'Bad weekday number'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2234
	    self dateFromWeek: week andWeekday: digit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2235
	    ^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2236
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2237
    "Read day number that follows the week. If the number is not given, consider it monday."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2238
    day := self nextDigit.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2239
    day <= 0 ifTrue: [day := 1].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2240
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2241
    self dateFromWeek: week andWeekday: day
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2242
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2243
    "Created: / 14-06-2005 / 12:06:47 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2244
    "Modified: / 15-06-2005 / 15:53:34 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2245
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2246
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2247
readYear
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2248
    "Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2249
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2250
    | read peek |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2251
    stream peek = $:
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2252
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2253
	    "Broken two digit year > 1999 follows."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2254
	    stream next.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2255
	    year := self nextDigitOrError + 2000.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2256
	    ^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2257
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2258
    "Expecting two-, three- or four-digit year"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2259
    "Read the first two digits. They must be there."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2260
    read := self nextDigits: 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2261
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2262
    "Check if there's a dash, this can help us deciding whether the year ends."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2263
    peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2264
    peek ifNil: [^self].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2265
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2266
    year := peek = $-
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2267
	ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2268
	    "OK, got two digits. These are expected to be the year after 1970."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2269
	    read < 70
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2270
		ifTrue: [read + 2000]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2271
		ifFalse: [read + 1900]]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2272
	ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2273
	    "Read the next digit for the case of three-digit year after 1900 (ie. year > 1999)."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2274
	     read := read * 10 + self nextDigitOrError.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2275
	     peek := stream peek.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2276
	     (peek isNil or: [peek = $-])
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2277
		ifTrue: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2278
		    "Read three digit year, return it."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2279
		    read + 1900]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2280
		ifFalse: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2281
		    "Read the fourth digit of the year. These can be month digits but the
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2282
		    two-digit year format is deprecated anyway."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2283
		    read := read * 10 + self nextDigitOrError]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2284
	]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2285
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2286
    "Created: / 14-06-2005 / 12:01:11 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2287
    "Modified: / 15-06-2005 / 17:31:56 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2288
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2289
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2290
!Timestamp::TimestampISO8601Builder methodsFor:'testing'!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2291
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2292
test
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2293
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2294
    self test_date.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2295
    self test_time.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2296
    self test_timezone.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2297
    self test_edge.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2298
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2299
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2300
        TimestampISO8601Builder new test
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2301
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2302
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2303
    "Created: / 15-06-2005 / 17:51:16 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2304
    "Modified: / 16-06-2005 / 10:15:55 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2305
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2306
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2307
test_date
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2308
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2309
    | ts |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2310
    ts := Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2311
         year: 2005 month: 6 day: 15
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2312
         hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2313
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2314
    "Test common dates"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2315
    self assert: ts = (self read: '20050615').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2316
    self assert: ts = (self read: '2005-06-15').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2317
    self assert: ts = (self read: '05-06-15').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2318
    self assert: ts = (self read: '05-0615'). "/ Is this correct?
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2319
    self assert: ts = (self read: ':50615'). "/ Should not happen and should not appear after 2009
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2320
    self assert: ts = (self read: '200506-15'). "/ Is this corect?
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2321
    self assert: ts = (self read: '105-06-15'). "/ Should not happen
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2322
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2323
    "Test week numbers"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2324
    "/self assert: ts = (self read: '05W243').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2325
    "/self assert: ts = (self read: '2005W24-3').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2326
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2327
    "Test day numbers"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2328
    "self assert: ts = (self read: '2005-166').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2329
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2330
    ts := Timestamp year: 2004 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2331
    self assert: ts = (self read: '2004-366').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2332
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2333
    ts := Timestamp year: 2005 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2334
    self assert: ts = (self read: '2004-365')."
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2335
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2336
    "Test february"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2337
    ts := Timestamp year: 2000 month: 2 day: 28 hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2338
    self assert: ts = (self read: '20000228').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2339
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2340
    ts := Timestamp year: 2000 month: 2 day: 29 hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2341
    self assert: ts = (self read: '20000229').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2342
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2343
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2344
        TimestampISO8601Builder new test_date
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2345
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2346
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2347
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2348
    "Created: / 15-06-2005 / 17:21:56 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2349
    "Modified: / 16-06-2005 / 11:50:04 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2350
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2351
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2352
test_edge
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2353
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2354
    | ts |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2355
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2356
    self test_mustFail: [self read: '20050229'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2357
    self test_mustFail: [self read: '20050029'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2358
    self test_mustFail: [self read: '20050332'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2359
    self test_mustFail: [self read: '2005-366'].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2360
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2361
    ts := Timestamp year: 2005 month: 1 day: 1 hour: 0 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2362
    self assert: ts = (self read: '20041231T22-0200').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2363
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2364
    ts := Timestamp year: 2004 month: 12 day: 31 hour: 22 minute: 0 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2365
    self assert: ts = (self read: '20050101T0000+0200').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2366
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2367
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2368
        TimestampISO8601Builder new test_edge
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2369
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2370
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2371
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2372
    "Created: / 16-06-2005 / 09:44:34 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2373
    "Modified: / 16-06-2005 / 11:48:59 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2374
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2375
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2376
test_mustFail: aBlock
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2377
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2378
    ConversionError
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2379
	handle: [:ex | ex return]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2380
	do: [
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2381
	    aBlock value.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2382
	    self error: 'Assertion failed'
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2383
	]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2384
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2385
    "Created: / 16-06-2005 / 09:43:37 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2386
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2387
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2388
test_time
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2389
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2390
    | ts |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2391
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2392
    ts := Timestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2393
    self assert: ts = (self read: '2005-06-15 17:37').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2394
    self assert: ts = (self read: '20050615T1737').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2395
    self assert: ts = (self read: '05-0615T17:3700').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2396
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2397
    ts := Timestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 30.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2398
    self assert: ts = (self read: '05-0615T17:3700.03').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2399
    self assert: ts = (self read: '2005-06-15T17:37:00.0305486-00:00').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2400
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2401
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2402
        TimestampISO8601Builder new test_time
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2403
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2404
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2405
    "Created: / 15-06-2005 / 17:39:26 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2406
    "Modified: / 16-06-2005 / 11:54:30 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2407
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2408
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2409
test_timezone
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2410
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2411
    | ts |
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2412
    ts := Timestamp
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2413
         year: 2005 month: 6 day: 15
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2414
         hour: 17 minute: 37 second: 0 millisecond: 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2415
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2416
    self assert: ts = (self read: '2005-06-15T17:37Z').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2417
    self assert: ts = (self read: '2005-06-15T17:37+0000').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2418
    self assert: ts = (self read: '2005-06-15T17:37-00:00').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2419
    self assert: ts = (self read: '2005-06-15T15:37:00-0200').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2420
    self assert: ts = (self read: '2005-06-15T19:37:00+0200').
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2421
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2422
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2423
        TimestampISO8601Builder new test_timezone
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2424
    "
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2425
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2426
    "Created: / 15-06-2005 / 17:40:23 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2427
    "Modified: / 16-06-2005 / 10:17:57 / masca"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2428
! !
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2429
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2430
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2431
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2432
version
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  2433
    ^ '$Id: Timestamp.st 10501 2010-02-13 23:34:44Z vranyj1 $'
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2434
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2435
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2436
version_CVS
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  2437
    ^ '§Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.127 2010/02/10 17:47:27 cg Exp §'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2438
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2439
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2440
Timestamp initialize!
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
  2441
17734
406b1590afe8 Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17732
diff changeset
  2442
17735
6a5bc05f696a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17734
diff changeset
  2443
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  2444