Timestamp.st
author Claus Gittinger <cg@exept.de>
Mon, 16 Feb 2009 10:46:56 +0100
changeset 11550 eea8c88e8de7
parent 11177 f5faa6cb49ed
child 11847 5c7ecb05e744
child 17711 39faaaf888b4
permissions -rw-r--r--
*** empty log message ***
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
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    21
!Timestamp class methodsFor:'documentation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    22
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    23
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    24
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 92
diff changeset
    26
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    27
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    28
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    36
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    37
documentation
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    38
"
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    39
    This class represents time values in milliSeconds starting some
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    40
    time in the past. 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    41
    (typically, from 1st. Jan 1970, as used in the Unix operating system,
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    42
     but other systems may bias the time differently.
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    43
     Actually, the implementation does not depend or even know which time/date 
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    44
     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
    45
     as returned from the OS.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    46
     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
    47
     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
    48
     (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
    49
     especially when performing comparisons).
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    50
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    51
    You should not interpret the osTime instance variable directly, instead
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    52
    (if at all), ask the OS to convert.
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    53
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    54
    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
    55
    (which represents the time as seconds from Jan 1., 1901).
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    56
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    57
    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
    58
    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
    59
    instances of Timestamp can.
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    60
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    61
    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
    62
    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
    63
    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
    64
    AbsoluteTime is still kept as an alias for backward compatibility.
3479
9ca6229713f4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3122
diff changeset
    65
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    66
    [author:]
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    67
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    68
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    69
    [See also:]
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    70
        Time Date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    71
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    72
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    73
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    74
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    75
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    76
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    77
initialize
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    78
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    79
    AbsoluteTime := self.       "backward compatibility"
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    80
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    81
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    82
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    83
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
    84
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
    85
    "return an instance of the receiver, given individual components.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    86
     See also `Timestamp now' and other protocol inherited
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    87
     from my superclass."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
    88
423
claus
parents: 392
diff changeset
    89
    ^ self basicNew 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    90
        fromOSTime:(OperatingSystem 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    91
                        computeOSTimeFromUTCYear:y month:m day:d 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    92
                                         hour:h minute:min second:s
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    93
                                         millisecond:millis)
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    94
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    95
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    96
     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
    97
     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
    98
     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
    99
     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
   100
     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
   101
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   102
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   103
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   104
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   105
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   106
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   107
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   108
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
   109
    "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
   110
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   111
    ^ self 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   112
        year:y month:m day:d hour:h 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   113
        minute:min second:s millisecond:0
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   114
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   115
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   116
     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
   117
     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
   118
    "
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   119
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   120
    "Modified: / 1.7.1996 / 15:22:26 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   121
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   122
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   123
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   124
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
   125
    "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
   126
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   127
    ^ 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
   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:1 month:1 year:1970 hour:1 minute:0 second:0 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   131
     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
   132
     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
   133
    "
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   134
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   135
    "Created: / 1.7.1996 / 14:46:09 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   136
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   137
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   138
!
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   139
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   140
decodeFromLiteralArray:anArray
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   141
    "decode an Timestamp literalArray.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   142
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   143
     anArray may be:
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   144
        #(Timestamp '200004182000.123')
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   145
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   146
     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
   147
     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
   148
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   149
        #(Timestamp #osTime: 12345678)     
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   150
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   151
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   152
    (anArray at:2) == #osTime: ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   153
        ^ self new osTime:(anArray at:3).
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   154
    ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   155
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   156
    ^ self 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   157
        readGeneralizedFrom:(anArray at:2) 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   158
        onError:[ self conversionErrorSignal 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   159
                    raiseErrorString:'literal array decoding' ]
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   160
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   161
    "
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   162
     Timestamp
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   163
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')      
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   164
    "
5379
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
423
claus
parents: 392
diff changeset
   167
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   168
    "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
   169
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   170
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   171
     from my superclass."
423
claus
parents: 392
diff changeset
   172
claus
parents: 392
diff changeset
   173
    ^ self 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   174
        year:aDate year 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   175
        month:aDate month 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   176
        day:aDate day 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   177
        hour:aTime hours 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   178
        minute:aTime minutes 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   179
        second:aTime seconds 
423
claus
parents: 392
diff changeset
   180
claus
parents: 392
diff changeset
   181
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   182
     Timestamp fromDate:(Date today) andTime:(Time now)  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   183
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   184
     Timestamp now 
423
claus
parents: 392
diff changeset
   185
    "
claus
parents: 392
diff changeset
   186
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   187
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   188
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   189
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   190
!
claus
parents: 392
diff changeset
   191
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   192
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   193
    "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
   194
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   195
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   196
    ^ (Date newDay:dayInYear year:year) asTimestamp
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   197
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   198
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   199
     Timestamp newDay:183 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   200
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   201
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   202
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   203
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   204
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   205
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   206
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   207
     The string is interpreted as 24 hour format, as printed.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   208
     Notice, that this is not the storeString format and 
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   209
     is different from the format expected by readFrom:.
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
   210
     The format read here is dd-mm-yyyy hh:mm:ss.iii"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   211
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   212
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   213
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   214
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   215
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
   216
    Error handle:[:ex |
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   217
        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
   218
    ] do:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   219
        newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   220
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   221
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   222
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   223
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   224
     Timestamp readFrom:'20-2-1995 13:11:06'                            
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   225
     Timestamp readFrom:'20-2-1995 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   226
     Timestamp readFrom:'20-2-2001 13:11'                               
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   227
     Timestamp readFrom:'20-2-1995 13:11:06.100'                        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   228
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   229
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'      
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   230
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   231
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   232
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   233
     Timestamp readFrom:'foo' onError:'wrong'                           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   234
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'                     
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   235
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   236
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   237
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   238
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   239
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
   240
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   241
readGeneralizedFrom:aStringOrStream 
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   242
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   243
     The string is interpreted as 24 hour format, as printed.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   244
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   245
     Notice, that this is not the storeString format and 
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   246
     is different from the format expected by readFrom:.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   247
     The format read here is either
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   248
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   249
     or:
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   250
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   251
    "
11126
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   252
    ^ self 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   253
        readGeneralizedFrom:aStringOrStream 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   254
        onError:[self conversionErrorSignal 
146ee0b7806e onversion errors
Claus Gittinger <cg@exept.de>
parents: 11003
diff changeset
   255
                    raiseErrorString:'Timestamp format error' ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   256
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   257
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   258
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
   259
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   260
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   261
    "return a new Timestamp, reading a printed representation from aStream.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   262
     The string is interpreted as 24 hour format, as printed.
5376
c2ef7d5e25ca oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents: 5292
diff changeset
   263
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   264
     Notice, that this is not the storeString format and 
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   265
     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
   266
     The format read here is either
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   267
        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
   268
     or:
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   269
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   270
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   271
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   272
    |newTime|
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   273
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   274
    ^ [
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   275
        |str day month year hour min sec millis c tzDelta|
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   276
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   277
        sec := millis := 0.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   278
        str := aStringOrStream readStream.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   279
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   280
        year := Integer readFrom:(str next:4).
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   281
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   282
        month := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   283
        (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
   284
        str peek == $- ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   285
        day := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   286
        (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
   287
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   288
        str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   289
        hour:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   290
        (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
   291
        str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   292
        min:= Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   293
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   294
        str atEnd ifFalse:[
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   295
            str peek == $: ifTrue:[ str next].
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   296
            sec := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   297
            (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
   298
            str atEnd ifFalse:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   299
                str peek == $. ifTrue:[
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   300
                    str next.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   301
                    millis := Integer readFrom:str.
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   302
                ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   303
                str skipSeparators.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   304
            ].
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   305
        ].
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   306
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   307
        str atEnd ifTrue:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   308
            "/ this is local time
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   309
            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
   310
                            hour:hour minute:min second:sec millisecond:millis.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   311
        ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   312
            c := str next.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   313
            c ~~ $Z ifTrue:[ 
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   314
                |tzh tzmin|
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   315
                tzh := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   316
                tzmin := Integer readFrom:(str next:2).
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   317
                c == $+ ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   318
                    "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
   319
                    hour := hour - tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   320
                    min := min - tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   321
                ] ifFalse:[
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   322
                    c ~~ $- ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   323
                        ^ exceptionBlock value.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   324
                    ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   325
                    "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
   326
                    hour := hour + tzh.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   327
                    min := min + tzmin.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   328
                ].
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   329
            ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   330
            "this is UTC time"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   331
            newTime := self UTCYear:year month:month day:day 
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   332
                              hour:hour minute:min second:sec millisecond:millis.
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   333
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   334
        newTime
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
   335
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   336
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   337
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
   338
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
   339
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   340
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   341
     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
   342
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   343
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   344
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   345
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   346
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   347
     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
   348
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   349
 No daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   350
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   351
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   352
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   353
     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
   354
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   355
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]   
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   356
     Timestamp readGeneralizedFrom:'199502201311' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   357
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   358
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   359
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   360
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'                     
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   361
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   362
     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
   363
     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
   364
     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
   365
     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
   366
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] 
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   367
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   368
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   369
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
   370
    "Modified: / 22-08-2006 / 12:30:11 / cg"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   371
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
   372
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   373
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   374
    "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
   375
     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
   376
     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
   377
     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
   378
     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
   379
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   380
     On error, raise an exception.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   381
     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
   382
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   383
    ^ self
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   384
        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   385
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   386
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   387
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   388
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   389
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   390
     Timestamp readIso8601FormatFrom:'1995T13:11'           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   391
     Timestamp readIso8601FormatFrom:'1995T13'              
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   392
     Timestamp readIso8601FormatFrom:'1995'              
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   393
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   394
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   395
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   396
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   397
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   398
   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
   399
     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
   400
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   401
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   402
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   403
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   404
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   405
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   406
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   407
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   408
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   409
     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
   410
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   411
     On error, raise an exception.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   412
     Please use this format for all external representations - its the standard."
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   413
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   414
    ^ self
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   415
        readIso8601FormatFrom:aStringOrStream 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   416
        yearAlreadyRead:nil 
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   417
        onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   418
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   419
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   420
secondsSince1970:sec
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   421
    "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
   422
     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
   423
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   424
    |divMod|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   425
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   426
    divMod := sec divMod:3600.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   427
    ^ 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
   428
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   429
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   430
     Timestamp secondsSince1970:0      
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   431
     Timestamp secondsSince1970:3600
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   432
     Timestamp secondsSince1970:3600*24
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   433
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   434
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   435
    "Created: / 21.10.1996 / 17:48:30 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   436
    "Modified: / 13.7.1999 / 12:31:22 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   437
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   438
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   439
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
   440
    "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
   441
     See also `Timestamp now' and other protocol inherited
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   442
     from my superclass."
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   443
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   444
    ^ 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
   445
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   446
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   447
     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
   448
     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
   449
     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
   450
     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
   451
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   452
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   453
    "Modified: / 1.7.1996 / 15:22:07 / cg"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   454
    "Created: / 13.7.1999 / 12:06:39 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   455
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   456
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   457
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   458
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
   459
    "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
   460
     See also `Timestamp now' and other protocol inherited
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   461
     from my superclass."
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   462
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   463
    ^ self basicNew 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   464
        fromOSTime:(OperatingSystem 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   465
                        computeOSTimeFromYear:y month:m day:d 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   466
                                         hour:h minute:min seconds:s millis:millis)
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   467
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   468
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   469
     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
   470
     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
   471
     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
   472
     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
   473
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   474
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   475
    "Modified: / 1.7.1996 / 15:22:07 / cg"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   476
    "Created: / 13.7.1999 / 12:28:44 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   477
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   478
! !
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   479
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   480
!Timestamp class methodsFor:'private'!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   481
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   482
basicReadFrom:aStream
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   483
    "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
   484
     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
   485
     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
   486
     is different from the format expected by readFrom:.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   487
     KLUDGE: 
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   488
        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
   489
        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
   490
        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
   491
     On error, raise an exception"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   492
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   493
    |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
   494
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   495
    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
   496
    firstNumber > 31 ifTrue:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   497
        "/ assume iso8601 format;
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   498
        ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   499
    ].
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   500
    aStream skipSeparators.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   501
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   502
    "/ consider this a kludge
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   503
    usFormat := (aStream peek == $/ ).
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   504
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   505
    [aStream peek isLetterOrDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   506
    aStream peek isDigit ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   507
        secondNumber := Integer readFrom:aStream onError:-1.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   508
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   509
        usFormat ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   510
            month := firstNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   511
            day := secondNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   512
        ] ifFalse:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   513
            month := secondNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   514
            day := firstNumber.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   515
        ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   516
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   517
    ] ifFalse:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   518
        possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   519
        month := Date indexOfMonth:possibeMonthName asLowercase.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   520
        day := firstNumber.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   521
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   522
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   523
    (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
   524
    (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
   525
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   526
    [aStream peek isDigit] whileFalse:[aStream next].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   527
    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
   528
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   529
    aStream atEnd ifTrue:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   530
        hour := min := sec := millis := 0.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   531
    ] ifFalse:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   532
        [aStream peek isDigit] whileFalse:[aStream next].
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   533
        hour := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   534
        (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
   535
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   536
        [aStream peek isDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   537
        min := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   538
        (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
   539
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   540
        aStream atEnd ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   541
            sec := millis := 0.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   542
        ] ifFalse:[
11140
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   543
            [aStream peek isDigit] whileFalse:[aStream next].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   544
            sec := Integer readFrom:aStream onError:-1.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   545
            (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
   546
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   547
            aStream peek = $. ifTrue:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   548
                aStream next.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   549
                millis := Integer readFrom:aStream onError:0.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   550
                millis >= 1000 ifTrue:[ ConversionError raiseErrorString:' - bad millisecond' ].
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   551
            ] ifFalse:[
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   552
                millis := 0.
130dd8b62622 be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents: 11126
diff changeset
   553
            ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   554
        ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   555
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   556
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   557
    "special check - only 24:00:00 is allowed;
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   558
     every time after that must wrap"
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   559
    hour == 24 ifTrue:[
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   560
        (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
   561
    ].
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   562
    ^ 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
   563
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   564
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   565
     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
   566
     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
   567
     (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
   568
     (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
   569
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream       
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   570
     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
   571
     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
   572
     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
   573
     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
   574
     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
   575
     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
   576
     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
   577
     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
   578
     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
   579
     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
   580
     Timestamp basicReadFrom:'foo' readStream                    
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   581
     Timestamp basicReadFrom:(Timestamp now printString readStream)                  
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   582
     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
   583
     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
   584
    "
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   585
!
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   586
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   587
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   588
    "common helper for read methods.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   589
     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
   590
     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
   591
     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
   592
     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
   593
     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
   594
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   595
     On error, raise an exception.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   596
     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
   597
7008
e154492de5d8 Remove unused method vars
Stefan Vogel <sv@exept.de>
parents: 7006
diff changeset
   598
    |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
   599
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   600
    str := aStringOrStream readStream.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   601
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   602
    month := day := 1.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   603
    hour := min := sec := millis := 0.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   604
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   605
    yearOrNil notNil ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   606
        year := yearOrNil
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   607
    ] ifFalse:[
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   608
        year := Integer readFrom:str onError:nil.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   609
        year isNil ifTrue:[ ConversionError raiseErrorString:' - bad year' ]
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   610
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   611
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   612
    str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   613
    str peek == $- ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   614
        str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   615
        "/ month follows.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   616
        month := Integer readFrom:str.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   617
        (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
   618
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   619
        str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   620
        str peek == $- ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   621
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   622
            "/ day follows.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   623
            day := Integer readFrom:str.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   624
            (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
   625
        ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   626
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   627
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   628
    str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   629
    str atEnd ifFalse:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   630
        "time follows"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   631
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   632
        str peek == $T ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   633
            "we treat the T as optional here"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   634
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   635
            str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   636
        ].
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   637
        hour := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   638
        (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
   639
        str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   640
        str peek == $: ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   641
            str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   642
            "/ minutes follow.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   643
            min := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   644
            (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
   645
            str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   646
            str peek == $: ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   647
                str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   648
                "/ seconds follow.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   649
                sec := Integer readFrom:str onError:-1.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   650
                (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
   651
                str skipSeparators.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   652
                str peek == $. ifTrue:[
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   653
                    str next.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   654
                    "/ millis follow.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   655
                    fraction := Number readMantissaFrom:str radix:10.    
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   656
                    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
   657
                ]
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   658
            ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   659
        ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   660
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   661
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   662
    "special check - only 24:00:00 is allowed;
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   663
     every time after that must wrap"
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   664
    hour == 24 ifTrue:[
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
   665
        (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
   666
    ].
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   667
    ^ self 
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   668
        year:year month:month day:day 
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   669
        hour:hour minute:min second:sec millisecond:millis.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   670
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   671
    "
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
   672
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'    
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   673
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   674
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'     
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   675
     Timestamp readIso8601FormatFrom:'1995T13:11:06'        
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   676
     Timestamp readIso8601FormatFrom:'1995T13:11'           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   677
     Timestamp readIso8601FormatFrom:'1995T13'              
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   678
     Timestamp readIso8601FormatFrom:'1995'              
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   679
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   680
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   681
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'    
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   682
     Timestamp readIso8601FormatFrom:'1995-02-20 13'    
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   683
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   684
   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
   685
     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
   686
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   687
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
   688
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   689
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   690
    "common helper for read methods.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   691
     Return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   692
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   693
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   694
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   695
     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
   696
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   697
     On error, raise an exception.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   698
     Please use this format for all external representations - its the standard."
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   699
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   700
    |retVal|
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   701
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   702
    ConversionError handle:[:ex |
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   703
        retVal := exceptionValue value
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   704
    ] do:[
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   705
        retVal := self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   706
    ].
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
   707
    ^ retVal
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   708
! !
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   709
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   710
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   711
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   712
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   713
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
   714
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   715
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   716
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
   717
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   718
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   719
     Timestamp now day 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   720
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   721
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   722
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   723
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   724
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   725
dayInWeek
7327
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   726
    "return the week-day of the receiver - 1 for monday, 7 for sunday
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   727
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday).  
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   728
     WARNING: does not care for pre-julian dates 
ab17eb5f11a6 printFormat
Claus Gittinger <cg@exept.de>
parents: 7111
diff changeset
   729
        (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
   730
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   731
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   732
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   733
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   734
     Timestamp now dayInWeek 
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   735
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   736
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   737
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   738
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   739
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   740
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   741
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   742
    "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
   743
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   744
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   745
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   746
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   747
     Timestamp now dayInYear 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   748
     Timestamp newDay:184 year:1996  
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   749
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   750
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   751
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   752
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   753
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   754
hour
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   755
    "return the hour (0..23).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   756
     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
   757
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   758
    ^ self hours
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   759
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   760
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   761
    "Modified: 1.7.1996 / 15:15:32 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   762
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   763
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   764
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   765
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   766
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   767
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
   768
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   769
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   770
     Timestamp now hours  
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   771
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   772
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   773
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   774
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   775
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   776
millisecond
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   777
    "return the millisecond (0..999).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   778
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   779
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   780
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   781
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   782
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   783
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   784
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   785
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   786
milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   787
    "return the milliseconds (0..999)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   788
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   789
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   790
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   791
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   792
     Timestamp now milliseconds   
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   793
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   794
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   795
    "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
   796
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   797
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   798
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   799
minute
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   800
    "return the minute (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   801
     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
   802
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   803
    ^ self minutes
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   804
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   805
    "Created: 1.7.1996 / 15:14:29 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   806
    "Modified: 1.7.1996 / 15:15:37 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   807
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   808
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   809
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   810
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   811
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   812
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   813
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   814
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   815
     Timestamp now minutes 
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   816
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   817
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   818
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   819
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   820
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   821
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   822
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   823
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   824
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   825
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   826
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   827
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   828
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   829
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   830
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   831
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   832
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   833
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   834
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   835
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   836
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   837
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   838
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   839
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
   840
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
   841
osTime:aTime
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
   842
    "set the internal representation of the time"
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
   843
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
   844
    osTime := aTime.
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
   845
!
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
   846
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   847
second
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   848
    "return the second (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   849
     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
   850
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   851
    ^ self seconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   852
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   853
    "Created: 1.7.1996 / 15:14:19 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   854
    "Modified: 1.7.1996 / 15:15:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   855
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   856
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   857
seconds
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   858
    "return the seconds (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   859
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   860
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   861
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   862
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   863
     Timestamp now seconds 
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   864
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   865
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   866
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   867
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
   868
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
   869
timeInfo
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
   870
    ^ (OperatingSystem computeTimeAndDateFrom:osTime)
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
   871
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
   872
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   873
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
   874
    "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
   875
     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
   876
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
   877
     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
   878
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
   879
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
   880
     If utcOffset is negative, the local timezone is east of Greenwich.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
   881
     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
   882
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   883
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   884
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   885
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   886
     Timestamp now utcOffset 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   887
     (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
   888
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   889
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   890
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   891
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   892
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
   893
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   894
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   895
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   896
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   897
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
   898
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   899
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   900
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   901
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   902
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   903
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   904
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   905
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   906
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   907
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   908
10736
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   909
deltaFrom:aTimestamp
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   910
    "return the delta as a timeDuration between 2 timeStamps.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   911
     The argument is supposed to be BEFORE the receiver"
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   912
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   913
    ^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds))
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   914
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   915
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   916
     |t1 t2|
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   917
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   918
     t1 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   919
     Delay waitForSeconds:0.5.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   920
     t2 := Timestamp now.
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   921
     t2 deltaFrom:t1   
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   922
    "
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   923
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   924
    "Created: / 04-10-2007 / 13:34:28 / cg"
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   925
!
ea9e95d7f9f2 + deltaFrom:
Claus Gittinger <cg@exept.de>
parents: 9620
diff changeset
   926
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   927
millisecondDeltaFrom:aTimestamp
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
   928
    "return the delta in milliseconds between 2 absolute times.
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   929
     The argument is supposed to be BEFORE the receiver"
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   930
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   931
    ^ self getMilliseconds - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   932
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   933
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   934
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   935
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   936
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   937
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   938
     t2 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   939
     t2 millisecondDeltaFrom:t1   
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   940
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
   941
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
   942
    "Modified: / 5.6.1998 / 04:21:33 / cg"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   943
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   944
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   945
secondDeltaFrom:aTimestamp
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   946
    "return the delta in seconds between 2 absolute times.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   947
     The argument is supposed to be BEFORE the receiver"
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   948
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   949
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   950
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   951
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   952
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   953
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   954
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   955
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   956
     t2 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   957
     t2 secondDeltaFrom:t1   
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   958
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   959
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
   960
    "Modified: / 5.6.1998 / 04:21:33 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   961
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   962
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   963
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   964
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   965
= aTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   966
    "return true if the argument, aTime represents the same time"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   967
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   968
    (aTime species == self species) ifFalse:[^ false].
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   969
    ^ (self getMilliseconds = aTime getMilliseconds)
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   970
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   971
    "Modified: 3.7.1996 / 13:10:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   972
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   973
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   974
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   975
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   976
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   977
    ^ osTime // 1000
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   978
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
   979
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   980
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   981
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   982
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   983
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   984
asAbsoluteTime
8254
73b6109ab982 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8246
diff changeset
   985
    "deprecated, use #asTimestamp"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   986
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   987
    <resource:#obsolete>
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   988
9061
20af48b9b295 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9056
diff changeset
   989
    self obsoleteMethodWarning:'use #asTimestamp'.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   990
    ^ self
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   991
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   992
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   993
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   994
    "return a Date object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   995
     The returned date will only represent the day - not the timeOfDay."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   996
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   997
    ^ Date fromOSTime:osTime 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   998
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   999
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1000
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1001
     Timestamp now asDate
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1002
     (Timestamp now addTime:3600) asDate 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1003
     (Timestamp now addTime:3600) asTime 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1004
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1005
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate  
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1006
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1007
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1008
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1009
asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1010
    "convert an utc timestamp to local time "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1011
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1012
    ^ self - self utcOffset
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1013
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1014
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1015
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1016
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1017
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1018
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1019
7466
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1020
asMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1021
    "return the number of milliSeconds elapsed since whatever time the
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1022
     OperatingSystem bases its time upon. Since this is totally
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1023
     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
  1024
     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
  1025
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1026
    ^ self getMilliseconds
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1027
!
87775b24d5ea category and comment change;
Claus Gittinger <cg@exept.de>
parents: 7327
diff changeset
  1028
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1029
asSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1030
    "return the number of seconds elapsed since whatever time the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1031
     OperatingSystem bases its time upon. Since this is totally
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1032
     OS-dependent, do not interpret the value returned by this method.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1033
     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
  1034
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1035
    ^ self getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1036
7004
6cd2080ea0a3 added asUTCSecondsSince1901
penk
parents: 6955
diff changeset
  1037
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1038
     Timestamp now asSeconds
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1039
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600) 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1040
     Time hour:23 minutes:33 seconds:0         
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1041
     Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1042
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1043
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1044
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1045
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1046
    "return a Time object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1047
     The returned time will only represent the timeOfDay - not the day."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1048
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1049
    ^ Time fromOSTime:osTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1050
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1051
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1052
     Timestamp now  
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1053
     Timestamp now asTime
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1054
     (Timestamp now addTime:3600) asTime 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1055
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1056
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1057
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1058
asTimestamp
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1059
    "return an Timestamp object from the receiver - thats the receiver."
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1060
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1061
    ^ self 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1062
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1063
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1064
asUtcTimestamp
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1065
    "convert a local time timestamp to UTC"
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1066
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1067
    ^ self + self utcOffset
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1068
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1069
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  1070
     Timestamp now asUtcTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1071
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1072
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  1073
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1074
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1075
    "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
  1076
     can be reconstructed with #decodeAsLiteralArray.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1077
     The encoding is: 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1078
        (#Timestamp YYYYMMDDhhmmss.iii)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1079
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1080
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1081
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1082
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  1083
    s := WriteStream on:(String new:18).
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1084
    self printGeneralizedOn:s isLocal:true.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1085
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1086
    ^ Array
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1087
        with:self class name
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1088
        with:s contents
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1089
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1090
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1091
      Timestamp now literalArrayEncoding
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  1092
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1093
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1094
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1095
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1096
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1097
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1098
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1099
"   
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1100
    secondsBetween1901and1970 := 
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1101
        ((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
  1102
        *  (24 * 60 * 60)
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1103
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1104
9449
6ba774be6aa1 stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents: 9433
diff changeset
  1105
    ^ self utcSecondsSince1970 + 2177452800.  
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1106
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1107
    "                                                 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1108
     Timestamp now utcSecondsSince1901 
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  1109
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1110
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1111
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1112
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1113
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1114
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1115
    "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
  1116
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1117
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1118
    self asDate addPrintBindingsTo:dict language:languageOrNil.
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1119
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1120
    self year == Date today year ifTrue:[
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1121
        dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m').
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1122
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  1123
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  1124
    super addPrintBindingsTo:dict language:languageOrNil.
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  1125
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  1126
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1127
printGeneralizedOn:aStream 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1128
    "append a representation of the receiver to aStream in a general format,
9385
f46f04a13052 comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
  1129
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1130
     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
  1131
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1132
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1133
    ^ self printGeneralizedOn:aStream isLocal:false.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1134
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1135
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1136
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1137
    "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
  1138
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1139
     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
  1140
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1141
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1142
     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
  1143
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1144
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1145
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1146
    t := OperatingSystem computeTimeAndDateFrom:osTime.
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1147
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1148
    t year    printOn:aStream leftPaddedTo:4 with:$0.
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1149
    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
  1150
    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
  1151
    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
  1152
    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
  1153
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1154
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1155
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1156
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1157
    isLocal ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1158
        "/ this should be printed as non-local-time
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1159
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  1160
        off := t utcOffset.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1161
        off == 0 ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1162
            aStream nextPut:$Z.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1163
        ] ifFalse:[ |min|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1164
            off < 0 ifTrue:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1165
                aStream nextPut:$+.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1166
                off := off negated.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1167
            ] ifFalse:[
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1168
                aStream nextPut:$-.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1169
            ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1170
            min := off // 60.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1171
            min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  1172
            min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1173
        ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1174
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1175
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1176
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1177
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1178
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1179
     Time now printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1180
     Date today printOn:Transcript. Transcript cr.        
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1181
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1182
     Time now asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1183
     Timestamp now printGeneralizedOn:Transcript. Transcript cr. 
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1184
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1185
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.           
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1186
     Date today printOn:Transcript. Transcript cr.           
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1187
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1188
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1189
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1190
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1191
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  1192
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1193
printIso8601FormatOn:aStream
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1194
    "append the iso8601 UTC representation of the receiver to aStream.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1195
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1196
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1197
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1198
        1999-01-01
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1199
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1200
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1201
    |format|
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1202
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1203
    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1204
    self milliseconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1205
        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1206
        self seconds = 0 ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1207
            format := '%(year)-%(month)-%(day)T%h:%m'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1208
            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1209
                format := '%(year)-%(month)-%(day)'.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1210
            ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1211
        ]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1212
    ].
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1213
    self printOn:aStream format:format 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1214
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1215
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1216
     Timestamp now printIso8601FormatOn:Transcript   
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1217
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1218
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1219
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1220
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1221
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1222
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1223
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1224
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1225
    "/ now, use ISO format...
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1226
    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
  1227
"/    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
  1228
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'  
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1229
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1230
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1231
     Timestamp now printOn:Transcript. Transcript cr. 
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1232
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1233
     Time now printOn:Transcript. Transcript cr.           
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1234
     Date today printOn:Transcript. Transcript cr.        
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1235
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1236
     Time now asTimestamp printOn:Transcript. Transcript cr.           
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1237
     Timestamp now printOn:Transcript. Transcript cr. 
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1238
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1239
     Date today asTimestamp printOn:Transcript. Transcript cr.           
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1240
     Date today printOn:Transcript. Transcript cr.           
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1241
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1242
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  1243
    "Modified: 1.7.1996 / 15:20:59 / cg"
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  1244
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1245
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1246
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1247
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1248
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1249
        'Fri, 04 Jul 2003 15:56:11 GMT'
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1250
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1251
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1252
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1253
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1254
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1255
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1256
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1257
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1258
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1259
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1260
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1261
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1262
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1263
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1264
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1265
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1266
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1267
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1268
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1269
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1270
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1271
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1272
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1273
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1274
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1275
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1276
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1277
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1278
    |meUTC timeInfo|
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1279
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1280
    meUTC := self class fromSeconds:((self asSeconds) + (self utcOffset)).
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1281
    timeInfo := meUTC timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1282
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1283
    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
  1284
            nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1285
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1286
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1287
    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
  1288
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1289
"/ The following line is wrong, because the names are printed in the current locale!!
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1290
"/    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
  1291
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1292
"/ the following is too slow for heavy use    
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1293
"/    timeInfo printOn:aStream format:' %y %h:%m:%s GMT'. 
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1294
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1295
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1296
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1297
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1298
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1299
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1300
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1301
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1302
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1303
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  1304
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1305
    "
8414
dca52c2725ef comment
ca
parents: 8396
diff changeset
  1306
     Timestamp now printRFC1123FormatOn:Transcript   
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1307
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1308
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1309
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1310
printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1311
    "return the Iso8601 representation of the receiver.
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1312
     This format looks like:
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1313
        1999-01-01T24:00:00
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1314
     or, for zero hr:min:sec, 
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1315
        1999-01-01
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1316
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1317
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1318
    ^ String streamContents:[:s | self printIso8601FormatOn:s]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1319
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1320
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1321
     Timestamp now printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1322
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1323
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  1324
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1325
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1326
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1327
     This format is used in HTTP requests and looks like:
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  1328
        'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1329
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1330
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1331
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1332
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1333
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1334
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1335
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1336
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  1337
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1338
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1339
    "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
  1340
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1341
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1342
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1343
    aStream nextPut:$(; 
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1344
            nextPutAll:self class name; 
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1345
            nextPutAll:' readIso8601FormatFrom:'''.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1346
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1347
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1348
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1349
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1350
     Timestamp now storeString 
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1351
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1352
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1353
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1354
    "
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1355
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1356
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1357
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1358
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1359
fromOSTime:anUninterpretedOSTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1360
    "strictly private: set the seconds from an OS time (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1361
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1362
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1363
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1364
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1365
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1366
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1367
getMilliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1368
    "strictly private: return the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1369
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1370
    ^ osTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1371
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1372
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1373
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1374
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1375
getSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1376
    "strictly private: return the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1377
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1378
    ^ osTime // 1000
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1379
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1380
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1381
setMilliseconds:millis
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1382
    "strictly private: set the milliseconds (since whatever)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1383
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1384
    osTime := millis.
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1385
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1386
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1387
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1388
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1389
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1390
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1391
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1392
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1393
    osTime := secs * 1000.
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  1394
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  1395
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1396
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1397
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1398
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1399
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1400
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1401
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  1402
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1403
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1404
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1405
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  1406
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1407
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1408
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1409
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1410
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1411
acceptVisitor:aVisitor with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1412
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1413
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1414
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  1415
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1416
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1417
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1418
version
11177
f5faa6cb49ed fix typo in comment
Stefan Vogel <sv@exept.de>
parents: 11140
diff changeset
  1419
    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.116 2008-09-26 10:57:30 stefan Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1420
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1421
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1422
Timestamp initialize!