Timestamp.st
author Stefan Vogel <sv@exept.de>
Thu, 16 Feb 2017 20:16:11 +0100
changeset 21466 17c794d37c87
parent 21388 c2cb27ae6231
child 21699 b8eea1f574cf
permissions -rw-r--r--
#TUNING by stefan class: String changed: #isEmpty #notEmpty use primitive code for ImmutableString
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
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
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
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
    14
"{ NameSpace: Smalltalk }"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
    15
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    16
AbstractTime subclass:#Timestamp
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    17
	instanceVariableNames:'osTime'
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
    18
	classVariableNames:'Epoch MaxOSTime MinOSTime TimeZoneInfo'
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    19
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    20
	category:'Magnitude-Time'
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    21
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    22
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    23
Object subclass:#TimestampBuilderAbstract
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    24
	instanceVariableNames:'year month day hour minute second millisecond isUtcTime
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    25
		hasTimezone yearAlreadyRead utcOffset'
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    26
	classVariableNames:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    27
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    28
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    29
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    30
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    31
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    32
	instanceVariableNames:'stream'
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    33
	classVariableNames:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    34
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    35
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    36
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    37
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    38
!Timestamp class methodsFor:'documentation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    39
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    40
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    41
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    42
 COPYRIGHT (c) 1989 by Claus Gittinger
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
    43
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    44
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    45
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    46
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    47
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    48
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    49
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    50
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    51
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    52
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    53
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    54
documentation
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    55
"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    56
    This class represents time values in milliSeconds starting some time in the past.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    57
    When printing and accessing values like #hour,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
    58
    the timestamp will be interpreted in the local timezone
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
    59
    (as opposed to UtcTimestamp, which presents itself in UTC,
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    60
     and as opposed to TZTimestamp, which remembers the timezone in which it was created).
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    61
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    62
    The internal representation, osTime, will typically start with 1970-01-01 0:00,
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    63
    as used in the Unix operating system, but other systems may bias the time differently.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    64
    Actually, the implementation does not depend or even know which time/date
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    65
    the OperatingSystem bases its time upon - it is simply keeping the value(s)
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    66
    as returned from the OS.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    67
    For conversion, these values are given back to the OS, which will know
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    68
    how to convert these times. This has the advantage, that timestamps on files
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    69
    (such as last-access-time or last-modification-time) can be handled transparently -
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    70
    especially when performing comparisons.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    71
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    72
    You should not interpret the osTime instance variable directly,
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    73
    instead (if at all), ask the OS to convert.
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    74
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    75
    The implementation of this class is not the same as in ST-80
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
    76
    (which represents the time as seconds from Jan 1., 1901).
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    77
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    78
    This class should not be confused with Time (which only represents the
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    79
    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
    80
    instances of Timestamp can.
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
    81
8264
b14c26a88e96 Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
    82
    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
    83
    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
    84
    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
    85
    AbsoluteTime is still kept as an alias for backward compatibility.
3479
9ca6229713f4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3122
diff changeset
    86
16922
148cb53b8691 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16921
diff changeset
    87
    Also Note:
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    88
        On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T00:00:00Z
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    89
        However, timestamp instances can now hold negative osTime values (which are timestamps
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    90
        before 1.1.1970 and greater than 4294967295 (2^32-1) for timestamps after 2038-01-19.
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    91
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    92
        For dates before 1582 (when calendars were changed from Julian to Grgorian),
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    93
        the so called 'proleptic gregorian calendar' is used. This assumes leap years to continue in
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    94
        the past as if a gregorian calendar was used. Thus, 0000 is considered a leap year.
16972
d8db8a2c3323 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16967
diff changeset
    95
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    96
    [author:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    97
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    98
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    99
    [See also:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   100
        UtcTimestamp Time Date
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   101
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   102
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   103
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   104
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   105
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   106
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   107
initialize
17008
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   108
    MinOSTime := OperatingSystem epochStartOSTime.
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   109
    MaxOSTime := OperatingSystem epochEndOSTime.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   110
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   111
    Epoch := UtcTimestamp basicNew setSeconds:0.
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   112
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   113
    "Modified: / 19-01-2017 / 17:01:59 / stefan"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   114
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   115
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   116
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   117
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   118
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   119
    "return an instance of the receiver, given individual components,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   120
     interpreted in the UTC timezone."
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   121
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   122
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   123
	    UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   124
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   125
    "
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
   126
     Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   127
     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
   128
     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
   129
     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
   130
     Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   131
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   132
     UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   133
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   134
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   135
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   136
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   137
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   138
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   139
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   140
decodeFromLiteralArray:anArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   141
    "decode a 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:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
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
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
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:[
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   153
        ^ self new osTime:(anArray at:3).
5379
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
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   156
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   157
        readGeneralizedFrom:(anArray at:2)
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   158
        onError:[ self conversionErrorSignal
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   159
                    raiseWith:anArray errorString:' - Timestamp 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
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   163
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   164
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   165
        decodeFromLiteralArray:#(Timestamp '20050323175226.014-01')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   166
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   167
        decodeFromLiteralArray:#(Timestamp '20050323175226.014Z')
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   168
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   169
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   170
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   171
epoch
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   172
    "the epoch is based to 0 for 1970-01-01 00:00:00.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   173
     However, we allow negative values to represent timestamps before that"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   174
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   175
    ^ Epoch
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   176
!
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   177
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   178
fromDate:aDate
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   179
    "return an instance of the receiver, initialized from a time and a date
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   180
     object.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   181
     See also `Timestamp now' and other protocol inherited
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   182
     from my superclass."
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   183
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   184
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   185
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   186
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   187
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   188
	hour:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   189
	minute:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   190
	second:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   191
	millisecond:0
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   192
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   193
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   194
     Timestamp fromDate:(Date today) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   195
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   196
     Timestamp now
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   197
    "
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   198
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   199
    "Modified: / 8.9.1995 / 15:07:30 / claus"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   200
    "Modified: / 19.4.1996 / 15:25:46 / cg"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   201
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   202
!
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   203
423
claus
parents: 392
diff changeset
   204
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   205
    "return an instance of the receiver, initialized from a time and a date
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   206
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   207
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   208
     from my superclass."
423
claus
parents: 392
diff changeset
   209
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   210
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   211
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   212
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   213
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   214
	hour:aTime hours
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   215
	minute:aTime minutes
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   216
	second:aTime seconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   217
	millisecond:aTime milliseconds
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   218
423
claus
parents: 392
diff changeset
   219
    "
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   220
     Timestamp fromDate:(Date today) andTime:(Time now)
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   221
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   222
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   223
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   224
     Timestamp now
423
claus
parents: 392
diff changeset
   225
    "
claus
parents: 392
diff changeset
   226
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   227
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   228
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   229
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   230
!
claus
parents: 392
diff changeset
   231
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   232
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   233
    "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
   234
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   235
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   236
    ^ self fromDate:(Date newDay:dayInYear year:year)
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   237
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   238
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   239
     Timestamp newDay:183 year:1996
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   240
     Timestamp newDay:1 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   241
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   242
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   243
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   244
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   245
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   246
secondsSince1970:secs
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   247
    "set time from elapsed seconds since 1-1-1970, 00:00:00.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   248
     This is the format used in the UNIX world"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   249
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   250
    ^ self basicNew setSeconds:secs.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   251
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   252
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   253
     Timestamp secondsSince1970:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   254
     Timestamp secondsSince1970:3600
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   255
     Timestamp secondsSince1970:3600*24
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   256
     (Timestamp year:2010 month:7 day:1 hour:0 minute:0 second:0)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   257
       =
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   258
     (Timestamp secondsSince1970:1277935200)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   259
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   260
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   261
    "Created: / 21-10-1996 / 17:48:30 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   262
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   263
    "Modified: / 08-01-2011 / 16:06:28 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   264
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   265
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   266
utcMillisecondsSince1970:secs
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   267
    "set time from elapsed milliseconds since the epoch 1-1-1970, 00:00:00."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   268
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   269
    ^ self basicNew setMilliseconds:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   270
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   271
    "Created: / 08-01-2011 / 16:09:32 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   272
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   273
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   274
utcNow
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   275
    "return now as utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   276
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   277
    ^ UtcTimestamp now
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   278
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   279
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   280
     Timestamp now
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   281
     Timestamp utcNow
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   282
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   283
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   284
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   285
utcSecondsSince1970:secs
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   286
    "set time from elapsed seconds since 1-1-1970, 00:00:00.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   287
     This is the format used in the UNIX world"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   288
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   289
    ^ self secondsSince1970:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   290
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   291
"/    |divMod|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   292
"/
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   293
"/    divMod := secs divMod:3600.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   294
"/    ^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2) millisecond:0.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   295
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   296
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   297
     Timestamp secondsSince1970:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   298
     Timestamp secondsSince1970:3600
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   299
     Timestamp secondsSince1970:3600*24
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   300
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   301
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   302
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   303
    "Created: / 08-01-2011 / 16:05:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   304
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   305
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   306
year:year month:month day:day  
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   307
    "return a new Timestamp, given the year, month and day (starting at 1).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   308
     Date protocol compatibility"
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   309
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   310
    ^ self
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   311
        year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   312
        month:month
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   313
        day:day
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   314
        hour:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   315
        minute:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   316
        second:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   317
        millisecond:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   318
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   319
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   320
     Timestamp year:1996 month:1 day:1 
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   321
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   322
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   323
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   324
year:y month:m day:d hour:h minute:min second:s
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   325
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   326
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   327
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   328
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   329
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:0
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   330
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   331
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   332
     Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   333
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   334
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   335
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
19771
405bdd780b99 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19713
diff changeset
   336
     Timestamp year:2080 month:7 day:1 hour:1 minute:0 second:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   337
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   338
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   339
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   340
    "Created: / 13.7.1999 / 12:06:39 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   341
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   342
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   343
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   344
year:y month:m day:d hour:h minute:min second:s millisecond:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   345
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   346
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   347
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   348
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   349
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   350
	    year:y month:m day:d hour:h minute:min second:s millisecond:millis
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   351
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   352
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   353
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   354
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   355
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   356
     UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   357
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   358
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   359
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   360
    "Created: / 13.7.1999 / 12:28:44 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   361
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   362
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   363
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   364
!Timestamp class methodsFor:'Compatibility-Squeak'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   365
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   366
current
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   367
    ^ self now
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   368
!
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   369
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   370
readFrom:aStringOrStream
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   371
    "Answer a new instance for the value given by aStringOrStream"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   372
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   373
    ^ self
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   374
        readFrom:aStringOrStream
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   375
        onError:[ TimeConversionError raiseRequestWith:aStringOrStream errorString:' - timestamp']
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   376
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   377
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   378
     self readFrom:'23-jun-2000 15:00'
14969
13470ec6f8c8 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 14713
diff changeset
   379
     self fromString:'23-jun-2000 15:00'
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   380
     self readFrom:'23-jun-2000 '
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   381
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   382
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   383
    "Modified (comment): / 20-08-2011 / 16:52:10 / cg"
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   384
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   385
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   386
year: year month: month day: day hour: hour minute: minute second: second millisecond: millisecond offset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   387
    ^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second millisecond: millisecond)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   388
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   389
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   390
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   391
     Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 millisecond:0 offset:(2 hours)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   392
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   393
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   394
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   395
year: year month: month day: day hour: hour minute: minute second: second offset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   396
    ^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   397
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   398
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   399
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   400
     Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:(2 hours)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   401
    "
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   402
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   403
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   404
!Timestamp class methodsFor:'format strings'!
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   405
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   406
defaultFormatString
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   407
    "a format string to present times in user interfaces.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   408
     Do not use this to store/retrieve times (use ISO8601 for that).
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   409
     Although the string below looks like ISO8601, it does not include TZ information,
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   410
     so when read back, it will always be interpreted as a local timestamp."
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   411
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   412
    ^ '%(year)-%(month)-%(day) %h:%m:%s.%i'
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   413
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   414
    "Created: / 16-01-2011 / 11:23:36 / cg"
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   415
! !
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   416
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   417
!Timestamp class methodsFor:'obsolete'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   418
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   419
day:d month:m year:y hour:h minutes:min seconds:s
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   420
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   421
    "This is obsolete. User #year:month:day:hour:minute:second:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   422
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   423
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   424
	year:y month:m day:d hour:h
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   425
	minute:min second:s millisecond:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   426
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   427
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   428
    "Modified: / 1.7.1996 / 15:22:26 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   429
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   430
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   431
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   432
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   433
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   434
    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   435
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   436
    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   437
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   438
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   439
     Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   440
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   441
     Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   442
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   443
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   444
    "Created: / 1.7.1996 / 14:46:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   445
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   446
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   447
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   448
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   449
newDay:day month:month year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   450
    <resource: #obsolete>
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   451
    "return a new Timestamp, given the year, month and day (starting at 1).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   452
     Date protocol compatibility"
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   453
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   454
    ^ self
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   455
	year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   456
	month:month
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   457
	day:day
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   458
	hour:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   459
	minute:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   460
	second:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   461
	millisecond:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   462
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   463
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   464
     Timestamp newDay:1 month:1 year:1996
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   465
    "
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   466
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   467
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   468
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   469
!Timestamp class methodsFor:'private'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   470
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   471
basicReadFrom:aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   472
    "return a new Timestamp, reading a printed representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   473
     The string is interpreted as 24 hour format, as printed.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   474
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   475
     Notice, that this is NOT the storeString format, which is iso8601
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   476
     This is more or less a heuristic attempt to read any reasonable format.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   477
     If the input starts with an integer > 31,
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   478
     it is assumed to be a year and the rest is read in iso8601 format.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   479
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   480
     KLUDGE:
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   481
        us and non-us format have different ordering of day and month;
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   482
        The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   483
        or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   484
     On error, raise an exception"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   485
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   486
    |monthOrYear firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName ch utcOffsetOrNil count|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   487
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   488
    count := 0.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   489
    monthOrYear := aStream throughAnyForWhich:[:ch | count := count+1. ch isDigit and:[count <= 4]].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   490
    firstNumber := Integer readFrom:monthOrYear onError:[TimeConversionError raiseErrorString:' - integer expected'].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   491
    firstNumber > 31 ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   492
        "/ assume iso8601 format;
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   493
        ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   494
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   495
    aStream skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   496
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   497
    "/ consider this a kludge
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   498
    usFormat := (aStream peek == $/ ).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   499
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   500
    [(ch := aStream peekOrNil) notNil and:[ch isLetterOrDigit]] whileFalse:[aStream next].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   501
    (ch notNil and:[ch isDigit]) ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   502
        secondNumber := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   503
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   504
        usFormat ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   505
            month := firstNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   506
            day := secondNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   507
        ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   508
            month := secondNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   509
            day := firstNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   510
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   511
    ] ifFalse:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   512
        possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   513
        month := Date indexOfMonth:possibeMonthName asLowercase.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   514
        day := firstNumber.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   515
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   516
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   517
    (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   518
    (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   519
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   520
    [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   521
    year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   522
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   523
    aStream atEnd ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   524
        hour := min := sec := millis := 0.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   525
    ] ifFalse:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   526
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   527
        hour := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   528
        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   529
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   530
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   531
        min := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   532
        (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   533
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   534
        aStream atEnd ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   535
            sec := millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   536
        ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   537
            [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   538
            sec := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   539
            (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   540
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   541
            aStream peek == $. ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   542
                aStream next.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   543
                millis := Integer readFrom:aStream onError:0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   544
                millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   545
            ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   546
                millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   547
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   548
            aStream atEnd ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   549
                utcOffsetOrNil := self utcOffsetFrom:aStream
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   550
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   551
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   552
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   553
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   554
    "special check - only 24:00:00 is allowed;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   555
     every time after that must wrap"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   556
    hour == 24 ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   557
        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   558
    ].
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   559
    utcOffsetOrNil notNil ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   560
        utcOffsetOrNil = 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   561
            "/ utc timestamp
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   562
            ^ UtcTimestamp year:year month:month day:day hour:hour minute:min second:sec millisecond:millis
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   563
        ].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   564
        ^ TZTimestamp new 
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   565
                UTCyear:year month:month day:day hour:hour minute:min second:sec millisecond:millis;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   566
                utcOffset:utcOffsetOrNil;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   567
                addSeconds:utcOffsetOrNil.
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   568
    ].
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   569
    "/ a local timestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   570
    ^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   571
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   572
    "some ad hoc formats:
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   573
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   574
     Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   575
     Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   576
     Timestamp basicReadFrom:'20-feb-1995 13:11:06' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   577
     Timestamp basicReadFrom:'20-foo-1995 13:11:06' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   578
     (Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month    - european
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   579
     (Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month    - us
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   580
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   581
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   582
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100 MESZ' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   583
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100+0200' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   584
     Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   585
     Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   586
     Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   587
     Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   588
     Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   589
     Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   590
     Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   591
     Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   592
     Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   593
     Timestamp basicReadFrom:'foo' readStream
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   594
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   595
     any iso8601 format:.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   596
     Timestamp basicReadFrom:(Timestamp now printString readStream)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   597
     Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   598
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   599
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000-0200' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   600
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   601
     UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   602
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   603
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   604
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   605
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   606
    "common helper for read methods.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   607
     Return a new Timestamp, reading an iso8601 representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   608
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   609
     If the time ends with a 'Z' it is the UTC (or zulu) time,
16292
efa6c17501b7 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16192
diff changeset
   610
     otherwise it is local time.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   611
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   612
     Missing month/day values are replaced with 1; i.e. 1999T24:00
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   613
     is the same as 1999-01-01T24:00:00.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   614
     Missing minute, second and ms values are replaced with 0;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   615
     i.e. 1999T12 is the same as 1999-01-01T12:00:00.000.
16292
efa6c17501b7 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16192
diff changeset
   616
     Partial hours, minutes, seconds are allowed at the end,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   617
     decimal separators are both $. and $, .
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   618
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   619
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   620
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   621
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   622
    "/ changed to use the new reader
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   623
    ^ TimestampISO8601Builder
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   624
	read:aStringOrStream withClass:self
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   625
	yearAlreadyReadAs:yearOrNil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   626
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   627
"/    |str day month dayInWeek week year hour min sec tmpDay millis fraction isUtcTime peekChar ch|
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   628
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   629
"/    str := aStringOrStream readStream.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   630
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   631
"/    month := day := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   632
"/    hour := millis := 0.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   633
"/    isUtcTime := false.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   634
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   635
"/    yearOrNil notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   636
"/        year := yearOrNil
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   637
"/    ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   638
"/        year := Integer readFrom:str onError:nil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   639
"/        year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   640
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   641
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   642
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   643
"/    (((ch := str peek) == $-) or:[ch == $W]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   644
"/        (ch == $-) ifTrue:[ str next ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   645
"/        str peek == $W ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   646
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   647
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   648
"/            "/ week follows
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   649
"/            week := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   650
"/            (week between:1 and:53) ifFalse:[ TimeConversionError raiseErrorString:' - bad week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   651
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   652
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   653
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   654
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   655
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   656
"/                dayInWeek := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   657
"/                (dayInWeek between:1 and:7) ifFalse:[ TimeConversionError raiseErrorString:' - bad day in week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   658
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   659
"/                dayInWeek := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   660
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   661
"/            tmpDay := Date newDayInWeek:dayInWeek week:week year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   662
"/            day := tmpDay day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   663
"/            month := tmpDay month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   664
"/            year := tmpDay year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   665
"/        ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   666
"/            "/ month follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   667
"/            month := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   668
"/            (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   669
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   670
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   671
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   672
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   673
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   674
"/                day := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   675
"/                (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   676
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   677
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   678
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   679
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   680
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   681
"/    str atEnd ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   682
"/        "time follows"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   683
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   684
"/        str peek == $T ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   685
"/            "we treat the T as optional here"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   686
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   687
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   688
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   689
"/        hour := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   690
"/        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   691
"/        str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   692
"/        str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   693
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   694
"/            "/ minutes follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   695
"/            min := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   696
"/            (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   697
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   698
"/            str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   699
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   700
"/                "/ seconds follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   701
"/                sec := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   702
"/                (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   703
"/                str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   704
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   705
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   706
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   707
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   708
"/        (peekChar == $. or:[peekChar == $,]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   709
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   710
"/            "/ decimals follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   711
"/            fraction := Number readMantissaFrom:str radix:10.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   712
"/            min isNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   713
"/                min := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   714
"/                fraction := min fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   715
"/                min := min truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   716
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   717
"/            (sec isNil and:[fraction ~= 0])ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   718
"/                sec := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   719
"/                fraction := sec fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   720
"/                sec := sec truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   721
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   722
"/            fraction ~= 0 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   723
"/                millis := (1000 * fraction) rounded.  "/ mhmh - should it be truncated ?
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   724
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   725
"/        ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   726
"/
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   727
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   728
"/        peekChar notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   729
"/            peekChar == $Z ifTrue:[
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   730
"/                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   731
"/                isUtcTime := true.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   732
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   733
"/                ((peekChar == $+) or:[peekChar == $- ]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   734
"/                    str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   735
"/                    self halt.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   736
"/                    isUtcTime := true.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   737
"/                ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   738
"/            ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   739
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   740
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   741
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   742
"/    min isNil ifTrue:[min := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   743
"/    sec isNil ifTrue:[sec := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   744
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   745
"/    "special check - only 24:00:00 is allowed;
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   746
"/     every time after that must wrap"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   747
"/    hour == 24 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   748
"/        (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   749
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   750
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   751
"/    isUtcTime ifTrue:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   752
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   753
"/            UTCYear:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   754
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   755
"/    ] ifFalse:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   756
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   757
"/            year:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   758
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   759
"/    ]
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   760
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   761
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   762
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   763
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   764
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   765
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   766
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   767
     Timestamp readIso8601FormatFrom:'1995T13:11.5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   768
     Timestamp readIso8601FormatFrom:'1995T13:11,5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   769
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   770
     Timestamp readIso8601FormatFrom:'1995T13.25'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   771
     Timestamp readIso8601FormatFrom:'1995T13.333333'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   772
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   773
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   774
     Timestamp readIso8601FormatFrom:'2014W40'   -> 29.sep.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   775
     Timestamp readIso8601FormatFrom:'2014W44-4' -> 30.oct.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   776
     Timestamp readIso8601FormatFrom:'2014W1'    -> 30.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   777
     Timestamp readIso8601FormatFrom:'2014W1-1'  -> same 30.dec.2013 !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   778
     Timestamp readIso8601FormatFrom:'2014W1-2'  -> 31.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   779
     Timestamp readIso8601FormatFrom:'2014W1-3'  -> 1.jan.2014       !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   780
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   781
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   782
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   783
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   784
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   785
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   786
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   787
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   788
     Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   789
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   790
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   791
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   792
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   793
    "common helper for read methods."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   794
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   795
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   796
        self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   797
    ] on:ConversionError do:exceptionValue.
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   798
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   799
    "Modified: / 09-02-2017 / 10:01:27 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   800
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   801
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   802
!Timestamp class methodsFor:'reading'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   803
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   804
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   805
    "return a new Timestamp, reading a printed representation from aStream using a formatString.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   806
     The formatString is similar to the one used when printing.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   807
     On error, exceptionalValue is returned.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   808
     If exceptionalValue is a one-arg block, an error message is passed as argument.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   809
     Format:
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   810
        %h      hours, 00..23 (i.e. european)  0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   811
        %u      hours, 00..12 (i.e. us)        0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   812
        %m      minutes, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   813
        %s      seconds, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   814
        %i      milliseconds, 000..999         0-padded to length 3
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   815
        %f      fractional seconds             any length, but only milliseconds kept
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   816
        %a      am/pm
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   817
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   818
        %d             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   819
        %D             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   820
        %(day)         - day
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   821
        %(dayOfYear)   - 1..365/366
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   822
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   823
        %(month)       - month
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   824
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   825
        %(monthName)   - monthName
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   826
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   827
        %(year)        - year, full 4 digits
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   828
        %Y             - year, last 2 digits only,
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   829
                         0..71 map to 2000..2071;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   830
                         72..99 map to 1972..1999;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   831
        %Y1900          - year, last 2 digits only, map to 1900..1999
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   832
        %Y2000          - year, last 2 digits only, map to 2000..2099
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   833
        %Y1950          - year, last 2 digits only, map to 1950..2049
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   834
        %Y1980          - year, last 2 digits only, map to 1980..2079
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   835
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   836
     an optional length after the % gives a field length;
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   837
        i.e. %2h%2m%2s parses '123557' as 12:35:37
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   838
        and '%4(year)%2(month)%2(day)' parses '20060620' as 2006-06-20 00:00:00
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   839
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   840
     Please consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   841
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   842
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   843
    |day month year dayOfYear monthAndDay
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   844
     hour minute second millisecond
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   845
     utcOffset inStream formatStream error fChar format itemHandler
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   846
     len now s fractionString fraction|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   847
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   848
    error := [:msg |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   849
                exceptionalValue isBlock ifTrue:[
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   850
                    ^ exceptionalValue valueWithOptionalArgument:'format error'
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   851
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   852
                    ^ exceptionalValue value
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   853
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   854
             ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   855
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   856
    itemHandler := [:format |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   857
        |input|
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   858
        
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   859
        input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   860
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   861
        ( #('d' 'D' 'day' ) includes:format ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   862
            day := Integer readFrom:input onError:[ error value:'invalid day' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   863
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   864
        ] ifFalse:[ ( format = 'month' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   865
            month := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   866
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   867
        ] ifFalse:[ ( format = 'year' or:[ format = 'y' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   868
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   869
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   870
        ] ifFalse:[ ( format = 'Y' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   871
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   872
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
18449
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   873
            (year < 70) ifTrue:[
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   874
                year := year + 2000
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   875
            ] ifFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   876
                year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   877
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   878
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   879
        ] ifFalse:[ (format = 'monthName') ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   880
            s := input nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetter].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   881
            month := Date indexOfMonth:s asLowercase language:languageOrNil
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   882
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   883
        ] ifFalse:[ (format = 'dayOfYear') ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   884
            dayOfYear := Integer readFrom:input onError:[ error value:'invalid day of year' ].
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   885
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   886
        ] ifFalse:[ ( format sameAs: 'Y1900' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   887
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   888
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   889
            year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   890
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   891
        ] ifFalse:[ ( format sameAs:  'Y1950' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   892
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   893
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   894
            (year between:0 and: 49) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   895
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   896
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   897
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   898
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   899
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   900
        ] ifFalse:[ ( format sameAs:  'Y1980' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   901
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   902
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   903
            (year between:0 and: 79) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   904
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   905
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   906
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   907
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   908
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   909
        ] ifFalse:[ ( format sameAs:  'Y2000' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   910
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   911
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   912
            year := year + 2000
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   913
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   914
        ] ifFalse:[ ( format = 'h' or:[ format = 'H' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   915
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   916
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   917
        ] ifFalse:[ ( format = 'u'  or:[ format = 'U']) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   918
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   919
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   920
        ] ifFalse:[ ( format = 'm'  or:[ format = 'M' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   921
            minute := Integer readFrom:input onError:[ error value:'invalid minute' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   922
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   923
        ] ifFalse:[ ( format = 's'  or:[ format = 'S' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   924
            second := Integer readFrom:input onError:[ error value:'invalid second' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   925
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   926
        ] ifFalse:[ ( format = 'i'  or:[ format = 'I' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   927
            millisecond := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   928
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   929
        ] ifFalse:[ ( format = 'f'  or:[ format = 'F' ]) ifTrue:[
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   930
            fractionString := input upToMatching:[:ch | ch isDigit not].
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   931
            fraction := FixedPoint readFrom:'0.',fractionString.
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   932
            millisecond := (fraction * 1000) truncated.
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   933
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   934
        ] ifFalse:[ ( format = 'tz' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   935
            utcOffset := self utcOffsetFrom:input.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   936
            utcOffset isNil ifTrue:[ error value:'invalid timezone' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   937
        ] ifFalse:[ ( format = 'a' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   938
            s := (input next:2) asLowercase.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   939
            s = 'am' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   940
                (hour between:0 and:12) ifFalse:[ error value:'invalid hour' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   941
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   942
                s = 'pm' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   943
                    (hour between:1 and:12) ifFalse:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   944
                    hour := hour + 12.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   945
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   946
                    error value:'invalid am/pm'
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   947
                ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   948
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   949
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   950
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   951
            error value:'unhandled format:',format
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   952
        ]]]]]]]]]]]]]]]]]]
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   953
    ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   954
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   955
    hour := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   956
    minute := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   957
    second := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   958
    millisecond := 0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
   959
    utcOffset := 0.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   960
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   961
    inStream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   962
    formatStream := formatString readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   963
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   964
    [formatStream atEnd] whileFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   965
        fChar := formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   966
        fChar = Character space ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   967
            inStream peek isSeparator ifFalse:[ error value: 'format error; space expcected' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   968
            inStream skipSeparators.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   969
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   970
            fChar == $% ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   971
                len := nil.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   972
                (formatStream peek isDigit) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   973
                    len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   974
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   975
                (formatStream peek == $() ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   976
                    formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   977
                    format := formatStream upTo:$).
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   978
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   979
                    (formatStream peek == ${) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   980
                        formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   981
                        format := formatStream upTo:$}.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   982
                    ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   983
                        (formatStream peek isLetter) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   984
                            format := formatStream nextAlphaNumericWord.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   985
                        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   986
                            error value:'unhandled format:',formatStream peek
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   987
                        ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   988
                    ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   989
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   990
                itemHandler value:format.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   991
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   992
                inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected'].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   993
                inStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   994
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   995
        ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   996
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   997
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   998
    year isNil ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   999
        year := (now := Timestamp now) year
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1000
    ].
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1001
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1002
    dayOfYear notNil ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1003
        monthAndDay := Date monthAndDayFromDayInYear:dayOfYear forYear:year.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1004
        month := (monthAndDay at:1).
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1005
        day := (monthAndDay at:2).  
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1006
    ].
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1007
    
18451
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1008
    ^ (self 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1009
        year:year month:month day:day 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1010
        hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1011
            + utcOffset
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1012
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1013
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1014
     Timestamp readFrom:'20-2-1995 13:11:06' format:'%day-%month-%year %h:%m:%s' language:nil onError:[self halt]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1015
     Timestamp readFrom:'20021995131106' format:'%2d%2month%4y%2h%2m%2s' language:nil onError:[self halt]
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1016
     Timestamp readFrom:'200295131106' format:'%2d%2month%2y%2h%2m%2s' language:nil onError:[self halt]
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1017
     Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1900)%2h%2m%2s' language:nil onError:[self halt]
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1018
     Timestamp readFrom:'200260131106' format:'%2d%2month%2(y2000)%2h%2m%2s' language:nil onError:[self halt]
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1019
     Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1950)%2h%2m%2s' language:nil onError:[self halt]
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1020
     Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1980)%2h%2m%2s' language:nil onError:[self halt]
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1021
     Timestamp readFrom:'March 7 2009 7:30pm EST' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1022
     Timestamp readFrom:'March 7 2009 7:30pm UTC' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt]
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1023
     Timestamp readFrom:'2015103' format:'%4y%3dayOfYear' onError:[self halt]
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1024
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1025
     Timestamp readFrom:'20-2-1995 13:11:06.999' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1026
     Timestamp readFrom:'20-2-1995 13:11:06.100' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1027
     Timestamp readFrom:'20-2-1995 13:11:06.010' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1028
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1029
     Timestamp readFrom:'20-2-1995 13:11:06.1' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1030
     Timestamp readFrom:'20-2-1995 13:11:06.01' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1031
     Timestamp readFrom:'20-2-1995 13:11:06.001' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1032
     Timestamp readFrom:'20-2-1995 13:11:06.12345' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1033
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1034
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1035
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1036
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1037
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1038
     The string is interpreted as 24 hour format, as printed.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1039
     Notice, that this is not the storeString format and
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  1040
     is different from the format expected by readFrom:.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1041
     The format read here is either dd-mm-yyyy hh:mm:ss.iii
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1042
     or iso8601 (if the first integer is >31).
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1043
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1044
     Please consider using a standard format, such as iso8601."
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1045
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1046
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1047
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1048
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1049
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
  1050
    Error handle:[:ex |
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1051
	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
  1052
    ] do:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1053
	newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1054
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
  1055
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1056
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1057
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1058
     Timestamp readFrom:'20-2-1995 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1059
     Timestamp readFrom:'20-2-1995 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1060
     Timestamp readFrom:'20-2-2001 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1061
     Timestamp readFrom:'20-2-1995 13:11:06.100'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1062
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1063
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1064
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1065
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1066
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1067
     Timestamp readFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1068
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1069
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1070
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1071
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1072
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1073
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1074
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1075
readGeneralizedFrom:aStringOrStream
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1076
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1077
     The format read here is either
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1078
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1079
     or:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1080
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1081
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1082
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1083
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1084
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1085
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1086
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1087
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1088
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1089
     is different from the format expected by readFrom:.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1090
    "
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1091
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1092
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1093
        readGeneralizedFrom:aStringOrStream
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1094
        short:false
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1095
        onError:[
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1096
            self conversionErrorSignal raiseWith:aStringOrStream errorString:' - Timestamp GeneralizedTime format error'
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1097
        ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1098
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1099
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1100
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1101
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1102
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1103
    "return a new Timestamp, reading a printed representation from aStream.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1104
     The format read here is either
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1105
	yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1106
     or:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1107
	yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1108
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1109
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1110
     This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1111
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1112
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1113
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1114
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1115
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1116
     is different from the format expected by readFrom:.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1117
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1118
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1119
    ^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1120
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1121
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1122
     |s|
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1123
     s := '' writeStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1124
     Timestamp now printGeneralizedOn:s.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1125
     Timestamp readGeneralizedFrom:s contents onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1126
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1127
 Daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1128
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1129
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1130
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1131
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1132
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1133
 No daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1134
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1135
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1136
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1137
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1138
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1139
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1140
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1141
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1142
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1143
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1144
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1145
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1146
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1147
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1148
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1149
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1150
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1151
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1152
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1153
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1154
    "Modified: / 22-08-2006 / 12:30:11 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1155
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1156
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1157
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1158
    "return a new Timestamp, reading a printed representation from aStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1159
     The long format read here is either
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1160
            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1161
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1162
            yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1163
     The (not recommended) short forms are:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1164
            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1165
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1166
            yy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1167
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1168
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1169
     This format is used for BER specification of the ASN.1 GeneralizedTime and
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1170
     UTCTime as defined in X.208 Sec. 33, so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1171
     The short form is no longer recommended.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1172
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1173
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1174
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1175
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1176
     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
  1177
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1178
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1179
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1180
    ^ [
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1181
        |newTime str day month year hour min sec millis c|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1182
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1183
        sec := millis := 0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1184
        str := aStringOrStream readStream.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1185
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1186
        shortFormat ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1187
            year := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1188
            year < 50 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1189
                year := year + 2000.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1190
            ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1191
                year := year + 1900.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1192
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1193
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1194
            year := Integer readFrom:(str next:4).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1195
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1196
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1197
        month := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1198
        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1199
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1200
        day := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1201
        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1202
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1203
        str skipSeparators.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1204
        hour:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1205
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1206
        str peek == $: ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1207
        min:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1208
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1209
        str atEnd ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1210
            str peek == $: ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1211
            sec := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1212
            (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1213
            str atEnd ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1214
                str peek == $. ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1215
                    str next.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1216
                    millis := Integer readFrom:str.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1217
                ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1218
                str skipSeparators.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1219
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1220
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1221
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1222
        str atEnd ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1223
            "/ this is local time
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1224
            newTime := self year:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1225
                            hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1226
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1227
            c := str next.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1228
            c ~~ $Z ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1229
                |tzh tzmin|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1230
                tzh := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1231
                tzmin := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1232
                c == $+ ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1233
                    "the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes"
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1234
                    hour := hour - tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1235
                    min := min - tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1236
                ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1237
                    c == $- ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1238
                        "the timezone is behind of UTC or WEST from Greenwich: add hours and minutes"
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1239
                        hour := hour + tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1240
                        min := min + tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1241
                    ] ifFalse:exceptionBlock
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1242
                ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1243
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1244
            "this is UTC time"
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1245
            newTime := self UTCYear:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1246
                              hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1247
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1248
        newTime
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1249
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1250
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1251
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1252
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1253
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1254
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1255
     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
  1256
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1257
     Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1258
     Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1259
     Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1260
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1261
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1262
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1263
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1264
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1265
     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
  1266
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1267
 No daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1268
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1269
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1270
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1271
     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
  1272
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1273
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1274
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1275
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1276
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1277
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1278
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1279
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1280
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1281
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1282
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[]
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1283
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1284
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1285
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1286
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1287
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1288
    "Modified: / 22-08-2006 / 12:30:11 / cg"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1289
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1290
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1291
readISO8601From:aStringOrStream
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1292
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1293
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1294
    ^ self readIso8601FormatFrom:aStringOrStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1295
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1296
    "Created: / 16-06-2005 / 16:13:36 / masca"
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1297
    "Modified: / 09-02-2017 / 10:04:53 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1298
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1299
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1300
readISO8601From:aStringOrStream onError:exceptionValue
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1301
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1302
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1303
    ^ self readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1304
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1305
    "Modified: / 09-02-2017 / 10:05:56 / stefan"
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1306
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1307
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1308
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1309
    "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
  1310
     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
  1311
     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
  1312
     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
  1313
     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
  1314
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1315
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1316
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1317
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1318
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1319
    "changed to use the new reader"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1320
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1321
    ^ TimestampISO8601Builder read:aStringOrStream withClass:self
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1322
"/    ^ self
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1323
"/        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1324
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1325
    "
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1326
     Timestamp readIso8601FormatFrom:'20141106T123843.299Z'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1327
     Timestamp readIso8601FormatFrom:'20141106T123843.299'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1328
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1329
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1330
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1331
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1332
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1333
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1334
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1335
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1336
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1337
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1338
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1339
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1340
     Timestamp readIso8601FormatFrom:'20141106T122831.894Z'
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1341
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1342
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1343
     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
  1344
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1345
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1346
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1347
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1348
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1349
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1350
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1351
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1352
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1353
     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
  1354
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1355
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1356
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1357
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1358
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1359
    "/ changed to use the new reader
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1360
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1361
        TimestampISO8601Builder read:aStringOrStream withClass:self
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1362
    ] on:ConversionError do:exceptionValue.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1363
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1364
"/    ^ self
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1365
"/        readIso8601FormatFrom:aStringOrStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1366
"/        yearAlreadyRead:nil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1367
"/        onError:exceptionValue
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1368
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1369
    "Modified: / 09-02-2017 / 10:02:03 / stefan"
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1370
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1371
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1372
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1373
    "please use this only for http-requests.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1374
     All other programs should use iso8601, which is the standard for times and dates.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1375
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1376
     All HTTP/1.0 date/time stamps must be represented in Universal Time (UT),
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1377
     also known as Greenwich Mean Time (GMT), without exception.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1378
     This is indicated in the first two formats by the inclusion of
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1379
     'GMT' as the three-letter abbreviation for time zone,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1380
     and should be assumed when reading the asctime format.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1381
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1382
     HTTP-date      = rfc1123-date | rfc850-date | asctime-date
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1383
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1384
     rfc1123-date   = wkday ',' SP date1 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1385
     rfc850-date    = weekday ',' SP date2 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1386
     asctime-date   = wkday SP date3 SP time SP 4DIGIT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1387
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1388
     date1          = 2DIGIT SP month SP 4DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1389
                      ; day month year (e.g., 02 Jun 1982)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1390
     date2          = 2DIGIT '-' month '-' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1391
                      ; day-month-year (e.g., 02-Jun-82)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1392
     date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1393
                      ; month day (e.g., Jun  2)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1394
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1395
     time           = 2DIGIT ':' 2DIGIT ':' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1396
                      ; 00:00:00 - 23:59:59
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1397
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1398
     wkday          = 'Mon' | 'Tue' | 'Wed'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1399
                    | 'Thu' | 'Fri' | 'Sat' | 'Sun'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1400
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1401
     weekday        = 'Monday' | 'Tuesday' | 'Wednesday'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1402
                    | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1403
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1404
     month          = 'Jan' | 'Feb' | 'Mar' | 'Apr'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1405
                    | 'May' | 'Jun' | 'Jul' | 'Aug'
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1406
                    | 'Sep' | 'Oct' | 'Nov' | 'Dec'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1407
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1408
     Mon, 17 Aug 2009 11:11:15 GMT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1409
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1410
     however, occasionally, someone presents us with non-UTC strings which include a timezone;
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1411
     thus, this also supports:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1412
         Mon, 17 Aug 2009 11:11:15 +xxxx
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1413
         Mon, 17 Aug 2009 11:11:15 -xxxx
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1414
     and:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1415
         Mon, 17 Aug 2009 11:11:15 PST
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1416
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1417
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1418
    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1419
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1420
    rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1421
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1422
    parts := rfc1123String asCollectionOfSubstringsSeparatedBy:Character space.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1423
    parts size == 6 ifTrue:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1424
        indexModifier := 0.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1425
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1426
        parts size == 5 ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1427
            indexModifier := -1.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1428
        ] ifFalse:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1429
            ^ exceptionBlock value
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1430
        ].
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1431
    ].
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1432
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1433
    day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1434
    year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1435
    time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1436
    monthName := parts at:3 + indexModifier.
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1437
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1438
    month := Date indexOfMonth:monthName language:#en.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1439
    month = 0 ifTrue:[^ exceptionBlock value].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1440
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1441
    utcOffsetString := parts at:6 + indexModifier ifAbsent:nil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1442
    utcOffset := self utcOffsetFrom:utcOffsetString.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1443
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1444
    (utcOffset isNil or:[utcOffset = 0]) ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1445
        ^ UtcTimestamp year:year month:month day:day hour:time hour minute:time minute second:time second millisecond:0.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1446
    ].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1447
    ^ TZTimestamp new 
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1448
            setOSTimeFromUTCYear:year month:month day:day hour:time hour minute:time minute second:time second millisecond:0;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1449
            utcOffset:utcOffset;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1450
            addSeconds:utcOffset.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1451
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1452
    "
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1453
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 GMT' onError:nil
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1454
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 UTC' onError:nil
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1455
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PST' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1456
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PDT' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1457
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 +0100' onError:nil
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1458
     self readRFC1123FormatFrom:'17 Aug 2009 11:11:15 +0100' onError:nil
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1459
    "
13085
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1460
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1461
    "Modified: / 05-10-2010 / 16:05:32 / cg"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1462
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1463
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1464
timezoneInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1465
    "return a table containing timezone information.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1466
     This may or may not be correct by the time you read this.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1467
     It is recommended to add explicit information in the form of +hh:mm to a printed
16990
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1468
     representation, instead of using names.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1469
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1470
     As this is searched for when reverse converting from utcOffset to TZName"
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1471
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1472
    "/ the table below can be customized via a setter,
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1473
    "/ if an application knows better 
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1474
    "/ (reading a system timeZone table, or limiting the table to military/non-military names only, for example)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1475
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1476
    TimeZoneInfo notNil ifTrue:[^ TimeZoneInfo].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1477
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1478
    "/ table is name, utcOffset(minutes), DST-flag, startDay, endDay
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1479
    ^ #(
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1480
            'Z'     0   false          "/ zulu
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1481
            'UTC'   0   false    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1482
            'GMT'   0   false    
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1483
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1484
            "/ US
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1485
            'HAST' -600 false          "/ hawai standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1486
            'AKST' -540 false          "/ alaska standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1487
            'YST'  -540 false          "/ yukon standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1488
            'PST'  -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1489
            'PT'   -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1490
            'MST'  -420 false          "/ mountain standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1491
            'CST'  -360 false          "/ central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1492
            'EST'  -300 false          "/ eastern standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1493
            'AST'  -240 false          "/ atlantic standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1494
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1495
            'NST'  -210 false          "/ new foundland standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1496
            'PMST' -180 false          "/ pierre & miquelon
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1497
            'WGT'  -180 false          "/ west greenland
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1498
            'EGT'  -60  false          "/ east greenland
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1499
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1500
            "/ europe
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1501
            'CET'   60  false          "/ central european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1502
            'EET'   120 false          "/ east european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1503
            'WET'   0   false          "/ west european
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1504
            "/ conflict with india!!
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1505
            "/ 'IST'   1               "/ irish standard time
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1506
            "/ 'IST'   1               "/ israel standard time
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1507
            'AZOT'   -60 false         "/ azores standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1508
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1509
            'MSK'   240 false          "/ moscow european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1510
            'MSD'   240 false
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1511
            'BT'    240 false          "/ baghdad
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1512
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1513
            "/ pacific
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1514
            'NZST'  720 false          "/ new zealand standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1515
            'FJT'   720 false          "/ fiji
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1516
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1517
            "/ south america
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1518
            'ART'   -180 false         "/ argentina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1519
            'BOT'   -240 false         "/ bolivia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1520
            'BRT'   -180 false         "/ brasilia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1521
            'CLT'   -240 false         "/ chile
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1522
            'ECT'   -300 false         "/ equador
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1523
            'PET'   -300 false         "/ peru
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1524
            'PYT'   -240 false         "/ paraguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1525
            'UYT'   -180 false         "/ uruguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1526
            'VET'   -270 false         "/ venezuela standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1527
            'VST'   -270 false         "/ venezuela standard
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1528
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1529
            "/ africa
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1530
            'CAT'   120 false          "/ central africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1531
            'EAT'   180 false          "/ east africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1532
            'SAST'  120 false          "/ south africa standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1533
            'WAT'   60 false           "/ west africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1534
            'WT'    0 false            "/ west sahara standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1535
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1536
            'AST'   180 false          "/ arabia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1537
            'IRT'   210 false          "/ iran time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1538
            'AFT'   270 false          "/ afghanistan time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1539
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1540
            'HKT'   480 false          "/ hongkong
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1541
            'IST'   330 false          "/ india standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1542
            'ICT'   420 false          "/ indochina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1543
            'CNST'  480 false          "/ china standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1544
            'JST'   540 false          "/ japan standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1545
            'KST'   540 false          "/ korea standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1546
            'SGT'   480 false          "/ singapore
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1547
            'MYT'   480 false          "/ malaysia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1548
            'AWST'  480 false          "/ australian west standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1549
            'ACWST' 525 false          "/ australian central western standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1550
            'ACST'  570 false          "/ australian central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1551
            'AEST'  600 false          "/ australian east standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1552
            'NFT'   690 false          "/ norfolk island, australia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1553
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1554
            'CHAST' 765 false          "/ chatham island standard
20429
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1555
            'WST'   780 false          "/ west samoa - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1556
            'TOT'   780 false          "/ tonga - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1557
            'TKT'   780 false          "/ tokelau - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1558
            'LINT'  840 false          "/ line islands - yes that's 14!!
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1559
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1560
            "/ misc
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1561
            'IDLW' -720 false          "/ international date line west
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1562
            'IDLE'  720 false          "/ international date line east
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1563
20616
566f5101bad2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20429
diff changeset
  1564
            'MEZ'   60  false           "/ mittel europäische Zeit /  central european (german)
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1565
            'MESZ'  120 true            "/ central european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1566
            'WESZ'  60  true            "/ west european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1567
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1568
            'WEZ'   0   false           "/ west european (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1569
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1570
            'HADT'  -540 true           "/ hawaii summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1571
            'ADT'   -180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1572
            'AKDT'  -540 true         "/ alaska summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1573
            'YDT'   -480 true         "/ yukon summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1574
            'PDT'   -420 true         "/ pacific daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1575
            'MDT'   -360 true         "/ mountain daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1576
            'CDT'   -300 true         "/ central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1577
            'EDT'   -240 true         "/ eastern daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1578
            'CLST'  -180 true         "/ chile summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1579
            'NDT'   -150 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1580
            'PMDT'  -120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1581
            'BRST'  -120 true         "/ brasilia summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1582
            'WGST'  -120 true         "/ west greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1583
            'EGST'   0 true           "/ east greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1584
            'AZOST'  0 true           "/ azores summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1585
            'EEST'   180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1586
            'CEST'   120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1587
            'WAST'   120 true         "/ west africa summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1588
            "/ 'WST'   60 true        "/ west sahara summer - conflict with west samoa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1589
            'WEST'  60 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1590
            'BST'   60 true           "/ british summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1591
            'IRST'  270 true          "/ iran summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1592
            'AWDT'  540 true          "/ australian west daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1593
            'ACDT'  630 true          "/ australian central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1594
            'AEDT'  660 true          "/ australian east daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1595
            'CHADT' 825 true          "/ chatham island daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1596
            'FJST'  780 true          "/ fiji summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1597
            'NZDT'  780 true          "/ new zealand summer
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1598
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1599
            "/ military
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1600
            'A'     60  false          "/ alpha
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1601
            'B'     120 false          "/ bravo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1602
            'C'     180 false          "/ charlie
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1603
            'D'     240 false          "/ delta
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1604
            'E'     300 false          "/ echo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1605
            'F'     360 false          "/ foxtrot
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1606
            'G'     420 false          "/ golf
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1607
            'H'     480 false          "/ hotel
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1608
            'I'     540 false          "/ also called india - how misleading
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1609
            'K'     600 false          "/ kilo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1610
            'L'     660 false          "/ lima - but not there
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1611
            'M'     720 false          "/ mike
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1612
            'N'     -60  false         "/ november (but also in other months)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1613
            'O'     -120 false         "/ oscar
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1614
            'P'     -180 false         "/ papa (not mama)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1615
            'Q'     -240 false         "/ quebec - really?
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1616
            'R'     -300 false         "/ romeo and juliet
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1617
            'S'     -360 false         "/ sierra
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1618
            'T'     -420 false         "/ tango (& not rumba)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1619
            'U'     -480 false         "/ uniform
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1620
            'V'     -540 false         "/ victor
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1621
            'W'     -600 false         "/ whiskey (scotch?)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1622
            'X'     -660 false         "/ xray
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1623
            'Y'     -720 false         "/ yankee
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1624
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1625
        ).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1626
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1627
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1628
utcOffsetFrom:aStringOrStream
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1629
    "return the utcOffset (in seconds) for a given time-zone name.
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1630
     Returns nil for invalid formats, 0 if no timezone offset is present.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1631
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1632
     Notice: this returns the negated value of what is read from a printed representation,
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1633
     which means that the sign is the same as what the utcOffset instance variable
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1634
     in timeStamp and OperatingSystem-timeInfo will be.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1635
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1636
     If utcOffset is negative, the local timezone is east of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1637
     If utcOffset is positive, the local timezone is west of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1638
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1639
     UtcOffset is what you have to ADD to correct the printed time to GMT.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1640
     I.e. for Germany, you'll get -3600 (+01h), for NewYork, you'll get +18000 (-05h)"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1641
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1642
    |ch offset stream|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1643
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1644
    stream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1645
    stream skipSeparators.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1646
17079
76e263370574 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17071
diff changeset
  1647
    ch := stream peekOrNil.
76e263370574 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17071
diff changeset
  1648
    ch isNil ifTrue:[^ 0].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1649
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1650
    ch isLetter ifTrue:[
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1651
        |table tzName i minuteOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1652
        
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1653
        table := self timezoneInfo.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1654
        tzName := stream upToElementForWhich:[:ch | ch isLetter not].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1655
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1656
        i := table indexOf:tzName.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1657
        i == 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1658
            ^ nil
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1659
        ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1660
        minuteOffset := (table at:i+1).
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1661
        offset := minuteOffset * 60
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1662
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1663
        |sign|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1664
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1665
        sign := 1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1666
        ch == $- ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1667
            sign := -1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1668
            stream next.
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1669
        ] ifFalse:[ch == $+ ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1670
            stream next.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1671
        ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1672
            stream skipSeparators
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1673
        ]].
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1674
        stream peekOrNil isDigit ifFalse:[^ nil].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1675
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1676
        offset := ((stream next:2) asNumber * 60 * 60).
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1677
        ch := stream peekOrNil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1678
        ch notNil ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1679
            ch == $: ifTrue:[ stream next ].
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1680
            offset := offset + ((stream next:2) asNumber * 60).
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1681
        ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1682
        offset := offset * sign
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1683
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1684
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  1685
    "/ return what would be an utcOffset (not what is at the end of an iso string)
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  1686
    ^ offset negated
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1687
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1688
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1689
     self utcOffsetFrom:'UTC'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1690
     self utcOffsetFrom:'PST'
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1691
     self utcOffsetFrom:'EST'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1692
     self utcOffsetFrom:'CET'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1693
     self utcOffsetFrom:'+0130'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1694
     self utcOffsetFrom:'+01:30'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1695
     self utcOffsetFrom:'+1:30'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1696
     self utcOffsetFrom:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1697
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1698
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1699
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1700
utcOffsetFromString:aString
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1701
    <resource: #obsolete>
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1702
    "return the utcOffset (in seconds) for a given time-zone name.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1703
     Returns nil for invalid formats"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1704
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1705
    ^ self utcOffsetFrom:aString
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1706
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1707
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1708
     self utcOffsetFromString:'UTC'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1709
     self utcOffsetFromString:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1710
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1711
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1712
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
  1713
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1714
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1715
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1716
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1717
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1718
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1719
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1720
    ^ self asDate day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1721
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1722
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1723
     Timestamp now day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1724
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1725
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1726
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1727
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1728
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1729
dayInWeek
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1730
    "return the week-day of the receiver - 1 for monday, 7 for sunday.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1731
     for pre-gregorian dates, it simply goes on assuming the current leapYear rules
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1732
     WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday)."
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1733
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1734
    ^ self asDate dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1735
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1736
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1737
     Timestamp now dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1738
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1739
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1740
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1741
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1742
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1743
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1744
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1745
    "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
  1746
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1747
    ^ self asDate dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1748
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1749
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1750
     Timestamp now dayInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1751
     (Timestamp newDay:184 year:1996) dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1752
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1753
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1754
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1755
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1756
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1757
dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1758
    "Answer the day of the month represented by me.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1759
     Same as day; for ST-80 compatibility."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1760
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1761
    ^ self asDate dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1762
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1763
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1764
     Timestamp now dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1765
     (Timestamp newDay:184 year:1996) dayOfMonth
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1766
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1767
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1768
    "Created: / 20-01-2011 / 12:26:54 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1769
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1770
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1771
dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1772
    "return the week-day of the receiver - 1 is sunday, 7 for saturday.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1773
     WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday).
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1774
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1775
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1776
    ^ self asDate dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1777
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1778
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1779
     Timestamp now dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1780
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1781
!
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1782
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1783
dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1784
    "return the week-day of the receiver as a string.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1785
     The returned string depends on the language setting.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1786
     Expect things like 'monday', 'tuesday' ..."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1787
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1788
    ^ self asDate dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1789
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1790
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1791
     Timestamp now dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1792
     (Timestamp newDay:184 year:1996) dayOfWeekName
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1793
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1794
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1795
    "Created: / 20-01-2011 / 12:28:46 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1796
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1797
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1798
hour
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1799
    "return the hour (0..23).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1800
     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
  1801
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1802
    ^ self hours
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1803
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1804
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1805
    "Modified: 1.7.1996 / 15:15:32 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1806
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1807
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1808
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1809
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1810
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1811
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1812
	^ self asTime hours.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1813
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1814
    ^ self timeInfo hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1815
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1816
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1817
     Timestamp now hours
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1818
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1819
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1820
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1821
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1822
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1823
millisecond
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1824
    "return the millisecond (0..999).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1825
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1826
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1827
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1828
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1829
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1830
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1831
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1832
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1833
milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1834
    "return the milliseconds (0..999)"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1835
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1836
    ^ osTime \\ 1000.
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1837
"/    ^ self timeInfo milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1838
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1839
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1840
     Timestamp now milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1841
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1842
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1843
    "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
  1844
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1845
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1846
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1847
minute
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1848
    "return the minute (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1849
     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
  1850
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1851
    ^ self minutes
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1852
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1853
    "Created: 1.7.1996 / 15:14:29 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1854
    "Modified: 1.7.1996 / 15:15:37 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1855
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1856
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1857
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1858
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1859
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1860
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1861
	^ self asTime minutes.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1862
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1863
    ^ self timeInfo minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1864
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1865
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1866
     Timestamp now minutes
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1867
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1868
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1869
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1870
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1871
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1872
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1873
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1874
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1875
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1876
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1877
	^ self asDate month.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1878
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1879
    ^ self timeInfo month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1880
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1881
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1882
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1883
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1884
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1885
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1886
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1887
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1888
monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1889
    "return the month of the receiver (1..12).
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1890
     For compatibility"
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1891
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1892
    ^ self asDate monthIndex.
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1893
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1894
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1895
     Timestamp now monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1896
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1897
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1898
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1899
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1900
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1901
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1902
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1903
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1904
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  1905
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1906
osTime:aTime
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1907
    "set the internal representation of the time"
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  1908
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1909
    osTime := aTime.
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1910
!
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  1911
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1912
second
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1913
    "return the second (0..59).
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1914
     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
  1915
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1916
    ^ self seconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1917
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1918
    "Created: 1.7.1996 / 15:14:19 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1919
    "Modified: 1.7.1996 / 15:15:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1920
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1921
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1922
seconds
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1923
    "return the seconds (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1924
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1925
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1926
	^ self asTime seconds.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1927
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1928
    ^ self timeInfo seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1929
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1930
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1931
     Timestamp now seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1932
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1933
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1934
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1935
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1936
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1937
timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1938
    "answer the number of minutes between local time and utc time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1939
     Delta is positive if local time is ahead of utc, negative if behind utc."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1940
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1941
    ^ self utcOffset negated // 60
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1942
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1943
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1944
     Timestamp now timeZoneDeltaInMinutes
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1945
     (Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1946
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1947
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1948
    "Modified: 20.12.1995 / 17:28:49 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1949
    "Modified: 1.7.1996 / 15:21:29 / cg"
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1950
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  1951
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1952
timeZoneName
16990
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1953
    "find the first zone which is in this range.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1954
     This is a bit naive, but should be sufficient in most cases
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1955
     (for a correct result, we'd have to care for start-end dates of summer time
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1956
      of that particular year...)"
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1957
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1958
    |myUtcOffset iAmDST bestNonDST|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1959
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1960
    myUtcOffset := self utcOffset negated.
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1961
    iAmDST := self timeInfo dst ? false.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1962
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1963
    bestNonDST := nil.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1964
    self class timezoneInfo inGroupsOf:3 do:[:name :offsetInMinutes :isDST|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1965
        |thisUtcOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1966
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1967
        thisUtcOffset := offsetInMinutes * 60.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1968
        thisUtcOffset = myUtcOffset ifTrue:[
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1969
            isDST == iAmDST ifTrue:[^ name ].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1970
        ].    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1971
        bestNonDST := name.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1972
    ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1973
    bestNonDST notNil ifTrue:[^ bestNonDST].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1974
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1975
    "/ nothing found - construct a standard offset string
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1976
    ^ ((self utcOffset > 0) ifTrue:['+'] ifFalse:['-'])
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1977
      , ((myUtcOffset abs // 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1978
      , ((myUtcOffset abs \\ 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1979
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1980
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1981
     Timestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1982
     UtcTimestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1983
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1984
     (Timestamp now asTZTimestampInZone:'MEZ') timeZoneName - will find international name
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1985
     (Timestamp now asTZTimestampInZone:'EST') timeZoneName
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1986
     (Timestamp now asTZTimestampInZone:'IDLE') timeZoneName - sorry - will find 'NZST'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1987
     (Timestamp now asTZTimestampInZone:'BRST') timeZoneName - sorry: will find military 'O'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1988
     (Timestamp now asTZTimestampInZone:'MYT') timeZoneName - will find hongkong; same timezone
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1989
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1990
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1991
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  1992
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1993
    "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
  1994
     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
  1995
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1996
     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
  1997
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1998
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  1999
     If utcOffset is negative, the local timezone is east of Greenwich.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2000
     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
  2001
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2002
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2003
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2004
	"/ we do not know about DST in the far future and in the long gone past.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2005
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2006
	^ self utcOffsetWithoutDst.
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2007
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2008
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2009
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2010
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2011
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2012
     Timestamp now utcOffset
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2013
     (Timestamp year:1995 month:7 day:1 hour:12 minute:0 second:0) utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2014
     (Timestamp year:1995 month:1 day:1 hour:12 minute:0 second:0) utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2015
     (Timestamp year:1689 month:7 day:1 hour:12 minute:0 second:0) utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2016
     (Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2017
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2018
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2019
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2020
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2021
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2022
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2023
utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2024
    "return the difference between UTC (Greenwich Mean Time) and the local time in seconds.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2025
     If daylight saving time applies to ourself, do not take that into account.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2026
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2027
     Add utcOffset to convert from local time to UTC time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2028
     Subtract utcOffset to convert from UTC time to local time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2029
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2030
     If utcOffset is negative, the local timezone is east of Greenwich.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2031
     If utcOffset is positive, the local timezone is west of Greenwich."
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2032
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2033
    |offset epochInfo|
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2034
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2035
    offset := 0.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2036
    [
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2037
	"DST may be in winter in the southern hemisphere. If we are in DST, add some days"
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2038
	epochInfo := OperatingSystem timeInfoFromSeconds:offset milliseconds:0 localTime:true.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2039
	offset := offset + (3600 * 24 * 90). "Add about 3 months"
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2040
    ] doWhile:[epochInfo dst and:[offset < (3600 * 24 * 365) "avoid endless loop"]].
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2041
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2042
    ^ epochInfo utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2043
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2044
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2045
     Timestamp now utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2046
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2047
!
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2048
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2049
weekInYear
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2050
    "return the week number of the receiver - 1 for Jan, 1st."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2051
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2052
    ^ Date weekInYearOf:self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2053
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2054
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2055
     (Timestamp newDay:1 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2056
     (Timestamp newDay:2 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2057
     (Timestamp newDay:3 year:2000) weekInYear
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2058
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2059
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2060
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2061
weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2062
    "return the week-day of the receiver as a string.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2063
     The returned string depends on the current language setting.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2064
     Expect things like 'monday', 'tuesday' ...
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2065
     For ST-80 compatibility"
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2066
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2067
    ^ self asDate weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2068
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2069
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2070
     Timestamp now weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2071
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2072
     but maybe a different day there, in the south pacific:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2073
     (Timestamp now asTZTimestampInZone:'LINT') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2074
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2075
     but maybe a different day there, in alaska:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2076
     (Timestamp now asTZTimestampInZone:'AKST') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2077
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2078
!
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2079
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2080
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2081
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2082
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2083
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2084
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2085
	^ self asDate year.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2086
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2087
    ^ self timeInfo year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2088
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2089
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2090
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2091
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2092
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2093
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2094
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2095
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2096
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2097
13199
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2098
ceilingSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2099
    "return a timestamp which represents the next full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2100
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2101
    |offs|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2102
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2103
    offs := (self milliseconds / 1000) ceiling.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2104
    ^ self class basicNew setSeconds:(self getSeconds + offs).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2105
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2106
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2107
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2108
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2109
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2110
     t2 := t1 ceilingSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2111
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2112
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2113
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2114
    "Created: / 08-01-2011 / 16:23:03 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2115
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2116
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2117
floorSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2118
    "return a timestamp truncated to the last full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2119
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2120
    ^ self class basicNew setSeconds:(self getSeconds).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2121
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2122
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2123
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2124
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2125
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2126
     t2 := t1 floorSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2127
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2128
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2129
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2130
    "Created: / 08-01-2011 / 16:20:55 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2131
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2132
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2133
millisecondDeltaFrom:aTimestamp
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
  2134
    "return the delta in milliseconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2135
     The argument is supposed to be BEFORE the receiver,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2136
	computes self - aTimestamp"
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2137
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2138
    ^ self getMilliseconds - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2139
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2140
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2141
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2142
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2143
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2144
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2145
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2146
     t2 millisecondDeltaFrom:t1
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2147
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2148
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2149
    "Modified: / 10-07-2010 / 09:37:18 / cg"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2150
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2151
13200
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2152
roundedToSecond
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2153
    "return a timestamp which represents the time rounded to the nearest full second"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2154
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2155
    |offs|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2156
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2157
    offs := (self milliseconds / 1000) rounded.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2158
    ^ self class basicNew setSeconds:(self getSeconds + offs).
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2159
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2160
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2161
     |t1 t2|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2162
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2163
     t1 := Timestamp now.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2164
     t2 := t1 roundedToSecond.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2165
     self halt
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2166
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2167
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2168
    "Created: / 08-01-2011 / 16:24:12 / cg"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2169
!
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2170
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2171
secondDeltaFrom:aTimestamp
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2172
    "return the delta in seconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2173
     The argument is supposed to be BEFORE the receiver,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2174
	computes self - aTimestamp"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2175
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2176
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2177
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2178
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2179
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2180
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2181
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2182
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2183
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2184
     t2 secondDeltaFrom:t1
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2185
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2186
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2187
    "Modified: / 10-07-2010 / 09:37:24 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2188
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2189
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2190
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2191
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2192
= aTimestamp
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2193
    "return true if the argument, aTime represents the same time.
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2194
     Notice: you can compare timestamps from different timezones for representing the
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2195
     same time, because they all store their milliseconds internally as utc time"
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2196
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2197
    aTimestamp isTimestamp ifFalse:[^ false].
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2198
    ^ (self getMilliseconds = aTimestamp getMilliseconds)
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2199
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2200
    "Modified: 3.7.1996 / 13:10:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2201
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2202
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2203
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2204
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2205
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2206
    ^ osTime // 1000
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2207
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2208
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2209
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2210
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2211
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2212
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2213
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2214
    "return a Date object from the receiver.
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2215
     The returned date will only represent the day - not the timeOfDay.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2216
     Notice: if you convert a local timestamp, you will get the local date;
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2217
     otherwise if you convert an utcTimestamp, you'll get the utc date."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2218
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2219
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2220
	|milliDelta dayDelta|
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2221
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2222
	"/ we do not know about DST in the far future and in the long gone past.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2223
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2224
	milliDelta := osTime - (1000 * self utcOffsetWithoutDst).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2225
	dayDelta := milliDelta // (24 * 3600 * 1000).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2226
	^ Epoch asDate addDays:dayDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2227
    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2228
    ^ self timeInfo asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2229
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2230
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2231
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2232
     Timestamp now asDate
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2233
     (Timestamp now addTime:3600) asDate
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2234
     (Timestamp now addTime:3600) asTime
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2235
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2236
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2237
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2238
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2239
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2240
asLocalTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2241
    "represent myself as a timestamp in the local timezone"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2242
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2243
    ^ self
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2244
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2245
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2246
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2247
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2248
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2249
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2250
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2251
asTZTimestamp
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2252
    "return a timestamp which represents the very same time,
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2253
     but will represent itself as a timestamp with the local utcOffset.
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2254
     Use this to make sure that a local timestamp can be read back in another timezone"
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2255
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2256
    ^ self asTZTimestamp:self utcOffset
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2257
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2258
    "see the different printStrings of:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2259
	 Timestamp now
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2260
     and
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2261
	 Timestamp now asTZTimestamp
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2262
    "
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2263
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2264
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2265
asTZTimestamp:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2266
    "return a timestamp which represents the very same time,
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2267
     but will represent itself as a timestamp with the given utcOffset"
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2268
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2269
    ^ (TZTimestamp fromOSTime:osTime) utcOffset:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2270
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2271
    "what is the time now in NewYork?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2272
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2273
     Timestamp now asTZTimestampInZone:'EST'
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2274
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2275
     what is the time now in Stuttgart?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2276
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2277
     Timestamp now asTZTimestampInZone:'MEZ'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2278
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2279
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2280
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2281
asTZTimestampInZone:timeZoneName
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2282
    "return a timestamp which represents the very same time,
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2283
     but will represent itself as a timestamp in the given timezone.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2284
     timeZoneName must be one of the standard names as listed in Timestamp >> timezoneInfo"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2285
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2286
    |utcOffset|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2287
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2288
    utcOffset := self class utcOffsetFrom:timeZoneName.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2289
    utcOffset isNil ifTrue:[
17132
01e2272e7912 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17131
diff changeset
  2290
        ^ TimeConversionError raiseRequestWith:self errorString:(' - Invalid/unknown timzone: %1' bindWith:timeZoneName)
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2291
    ].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2292
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2293
    ^ self asTZTimestamp:utcOffset
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2294
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2295
    "what is the time now in NewYork?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2296
       Timestamp now asTZTimestampInZone:'EST'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2297
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2298
     what is the time now in Stuttgart?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2299
       Timestamp now asTZTimestampInZone:'MEZ'
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2300
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2301
     an error os raised for any unknown/invalid timezone:
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2302
       Timestamp now asTZTimestampInZone:'BlaBla'
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2303
    "
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2304
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2305
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2306
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2307
    "return a Time object from the receiver.
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  2308
     The returned time will only represent the timeOfDay - not the day,
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2309
     and does not include the milliseconds."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2310
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2311
    |secondDelta|
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2312
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2313
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2314
	secondDelta := osTime // 1000.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2315
	"/ we do not know about DST in the far future and in the long gone past.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2316
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2317
	secondDelta := (secondDelta - self utcOffsetWithoutDst) \\ (24*3600).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2318
	^ Epoch asTime addSeconds:secondDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2319
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2320
    ^ self timeInfo asTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2321
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2322
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2323
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2324
     Timestamp now asTime
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2325
     UtcTimestamp now asTime
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2326
     (Timestamp now addTime:3600) asTime
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2327
     (Timestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2328
     (UtcTimestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2329
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2330
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2331
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2332
asTimeWithMilliseconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2333
    "return a Time object from the receiver.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2334
     The returned time will only represent the timeOfDay - not the day,
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2335
     it will include the milliseconds."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2336
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2337
    |milliSecondDelta|
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2338
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2339
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2340
	milliSecondDelta := osTime - (self utcOffset * 1000).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2341
	^ self class epoch asTime addMilliseconds:milliSecondDelta.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2342
    ].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2343
    ^ self timeInfo asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2344
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2345
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2346
     Timestamp now
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2347
     Timestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2348
     UtcTimestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2349
     (Timestamp now addTime:3600) asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2350
     (Timestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2351
     (UtcTimestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2352
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2353
!
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2354
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2355
asTimestamp
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2356
    "return an Timestamp object from the receiver - that's the receiver."
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2357
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2358
    ^ self
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2359
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2360
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2361
asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2362
    ^ self asUtcTimestamp
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2363
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2364
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2365
     Timestamp now
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2366
     Timestamp now asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2367
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2368
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2369
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2370
asUtcTimestamp
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2371
    "return a timestamp which represents the very same timestamp,
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2372
     but will represent itself as a timestamp in the UTC timezone"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2373
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2374
    ^ UtcTimestamp fromOSTime:osTime
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2375
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2376
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2377
     Timestamp now asUtcTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2378
     Timestamp now asUtcTimestamp asLocalTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2379
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2380
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2381
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2382
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2383
    "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
  2384
     can be reconstructed with #decodeAsLiteralArray.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2385
     The encoding is:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2386
        (#Timestamp YYYYMMDDhhmmss.iiiZ)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2387
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2388
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2389
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2390
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2391
    s := WriteStream on:(String new:18).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2392
    self printGeneralizedOn:s isLocal:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2393
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2394
    ^ Array
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2395
        with:self class name
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2396
        with:s contents
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2397
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2398
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  2399
      Timestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2400
        decodeAsLiteralArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2401
      UtcTimestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2402
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2403
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2404
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2405
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2406
utcOffset:anOffset
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2407
   "answer a DateTime equivalent to the receiver but offset from UTC by offset"
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2408
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2409
    ^ TZTimestamp new 
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2410
        osTime:osTime;
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2411
        utcOffset:(anOffset asTimeDuration)  
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2412
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2413
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2414
     Timestamp now  -- now as local time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2415
     Timestamp now asTZTimestamp -- now in your local timezone
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2416
     Timestamp now asUtcTimestamp -- now in greenwich
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2417
     UtcTimestamp now -- now in greenwich
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2418
     Timestamp now utcOffset:(-2 hours)2015-11-09 17:29:35.803+02 -- now in East Europe
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2419
     Timestamp now utcOffset:(5 hours) -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2420
     Timestamp now asTZTimestampInZone:'EST' -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2421
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2422
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2423
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2424
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2425
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2426
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2427
"
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2428
    secondsBetween1901and1970 :=
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2429
	((Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901))
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2430
	*  (24 * 60 * 60)
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  2431
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2432
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2433
    ^ self utcSecondsSince1970 + 2177452800.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2434
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2435
    "
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2436
     Timestamp now utcSecondsSince1901
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2437
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2438
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2439
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2440
!Timestamp methodsFor:'initialization'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2441
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2442
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2443
    "private: ask the operating system to compute the internal osTime (based on the epoch),
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2444
     given y,m,d and h,m,s in my time."
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2445
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2446
    self setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2447
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2448
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2449
setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2450
    "private: ask the operating system to compute the internal osTime (based on the epoch),
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2451
     given y,m,d and h,m,s in local time"
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2452
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2453
    Error handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2454
        "handler for timestamps before the epoch or after the OS representable time (2038 on current Unices).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2455
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2456
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2457
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2458
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2459
        deltaDays := self class epoch asDate subtractDate:(Date year:y month:m day:d).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2460
        "/ deltadays will be negative for dates before the epoch and positive if after.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2461
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2462
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2463
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2464
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2465
        osTime := osTime + millis.
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2466
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2467
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2468
                computeOSTimeFromUTCYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2469
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2470
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2471
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2472
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2473
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2474
setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2475
    "private: ask the operating system to compute the internal osTime (based on the epoch),
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2476
     given y,m,d and h,m,s in local time. If the OS cannot do it, do it here."
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2477
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2478
    TimeConversionError handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2479
        "handler for timestamps before the epoch or after the OS representable time (2038 on current Unices).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2480
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2481
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2482
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2483
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2484
        deltaDays := self class epoch asDate subtractDate:(Date year:y month:m day:d).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2485
        "/ deltadays will be negative for dates before the epoch and positive if after.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2486
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2487
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2488
        osTime := osTime + self utcOffset.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2489
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2490
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2491
        osTime := osTime + millis.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2492
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2493
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2494
                computeOSTimeFromYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2495
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2496
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2497
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2498
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2499
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2500
year:y month:m day:d hour:h minute:min second:s millisecond:millis
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2501
    "private: ask the operating system to compute the internal osTime (based on the epoch),
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2502
     given y,m,d and h,m,s in my time."
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2503
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2504
    self setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis
19652
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2505
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2506
    "
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2507
     self basicNew
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2508
         year:2016 month:4 day:16 hour:17 minute:21 second:13 millisecond:726
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2509
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2510
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2511
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2512
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2513
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2514
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2515
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2516
    "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
  2517
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  2518
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2519
    |date|
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2520
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2521
    date := self asDate.
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2522
    date addPrintBindingsTo:dict language:languageOrNil.
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2523
    super addPrintBindingsTo:dict language:languageOrNil.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2524
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2525
    date year == Date today year ifTrue:[
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2526
        dict at:#yearOrTime put:('%h:%m' expandPlaceholdersWith:dict).
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2527
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2528
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2529
    "
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2530
     |d|
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2531
     d := Dictionary new.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2532
     Timestamp now addPrintBindingsTo:d language:nil.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2533
     d inspect.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2534
    "
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2535
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2536
    "used by:
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2537
        Timestamp now printStringFormat:'%y-%m-%d'
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2538
        Timestamp now printStringFormat:'%(dayOfYear)'
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2539
    "
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2540
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2541
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2542
printGeneralizedOn:aStream
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2543
    "append a representation of the receiver to aStream in a general format,
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2544
     top-down, without separators: 'yyyymmddHHMMSS.mmmZ'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2545
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2546
     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
  2547
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2548
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2549
    ^ self printGeneralizedOn:aStream isLocal:false short:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2550
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2551
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2552
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2553
    "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
  2554
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2555
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2556
     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
  2557
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2558
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2559
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2560
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2561
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2562
    self printGeneralizedOn:aStream isLocal:isLocal short:false
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2563
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2564
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2565
    "Modified: / 1.7.1996 / 15:20:59 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2566
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2567
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2568
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2569
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2570
    "append a representation of the receiver to aStream in a general format,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2571
     top-down, without separators;
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2572
        long format:  'yyyymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2573
        short format: 'yymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2574
     Using the short format is strictly discouraged!!
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2575
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2576
     This format is used for the ASN.1 GeneralizedTime and UTCTime
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2577
     as defined in X.208 Sec. 33, so read this before changing the output format.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2578
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2579
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2580
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2581
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2582
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2583
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2584
    isLocal ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2585
        t := self timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2586
        off := t utcOffset.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2587
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2588
        t := self asUtcTimestamp timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2589
        off := 0.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2590
    ].
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2591
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2592
    shortFormat ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2593
        self assert:(t year between:1951 and:2049).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2594
        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2595
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2596
        t year    printOn:aStream leftPaddedTo:4 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2597
    ].
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2598
    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
  2599
    t day     printOn:aStream leftPaddedTo:2 with:$0.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2600
    t hours   printOn:aStream leftPaddedTo:2 with:$0.
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2601
    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
  2602
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2603
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2604
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2605
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2606
    (self isUtcTimestamp or:[off == 0]) ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2607
        aStream nextPut:$Z.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2608
    ] ifFalse:[ |min|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2609
        off < 0 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2610
            aStream nextPut:$+.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2611
            off := off negated.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2612
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2613
            aStream nextPut:$-.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2614
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2615
        min := off // 60.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2616
        min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2617
        min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2618
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2619
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2620
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2621
     Timestamp now printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2622
     Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2623
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2624
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2625
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2626
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2627
     Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2628
     Timestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2629
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2630
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2631
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2632
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2633
     Date today printOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2634
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2635
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2636
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2637
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2638
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2639
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2640
printISO8601
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2641
    <resource: #obsolete>
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2642
    "print as UTC in a format like 2014-10-17T17:08:44Z"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2643
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2644
    ^ self printStringIso8601
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2645
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2646
    "Created: / 16-06-2005 / 16:11:15 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2647
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2648
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2649
printISO8601Compressed
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2650
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2651
    "return a printString as UTC in a format like 20141017T170939Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2652
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2653
    ^ self printStringIso8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2654
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2655
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2656
     Timestamp now printISO8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2657
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2658
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2659
    "Created: / 16-06-2005 / 16:11:31 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2660
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2661
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2662
printISO8601CompressedOn: aStream
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2663
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2664
    "print as UTC in a format like 20141017T170939Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2665
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2666
    self printIso8601CompressedOn: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2667
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2668
    "Created: / 16-06-2005 / 16:11:50 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2669
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2670
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2671
printISO8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2672
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2673
    "print as UTC in a format like 2014-10-17T17:08:44Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2674
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2675
    self printIso8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2676
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2677
    "Created: / 16-06-2005 / 16:11:07 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2678
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2679
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2680
printIso8601CompressedOn: aStream
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2681
    "print as UTC in a format like 20141017T170939Z on aStream"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2682
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2683
    TimestampISO8601Builder printCompressed: self on: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2684
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2685
    "Created: / 16-06-2005 / 16:11:50 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2686
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2687
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2688
printIso8601FormatOn:aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2689
    "append the iso8601 representation of the receiver to aStream.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2690
     This format looks like:
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2691
	1999-01-01T24:00:00
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2692
     or, for zero hr:min:sec,
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2693
	1999-01-01
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2694
     Of course, a 24 hour clock is used.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2695
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2696
     Timezone information (eg. Z or +0100) is added, so the reader will read as local time."
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2697
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2698
    self printIso8601FormatOn:aStream timeSeparator:$T
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2699
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2700
    "
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2701
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2702
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2703
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2704
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2705
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2706
    "
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2707
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2708
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2709
printIso8601FormatOn:aStream timeSeparator:sepChar
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2710
    "append the iso8601 representation of the receiver to aStream.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2711
     This format looks like:
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2712
	1999-01-01T24:00:00
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2713
     or, for zero hr:min:sec,
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2714
	1999-01-01
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2715
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2716
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2717
     Timezone information (eg. Z or +0100) is added, so the reader will read as local time."
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2718
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2719
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2720
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2721
    self isUtcTimestamp ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2722
	asUTC := true. asLocal := false.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2723
    ] ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2724
	self isLocalTimestamp ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2725
	    asUTC := false. asLocal := false.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2726
	] ifFalse:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2727
	    asUTC := false. asLocal := false.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2728
	]
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2729
    ].
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2730
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2731
    Timestamp::TimestampISO8601Builder
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2732
	print:self compact:false
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2733
	asLocal:asLocal asUTC:asUTC withMilliseconds:true
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2734
	timeSeparator:sepChar
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2735
	on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2736
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2737
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2738
"/    |format|
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2739
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2740
"/    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2741
"/    self milliseconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2742
"/        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2743
"/        self seconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2744
"/            format := '%(year)-%(month)-%(day)T%h:%m'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2745
"/            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2746
"/                format := '%(year)-%(month)-%(day)'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2747
"/            ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2748
"/        ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2749
"/    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2750
"/    self printOn:aStream format:format
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2751
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2752
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2753
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2754
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2755
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2756
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2757
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2758
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2759
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2760
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2761
printIso8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2762
    "print as UTC in a format like 2014-10-17T17:08:44Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2763
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2764
    TimestampISO8601Builder print: self on: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2765
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2766
    "Created: / 16-06-2005 / 16:11:07 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2767
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2768
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2769
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2770
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2771
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2772
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2773
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2774
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2775
    self isUtcTimestamp ifTrue:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2776
	asUTC := true. asLocal := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2777
    ] ifFalse:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2778
	self isLocalTimestamp ifTrue:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2779
	    asUTC := false. asLocal := true.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2780
	] ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2781
	    asUTC := false. asLocal := false.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2782
	]
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2783
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2784
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2785
    Timestamp::TimestampISO8601Builder
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2786
	print:self compact:false
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2787
	asLocal:asLocal asUTC:asUTC withMilliseconds:true
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2788
	timeSeparator:(Character space)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2789
	on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2790
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2791
"/    self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2792
"/    self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2793
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2794
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2795
    "
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2796
     |tHere tNewYork|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2797
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2798
     Timestamp now printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2799
     Timestamp now asUtcTimestamp printOn:Transcript. Transcript cr.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2800
     (Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')) printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2801
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2802
     tHere := Timestamp now.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2803
     tNewYork := tHere asTZTimestamp:(Timestamp utcOffsetFrom:'EST').
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2804
     tHere printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2805
     tNewYork printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2806
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2807
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2808
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2809
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2810
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2811
     Time now asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2812
     Timestamp now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2813
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2814
     Date today asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2815
     Date today printOn:Transcript. Transcript cr.
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2816
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2817
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2818
    "Modified: 1.7.1996 / 15:20:59 / cg"
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2819
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2820
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2821
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2822
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2823
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2824
	'Fri, 04 Jul 2003 15:56:11 GMT'
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2825
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2826
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2827
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2828
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2829
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2830
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2831
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2832
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2833
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2834
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2835
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2836
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2837
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2838
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2839
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2840
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2841
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2842
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2843
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2844
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2845
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2846
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2847
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2848
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2849
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2850
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2851
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2852
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2853
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2854
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2855
    timeInfo := self asUtcTimestamp timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2856
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2857
    aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek);
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2858
	    nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2859
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2860
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2861
    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
  2862
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2863
    "/ the following is too slow for heavy use
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2864
    "/    timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT' language:#en.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2865
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2866
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2867
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2868
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2869
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2870
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2871
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2872
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2873
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2874
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  2875
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2876
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2877
     String streamContents:[:s| Timestamp now printRFC1123FormatOn:s]
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2878
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2879
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2880
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2881
printStringIso8601
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2882
    "return a printString as UTC in a format like 2014-10-17T17:08:44Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2883
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2884
    ^ TimestampISO8601Builder print: self
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2885
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2886
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2887
     Timestamp now printStringIso8601
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2888
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2889
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2890
    "Created: / 16-06-2005 / 16:11:15 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2891
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2892
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2893
printStringIso8601Compressed
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2894
    "return a printString as UTC in a format like 20141017T170939Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2895
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2896
    ^ TimestampISO8601Builder printCompressed: self
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2897
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2898
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2899
     Timestamp now printStringIso8601Compressed
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2900
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2901
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2902
    "Created: / 16-06-2005 / 16:11:31 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2903
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2904
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2905
printStringIso8601Format
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2906
    "return the Iso8601 representation of the receiver with local timezon information.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2907
     This format looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2908
	1999-01-01T24:00:00
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2909
     or, for zero hr:min:sec,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2910
	1999-01-01
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2911
     Of course, a 24 hour clock is used."
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2912
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2913
    ^ String streamContents:[:s | self printIso8601FormatOn:s]
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2914
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2915
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2916
     Timestamp now printStringIso8601Format
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2917
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2918
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2919
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2920
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2921
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2922
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2923
	'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2924
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2925
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2926
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2927
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2928
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2929
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2930
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2931
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2932
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2933
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2934
    "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
  2935
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2936
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2937
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2938
    aStream nextPut:$(;
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2939
	    nextPutAll:self storeStringClass name;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2940
	    nextPutAll:' readIso8601FormatFrom:'''.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2941
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2942
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  2943
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2944
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2945
     Timestamp now storeString
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2946
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  2947
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2948
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2949
    "
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2950
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2951
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2952
storeStringClass
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2953
    ^ self class
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2954
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2955
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2956
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2957
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2958
computeTimeInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2959
    |d t info|
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2960
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2961
    "/ fake an info which the OS cannot give me
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2962
    d := self asDate.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2963
    t := self asTime.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2964
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2965
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2966
	 hours:t hours minutes:t minutes seconds:t seconds milliseconds:self milliseconds
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2967
	 utcOffset:(self utcOffset) dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2968
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2969
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2970
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2971
	(Timestamp year:1592 month:7 day:1 hour:12 minute:0 second:0 millisecond:555) computeTimeInfo
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2972
	(Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0 millisecond:555) computeTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2973
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2974
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2975
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2976
computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2977
    |utcTimestamp d t info|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2978
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2979
    "/ fake an info which the OS cannot give me
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2980
    utcTimestamp := self asUtcTimestamp.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2981
    d := utcTimestamp asDate.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2982
    t := utcTimestamp asTime.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2983
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2984
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2985
	 hours:t hours minutes:t minutes seconds:t seconds milliseconds:self milliseconds
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2986
	 utcOffset:0 dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2987
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2988
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2989
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2990
	(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2991
	(Timestamp year:1592 month:7 day:1 hour:12 minute:0 second:0) computeUtcTimeInfo
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2992
	(Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0) computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2993
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2994
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2995
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2996
fromOSTime:anUninterpretedOSTime
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2997
    "strictly private: set the milliseconds from an OS time (since the epoch).
16943
b573bff7b937 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16942
diff changeset
  2998
     Notice: timestamps always have millisecond precision (in contrast to Time, where it is optional)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2999
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3000
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3001
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3002
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3003
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3004
16942
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3005
fromOSTimeWithMilliseconds:anUninterpretedOSTime
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3006
    "strictly private: set the milliseconds from an OS time (since the epoch)"
16942
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3007
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3008
    osTime := anUninterpretedOSTime
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3009
!
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3010
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3011
getMilliseconds
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3012
    "strictly private: return the milliseconds (since the epoch) in utc"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3013
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3014
    ^ osTime
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3015
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3016
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3017
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3018
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3019
getSeconds
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3020
    "strictly private: return the seconds (since the epoch) in utc"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3021
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3022
    ^ osTime // 1000
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3023
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3024
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3025
setMilliseconds:millis
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3026
    "strictly private: set the milliseconds (since the epoch)"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3027
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3028
    osTime := millis.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3029
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3030
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3031
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3032
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3033
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3034
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3035
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3036
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3037
    osTime := (secs * 1000).
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3038
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3039
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3040
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3041
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3042
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3043
timeInfo
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3044
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3045
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3046
	^ self computeTimeInfo
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3047
    ].
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3048
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3049
    ^ OperatingSystem computeTimeAndDateFrom:osTime
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3050
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3051
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3052
	(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3053
	(UtcTimestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3054
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3055
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3056
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3057
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3058
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3059
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  3060
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3061
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3062
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3063
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3064
    "
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3065
!
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3066
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3067
utcTimeInfo
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3068
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3069
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3070
	^ self computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3071
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3072
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3073
    ^ OperatingSystem computeUTCTimeAndDateFrom:osTime
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3074
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3075
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3076
	(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3077
	(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) utcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3078
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3079
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3080
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
  3081
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
  3082
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3083
!Timestamp methodsFor:'testing'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3084
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3085
isLocalTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3086
    "return true, if I am a local timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3087
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3088
    ^ true
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3089
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3090
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3091
isTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3092
    "return true, if I am a timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3093
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3094
    ^ true
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3095
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3096
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3097
isUtcTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3098
    "return true, if I am a utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3099
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3100
    ^ false
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3101
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3102
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3103
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3104
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3105
acceptVisitor:aVisitor with:aParameter
16718
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3106
    "dispatch for visitor pattern; send #visitTimestamp:with: to aVisitor."
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3107
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3108
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3109
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3110
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3111
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3112
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3113
malformed:aString
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3114
    TimeConversionError raiseErrorString:(' - ', aString)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3115
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3116
    "Created: / 15-06-2005 / 15:54:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3117
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3118
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3119
!Timestamp::TimestampBuilderAbstract methodsFor:'support'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3120
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3121
addHoursAndMinutes: arrayWithHoursAndMinutes
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3122
    "Add the given number of hours and minutes to the current timestamp state. If the time
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3123
    is to be subtracted, both numbers in the array must be negated. When the are not the same
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3124
    sign, the behavior may be strange. It's intended only for time zone corrections, where
16977
deb0f10f246a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16975
diff changeset
  3125
    not more than 14 (in fact, 23) hours is added or subtracted (ie. date can be modified only
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3126
    one day forward or backward)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3127
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3128
    | hours minutes |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3129
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3130
    hours := arrayWithHoursAndMinutes first.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3131
    minutes := arrayWithHoursAndMinutes second.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3132
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3133
    utcOffset := (((hours * 60) + minutes) * 60).
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3134
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3135
    minutes isZero ifFalse: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3136
        minute := minute + minutes.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3137
        minute >= 60 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3138
            hours := hours + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3139
            minute := minute - 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3140
        ].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3141
        minute < 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3142
            hours := hours - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3143
            minute := minute + 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3144
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3145
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3146
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3147
    "Hours may get zero by time zone specification or by minutes modifications above."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3148
    hours isZero ifTrue: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3149
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3150
    "Add or subtract the hour and make date corrections if necessary."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3151
    hour := hour + hours.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3152
    hour < 0 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3153
        "Oops, got to previous day, must adjust even the date."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3154
        hour := 24 - ((hour negated) \\ 24).
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3155
        day := day - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3156
        day <= 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3157
            "Go to previous month..."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3158
            month := month - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3159
            month <= 0 ifTrue: [year := year - 1. month := 12].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3160
            day := self lastDayInMonth: month
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3161
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3162
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3163
    hour >= 24 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3164
        hour := hour \\ 24.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3165
        day := day + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3166
        day > (self lastDayInMonth: month) ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3167
            month := month + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3168
            month > 12 ifTrue: [year := year + 1. month := 1].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3169
            day := 1
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3170
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3171
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3172
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3173
    "Created: / 15-06-2005 / 16:45:49 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3174
    "Modified: / 16-06-2005 / 15:04:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3175
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3176
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3177
dateFromDayNumber: dayInYear
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3178
    "Set month and day from an absolute number of the day in the year. 1.1. is day number one."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3179
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3180
    |monthAndDay|
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3181
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3182
    (dayInYear between: 1 and: 365) ifFalse: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3183
	(dayInYear = 366 and:[self leapYear: year])
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3184
	    ifFalse: [self malformed: 'Bad day number: ' , dayInYear printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3185
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3186
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3187
    monthAndDay := Date monthAndDayFromDayInYear:dayInYear forYear:year.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3188
    month := monthAndDay at:1.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3189
    day := monthAndDay at:2
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3190
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3191
    "Created: / 15-06-2005 / 11:27:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3192
    "Modified: / 16-06-2005 / 12:31:37 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3193
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3194
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3195
dateFromWeek: weekInteger andWeekday: dayInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3196
    "Compute the month and day. Find the first day (weekday) in the year, maybe even
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3197
    adjust the year. Both week and day are 1-based, the first week in a year is the one
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3198
    with thursday (or the one containing 4.1.)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3199
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3200
    |tmpDate|
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3201
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3202
    "Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3203
    (dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3204
    (weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3205
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3206
    tmpDate := Date newDayInWeek:dayInteger week:weekInteger year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3207
    day := tmpDate day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3208
    month := tmpDate month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3209
    year := tmpDate year.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3210
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3211
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3212
isAllowedDay: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3213
    "Answer whether the given day is allowed in the current month."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3214
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3215
    ^anInteger between: 1 and: (self lastDayInMonth: month)
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3216
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3217
    "Created: / 15-06-2005 / 16:22:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3218
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3219
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3220
lastDayInMonth: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3221
    "Answer the number of the last day of the given month in the current year."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3222
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3223
    ^ anInteger = 2
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3224
	ifTrue: [(self leapYear: year) ifTrue: [29] ifFalse: [28]]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3225
	ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3226
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3227
    "Created: / 15-06-2005 / 17:12:31 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3228
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3229
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3230
leapYear: anInteger
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3231
    ^ Date leapYear:anInteger.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3232
!
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3233
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3234
timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3235
    "Answer the timestamp as it has been parsed."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3236
    "Notes:
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3237
     - When reading, the time has either been adjusted to UTZ/zulu or explicit offset time,
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3238
       or is a local time stamp.
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3239
     Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3240
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3241
    (timestampClass == UtcTimestamp) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3242
	^ UtcTimestamp
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3243
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3244
	    hour: hour minute: minute second: second millisecond: millisecond
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3245
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3246
    (timestampClass == TZTimestamp) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3247
	"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3248
	^ ((TZTimestamp
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3249
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3250
	    hour: hour minute: minute second: second millisecond: millisecond) utcOffset:utcOffset)
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3251
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3252
16989
de9bc5f12297 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16988
diff changeset
  3253
    (isUtcTime or:[hasTimezone and:[utcOffset == 0]]) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3254
	^ ((timestampClass == Timestamp) ifTrue:UtcTimestamp ifFalse:timestampClass)
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3255
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3256
	    hour: hour minute: minute second: second millisecond: millisecond
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3257
    ].
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3258
    hasTimezone ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3259
	"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3260
	^ (((timestampClass == Timestamp) ifTrue:TZTimestamp ifFalse:timestampClass)
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3261
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3262
	    hour: hour minute: minute second: second millisecond: millisecond) utcOffset:utcOffset
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3263
    ].
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3264
    "/ there was no timezone info, so make it a local timestamp again.
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3265
    ^ (timestampClass
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3266
	year: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3267
	hour: hour minute: minute second: second millisecond: millisecond)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3268
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3269
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3270
yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3271
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3272
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3273
    year := yearArg.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3274
    yearAlreadyRead := true.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3275
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3276
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3277
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3278
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3279
documentation
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3280
"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3281
    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3282
    Also, class methods can be used to print but the main reading job is done in instance protocol.
16915
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3283
    It has been written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3284
    (which was now changed to call this as well).
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3285
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3286
    It produces timestamps, i.e. when the string (or stream) contains only a time, an error will result
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3287
    (it may also pass in some cases but with the time undestood as date). It survives incomplete dates,
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3288
    broken years, incomplete times and timezones. All times read with timezone difference are recomputed
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3289
    to UTC before the timestamp is created (even passing across new year boundary is handled correctly).
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3290
    Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3291
    All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3292
    possible.
16915
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3293
    For an example of what the builder can read, see the examples method and ISO 8601 itself.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3294
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3295
    [author:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3296
	Martin Dvorak (masca@volny.cz)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3297
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3298
    [instance variables:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3299
	stream          A stream the builder operates on. Assigned on each call to instance method #read:,
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3300
			so the builder instance can be reused (by at most one thread).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3301
	year            Current timestamp year. No default value, date must be present.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3302
	month           Current timestamp month. May change during parsing. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3303
	day             Current timestamp day. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3304
	hour            Current timestamp hour. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3305
	minute          Current timestamp minute. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3306
	second          Current timestamp second. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3307
	millisecond     Current timestamp millisecond. Defaults to 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3308
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3309
    [see also:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3310
	Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3311
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3312
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3313
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3314
examples
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3315
"
16915
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3316
    See the unit tests in exept:regression >> RegressionTests::timeAndDateTest
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3317
    It covers the main features this builder has.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3318
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3319
    Just to introduce some coding examples, try:
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3320
        Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now)
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3321
        UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now)
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3322
        Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now)
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3323
        Timestamp readISO8601From: (TimestampISO8601Builder print: TZTimestamp now)
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3324
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3325
    Timestamp readISO8601From:'fooBar' onError:[ Timestamp now ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3326
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3327
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3328
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3329
history
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3330
    "Created: / 16-06-2005 / 16:28:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3331
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3332
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3333
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3334
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3335
print: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3336
    "Returns the printString of the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3337
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3338
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3339
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3340
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3341
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3342
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3343
    self print: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3344
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3345
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3346
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3347
     self print:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3348
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3349
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3350
    "Created: / 15-06-2005 / 17:52:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3351
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3352
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3353
print:aTimestamp asLocal:asLocal on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3354
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3355
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3356
     The time is always printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3357
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3358
    self print:aTimestamp compact:false asLocal:asLocal asUTC:asLocal not withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3359
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3360
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3361
     self print:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3362
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3363
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3364
    "Created: / 15-06-2005 / 17:56:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3365
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3366
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3367
print:aTimestamp on:aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3368
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3369
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3370
     The time is printed as UTC time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3371
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3372
    self print:aTimestamp compact:false asLocal:false asUTC:true withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3373
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3374
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3375
     self print:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3376
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3377
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3378
    "Created: / 15-06-2005 / 17:56:51 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3379
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3380
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3381
printAsLocalTime: aTimestamp on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3382
    "Print the given timestamp in general ISO8601 format,
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3383
     such as '2014-11-06T11:48:09+01'.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3384
     The time is printed as local time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3385
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3386
    self print:aTimestamp compact:false asLocal:true asUTC:false withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3387
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3388
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3389
     self printAsLocalTime:(Timestamp now) on:Transcript
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3390
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3391
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3392
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3393
printCompressed: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3394
    "Return a printString in compressed format such as '20141106T114636Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3395
     (for example, for timestamp interchange with mobile devices).
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3396
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3397
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3398
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3399
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3400
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3401
    self printCompressed: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3402
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3403
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3404
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3405
     self printCompressed:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3406
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3407
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3408
    "Created: / 15-06-2005 / 17:52:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3409
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3410
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3411
printCompressed:aTimestamp asLocal:asLocal on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3412
    "generates a compressed string representation, such as '20141106T114636Z'"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3413
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3414
    self print:aTimestamp compact:true asLocal:asLocal asUTC:asLocal not withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3415
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3416
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3417
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3418
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3419
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3420
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3421
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3422
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3423
printCompressed: aTimestamp on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3424
    "generates a compressed string representation, such as '20141106T114636Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3425
     The time is printed as UTC time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3426
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3427
    self print:aTimestamp compact:true asLocal:false asUTC:true withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3428
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3429
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3430
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3431
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3432
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3433
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3434
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3435
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3436
printCompressedAsLocalTime: aTimestamp on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3437
    "generates a compressed string representation, such as '20141106T114636Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3438
     The time is printed as local time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3439
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3440
    self print:aTimestamp compact:true asLocal:true asUTC:false withMilliseconds:true on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3441
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3442
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3443
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3444
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3445
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3446
    "Created: / 15-06-2005 / 17:54:17 / masca"
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3447
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3448
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3449
printTimeZone:tzOffsetArg on: aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3450
    "Print the timezone delta"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3451
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3452
    |tzOffset tzHours tzMinutes|
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3453
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3454
    tzOffset := tzOffsetArg.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  3455
    tzOffset == 0 ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3456
	aStream nextPutAll:'+00'.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  3457
    ] ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3458
	tzOffset := tzOffset // 60.     "/ convert from seconds to minutes
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3459
	tzOffset < 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3460
	    tzOffset := tzOffset negated.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3461
	    aStream nextPut:$+
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3462
	] ifFalse:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3463
	    aStream nextPut:$-.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3464
	].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3465
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3466
	tzHours := tzOffset // 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3467
	tzMinutes := tzOffset \\ 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3468
	(tzHours ~= 0 or:[tzMinutes ~= 0]) ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3469
	    aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3470
		nextPutAll:(tzHours printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3471
	    tzMinutes ~= 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3472
		aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3473
		    nextPut: $:;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3474
		    nextPutAll: (tzMinutes printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3475
	    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3476
	].
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3477
    ].
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3478
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3479
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3480
     self print:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3481
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3482
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3483
     self print:(Timestamp now) asLocal:false on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3484
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3485
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3486
     self printCompressed:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3487
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3488
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3489
     self printCompressed:(Timestamp now) asLocal:false on:Transcript.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3490
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3491
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3492
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3493
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3494
!Timestamp::TimestampISO8601Builder class methodsFor:'printing - basic'!
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3495
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3496
print: aTimestamp compact:compact asLocal:asLocal asUTC:asUTC withMilliseconds:withMillis on: aStream
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3497
    "Print the given timestamp in general ISO8601 format,
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3498
     such as '2014-11-06T11:48:09Z'.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3499
	compact: if true, the compact format (without separating dashes and colons is generated)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3500
	asLocal: if true, generates a localtime string (with the machine's current timezone setting)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3501
	asUTC: if true, generates a utc string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3502
	    if both are false:
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3503
		generate a string depending on the type of timestamp:
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3504
		    if local: generate a local timezone string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3505
		    if utc: generate a utc string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3506
		    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3507
	withMilliseconds: if false, no milliseconds are generated"
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3508
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3509
    self
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3510
	print:aTimestamp
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3511
	compact:compact asLocal:asLocal asUTC:asUTC
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3512
	withMilliseconds:withMillis
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3513
	timeSeparator:$T
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3514
	on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3515
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3516
    "
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3517
     self print:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3518
     self printAsLocalTime:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3519
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3520
    "
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3521
!
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3522
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3523
print:aTimestamp compact:compact asLocal:asLocal asUTC:asUTC withMilliseconds:withMillis timeSeparator:tSep on:aStream
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3524
    "Print the given timestamp in general ISO8601 format,
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3525
     such as '2014-11-06T11:48:09Z'.
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3526
        compact: if true, the compact format (without separating dashes and colons is generated)
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3527
        asLocal: if true, generates a localtime string (without any timezone info)
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3528
        asUTC: if true, generates a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3529
            if both are false:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3530
                generate a string depending on the type of timestamp:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3531
                    if local: generate a local timezone string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3532
                    if utc: generate a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3533
                    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3534
        withMilliseconds: if false, no milliseconds are generated"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3535
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3536
    |timeInfo millis |
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3537
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3538
    asLocal ifTrue:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3539
        "/ force local
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3540
        timeInfo := aTimestamp asLocalTimestamp timeInfo.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3541
    ] ifFalse:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3542
        asUTC ifTrue:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3543
            "/ force utc
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3544
            timeInfo := aTimestamp asUtcTimestamp timeInfo.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3545
        ] ifFalse:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3546
            "/ in the timestamps own format
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3547
            timeInfo := aTimestamp timeInfo.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3548
        ]
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3549
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3550
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3551
    timeInfo year printOn:aStream leftPaddedTo:4 with:$0.
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3552
    compact ifFalse:[ aStream nextPut: $- ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3553
    timeInfo month printOn:aStream leftPaddedTo:2 with:$0.
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3554
    compact ifFalse:[ aStream nextPut: $- ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3555
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3556
    aStream nextPut:tSep.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3557
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3558
    compact ifFalse:[ aStream nextPut: $:].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3559
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3560
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3561
    "always print the seconds, even if 0. 
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3562
     According to http://www.w3.org/TR/xmlschema11-2/#dateTime  this is mandatory"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3563
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3564
    compact ifFalse:[ aStream nextPut: $:].
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3565
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3566
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3567
    millis := withMillis ifTrue:[timeInfo milliseconds] ifFalse:[0].
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3568
    millis ~= 0 ifTrue:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3569
        aStream nextPut: $..
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3570
        millis printOn:aStream leftPaddedTo:3 with:$0.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3571
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3572
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3573
    asUTC ifTrue:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3574
        aStream nextPut: $Z
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3575
    ] ifFalse:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3576
        asLocal ifFalse:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3577
            self printTimeZone:aTimestamp utcOffset on:aStream.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3578
        ].
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3579
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3580
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3581
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3582
     self print:(Timestamp now) on:Transcript
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3583
     self printAsLocalTime:(Timestamp now) on:Transcript
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3584
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3585
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3586
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3587
    "Created: / 15-06-2005 / 17:56:51 / masca"
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3588
! !
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3589
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3590
!Timestamp::TimestampISO8601Builder class methodsFor:'public parsing'!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3591
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3592
read: stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3593
    ^ self new read:stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3594
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3595
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3596
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3597
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3598
read: stringOrStream withClass:timestampClass yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3599
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3600
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3601
    ^ self new
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3602
	yearAlreadyReadAs:yearArg;
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3603
	read:stringOrStream withClass:timestampClass
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3604
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3605
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3606
! !
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3607
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3608
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3609
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3610
nextDigit
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3611
    | char |
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3612
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3613
    char := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3614
    char isNil ifTrue: [^-1].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3615
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3616
    char isDigit ifTrue: [
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3617
	stream next.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3618
	^ char codePoint - $0 codePoint
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3619
    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3620
    ^ -1
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3621
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3622
    "Created: / 14-06-2005 / 11:48:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3623
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3624
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3625
nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3626
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3627
    | digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3628
    digit := self nextDigit.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3629
    ^ digit < 0
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3630
	ifTrue: [self malformed: 'No digit found']
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3631
	ifFalse: [digit]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3632
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3633
    "Created: / 15-06-2005 / 10:57:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3634
    "Modified: / 15-06-2005 / 17:22:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3635
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3636
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3637
nextDigits: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3638
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3639
    | char number |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3640
    number := 0.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3641
    anInteger timesRepeat: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3642
	char := stream peekOrNil.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3643
	char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3644
	char isDigit
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3645
	    ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3646
		stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3647
		number := number * 10 + char codePoint - $0 codePoint]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3648
	    ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3649
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3650
    ^ number
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3651
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3652
    "Created: / 14-06-2005 / 11:57:22 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3653
    "Modified: / 15-06-2005 / 15:54:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3654
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3655
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3656
!Timestamp::TimestampISO8601Builder methodsFor:'public processing'!
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3657
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3658
read:stringOrStream withClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3659
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3660
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3661
    stream := stringOrStream readStream.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3662
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3663
    month := day := 1.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3664
    hour := minute := second := millisecond := 0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3665
    isUtcTime := hasTimezone := false.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3666
    utcOffset := 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3667
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  3668
    yearAlreadyRead ~~ true ifTrue:[
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3669
        "Read the year. This will read and swallow up to four year digits."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3670
        self readYear.
16923
719c8a7b1cdd class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16922
diff changeset
  3671
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3672
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3673
    "Check if date has been read, ie. T or space necountered. If yes, read the time.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3674
    There is possible inconsistency - a dash may be read followed by T, which is not
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3675
    valid. But don't mind that, timestamps will be well-formatted in most cases."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3676
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3677
    peek ifNil: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3678
        "End of stream, only year has been read."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3679
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3680
    peek == $- ifTrue: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3681
        "Skip the dash after year, if present."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3682
        stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3683
        peek := stream peekOrNil].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3684
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3685
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3686
    (peek == $T or: [peek == Character space])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3687
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3688
            "Got time signature. Skip the signature, read time and answer the timestamp."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3689
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3690
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3691
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3692
            self readTimezone.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3693
            ^ self timestampWithClass:timestampClass
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3694
        ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3695
        ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3696
            "Date not read completely yet, expecting month/day or week/day or day"
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3697
            peek == $W
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3698
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3699
                    "Parse week number and (possibly) day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3700
                    stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3701
                    self readWeekNumber]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3702
                ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3703
                    "Got digit, read month number followed by day or day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3704
                    self readMonthOrDay]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3705
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3706
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3707
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3708
    peek ifNil: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3709
        "End of stream, only year has been read."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3710
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3711
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3712
    (peek asUppercase == $T or: [peek == Character space])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3713
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3714
            "Got time signature, expecting time follows. Otherwise only date was in the stream."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3715
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3716
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3717
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3718
            self readTimezone
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3719
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3720
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3721
    ^ self timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3722
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3723
    "Created: / 14-06-2005 / 11:45:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3724
    "Modified: / 16-06-2005 / 10:15:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3725
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3726
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3727
!Timestamp::TimestampISO8601Builder methodsFor:'reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3728
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3729
readFraction
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3730
    "Read an arbitrary number of digits representing a fraction."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3731
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3732
    ^ Fraction readDecimalFractionFrom:stream onError:[self malformed: 'Missing digits after fraction separator'].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3733
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3734
"/    | anyDigit digit factor fraction |
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3735
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3736
"/    factor := (1 / 10).
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3737
"/    fraction := 0.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3738
"/    anyDigit := false.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3739
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3740
"/    [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3741
"/        digit := self nextDigit.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3742
"/        digit >= 0
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3743
"/    ] whileTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3744
"/        anyDigit := true.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3745
"/        fraction := digit * factor + fraction.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3746
"/        factor := (factor / 10)
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3747
"/    ].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3748
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3749
"/    anyDigit ifFalse: [self malformed: 'Missing digits after fraction separator'].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3750
"/    ^ fraction
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3751
"/
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3752
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3753
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3754
readMilliseconds
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3755
    "Read an arbitrary number of digits representing milliseconds. As the timestamp can
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3756
    hold only integer amounts of milliseconds, don't mind the rest of the digits."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3757
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3758
    millisecond := (self readFraction * 1000) asInteger
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3759
"/    | digit factor |
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3760
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3761
"/    factor := 100.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3762
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3763
"/    [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3764
"/        digit := self nextDigit.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3765
"/        digit >= 0
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3766
"/    ] whileTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3767
"/        factor > 0 ifTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3768
"/            "Factor still > 0, did not read all three digits of mantissa."
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3769
"/            millisecond := digit * factor + millisecond.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3770
"/            factor := (factor / 10) integerPart
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3771
"/        ]
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3772
"/    ].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3773
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3774
"/    factor = 100 ifTrue: [self malformed: 'No digits after millisecond separator']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3775
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3776
    "Created: / 15-06-2005 / 15:25:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3777
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3778
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3779
readMonthOrDay
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3780
    "Read month number, optionally followed by day, or absolute day number (three digit)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3781
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3782
    | dayDigit1 dayDigit2 |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3783
    month := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3784
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3785
    stream peekOrNil = $-
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3786
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3787
	    "Got dash. Day number must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3788
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3789
	    day := self nextDigits: 2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3790
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3791
	    ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3792
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3793
    dayDigit1 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3794
    dayDigit1 < 0 ifTrue: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3795
	"No more digits than month, leave day unspecified."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3796
	(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3797
	^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3798
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3799
    dayDigit2 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3800
    dayDigit2 < 0
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3801
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3802
	    "Read only three digits, this is absolute day number in a year."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3803
	    self dateFromDayNumber: month * 10 + dayDigit1]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3804
	ifFalse: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3805
	    "Read four digits. So there's month and day."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3806
	    (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3807
	    day := dayDigit1 * 10 + dayDigit2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3808
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3809
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3810
    "Created: / 15-06-2005 / 11:12:02 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3811
    "Modified: / 16-06-2005 / 11:47:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3812
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3813
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3814
readTime
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3815
    "Date read, don't mind it. Read only the time value."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3816
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3817
    | peek f |
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3818
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3819
    hour := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3820
    (hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3821
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3822
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3823
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3824
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3825
        "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3826
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3827
        minute := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3828
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3829
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3830
            "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3831
            minute := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3832
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3833
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3834
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3835
                minute := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3836
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3837
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3838
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3839
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3840
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3841
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3842
    minute isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3843
        f := minute.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3844
        minute := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3845
        second := (f - minute) * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3846
        second isInteger ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3847
            f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3848
            second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3849
            millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3850
            millisecond := millisecond rounded.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3851
        ].
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3852
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3853
    (minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3854
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3855
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3856
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3857
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3858
        "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3859
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3860
        second := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3861
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3862
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3863
            "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3864
            second := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3865
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3866
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3867
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3868
                second := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3869
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3870
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3871
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3872
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3873
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3874
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3875
    second isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3876
        f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3877
        second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3878
        millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3879
        millisecond := millisecond rounded.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3880
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3881
    (second between: 0 and: 59) ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3882
        "Seconds are usually in this range, do a special check for leap seconds."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3883
        second <= 61
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3884
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3885
                "Leap seconds can occur only on midnight on 31.12. or 30.6. Don't check year
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3886
                as it's not deterministic."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3887
                (minute = 59 and: [hour = 23 and: [(month = 12 and: [day = 31]) or: [month = 6 and: [day = 30]]]])
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3888
                    ifFalse: [self malformed: 'Bad leap second']]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3889
            ifFalse: [self malformed: 'Bad second: ' , second printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3890
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3891
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3892
    "Hour, minute and second read. Read appendices."
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3893
    ((peek := stream peekOrNil) == $. or:[peek == $,])
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3894
        ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3895
            "Read dot. Skip it and read milliseconds."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3896
            stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3897
            self readMilliseconds].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3898
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3899
    hour = 24 ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3900
        (minute = 0 and: [second = 0 and: [millisecond = 0]])
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3901
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3902
                "On 24 hour, advance to the next day."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3903
                "hour := 0.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3904
                self addMinutes: 1440"]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  3905
            ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3906
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3907
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3908
    "Created: / 14-06-2005 / 17:27:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3909
    "Modified: / 30-06-2005 / 11:34:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3910
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3911
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3912
readTimezone
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3913
    "Read time zone information. There are three possibilities of what can occur.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3914
    If there is nothing more to read, the offset is unknown - this is treated as
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3915
    Zulu time as this may not be true."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3916
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3917
    | peek tzOffset |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3918
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3919
    peek := stream peek.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3920
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3921
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3922
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3923
    "If the time is in Zulu, don't modify the timestamp. This makes the machine
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3924
    run in Zulu time zone, maybe some corrections would be nice."
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3925
    peek == $Z ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3926
        "Time read, skip Zulu signature and exit."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3927
        isUtcTime := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3928
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3929
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3930
    ].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3931
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3932
    (peek == $+ or:[peek == $-]) ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3933
        "Read a plus/minus, expect a negative/positive time zone difference."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3934
        hasTimezone := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3935
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3936
        tzOffset := self readTimezoneOffset.
19917
b273314a4ef7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19916
diff changeset
  3937
        peek == $+ ifTrue:[
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3938
            tzOffset := tzOffset collect: [:e | e negated].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3939
        ].    
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3940
        self addHoursAndMinutes: tzOffset.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3941
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  3942
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3943
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3944
    "This is local time"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3945
    isUtcTime := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3946
    hasTimezone := false.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3947
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3948
    "Created: / 16-06-2005 / 09:54:21 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3949
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3950
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3951
readTimezoneOffset
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3952
    "Read time zone offset as a number minutes. Generally, there should be hours only
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3953
    but as the format introduces minutes in offsets, we must accept them."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3954
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3955
    | hours digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3956
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3957
    "Read hours."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3958
    hours := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3959
    (hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3960
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3961
    stream peekOrNil = $:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3962
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3963
	    "Colon read, minutes must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3964
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3965
	    digit := self nextDigits: 2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3966
	    (digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3967
	    ^Array with: hours with: digit].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3968
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3969
    "Read next digit and check whether minutes follow. If not, return only with hours. If yes,
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3970
     check boundaries."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3971
    digit := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3972
    digit < 0 ifTrue: [^Array with: hours with: 0].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3973
    digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3974
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3975
    "Read the last digit of offset, it must be present."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3976
    ^Array with: hours with: digit * 10 + self nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3977
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3978
    "Created: / 15-06-2005 / 15:35:41 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3979
    "Modified: / 15-06-2005 / 17:45:58 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3980
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3981
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3982
readWeekNumber
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3983
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3984
    | week dayInWeek digit |
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3985
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3986
    "Read week number. It is always two digits long."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3987
    week := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3988
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3989
    stream peekOrNil = $-
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3990
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3991
	    "Got dash, day number must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3992
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3993
	    digit := self nextDigit.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3994
	    digit < 0 ifTrue: [self malformed: 'Bad weekday number'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3995
	    digit > 7 ifTrue: [self malformed: 'Bad weekday number'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3996
	    self dateFromWeek: week andWeekday: digit.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3997
	    ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3998
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3999
    "Read day number that follows the week. If the number is not given, consider it monday."
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4000
    dayInWeek := self nextDigit.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4001
    dayInWeek <= 0 ifTrue: [dayInWeek := 1].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4002
    dayInWeek > 7 ifTrue: [self malformed: 'Bad weekday number'].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4003
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4004
    self dateFromWeek: week andWeekday: dayInWeek
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4005
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4006
    "Created: / 14-06-2005 / 12:06:47 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4007
    "Modified: / 15-06-2005 / 15:53:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4008
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4009
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4010
readYear
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4011
    "Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4012
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4013
    | read peek |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4014
    stream peekOrNil = $:
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4015
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4016
            "Broken two digit year > 1999 follows."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4017
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4018
            year := self nextDigitOrError + 2000.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4019
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4020
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4021
    "Expecting two-, three- or four-digit year"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4022
    "Read the first two digits. They must be there."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4023
    read := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4024
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4025
    "Check if there's a dash, this can help us deciding whether the year ends."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4026
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4027
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4028
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4029
    ((peek == $-) or:[peek == $W])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4030
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4031
            "OK, got two digits. These are expected to be the year after 1970."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4032
            year := read < 70
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4033
                ifTrue: [read + 2000]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4034
                ifFalse: [read + 1900]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4035
        ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4036
            "Read the next digit for the case of three-digit year after 1900 (ie. year > 1999)."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4037
             read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4038
             peek := stream peekOrNil.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4039
             (peek isNil or: [peek == $-])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4040
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4041
                    "Read three digit year, return it."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4042
                    year :=  read + 1900
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4043
                ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4044
                    "Read the fourth digit of the year. These can be month digits but the
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4045
                    two-digit year format is deprecated anyway."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4046
                    read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4047
                    year :=  read.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4048
                ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4049
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4050
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4051
    "Created: / 14-06-2005 / 12:01:11 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4052
    "Modified: / 15-06-2005 / 17:31:56 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4053
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4054
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4055
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4056
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4057
version
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4058
    ^ '$Header$'
12164
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4059
!
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4060
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4061
version_CVS
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4062
    ^ '$Header$'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4063
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4064
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  4065
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4066
Timestamp initialize!