Timestamp.st
author Claus Gittinger <cg@exept.de>
Sun, 03 Nov 2019 11:45:51 +0100
changeset 24879 9ec224d47bc0
parent 24850 8048f0088a90
child 25220 b6b8db23fd8f
permissions -rw-r--r--
#OTHER by exept storeStringClass
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24879
9ec224d47bc0 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 24850
diff changeset
     1
"{ Encoding: utf8 }"
9ec224d47bc0 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 24850
diff changeset
     2
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     3
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
     5
	      All Rights Reserved
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     6
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    13
"
5376
c2ef7d5e25ca oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents: 5292
diff changeset
    14
"{ Package: 'stx:libbasic' }"
c2ef7d5e25ca oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents: 5292
diff changeset
    15
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
    16
"{ NameSpace: Smalltalk }"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
    17
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    18
AbstractTime subclass:#Timestamp
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
    19
	instanceVariableNames:'osTime additionalPicoseconds'
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
    20
	classVariableNames:'Epoch MaxOSTime MinOSTime TimeZoneInfo'
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    21
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    22
	category:'Magnitude-Time'
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    23
!
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    24
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    25
Object subclass:#TimestampBuilderAbstract
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    26
	instanceVariableNames:'year month day hour minute second millisecond isUtcTime
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
    27
		hasTimezone yearAlreadyRead utcOffset picos'
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    28
	classVariableNames:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    29
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    30
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    31
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    32
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    33
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder
17005
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    34
	instanceVariableNames:'stream'
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    35
	classVariableNames:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    36
	poolDictionaries:''
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    37
	privateIn:Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    38
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
    39
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
    40
!Timestamp class methodsFor:'documentation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    41
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    42
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    43
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    44
 COPYRIGHT (c) 1989 by Claus Gittinger
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
    45
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    46
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    47
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    48
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    49
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    50
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    51
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    52
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    53
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    54
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    55
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    56
documentation
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    57
"
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    58
    This class represents time values in milliseconds, starting some time in the past.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
    59
    This base-time is called 'epoch' and always an UTC time.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
    60
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    61
    When printing and accessing values like #hour,
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    62
    the timestamp will be interpreted in the local timezone.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
    63
    (as opposed to UtcTimestamp, which presents itself in UTC,
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    64
     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
    65
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
    66
    The internal representation, osTime, will typically start with 1970-01-01 00:00 UTC,
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    67
    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
    68
    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
    69
    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
    70
    as returned from the OS.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    71
    For conversion, these values are given back to the OS, which will know
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    72
    how to convert them. This has the advantage that timestamps on files
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    73
    (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
    74
    especially when performing comparisons.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    75
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    76
    You should not interpret the osTime instance variable directly,
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
    77
    instead (if at all), ask the OS to convert.
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    78
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
    79
    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
    80
    (which represents the time as seconds from Jan 1., 1901).
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
    81
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
    82
    This class should not be confused with Time (which only represents the time within one day). 
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    83
    Time instances cannot be used to compare times across midnight, whereas instances of Timestamp can.
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    84
    Also, it should not be confused with TimeDuration, which represents a time-difference.
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    85
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    86
    Notice: 
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    87
        this class was once called AbsoluteTime. Einstein told us in 1905, that talking
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    88
        about an absolute time is not a good idea (at least in our universe). So in 2004 the class
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    89
        has been renamed to Timestamp which makes us more compatible to other ST dialects (e.g. VW)
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    90
        AbsoluteTime was kept as an alias for backward compatibility and was finally removed in 2017.
3479
9ca6229713f4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3122
diff changeset
    91
16922
148cb53b8691 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16921
diff changeset
    92
    Also Note:
21699
b8eea1f574cf #OTHER by mawalch
mawalch
parents: 21388
diff changeset
    93
        On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T03:14:07Z
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
    94
        However, timestamp instances can hold negative osTime values (which are timestamps
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
    95
        before 1.1.1970 and also osTimes greater than 4294967295 (2^32-1) for timestamps after 2038-01-19.
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
    96
        Thus, ST/X will have no problem when dealing with dates before the epoch or after 2038.
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    97
21699
b8eea1f574cf #OTHER by mawalch
mawalch
parents: 21388
diff changeset
    98
        For dates before 1582 (when calendars were changed from Julian to Gregorian),
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
    99
        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
   100
        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
   101
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   102
    ALso Note:
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   103
        because all timestamps keep the internal time value in UTC, they can be easily compared
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   104
        for being before/same/after another. Only when printing, a difference is made.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   105
        The timezone is compensated out when a timestamp is created and recalculated in when printed.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   106
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   107
    News:
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   108
        The additional instance variable picoSeconds can be used to add more resolution. 
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   109
        If non-nil, it holds additional picoseconds to be added to the millisecond osTime
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   110
        (i.e. the picoSeconds are an integer between 0 and 1000*1000*1000.
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
   111
        Although, not all OSs give us that detail when asking for the current time,
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   112
        the picos can still be used in physical computations. 
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
   113
        Some OSs will provide microsecond resolution.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   114
        Notice: 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   115
            the picos are to be added to the millis, to get picos within the second.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   116
            this is ugly, but makes all the rest backward compatible.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   117
            Also, most timestamps only require/have millisecond resolution,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   118
            so the pico instvar is nil/0 and does not require an aditional largeInteger operation.
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
   119
22867
434085ae9420 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22842
diff changeset
   120
        The typical OS-time resolution is in the milli- or microsecond range.
434085ae9420 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22842
diff changeset
   121
        External logging hardware may generate timestamps in the micro- or nanosecond range.
434085ae9420 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22842
diff changeset
   122
        Picosecond resolution should be good enough for almost any application (at least for the near future).
434085ae9420 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22842
diff changeset
   123
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
   124
    [author:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   125
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
   126
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   127
    [See also:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   128
        UtcTimestamp Time Date
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   129
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   130
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   131
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   132
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   133
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   134
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   135
initialize
17008
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   136
    MinOSTime := OperatingSystem epochStartOSTime.
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   137
    MaxOSTime := OperatingSystem epochEndOSTime.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   138
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   139
    Epoch := UtcTimestamp basicNew setSeconds:0.
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   140
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   141
    "Modified: / 19-01-2017 / 17:01:59 / stefan"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   142
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   143
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   144
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   145
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   146
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
   147
    "return an instance of the receiver, given individual components,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   148
     interpreted in the UTC timezone."
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   149
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   150
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   151
	    UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   152
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   153
    "
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
   154
     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
   155
     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
   156
     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
   157
     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
   158
     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
   159
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   160
     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
   161
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   162
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   163
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   164
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   165
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   166
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   167
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   168
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   169
    "return an instance of the receiver, given individual components,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   170
     interpreted in the UTC timezone."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   171
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   172
    ^ self basicNew
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   173
        UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   174
        additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   175
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   176
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   177
     Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   178
     Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   179
     Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   180
     Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   181
     Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   182
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   183
     UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   184
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   185
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   186
    "Modified: / 1.7.1996 / 15:22:07 / cg"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   187
    "Created: / 13.7.1999 / 12:34:37 / stefan"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   188
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   189
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   190
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   191
decodeFromLiteralArray:anArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   192
    "decode a Timestamp literalArray.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   193
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   194
     anArray may be:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   195
        #(Timestamp '200004182000.123')
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   196
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   197
     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
   198
     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
   199
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   200
        #(Timestamp #osTime: 12345678)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   201
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   202
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   203
    (anArray at:2) == #osTime: ifTrue:[
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   204
        ^ self new osTime:(anArray at:3).
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   205
    ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   206
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   207
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   208
        readGeneralizedFrom:(anArray at:2)
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   209
        onError:[ self conversionErrorSignal
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   210
                    raiseWith:anArray errorString:' - Timestamp literal array decoding' ]
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   211
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   212
    "
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   213
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   214
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   215
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   216
        decodeFromLiteralArray:#(Timestamp '20050323175226.014-01')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   217
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   218
        decodeFromLiteralArray:#(Timestamp '20050323175226.014Z')
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   219
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   220
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   221
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   222
epoch
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   223
    "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
   224
     However, we allow negative values to represent timestamps before that"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   225
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   226
    ^ Epoch
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   227
!
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   228
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   229
fromDate:aDate
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   230
    "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
   231
     object.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   232
     See also `Timestamp now' and other protocol inherited
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   233
     from my superclass."
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   234
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   235
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   236
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   237
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   238
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   239
	hour:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   240
	minute:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   241
	second:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   242
	millisecond:0
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   243
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   244
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   245
     Timestamp fromDate:(Date today) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   246
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   247
     Timestamp now
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   248
    "
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   249
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   250
    "Modified: / 8.9.1995 / 15:07:30 / claus"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   251
    "Modified: / 19.4.1996 / 15:25:46 / cg"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   252
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   253
!
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   254
423
claus
parents: 392
diff changeset
   255
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   256
    "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
   257
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   258
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   259
     from my superclass."
423
claus
parents: 392
diff changeset
   260
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   261
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   262
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   263
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   264
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   265
	hour:aTime hours
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   266
	minute:aTime minutes
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   267
	second:aTime seconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   268
	millisecond:aTime milliseconds
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   269
423
claus
parents: 392
diff changeset
   270
    "
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   271
     Timestamp fromDate:(Date today) andTime:(Time now)
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   272
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   273
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   274
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   275
     Timestamp now
423
claus
parents: 392
diff changeset
   276
    "
claus
parents: 392
diff changeset
   277
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   278
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   279
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   280
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   281
!
claus
parents: 392
diff changeset
   282
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   283
fromDate:aDate hour:hour minute:minute second:second
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   284
    "return an instance of the receiver, initialized from a time and a date object.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   285
     See also `Timestamp now' and other protocol inherited from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   286
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   287
    ^ self fromDate:aDate hour:hour minute:minute second:second millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   288
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   289
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   290
     Timestamp fromDate:(Date today) andTime:(Time now)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   291
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   292
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   293
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   294
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   295
fromDate:aDate hour:hour minute:minute second:second microsecond:micros
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   296
    "return an instance of the receiver, initialized from a time and a date object.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   297
     See also `Timestamp now' and other protocol inherited from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   298
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   299
    ^ (self
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   300
        year:aDate year
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   301
        month:aDate month
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   302
        day:aDate day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   303
        hour:hour
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   304
        minute:minute
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   305
        second:second
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   306
        millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   307
      ) setMicrosecond:micros
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   308
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   309
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   310
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:123456
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   311
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:140
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   312
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   313
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   314
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   315
fromDate:aDate hour:hour minute:minute second:second millisecond:millis
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   316
    "return an instance of the receiver, initialized from a time and a date object.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   317
     See also `Timestamp now' and other protocol inherited from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   318
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   319
    ^ self
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   320
        year:aDate year
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   321
        month:aDate month
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   322
        day:aDate day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   323
        hour:hour
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   324
        minute:minute
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   325
        second:second
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   326
        millisecond:millis
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   327
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   328
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   329
     Timestamp fromDate:(Date today) andTime:(Time now)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   330
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   331
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30 millisecond:140
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   332
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   333
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   334
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   335
fromDate:aDate hour:hour minute:minute second:second nanosecond:nanos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   336
    "return an instance of the receiver, initialized from a time and a date object.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   337
     See also `Timestamp now' and other protocol inherited from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   338
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   339
    ^ (self
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   340
        year:aDate year
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   341
        month:aDate month
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   342
        day:aDate day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   343
        hour:hour
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   344
        minute:minute
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   345
        second:second
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   346
        millisecond:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   347
      ) setNanosecond:nanos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   348
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   349
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   350
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:123456
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   351
     Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:140
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   352
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   353
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   354
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   355
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   356
    "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
   357
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   358
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   359
    ^ self fromDate:(Date newDay:dayInYear year:year)
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   360
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   361
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   362
     Timestamp newDay:183 year:1996
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   363
     Timestamp newDay:1 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   364
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   365
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   366
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   367
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   368
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   369
secondsSince1970:secs
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   370
    "set time from elapsed seconds since 1-1-1970, 00:00:00 (UTC).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   371
     This is the format used in the UNIX world.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   372
     Notice that the internal storage is always UTC based."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   373
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   374
    ^ self basicNew setSeconds:secs.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   375
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   376
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   377
     UtcTimestamp secondsSince1970:0        -> 1970-01-01 00:00:00Z       
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   378
     Timestamp secondsSince1970:0           -> 1970-01-01 01:00:00 (local germany, ST)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   379
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   380
     Timestamp secondsSince1970:3600
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   381
     Timestamp secondsSince1970:3600*24
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   382
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   383
     (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
   384
       =
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   385
     (Timestamp secondsSince1970:1277935200)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   386
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   387
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   388
    "Created: / 21-10-1996 / 17:48:30 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   389
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   390
    "Modified: / 08-01-2011 / 16:06:28 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   391
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   392
23565
28bca8eff682 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23564
diff changeset
   393
utcMillisecondsSince1970:millis
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   394
    "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
   395
23565
28bca8eff682 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23564
diff changeset
   396
    ^ self basicNew setMilliseconds:millis
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   397
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   398
    "Created: / 08-01-2011 / 16:09:32 / cg"
23565
28bca8eff682 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23564
diff changeset
   399
    "Modified (format): / 14-12-2018 / 19:45:12 / Claus Gittinger"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   400
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   401
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   402
utcNow
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   403
    "return now as utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   404
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   405
    ^ UtcTimestamp now
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   406
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   407
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   408
     Timestamp now
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   409
     Timestamp utcNow
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   410
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   411
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   412
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   413
utcSecondsSince1970:secs
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   414
    "set time from the elapsed seconds since 1-1-1970, 00:00:00 UTC.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   415
     This is the format used in the UNIX world.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   416
     Notice that the internal storage is always UTC based."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   417
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   418
    ^ UtcTimestamp secondsSince1970:secs
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   419
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   420
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   421
     UtcTimestamp secondsSince1970:0        -> 1970-01-01 00:00:00Z       
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   422
     Timestamp secondsSince1970:0           -> 1970-01-01 01:00:00 (local germany, ST)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   423
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   424
     UtcTimestamp secondsSince1970:3600     -> 1970-01-01 01:00:00Z
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   425
     Timestamp secondsSince1970:3600        -> 1970-01-01 02:00:00 (local)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   426
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   427
     Timestamp secondsSince1970:3600*24
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   428
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   429
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   430
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   431
    "Created: / 08-01-2011 / 16:05:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   432
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   433
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   434
year:year month:month day:day  
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   435
    "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
   436
     Date protocol compatibility"
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   437
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   438
    ^ self
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   439
        year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   440
        month:month
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   441
        day:day
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   442
        hour:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   443
        minute:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   444
        second:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   445
        millisecond:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   446
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
     Timestamp year:1996 month:1 day:1 
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   449
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   450
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   451
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   452
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
   453
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   454
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   455
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   456
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   457
    ^ 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
   458
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   459
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   460
     Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   461
     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
   462
     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
   463
     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
   464
     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
   465
    "
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
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   468
    "Created: / 13.7.1999 / 12:06:39 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   469
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
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
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   472
year:y month:m day:d hour:h minute:min second:s microsecond:micros
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   473
    "return an instance of the receiver, given individual components.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   474
     See also `Timestamp now' and other protocol inherited
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   475
     from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   476
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   477
    ^ (self year:y month:m day:d hour:h minute:min second:s) setMicrosecond:micros
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   478
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   479
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   480
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 microsecond:100
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   481
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   482
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   483
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   484
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
   485
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   486
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   487
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   488
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   489
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   490
	    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
   491
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   492
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   493
     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
   494
     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
   495
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   496
     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
   497
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   498
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   499
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   500
    "Created: / 13.7.1999 / 12:28:44 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   501
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   502
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   503
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   504
year:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   505
    "return an instance of the receiver, given individual components.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   506
     See also `Timestamp now' and other protocol inherited
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   507
     from my superclass."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   508
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   509
    ^ self basicNew
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   510
            year:y month:m day:d hour:h minute:min second:s 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   511
            millisecond:millis additionalPicoseconds:picos 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   512
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   513
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   514
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   515
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   516
     Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   517
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   518
     UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   519
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   520
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   521
    "Modified: / 1.7.1996 / 15:22:07 / cg"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   522
    "Created: / 13.7.1999 / 12:28:44 / stefan"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   523
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   524
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   525
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   526
!Timestamp class methodsFor:'Compatibility-Squeak'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   527
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   528
current
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   529
    ^ self now
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   530
!
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   531
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   532
readFrom:aStringOrStream
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   533
    "Answer a new instance for the value given by aStringOrStream"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   534
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   535
    ^ self
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   536
        readFrom:aStringOrStream
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   537
        onError:[ 
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   538
            TimeConversionError raiseRequestWith:aStringOrStream errorString:' - timestamp'
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   539
        ]
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   540
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   541
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   542
     self readFrom:'23-jun-2000 15:00'
14969
13470ec6f8c8 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 14713
diff changeset
   543
     self fromString:'23-jun-2000 15:00'
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   544
     self readFrom:'23-jun-2000 '
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   545
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   546
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   547
    "Modified (comment): / 20-08-2011 / 16:52:10 / cg"
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   548
    "Modified (format): / 14-12-2018 / 19:14:16 / Claus Gittinger"
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   549
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   550
24160
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   551
year:year day:dayInYear
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   552
    "return a new Timestamp, given the year and the day-in-year (starting at 1).
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   553
     See also: Date today / Time now / Timestamp now.
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   554
     Squeak compatibility"
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   555
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   556
    ^ self newDay:dayInYear year:year
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   557
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   558
    "
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   559
     self year:1970 day:1
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   560
     self year:2000 day:1
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   561
    "
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   562
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   563
    "Created: / 26-05-2019 / 11:59:20 / Claus Gittinger"
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   564
!
93d4db241317 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23776
diff changeset
   565
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   566
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
   567
    ^ (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
   568
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   569
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   570
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   571
     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
   572
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   573
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   574
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   575
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
   576
    ^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   577
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   578
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   579
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   580
     Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:(2 hours)
24163
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
   581
     Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:0
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
   582
    "
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
   583
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
   584
    "Modified (comment): / 26-05-2019 / 12:10:28 / Claus Gittinger"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   585
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   586
22837
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   587
!Timestamp class methodsFor:'class access'!
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   588
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   589
timestampISO8601Builder
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   590
    "I hate private class overuse...
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   591
     ... I need such ugly hacks whenever someone thinks that he/she must keep a secret...
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   592
     See Time for such its use"
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   593
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   594
    ^ TimestampISO8601Builder
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   595
! !
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   596
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   597
!Timestamp class methodsFor:'format strings'!
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   598
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   599
defaultFormatString
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   600
    "a format string to present times in user interfaces.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   601
     Do not use this to store/retrieve times (use ISO8601 for that).
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   602
     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
   603
     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
   604
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   605
    ^ '%(year)-%(month)-%(day) %h:%m:%s.%i'
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   606
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   607
    "Created: / 16-01-2011 / 11:23:36 / cg"
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   608
! !
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   609
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   610
!Timestamp class methodsFor:'obsolete'!
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
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
   613
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   614
    "This is obsolete. User #year:month:day:hour:minute:second:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   615
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   616
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   617
	year:y month:m day:d hour:h
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   618
	minute:min second:s millisecond:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   619
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   620
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   621
    "Modified: / 1.7.1996 / 15:22:26 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   622
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   623
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   624
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   625
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
   626
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   627
    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   628
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   629
    ^ 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
   630
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   631
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   632
     Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   633
     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
   634
     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
   635
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   636
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   637
    "Created: / 1.7.1996 / 14:46:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   638
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   639
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   640
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   641
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   642
newDay:day month:month year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   643
    <resource: #obsolete>
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   644
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   645
    "return a new Timestamp, given the year, month and day (starting at 1).
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   646
     Date protocol compatibility.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   647
     Obsolete: use year:month:day:."
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   648
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   649
    ^ self
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   650
        year:year
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   651
        month:month
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   652
        day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   653
        hour:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   654
        minute:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   655
        second:0
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   656
        millisecond:0
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   657
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   658
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   659
     Timestamp newDay:1 month:1 year:1996
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   660
    "
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   661
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   662
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   663
!Timestamp class methodsFor:'private'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   664
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   665
basicReadFrom:aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   666
    "return a new Timestamp, reading a printed representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   667
     The string is interpreted as 24 hour format, as printed.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   668
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   669
     Notice, that this is NOT the storeString format, which is iso8601
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   670
     This is more or less a heuristic attempt to read any reasonable format.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   671
     If the input starts with an integer > 31,
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   672
     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
   673
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   674
     KLUDGE:
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   675
        us and non-us format have different ordering of day and month;
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   676
        The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   677
        or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   678
        or (us-format with year first) yyyy-mm-ddThh:mm:ss.iii
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   679
     On error, raise an exception"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   680
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   681
    |monthOrYear firstNumber secondNumber day month year hour min sec 
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   682
     millis usFormat possibeMonthName ch utcOffsetOrNil 
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   683
     mantissa fraction picos ts
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   684
     monthName|
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   685
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
   686
    aStream skipSeparators isLetter ifTrue:[
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   687
        "/ US format, like 'July 21, 1983 01:15:00' ?
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   688
        monthName := aStream throughAnyForWhich:[:ch | ch isLetter].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   689
        month := Date indexOfMonth:monthName asLowercase.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   690
        aStream skipSeparators.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   691
        day := Integer readFrom:aStream onError:-1.
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
   692
        aStream skipSeparators == $, ifTrue:[
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   693
            aStream next
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   694
        ].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   695
    ] ifFalse:[
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   696
        monthOrYear := aStream throughAnyAtMost:4 forWhich:[:ch | ch isDigit].
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   697
        firstNumber := Integer readFrom:monthOrYear onError:[TimeConversionError raiseErrorString:' - integer expected'].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   698
        firstNumber > 31 ifTrue:[
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   699
            "/ assume iso8601 format;
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   700
            ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   701
        ].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   702
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   703
        "/ consider this a kludge
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
   704
        usFormat := aStream skipSeparators == $/.
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   705
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   706
        [(ch := aStream peekOrNil) notNil and:[ch isLetterOrDigit not]] whileTrue:[aStream next].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   707
        (ch notNil and:[ch isDigit]) ifTrue:[
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   708
            secondNumber := Integer readFrom:aStream onError:-1.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   709
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   710
            usFormat ifTrue:[
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   711
                month := firstNumber.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   712
                day := secondNumber.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   713
            ] ifFalse:[
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   714
                month := secondNumber.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   715
                day := firstNumber.
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   716
            ].
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   717
        ] ifFalse:[
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   718
            possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   719
            month := Date indexOfMonth:possibeMonthName asLowercase.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   720
            day := firstNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   721
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   722
    ].
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   723
    
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   724
    (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   725
    (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   726
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   727
    [(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
   728
    year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   729
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   730
    picos := 0.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   731
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   732
    aStream atEnd ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   733
        hour := min := sec := millis := 0.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   734
    ] ifFalse:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   735
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   736
        hour := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   737
        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   738
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   739
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   740
        min := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   741
        (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   742
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   743
        aStream atEnd ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   744
            sec := millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   745
        ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   746
            [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   747
            sec := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   748
            (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   749
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   750
            ((ch := aStream peek) == $. or:[ch == $,]) ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   751
                aStream next.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   752
                mantissa := Number readMantissaAndScaleFrom:aStream radix:10.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   753
                fraction := (mantissa at:2) / (10 raisedTo:(mantissa at:3)).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   754
                (mantissa at:3) > 3 ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   755
                    picos := fraction * (1000 * 1000 * 1000 * 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   756
                    millis := picos // (1000 * 1000 * 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   757
                    picos := picos \\ (1000 * 1000 * 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   758
                ] ifFalse:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   759
                    millis := fraction * 1000.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   760
                ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   761
                "/ millis := Integer readFrom:aStream onError:0.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   762
                "/ millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ].
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   763
            ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   764
                millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   765
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   766
            aStream atEnd ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   767
                utcOffsetOrNil := self utcOffsetFrom:aStream
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   768
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   769
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   770
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   771
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   772
    "special check - only 24:00:00 is allowed;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   773
     every time after that must wrap"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   774
    hour == 24 ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   775
        (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
   776
    ].
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   777
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   778
    utcOffsetOrNil notNil ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   779
        utcOffsetOrNil = 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   780
            "/ utc timestamp
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   781
            ts := UtcTimestamp year:year month:month day:day hour:hour minute:min second:sec millisecond:millis
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   782
        ] ifFalse:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   783
            "/ tz timestamp
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   784
            ts := ((TZTimestamp basicNew 
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   785
                    setOSTimeFromUTCYear:year month:month day:day 
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   786
                    hour:hour minute:min second:sec millisecond:millis
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   787
                    ) utcOffset:utcOffsetOrNil
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   788
                  ) addSeconds:utcOffsetOrNil.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   789
        ].
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   790
    ] ifFalse:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   791
        "/ a local timestamp
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
   792
        ts := self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis.
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   793
    ].
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   794
    picos ~~ 0 ifTrue:[ ts additionalPicoseconds:picos ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
   795
    ^ ts
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   796
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   797
    "some ad hoc formats:
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   798
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   799
     Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   800
     Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   801
     Timestamp basicReadFrom:'20-feb-1995 13:11:06' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   802
     Timestamp basicReadFrom:'20-foo-1995 13:11:06' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   803
     (Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month    - european
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   804
     (Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month    - us
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   805
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   806
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   807
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100 MESZ' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   808
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100+0200' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   809
     Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   810
     Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   811
     Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   812
     Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   813
     Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   814
     Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   815
     Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   816
     Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   817
     Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   818
     Timestamp basicReadFrom:'foo' readStream
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   819
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   820
     any iso8601 format:.
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   821
     Timestamp basicReadFrom:(Timestamp now printString readStream)    
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   822
     Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream      
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   823
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream      
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   824
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000-0200' readStream 
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   825
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   826
     Timestamp basicReadFrom:'1995-10-20T12:10:00.000' readStream
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   827
     Timestamp basicReadFrom:'2018-03-30T03:24:00'readStream  
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
   828
     Timestamp basicReadFrom:'2018-3-30T03:24:00'readStream   
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   829
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   830
     UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   831
    "
22337
9a707f3b74c2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22331
diff changeset
   832
9a707f3b74c2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22331
diff changeset
   833
    "Modified: / 09-11-2017 / 10:10:07 / cg"
23564
cf0cf0b4de18 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23559
diff changeset
   834
    "Modified: / 14-12-2018 / 19:22:17 / Claus Gittinger"
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
   835
    "Modified: / 28-09-2019 / 15:24:25 / Stefan Vogel"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   836
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   837
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   838
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   839
    "common helper for read methods.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   840
     Return a new Timestamp, reading an iso8601 representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   841
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   842
     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
   843
     otherwise it is local time.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   844
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   845
     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
   846
     is the same as 1999-01-01T24:00:00.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   847
     Missing minute, second and ms values are replaced with 0;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   848
     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
   849
     Partial hours, minutes, seconds are allowed at the end,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   850
     decimal separators are both $. and $, .
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   851
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   852
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   853
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   854
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   855
    "/ changed to use the new reader
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   856
    ^ TimestampISO8601Builder
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   857
	read:aStringOrStream withClass:self
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   858
	yearAlreadyReadAs:yearOrNil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   859
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   860
"/    |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
   861
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   862
"/    str := aStringOrStream readStream.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   863
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   864
"/    month := day := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   865
"/    hour := millis := 0.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   866
"/    isUtcTime := false.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   867
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   868
"/    yearOrNil notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   869
"/        year := yearOrNil
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   870
"/    ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   871
"/        year := Integer readFrom:str onError:nil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   872
"/        year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   873
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   874
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   875
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   876
"/    (((ch := str peek) == $-) or:[ch == $W]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   877
"/        (ch == $-) ifTrue:[ str next ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   878
"/        str peek == $W ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   879
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   880
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   881
"/            "/ week follows
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   882
"/            week := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   883
"/            (week between:1 and:53) ifFalse:[ TimeConversionError raiseErrorString:' - bad week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   884
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   885
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   886
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   887
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   888
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   889
"/                dayInWeek := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   890
"/                (dayInWeek between:1 and:7) ifFalse:[ TimeConversionError raiseErrorString:' - bad day in week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   891
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   892
"/                dayInWeek := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   893
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   894
"/            tmpDay := Date newDayInWeek:dayInWeek week:week year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   895
"/            day := tmpDay day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   896
"/            month := tmpDay month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   897
"/            year := tmpDay year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   898
"/        ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   899
"/            "/ month follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   900
"/            month := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   901
"/            (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   902
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   903
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   904
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   905
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   906
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   907
"/                day := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   908
"/                (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   909
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   910
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   911
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   912
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   913
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   914
"/    str atEnd ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   915
"/        "time follows"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   916
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   917
"/        str peek == $T ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   918
"/            "we treat the T as optional here"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   919
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   920
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   921
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   922
"/        hour := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   923
"/        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   924
"/        str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   925
"/        str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   926
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   927
"/            "/ minutes follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   928
"/            min := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   929
"/            (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   930
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   931
"/            str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   932
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   933
"/                "/ seconds follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   934
"/                sec := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   935
"/                (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   936
"/                str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   937
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   938
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   939
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   940
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   941
"/        (peekChar == $. or:[peekChar == $,]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   942
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   943
"/            "/ decimals follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   944
"/            fraction := Number readMantissaFrom:str radix:10.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   945
"/            min isNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   946
"/                min := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   947
"/                fraction := min fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   948
"/                min := min truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   949
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   950
"/            (sec isNil and:[fraction ~= 0])ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   951
"/                sec := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   952
"/                fraction := sec fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   953
"/                sec := sec truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   954
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   955
"/            fraction ~= 0 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   956
"/                millis := (1000 * fraction) rounded.  "/ mhmh - should it be truncated ?
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   957
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   958
"/        ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   959
"/
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   960
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   961
"/        peekChar notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   962
"/            peekChar == $Z ifTrue:[
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   963
"/                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   964
"/                isUtcTime := true.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   965
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   966
"/                ((peekChar == $+) or:[peekChar == $- ]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   967
"/                    str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   968
"/                    self halt.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   969
"/                    isUtcTime := true.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   970
"/                ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   971
"/            ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   972
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   973
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   974
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   975
"/    min isNil ifTrue:[min := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   976
"/    sec isNil ifTrue:[sec := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   977
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   978
"/    "special check - only 24:00:00 is allowed;
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   979
"/     every time after that must wrap"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   980
"/    hour == 24 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   981
"/        (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
   982
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   983
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   984
"/    isUtcTime ifTrue:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   985
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   986
"/            UTCYear:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   987
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   988
"/    ] ifFalse:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   989
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   990
"/            year:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   991
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   992
"/    ]
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   993
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   994
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   995
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   996
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   997
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   998
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   999
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1000
     Timestamp readIso8601FormatFrom:'1995T13:11.5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1001
     Timestamp readIso8601FormatFrom:'1995T13:11,5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1002
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1003
     Timestamp readIso8601FormatFrom:'1995T13.25'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1004
     Timestamp readIso8601FormatFrom:'1995T13.333333'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1005
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1006
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1007
     Timestamp readIso8601FormatFrom:'2014W40'   -> 29.sep.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1008
     Timestamp readIso8601FormatFrom:'2014W44-4' -> 30.oct.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1009
     Timestamp readIso8601FormatFrom:'2014W1'    -> 30.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1010
     Timestamp readIso8601FormatFrom:'2014W1-1'  -> same 30.dec.2013 !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1011
     Timestamp readIso8601FormatFrom:'2014W1-2'  -> 31.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1012
     Timestamp readIso8601FormatFrom:'2014W1-3'  -> 1.jan.2014       !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1013
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1014
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1015
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1016
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1017
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1018
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1019
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1020
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1021
     Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1022
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1023
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1024
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1025
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1026
    "common helper for read methods."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1027
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1028
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1029
        self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1030
    ] on:ConversionError do:exceptionValue.
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1031
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1032
    "Modified: / 09-02-2017 / 10:01:27 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1033
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1034
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1035
!Timestamp class methodsFor:'reading'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1036
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1037
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1038
    "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
  1039
     The formatString is similar to the one used when printing.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1040
     On error, exceptionalValue is returned.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1041
     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
  1042
     Format:
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1043
        %h      hours, 00..23 (i.e. european)  0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1044
        %u      hours, 00..12 (i.e. us)        0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1045
        %m      minutes, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1046
        %s      seconds, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1047
        %i      milliseconds, 000..999         0-padded to length 3
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1048
        %f      fractional seconds             any length, but only milliseconds kept
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1049
        %F      fractional seconds             any length, up to picoseconds kept
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1050
        %a      am/pm
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1051
        %tz     timezone
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1052
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1053
        %d             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1054
        %D             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1055
        %(day)         - day
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1056
        %(dayOfYear)   - 1..365/366
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1057
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1058
        %(month)       - month
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1059
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1060
        %(monthName)   - monthName
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1061
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1062
        %(year)        - year, full 4 digits
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1063
        %Y             - year, last 2 digits only,
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1064
                         0..71 map to 2000..2071;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1065
                         72..99 map to 1972..1999;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1066
        %Y1900          - year, last 2 digits only, map to 1900..1999
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1067
        %Y2000          - year, last 2 digits only, map to 2000..2099
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1068
        %Y1950          - year, last 2 digits only, map to 1950..2049
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1069
        %Y1980          - year, last 2 digits only, map to 1980..2079
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1070
        %Y1970          - year, last 2 digits only, map to 1970..2069
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1071
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1072
     an optional length after the % gives a field length;
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1073
        i.e. %2h%2m%2s parses '123557' as 12:35:37
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1074
        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
  1075
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1076
     Please consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1077
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1078
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1079
    |day month year dayOfYear monthAndDay
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1080
     hour minute second millisecond
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1081
     utcOffset inStream formatStream error fChar format itemHandler
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  1082
     len s fractionString fraction picos ts|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1083
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1084
    error := [:msg |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1085
                exceptionalValue isBlock ifTrue:[
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1086
                    ^ exceptionalValue valueWithOptionalArgument:'format error'
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1087
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1088
                    ^ exceptionalValue value
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1089
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1090
             ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1091
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1092
    itemHandler := [:format |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1093
        |input|
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1094
        
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1095
        input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1096
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1097
        ( #('d' 'D' 'day' ) includes:format ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1098
            day := Integer readFrom:input onError:[ error value:'invalid day' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1099
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1100
        ] ifFalse:[ ( format = 'month' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1101
            month := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1102
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1103
        ] ifFalse:[ ( format = 'year' or:[ format = 'y' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1104
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1105
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1106
        ] ifFalse:[ ( format = 'Y' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1107
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1108
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
18449
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
  1109
            (year < 70) ifTrue:[
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
  1110
                year := year + 2000
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
  1111
            ] ifFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1112
                year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1113
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1114
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1115
        ] ifFalse:[ (format = 'monthName') ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1116
            s := input nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetter].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1117
            month := Date indexOfMonth:s asLowercase language:languageOrNil
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1118
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1119
        ] ifFalse:[ (format = 'dayOfYear') ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1120
            dayOfYear := Integer readFrom:input onError:[ error value:'invalid day of year' ].
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1121
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1122
        ] ifFalse:[ ( format sameAs: 'Y1900' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1123
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1124
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1125
            year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1126
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1127
        ] ifFalse:[ ( format sameAs:  'Y1950' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1128
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1129
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1130
            (year between:0 and: 49) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1131
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1132
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1133
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1134
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1135
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1136
        ] ifFalse:[ ( format sameAs:  'Y1980' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1137
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1138
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1139
            (year between:0 and: 79) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1140
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1141
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1142
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1143
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1144
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1145
        ] ifFalse:[ ( format sameAs:  'Y1970' ) ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1146
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1147
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1148
            (year between:0 and: 69) ifTrue:[ 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1149
                year := year + 2000
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1150
            ] ifFalse:[    
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1151
                year := year + 1900
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1152
            ]  
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1153
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1154
        ] ifFalse:[ ( format sameAs:  'Y2000' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1155
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1156
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1157
            year := year + 2000
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1158
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1159
        ] ifFalse:[ ( format = 'h' or:[ format = 'H' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1160
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1161
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1162
        ] ifFalse:[ ( format = 'u'  or:[ format = 'U']) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1163
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1164
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1165
        ] ifFalse:[ ( format = 'm'  or:[ format = 'M' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1166
            minute := Integer readFrom:input onError:[ error value:'invalid minute' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1167
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1168
        ] ifFalse:[ ( format = 's'  or:[ format = 'S' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1169
            second := Integer readFrom:input onError:[ error value:'invalid second' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1170
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1171
        ] ifFalse:[ ( format = 'i'  or:[ format = 'I' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1172
            millisecond := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1173
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1174
        ] ifFalse:[ ( format = 'f'  or:[ format = 'F' ]) ifTrue:[
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1175
            fractionString := input upToMatching:[:ch | ch isDigit not].
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1176
            fraction := FixedPoint readFrom:'0.',fractionString.
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1177
            format = 'f' ifTrue:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1178
                millisecond := (fraction * 1000) truncated.
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1179
            ] ifFalse:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1180
                picos := (fraction * 1000*1000*1000*1000) truncated.
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1181
                millisecond := picos // (1000*1000*1000).
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1182
                picos := picos \\ (1000*1000*1000).
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1183
            ].
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1184
        ] ifFalse:[ ( format = 'tz' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1185
            utcOffset := self utcOffsetFrom:input.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1186
            utcOffset isNil ifTrue:[ error value:'invalid timezone' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1187
        ] ifFalse:[ ( format = 'a' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1188
            s := (input next:2) asLowercase.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1189
            s = 'am' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1190
                (hour between:0 and:12) ifFalse:[ error value:'invalid hour' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1191
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1192
                s = 'pm' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1193
                    (hour between:1 and:12) ifFalse:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1194
                    hour := hour + 12.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1195
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1196
                    error value:'invalid am/pm'
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1197
                ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1198
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1199
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1200
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1201
            error value:'unhandled format:',format
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  1202
        ]]]]]]]]]]]]]]]]]]]
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
  1203
    ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1204
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1205
    hour := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1206
    minute := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1207
    second := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1208
    millisecond := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1209
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1210
    inStream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1211
    formatStream := formatString readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1212
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1213
    [formatStream atEnd] whileFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1214
        fChar := formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1215
        fChar = Character space ifTrue:[
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1216
            inStream peek isSeparator ifFalse:[ error value: 'format error; space expeccted' ].
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1217
            inStream skipSeparators.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1218
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1219
            fChar == $% ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1220
                len := nil.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1221
                (formatStream peek isDigit) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1222
                    len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1223
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1224
                (formatStream peek == $() ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1225
                    formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1226
                    format := formatStream upTo:$).
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1227
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1228
                    (formatStream peek == ${) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1229
                        formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1230
                        format := formatStream upTo:$}.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1231
                    ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1232
                        (formatStream peek isLetter) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1233
                            format := formatStream nextAlphaNumericWord.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1234
                        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1235
                            error value:'unhandled format:',formatStream peek
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1236
                        ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1237
                    ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1238
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1239
                itemHandler value:format.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1240
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1241
                inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected'].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1242
                inStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1243
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1244
        ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1245
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1246
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1247
    year isNil ifTrue:[
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  1248
        year := Timestamp now year
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1249
    ].
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1250
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1251
    dayOfYear notNil ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1252
        monthAndDay := Date monthAndDayFromDayInYear:dayOfYear forYear:year.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1253
        month := (monthAndDay at:1).
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1254
        day := (monthAndDay at:2).  
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1255
    ].
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1256
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1257
    utcOffset notNil ifTrue:[
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1258
        utcOffset == 0 ifTrue:[
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1259
            ts := (UtcTimestamp 
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1260
                year:year month:month day:day 
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1261
                hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond)
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1262
        ] ifFalse:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1263
            ts := ((TZTimestamp basicNew
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1264
                    setOSTimeFromUTCYear:year month:month day:day 
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1265
                    hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1266
               ) utcOffset:utcOffset
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1267
              ) addSeconds:utcOffset.
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1268
        ]              
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1269
    ] ifFalse:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1270
        ts := (self 
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1271
            year:year month:month day:day 
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1272
            hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) 
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  1273
    ].
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1274
    picos notNil ifTrue:[
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1275
        ts additionalPicoseconds:picos
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1276
    ].
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1277
    ^ ts.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1278
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1279
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1280
     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
  1281
     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
  1282
     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
  1283
     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
  1284
     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
  1285
     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
  1286
     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
  1287
     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
  1288
     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
  1289
     Timestamp readFrom:'2015103' format:'%4y%3dayOfYear' onError:[self halt]
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1290
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1291
     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
  1292
     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
  1293
     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
  1294
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1295
     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
  1296
     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
  1297
     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
  1298
     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
  1299
    "
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  1300
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1301
    "Modified: / 28-09-2019 / 15:25:17 / Stefan Vogel"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1302
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1303
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1304
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1305
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1306
     The string is interpreted as 24 hour format, as printed.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1307
     Notice, that this is not the storeString format and
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  1308
     is different from the format expected by readFrom:.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1309
     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
  1310
     or iso8601 (if the first integer is >31).
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1311
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1312
     Please consider using a standard format, such as iso8601."
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1313
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1314
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1315
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1316
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1317
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
  1318
    Error handle:[:ex |
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1319
	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
  1320
    ] do:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1321
	newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1322
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
  1323
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1324
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1325
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1326
     Timestamp readFrom:'20-2-1995 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1327
     Timestamp readFrom:'20-2-1995 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1328
     Timestamp readFrom:'20-2-2001 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1329
     Timestamp readFrom:'20-2-1995 13:11:06.100'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1330
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1331
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1332
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1333
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1334
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1335
     Timestamp readFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1336
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1337
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1338
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1339
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1340
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1341
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1342
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1343
readGeneralizedFrom:aStringOrStream
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1344
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1345
     The format read here is either
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1346
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1347
     or:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1348
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1349
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1350
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1351
     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
  1352
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1353
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1354
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1355
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1356
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1357
     is different from the format expected by readFrom:.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1358
    "
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1359
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1360
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1361
        readGeneralizedFrom:aStringOrStream
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1362
        short:false
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1363
        onError:[
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1364
            self conversionErrorSignal raiseWith:aStringOrStream errorString:' - Timestamp GeneralizedTime format error'
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1365
        ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1366
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1367
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1368
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1369
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1370
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1371
    "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
  1372
     The format read here is either
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1373
	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
  1374
     or:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1375
	yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1376
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1377
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1378
     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
  1379
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1380
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1381
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1382
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1383
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1384
     is different from the format expected by readFrom:.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1385
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1386
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1387
    ^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1388
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1389
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1390
     |s|
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1391
     s := '' writeStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1392
     Timestamp now printGeneralizedOn:s.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1393
     Timestamp readGeneralizedFrom:s contents onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1394
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1395
 Daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1396
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1397
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1398
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1399
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1400
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1401
 No daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1402
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1403
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1404
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1405
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1406
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1407
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1408
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1409
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1410
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1411
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1412
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1413
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1414
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1415
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1416
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1417
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1418
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1419
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1420
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1421
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1422
    "Modified: / 22-08-2006 / 12:30:11 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1423
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1424
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1425
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1426
    "return a new Timestamp, reading a printed representation from aStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1427
     The long format read here is either
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1428
            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1429
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1430
            yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1431
     The (not recommended) short forms are:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1432
            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1433
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1434
            yy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1435
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1436
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1437
     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
  1438
     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
  1439
     The short form is no longer recommended.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1440
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1441
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1442
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1443
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1444
     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
  1445
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1446
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1447
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1448
    ^ [
22653
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1449
        |newTime str day month year hour min sec millis c fraction|
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1450
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1451
        sec := millis := 0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1452
        str := aStringOrStream readStream.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1453
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1454
        shortFormat ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1455
            year := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1456
            year < 50 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1457
                year := year + 2000.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1458
            ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1459
                year := year + 1900.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1460
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1461
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1462
            year := Integer readFrom:(str next:4).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1463
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1464
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1465
        month := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1466
        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1467
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1468
        day := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1469
        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1470
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1471
        str skipSeparators.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1472
        hour:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1473
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1474
        str peek == $: ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1475
        min:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1476
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
24850
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1477
        str peekOrNil == $: ifTrue:[ str next].
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1478
        sec := Integer readFrom:(str next:2).
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1479
        (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1480
        str peekOrNil == $. ifTrue:[
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1481
            str next.
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1482
            "/ the old code here was wrong in assuming that exactly 3 digits
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1483
            "/ are coming; thus hh:mm:ss.1 was interpreted as 1ms (instead of 100)
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1484
            "/ thus: count the zeros...
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1485
            str peek isDigit ifTrue:[
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1486
                fraction := Number readMantissaFrom:str radix:10.
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1487
                fraction isNil ifTrue:[^ exceptionBlock value].
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1488
                millis := (fraction * 1000) rounded.
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1489
            ] ifFalse:[
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1490
                millis := 0
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1491
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1492
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1493
24850
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1494
        str skipSeparators isNil ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1495
            "/ this is local time
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1496
            newTime := self year:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1497
                            hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1498
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1499
            c := str next.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1500
            c ~~ $Z ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1501
                |tzh tzmin|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1502
                tzh := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1503
                tzmin := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1504
                c == $+ ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1505
                    "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
  1506
                    hour := hour - tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1507
                    min := min - tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1508
                ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1509
                    c == $- ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1510
                        "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
  1511
                        hour := hour + tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1512
                        min := min + tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1513
                    ] ifFalse:exceptionBlock
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1514
                ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1515
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1516
            "this is UTC time"
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1517
            newTime := self UTCYear:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1518
                              hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1519
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1520
        newTime
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1521
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1522
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1523
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1524
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1525
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1526
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1527
     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
  1528
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1529
     Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1530
     Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1531
     Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1532
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1533
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1534
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1535
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1536
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1537
     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
  1538
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1539
 No daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1540
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1541
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1542
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1543
     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
  1544
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1545
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1546
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1547
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1548
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1549
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1550
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1551
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1552
     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
  1553
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1554
     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
  1555
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1556
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1557
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1558
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1559
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1560
    "Modified: / 22-08-2006 / 12:30:11 / cg"
24850
8048f0088a90 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24809
diff changeset
  1561
    "Modified: / 22-10-2019 / 16:09:25 / Stefan Vogel"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1562
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1563
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1564
readISO8601From:aStringOrStream
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  1565
    "obsoleted due to uc/lc confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  1566
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1567
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1568
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1569
    ^ self readIso8601FormatFrom:aStringOrStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1570
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1571
    "Created: / 16-06-2005 / 16:13:36 / masca"
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1572
    "Modified: / 09-02-2017 / 10:04:53 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1573
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1574
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1575
readISO8601From:aStringOrStream onError:exceptionValue
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  1576
    "obsoleted due to uc/lc confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  1577
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1578
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1579
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1580
    ^ self readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1581
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1582
    "Modified: / 09-02-2017 / 10:05:56 / stefan"
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1583
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1584
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1585
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1586
    "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
  1587
     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
  1588
     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
  1589
     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
  1590
     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
  1591
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1592
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1593
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1594
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1595
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1596
    "changed to use the new reader"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1597
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1598
    ^ TimestampISO8601Builder read:aStringOrStream withClass:self
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1599
"/    ^ self
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1600
"/        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1601
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1602
    "
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1603
     Timestamp readIso8601FormatFrom:'20141106T123843.299Z'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1604
     Timestamp readIso8601FormatFrom:'20141106T123843.299'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1605
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1606
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1607
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1608
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1609
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1610
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1611
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1612
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1613
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1614
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1615
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1616
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1617
     Timestamp readIso8601FormatFrom:'20141106T122831.894Z'
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1618
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1619
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1620
     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
  1621
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1622
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1623
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1624
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1625
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1626
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1627
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1628
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1629
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1630
     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
  1631
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1632
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1633
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1634
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1635
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1636
    "/ changed to use the new reader
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1637
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1638
        TimestampISO8601Builder read:aStringOrStream withClass:self
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1639
    ] on:ConversionError do:exceptionValue.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1640
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1641
"/    ^ self
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1642
"/        readIso8601FormatFrom:aStringOrStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1643
"/        yearAlreadyRead:nil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1644
"/        onError:exceptionValue
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1645
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1646
    "Modified: / 09-02-2017 / 10:02:03 / stefan"
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1647
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1648
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1649
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1650
    "please use this only for http-requests.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1651
     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
  1652
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1653
     All HTTP/1.0 date/time stamps must be represented in Universal Time (UT),
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1654
     also known as Greenwich Mean Time (GMT), without exception.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1655
     This is indicated in the first two formats by the inclusion of
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1656
     'GMT' as the three-letter abbreviation for time zone,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1657
     and should be assumed when reading the asctime format.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1658
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1659
     HTTP-date      = rfc1123-date | rfc850-date | asctime-date
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1660
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1661
     rfc1123-date   = wkday ',' SP date1 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1662
     rfc850-date    = weekday ',' SP date2 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1663
     asctime-date   = wkday SP date3 SP time SP 4DIGIT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1664
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1665
     date1          = 2DIGIT SP month SP 4DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1666
                      ; day month year (e.g., 02 Jun 1982)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1667
     date2          = 2DIGIT '-' month '-' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1668
                      ; day-month-year (e.g., 02-Jun-82)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1669
     date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1670
                      ; month day (e.g., Jun  2)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1671
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1672
     time           = 2DIGIT ':' 2DIGIT ':' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1673
                      ; 00:00:00 - 23:59:59
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1674
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1675
     wkday          = 'Mon' | 'Tue' | 'Wed'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1676
                    | 'Thu' | 'Fri' | 'Sat' | 'Sun'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1677
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1678
     weekday        = 'Monday' | 'Tuesday' | 'Wednesday'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1679
                    | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1680
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1681
     month          = 'Jan' | 'Feb' | 'Mar' | 'Apr'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1682
                    | 'May' | 'Jun' | 'Jul' | 'Aug'
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1683
                    | 'Sep' | 'Oct' | 'Nov' | 'Dec'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1684
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1685
     Mon, 17 Aug 2009 11:11:15 GMT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1686
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1687
     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
  1688
     thus, this also supports:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1689
         Mon, 17 Aug 2009 11:11:15 +xxxx
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1690
         Mon, 17 Aug 2009 11:11:15 -xxxx
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1691
     and:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1692
         Mon, 17 Aug 2009 11:11:15 PST
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1693
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1694
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1695
    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1696
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1697
    rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1698
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1699
    parts := rfc1123String asCollectionOfSubstringsSeparatedBy:Character space.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1700
    parts size == 6 ifTrue:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1701
        indexModifier := 0.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1702
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1703
        parts size == 5 ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1704
            indexModifier := -1.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1705
        ] ifFalse:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1706
            ^ exceptionBlock value
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1707
        ].
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1708
    ].
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1709
24404
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1710
    (parts at:2 + indexModifier) first isDigit ifTrue:[
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1711
        day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1712
        year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1713
        monthName := parts at:3 + indexModifier.
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1714
        time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1715
    ] ifFalse:[
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1716
        monthName := (parts at:2 + indexModifier).
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1717
        day := Integer readFrom:(parts at:3 + indexModifier) onError:[^ exceptionBlock].  
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1718
        year := Integer readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].  
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1719
        time := Time readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1720
    ].
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1721
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1722
    month := Date indexOfMonth:monthName language:#en.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1723
    month = 0 ifTrue:[^ exceptionBlock value].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1724
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1725
    utcOffsetString := parts at:6 + indexModifier ifAbsent:nil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1726
    utcOffset := self utcOffsetFrom:utcOffsetString.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1727
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1728
    (utcOffset isNil or:[utcOffset = 0]) ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1729
        ^ 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
  1730
    ].
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1731
    ^ ((TZTimestamp new 
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1732
            setOSTimeFromUTCYear:year month:month day:day 
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1733
            hour:time hour minute:time minute second:time second millisecond:0
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1734
       ) utcOffset:utcOffset
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  1735
      ) addSeconds:utcOffset.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1736
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1737
    "
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1738
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 GMT' onError:nil
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1739
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 UTC' onError:nil
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1740
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PST' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1741
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PDT' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1742
     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
  1743
     self readRFC1123FormatFrom:'17 Aug 2009 11:11:15 +0100' onError:nil
24404
0681f4ab2d53 #FEATURE by alkurz
alkurz
parents: 24163
diff changeset
  1744
     self readRFC1123FormatFrom:'Thu Jul 4 15:04:40 2019 +0200' onError:nil
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1745
    "
13085
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1746
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1747
    "Modified: / 05-10-2010 / 16:05:32 / cg"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1748
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1749
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1750
timezoneInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1751
    "return a table containing timezone information.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1752
     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
  1753
     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
  1754
     representation, instead of using names.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1755
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1756
     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
  1757
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1758
    "/ the table below can be customized via a setter,
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1759
    "/ if an application knows better 
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1760
    "/ (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
  1761
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1762
    TimeZoneInfo notNil ifTrue:[^ TimeZoneInfo].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1763
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1764
    "/ table is name, utcOffset(minutes), DST-flag, startDay, endDay
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1765
    ^ #(
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1766
            'Z'     0   false          "/ zulu
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1767
            'UTC'   0   false    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1768
            'GMT'   0   false    
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1769
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1770
            "/ US
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1771
            'HAST' -600 false          "/ hawai standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1772
            'AKST' -540 false          "/ alaska standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1773
            'YST'  -540 false          "/ yukon standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1774
            'PST'  -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1775
            'PT'   -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1776
            'MST'  -420 false          "/ mountain standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1777
            'CST'  -360 false          "/ central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1778
            'EST'  -300 false          "/ eastern standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1779
            'AST'  -240 false          "/ atlantic standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1780
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1781
            'NST'  -210 false          "/ new foundland standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1782
            'PMST' -180 false          "/ pierre & miquelon
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1783
            'WGT'  -180 false          "/ west greenland
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1784
            'EGT'  -60  false          "/ east greenland
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1785
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1786
            "/ europe
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1787
            'CET'   60  false          "/ central european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1788
            'EET'   120 false          "/ east european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1789
            'WET'   0   false          "/ west european
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1790
            "/ conflict with india!!
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1791
            "/ 'IST'   1               "/ irish standard time
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1792
            "/ 'IST'   1               "/ israel standard time
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1793
            'AZOT'   -60 false         "/ azores standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1794
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1795
            'MSK'   240 false          "/ moscow european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1796
            'MSD'   240 false
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1797
            'BT'    240 false          "/ baghdad
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1798
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1799
            "/ pacific
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1800
            'NZST'  720 false          "/ new zealand standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1801
            'FJT'   720 false          "/ fiji
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1802
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1803
            "/ south america
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1804
            'ART'   -180 false         "/ argentina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1805
            'BOT'   -240 false         "/ bolivia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1806
            'BRT'   -180 false         "/ brasilia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1807
            'CLT'   -240 false         "/ chile
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1808
            'ECT'   -300 false         "/ equador
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1809
            'PET'   -300 false         "/ peru
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1810
            'PYT'   -240 false         "/ paraguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1811
            'UYT'   -180 false         "/ uruguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1812
            'VET'   -270 false         "/ venezuela standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1813
            'VST'   -270 false         "/ venezuela standard
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1814
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1815
            "/ africa
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1816
            'CAT'   120 false          "/ central africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1817
            'EAT'   180 false          "/ east africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1818
            'SAST'  120 false          "/ south africa standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1819
            'WAT'   60 false           "/ west africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1820
            'WT'    0 false            "/ west sahara standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1821
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1822
            'AST'   180 false          "/ arabia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1823
            'IRT'   210 false          "/ iran time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1824
            'AFT'   270 false          "/ afghanistan time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1825
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1826
            'HKT'   480 false          "/ hongkong
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1827
            'IST'   330 false          "/ india standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1828
            'ICT'   420 false          "/ indochina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1829
            'CNST'  480 false          "/ china standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1830
            'JST'   540 false          "/ japan standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1831
            'KST'   540 false          "/ korea standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1832
            'SGT'   480 false          "/ singapore
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1833
            'MYT'   480 false          "/ malaysia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1834
            'AWST'  480 false          "/ australian west standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1835
            'ACWST' 525 false          "/ australian central western standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1836
            'ACST'  570 false          "/ australian central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1837
            'AEST'  600 false          "/ australian east standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1838
            'NFT'   690 false          "/ norfolk island, australia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1839
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1840
            'CHAST' 765 false          "/ chatham island standard
20429
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1841
            'WST'   780 false          "/ west samoa - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1842
            'TOT'   780 false          "/ tonga - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1843
            'TKT'   780 false          "/ tokelau - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1844
            'LINT'  840 false          "/ line islands - yes that's 14!!
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1845
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1846
            "/ misc
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1847
            'IDLW' -720 false          "/ international date line west
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1848
            'IDLE'  720 false          "/ international date line east
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1849
24879
9ec224d47bc0 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 24850
diff changeset
  1850
            'MEZ'   60  false           "/ mittel europäische Zeit /  central european (german)
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1851
            'MESZ'  120 true            "/ central european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1852
            'WESZ'  60  true            "/ west european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1853
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1854
            'WEZ'   0   false           "/ west european (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1855
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1856
            'HADT'  -540 true           "/ hawaii summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1857
            'ADT'   -180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1858
            'AKDT'  -540 true         "/ alaska summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1859
            'YDT'   -480 true         "/ yukon summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1860
            'PDT'   -420 true         "/ pacific daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1861
            'MDT'   -360 true         "/ mountain daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1862
            'CDT'   -300 true         "/ central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1863
            'EDT'   -240 true         "/ eastern daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1864
            'CLST'  -180 true         "/ chile summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1865
            'NDT'   -150 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1866
            'PMDT'  -120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1867
            'BRST'  -120 true         "/ brasilia summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1868
            'WGST'  -120 true         "/ west greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1869
            'EGST'   0 true           "/ east greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1870
            'AZOST'  0 true           "/ azores summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1871
            'EEST'   180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1872
            'CEST'   120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1873
            'WAST'   120 true         "/ west africa summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1874
            "/ 'WST'   60 true        "/ west sahara summer - conflict with west samoa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1875
            'WEST'  60 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1876
            'BST'   60 true           "/ british summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1877
            'IRST'  270 true          "/ iran summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1878
            'AWDT'  540 true          "/ australian west daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1879
            'ACDT'  630 true          "/ australian central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1880
            'AEDT'  660 true          "/ australian east daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1881
            'CHADT' 825 true          "/ chatham island daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1882
            'FJST'  780 true          "/ fiji summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1883
            'NZDT'  780 true          "/ new zealand summer
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1884
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1885
            "/ military
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1886
            'A'     60  false          "/ alpha
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1887
            'B'     120 false          "/ bravo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1888
            'C'     180 false          "/ charlie
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1889
            'D'     240 false          "/ delta
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1890
            'E'     300 false          "/ echo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1891
            'F'     360 false          "/ foxtrot
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1892
            'G'     420 false          "/ golf
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1893
            'H'     480 false          "/ hotel
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1894
            'I'     540 false          "/ also called india - how misleading
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1895
            'K'     600 false          "/ kilo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1896
            'L'     660 false          "/ lima - but not there
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1897
            'M'     720 false          "/ mike
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1898
            'N'     -60  false         "/ november (but also in other months)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1899
            'O'     -120 false         "/ oscar
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1900
            'P'     -180 false         "/ papa (not mama)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1901
            'Q'     -240 false         "/ quebec - really?
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1902
            'R'     -300 false         "/ romeo and juliet
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1903
            'S'     -360 false         "/ sierra
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1904
            'T'     -420 false         "/ tango (& not rumba)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1905
            'U'     -480 false         "/ uniform
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1906
            'V'     -540 false         "/ victor
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1907
            'W'     -600 false         "/ whiskey (scotch?)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1908
            'X'     -660 false         "/ xray
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1909
            'Y'     -720 false         "/ yankee
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1910
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1911
        ).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1912
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1913
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1914
utcOffsetFrom:aStringOrStream
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1915
    "return the utcOffset (in seconds) for a given time-zone name.
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1916
     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
  1917
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1918
     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
  1919
     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
  1920
     in timeStamp and OperatingSystem-timeInfo will be.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1921
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1922
     If utcOffset is negative, the local timezone is east of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1923
     If utcOffset is positive, the local timezone is west of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1924
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1925
     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
  1926
     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
  1927
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1928
    |ch offset stream|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1929
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1930
    stream := aStringOrStream readStream.
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1931
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1932
    ch := stream skipSeparators.
17079
76e263370574 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17071
diff changeset
  1933
    ch isNil ifTrue:[^ 0].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1934
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1935
    ch isLetter ifTrue:[
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1936
        |table tzName i minuteOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1937
        
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1938
        table := self timezoneInfo.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1939
        tzName := stream upToElementForWhich:[:ch | ch isLetter not].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1940
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1941
        i := table indexOf:tzName.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1942
        i == 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1943
            ^ nil
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1944
        ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1945
        minuteOffset := (table at:i+1).
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1946
        offset := minuteOffset * 60
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1947
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1948
        |sign|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1949
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1950
        sign := 1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1951
        ch == $- ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1952
            sign := -1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1953
            stream next.
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1954
        ] ifFalse:[ch == $+ ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1955
            stream next.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1956
        ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1957
            stream skipSeparators
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1958
        ]].
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1959
        stream peekOrNil isDigit ifFalse:[^ nil].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1960
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1961
        offset := ((stream next:2) asNumber * 60 * 60).
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1962
        ch := stream peekOrNil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1963
        ch notNil ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1964
            ch == $: ifTrue:[ stream next ].
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1965
            offset := offset + ((stream next:2) asNumber * 60).
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1966
        ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1967
        offset := offset * sign
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1968
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1969
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  1970
    "/ 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
  1971
    ^ offset negated
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1972
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1973
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1974
     self utcOffsetFrom:'UTC'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1975
     self utcOffsetFrom:'PST'
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1976
     self utcOffsetFrom:'EST'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1977
     self utcOffsetFrom:'CET'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1978
     self utcOffsetFrom:'+0130'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1979
     self utcOffsetFrom:'+01:30'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1980
     self utcOffsetFrom:'+1:30'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1981
     self utcOffsetFrom:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1982
    "
24809
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1983
e347fb41b7d7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24597
diff changeset
  1984
    "Modified: / 28-09-2019 / 15:25:45 / Stefan Vogel"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1985
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1986
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1987
utcOffsetFromString:aString
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1988
    <resource: #obsolete>
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1989
    "return the utcOffset (in seconds) for a given time-zone name.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1990
     Returns nil for invalid formats"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1991
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1992
    ^ self utcOffsetFrom:aString
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1993
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1994
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1995
     self utcOffsetFromString:'UTC'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1996
     self utcOffsetFromString:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1997
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1998
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1999
22914
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  2000
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2001
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2002
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2003
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2004
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2005
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2006
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2007
    ^ self asDate day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  2008
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2009
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2010
     Timestamp now day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2011
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2012
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2013
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2014
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2015
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2016
dayInWeek
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2017
    "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
  2018
     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
  2019
     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
  2020
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2021
    ^ self asDate dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2022
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2023
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2024
     Timestamp now dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2025
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2026
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2027
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2028
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2029
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2030
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2031
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2032
    "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
  2033
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2034
    ^ self asDate dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2035
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2036
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2037
     Timestamp now dayInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2038
     (Timestamp newDay:184 year:1996) dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2039
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2040
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2041
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2042
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2043
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2044
dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2045
    "Answer the day of the month represented by me.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2046
     Same as day; for ST-80 compatibility."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2047
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2048
    ^ self asDate dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2049
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2050
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2051
     Timestamp now dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2052
     (Timestamp newDay:184 year:1996) dayOfMonth
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2053
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2054
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2055
    "Created: / 20-01-2011 / 12:26:54 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2056
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2057
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2058
dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2059
    "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
  2060
     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
  2061
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2062
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2063
    ^ self asDate dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2064
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2065
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2066
     Timestamp now dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2067
    "
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
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2070
dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2071
    "return the week-day of the receiver as a string.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2072
     The returned string depends on the language setting.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2073
     Expect things like 'monday', 'tuesday' ..."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2074
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2075
    ^ self asDate dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2076
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2077
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2078
     Timestamp now dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2079
     (Timestamp newDay:184 year:1996) dayOfWeekName
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2080
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2081
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2082
    "Created: / 20-01-2011 / 12:28:46 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2083
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  2084
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2085
exactMicroseconds
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2086
    "return the exact microseconds within the stamp's second (0 .. 999.999...) as a fixedPoint number.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2087
     notice: 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2088
        that is NOT the total number of microseconds,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2089
        but the fractional part (within the second) only.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2090
     A fixedPoint number holds the exact value, but prints itself rounded!!"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2091
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2092
    |millis microsFromMillis|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2093
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2094
    millis := (osTime \\ 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2095
    microsFromMillis := millis * 1000.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2096
    additionalPicoseconds notNil ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2097
        ^ microsFromMillis + (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000) scale:3)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2098
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2099
    ^ microsFromMillis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2100
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2101
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2102
     |ts|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2103
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2104
     ts := Timestamp nowWithMicroseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2105
     Transcript showCR:ts.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2106
     Transcript showCR:ts microseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2107
     Transcript showCR:ts exactMicroseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2108
     Transcript showCR:ts nanoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2109
     Transcript showCR:ts picoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2110
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2111
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2112
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2113
exactMilliseconds
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2114
    "return the exact milliseconds within the stamp's second (0 .. 999.999...) as a fixedPoint number.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2115
     notice: 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2116
        that is NOT the total number of microseconds,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2117
        but the fractional part (within the second) only.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2118
     A fixedPoint number holds the exact value, but prints itself rounded!!"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2119
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2120
    |millis|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2121
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2122
    millis := (osTime \\ 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2123
    additionalPicoseconds notNil ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2124
        ^ millis + (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000) scale:3)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2125
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2126
    ^ millis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2127
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2128
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2129
     |ts|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2130
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2131
     ts := Timestamp nowWithMicroseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2132
     Transcript showCR:ts.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2133
     Transcript showCR:ts milliseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2134
     Transcript showCR:ts exactMilliseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2135
     Transcript showCR:ts microseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2136
     Transcript showCR:ts nanoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2137
     Transcript showCR:ts picoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2138
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2139
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2140
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2141
exactMinutes
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2142
    "return the exact minutes within the stamp's hour (00 .. 59.999...) as a fixedPoint number.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2143
     Notice: 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2144
        that is NOT the total number of minutes,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2145
        but the fractional part (within the hour) only.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2146
     A fixedPoint number holds the exact value, but prints itself rounded!!"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2147
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2148
    |minutes additionalSeconds|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2149
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2150
    minutes := FixedPoint numerator:(osTime \\ (60*60*1000)) / 60 denominator:1000 scale:3.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2151
    additionalPicoseconds notNil ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2152
        additionalSeconds := (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000*1000) scale:3).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2153
        minutes := minutes + (additionalSeconds / 60).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2154
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2155
    ^ minutes.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2156
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2157
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2158
     |ts|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2159
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2160
     ts := Timestamp nowWithMicroseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2161
     Transcript showCR:ts.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2162
     Transcript showCR:ts minutes.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2163
     Transcript showCR:ts exactMinutes.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2164
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2165
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2166
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2167
exactNanoseconds
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2168
    "return the exact nanoseconds within the stamp's second (0 .. 999.999...).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2169
     notice: 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2170
        that is NOT the total number of nanoseconds,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2171
        but the fractional part (within the second) only.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2172
     A fixedPoint number holds the exact value, but prints itself rounded!!"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2173
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2174
    |millis nanosFromMillis|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2175
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2176
    millis := (osTime \\ 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2177
    nanosFromMillis := millis * 1000 * 1000.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2178
    additionalPicoseconds notNil ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2179
        ^ nanosFromMillis + (FixedPoint numerator:additionalPicoseconds denominator:(1000) scale:3)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2180
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2181
    ^ nanosFromMillis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2182
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2183
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2184
     |ts|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2185
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2186
     ts := Timestamp now + 100.3 nanoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2187
     Transcript showCR:ts.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2188
     Transcript showCR:ts milliseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2189
     Transcript showCR:ts exactMilliseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2190
     Transcript showCR:ts microseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2191
     Transcript showCR:ts exactMicroseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2192
     Transcript showCR:ts nanoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2193
     Transcript showCR:ts exactNanoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2194
     Transcript showCR:ts picoseconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2195
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2196
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2197
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2198
exactSeconds
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2199
    "return the exact seconds within the stamp's minute (00 .. 59.999...) as a fixedPoint number.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2200
     Notice: 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2201
        that is NOT the total number of seconds,
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2202
        but the fractional part (within the minute) only.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2203
     A fixedPoint number holds the exact value, but prints itself rounded!!"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2204
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2205
    |seconds additionalSeconds|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2206
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2207
    seconds := FixedPoint numerator:(osTime \\ (60*1000)) denominator:1000 scale:3.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2208
    additionalPicoseconds notNil ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2209
        additionalSeconds := (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000*1000) scale:3).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2210
        seconds := seconds + additionalSeconds
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2211
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2212
    ^ seconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2213
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2214
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2215
     |ts|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2216
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2217
     ts := Timestamp fromDate:(Date today) hour:10 minute:30 second:20 millisecond:300.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2218
     Transcript showCR:ts.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2219
     Transcript showCR:ts seconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2220
     Transcript showCR:ts exactSeconds.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2221
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2222
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2223
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2224
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2225
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2226
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2227
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2228
	^ self asTime hours.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2229
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2230
    ^ self timeInfo hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  2231
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2232
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2233
     Timestamp now hours
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2234
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2235
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2236
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2237
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2238
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2239
microseconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2240
    "return the truncated microseconds within the stamp's second (0..999999).
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2241
     notice: that is NOT the total number of microseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2242
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2243
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2244
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2245
    |millis microsFromMillis|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2246
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2247
    millis := (osTime \\ 1000).
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2248
    microsFromMillis := millis * 1000.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2249
    additionalPicoseconds notNil ifTrue:[
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2250
        ^ microsFromMillis + (additionalPicoseconds // (1000*1000))
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2251
    ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2252
    ^ microsFromMillis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2253
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2254
    "
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2255
     -- (definitely millisecond resolution here)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2256
     Timestamp now                          
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2257
     Timestamp now microseconds             
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2258
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2259
     -- (but some OS's only deliver millisecond resolution also here)
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2260
     Timestamp nowWithMicroseconds microseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2261
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2262
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2263
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2264
     t1 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2265
     t2 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2266
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2267
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2268
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2269
     t1 := Timestamp now microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2270
     t2 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2271
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2272
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2273
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2274
    "Created: 1.7.1996 / 15:15:02 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2275
    "Modified: 2.7.1996 / 09:21:41 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2276
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2277
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2278
millisecond
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2279
    "return the truncated millisecond within the stamp's second (0..999).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2280
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2281
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2282
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2283
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2284
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2285
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2286
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2287
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2288
milliseconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2289
    "return the truncated milliseconds within the stamp's second (0..999)"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2290
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2291
    ^ osTime \\ 1000.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2292
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2293
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2294
     Timestamp now milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2295
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2296
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2297
    "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
  2298
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2299
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2300
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2301
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2302
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2303
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2304
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2305
	^ self asTime minutes.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2306
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2307
    ^ self timeInfo minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2308
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2309
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2310
     Timestamp now minutes
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2311
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2312
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2313
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2314
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2315
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2316
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2317
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2318
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2319
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2320
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2321
	^ self asDate month.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2322
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2323
    ^ self timeInfo month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2324
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2325
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2326
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2327
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2328
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2329
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2330
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2331
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2332
monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2333
    "return the month of the receiver (1..12).
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2334
     For compatibility"
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2335
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2336
    ^ self asDate monthIndex.
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2337
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2338
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2339
     Timestamp now monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2340
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2341
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2342
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2343
nanoseconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2344
    "return the truncated nanoseconds within the stamp's second (0..999999999).
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2345
     notice: that is NOT the total number of nanoseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2346
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2347
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2348
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2349
    |nanosFromMillis|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2350
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2351
    nanosFromMillis := (osTime \\ 1000) * (1000 * 1000).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2352
    additionalPicoseconds notNil ifTrue:[
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2353
        ^ nanosFromMillis + (additionalPicoseconds // 1000)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2354
    ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2355
    ^ nanosFromMillis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2356
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2357
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2358
     Timestamp now nanoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2359
     Timestamp nowWithMicroseconds nanoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2360
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2361
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2362
     t1 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2363
     t2 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2364
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2365
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2366
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2367
     t1 := Timestamp now nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2368
     t2 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2369
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2370
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2371
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2372
    "Created: 1.7.1996 / 15:15:02 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2373
    "Modified: 2.7.1996 / 09:21:41 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2374
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2375
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2376
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2377
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2378
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2379
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2380
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2381
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2382
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2383
picoseconds
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2384
    "return the picoseconds within the stamp's second (0..999999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2385
     notice: that is NOT the total number of picoseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2386
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2387
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2388
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2389
    |picosFromMillis|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2390
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2391
    picosFromMillis := (osTime \\ 1000) * (1000 * 1000 * 1000).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2392
    ^ picosFromMillis + (additionalPicoseconds ? 0)
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2393
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2394
    "
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2395
     Timestamp now picoseconds
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2396
     Timestamp nowWithMicroseconds picoseconds
22614
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2397
    "
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2398
!
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2399
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2400
seconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2401
    "return the truncated seconds (0..59)"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2402
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2403
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2404
        ^ self asTime seconds.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2405
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2406
    ^ self timeInfo seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2407
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2408
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2409
     Timestamp now seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2410
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2411
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2412
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2413
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2414
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2415
timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2416
    "answer the number of minutes between local time and utc time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2417
     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
  2418
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2419
    ^ self utcOffset negated // 60
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2420
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2421
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2422
     Timestamp now timeZoneDeltaInMinutes
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2423
     (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
  2424
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2425
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2426
    "Modified: 20.12.1995 / 17:28:49 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2427
    "Modified: 1.7.1996 / 15:21:29 / cg"
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2428
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2429
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2430
timeZoneName
16990
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2431
    "find the first zone which is in this range.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2432
     This is a bit naive, but should be sufficient in most cases
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2433
     (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
  2434
      of that particular year...)"
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2435
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2436
    |myUtcOffset iAmDST bestNonDST|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2437
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2438
    myUtcOffset := self utcOffset negated.
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2439
    iAmDST := self timeInfo dst ? false.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2440
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2441
    bestNonDST := nil.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2442
    self class timezoneInfo inGroupsOf:3 do:[:name :offsetInMinutes :isDST|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2443
        |thisUtcOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2444
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2445
        thisUtcOffset := offsetInMinutes * 60.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2446
        thisUtcOffset = myUtcOffset ifTrue:[
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2447
            isDST == iAmDST ifTrue:[^ name ].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2448
        ].    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2449
        bestNonDST := name.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2450
    ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2451
    bestNonDST notNil ifTrue:[^ bestNonDST].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2452
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2453
    "/ nothing found - construct a standard offset string
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2454
    ^ ((self utcOffset > 0) ifTrue:['+'] ifFalse:['-'])
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2455
      , ((myUtcOffset abs // 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2456
      , ((myUtcOffset abs \\ 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2457
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2458
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2459
     Timestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2460
     UtcTimestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2461
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2462
     (Timestamp now asTZTimestampInZone:'MEZ') timeZoneName - will find international name
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2463
     (Timestamp now asTZTimestampInZone:'EST') timeZoneName
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2464
     (Timestamp now asTZTimestampInZone:'IDLE') timeZoneName - sorry - will find 'NZST'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2465
     (Timestamp now asTZTimestampInZone:'BRST') timeZoneName - sorry: will find military 'O'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2466
     (Timestamp now asTZTimestampInZone:'MYT') timeZoneName - will find hongkong; same timezone
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2467
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2468
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2469
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2470
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2471
    "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
  2472
     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
  2473
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2474
     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
  2475
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2476
22890
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2477
     If utcOffset is negative, the local timezone is east of Greenwich (Russia, Asia).
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2478
     If utcOffset is positive, the local timezone is west of Greenwich (USA)."
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2479
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2480
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
22890
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2481
        "/ fake an info which the OS cannot give me
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2482
        "/ we do not know about DST in the far future and in the long gone past.
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2483
        "/ Take the utcOffset without DST
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2484
        ^ self utcOffsetWithoutDst.
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2485
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2486
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2487
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2488
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2489
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2490
     Timestamp now utcOffset
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2491
     (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
  2492
     (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
  2493
     (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
  2494
     (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
  2495
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2496
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2497
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2498
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2499
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2500
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2501
utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2502
    "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
  2503
     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
  2504
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2505
     Add utcOffset to convert from local time to UTC time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2506
     Subtract utcOffset to convert from UTC time to local time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2507
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2508
     If utcOffset is negative, the local timezone is east of Greenwich.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2509
     If utcOffset is positive, the local timezone is west of Greenwich."
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2510
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2511
    |offset epochInfo|
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2512
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2513
    offset := 0.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2514
    [
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2515
	"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
  2516
	epochInfo := OperatingSystem timeInfoFromSeconds:offset milliseconds:0 localTime:true.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2517
	offset := offset + (3600 * 24 * 90). "Add about 3 months"
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2518
    ] doWhile:[epochInfo dst and:[offset < (3600 * 24 * 365) "avoid endless loop"]].
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2519
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2520
    ^ epochInfo utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2521
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2522
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2523
     Timestamp now utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2524
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2525
!
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2526
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2527
weekInYear
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2528
    "return the week number of the receiver - 1 for Jan, 1st."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2529
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2530
    ^ Date weekInYearOf:self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2531
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2532
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2533
     (Timestamp newDay:1 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2534
     (Timestamp newDay:2 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2535
     (Timestamp newDay:3 year:2000) weekInYear
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2536
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2537
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2538
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2539
weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2540
    "return the week-day of the receiver as a string.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2541
     The returned string depends on the current language setting.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2542
     Expect things like 'monday', 'tuesday' ...
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2543
     For ST-80 compatibility"
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2544
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2545
    ^ self asDate weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2546
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2547
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2548
     Timestamp now weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2549
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2550
     but maybe a different day there, in the south pacific:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2551
     (Timestamp now asTZTimestampInZone:'LINT') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2552
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2553
     but maybe a different day there, in alaska:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2554
     (Timestamp now asTZTimestampInZone:'AKST') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2555
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2556
!
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2557
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2558
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2559
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2560
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2561
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2562
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2563
	^ self asDate year.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2564
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2565
    ^ self timeInfo year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2566
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2567
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2568
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2569
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2570
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2571
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2572
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2573
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2574
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2575
13199
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2576
ceilingSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2577
    "return a timestamp which represents the next full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2578
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2579
    |offs|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2580
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2581
    offs := (self milliseconds / 1000) ceiling.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2582
    ^ self class basicNew setSeconds:(self getSeconds + offs).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2583
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2584
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2585
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2586
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2587
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2588
     t2 := t1 ceilingSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2589
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2590
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2591
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2592
    "Created: / 08-01-2011 / 16:23:03 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2593
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2594
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2595
floorSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2596
    "return a timestamp truncated to the last full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2597
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2598
    ^ self class basicNew setSeconds:(self getSeconds).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2599
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2600
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2601
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2602
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2603
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2604
     t2 := t1 floorSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2605
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2606
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2607
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2608
    "Created: / 08-01-2011 / 16:20:55 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2609
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2610
22940
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2611
microsecondDeltaFrom:aTimestamp
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2612
    "return the delta in (truncated) microseconds between 2 timestamps.
22940
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2613
     The argument is supposed to be BEFORE the receiver,
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2614
        computes self - aTimestamp"
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2615
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2616
    ^ self getMicroseconds - (aTimestamp getMicroseconds)
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2617
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2618
    "
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2619
     |t1 t2|
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2620
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2621
     t1 := Timestamp now.
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2622
     Delay waitForSeconds:0.5.
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2623
     t2 := Timestamp now.
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2624
     t2 microsecondDeltaFrom:t1
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2625
    "
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2626
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2627
    "Modified: / 10-07-2010 / 09:37:18 / cg"
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2628
    "Modified (comment): / 26-02-2019 / 14:02:16 / Claus Gittinger"
22940
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2629
!
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  2630
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2631
millisecondDeltaFrom:aTimestamp
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2632
    "return the delta in (truncated) milliseconds between 2 timestamps.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2633
     The argument is supposed to be BEFORE the receiver,
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2634
        computes self - aTimestamp"
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2635
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2636
    ^ osTime - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2637
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2638
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2639
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2640
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2641
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2642
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2643
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2644
     t2 millisecondDeltaFrom:t1
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2645
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2646
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2647
    "Modified: / 10-07-2010 / 09:37:18 / cg"
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2648
    "Modified: / 27-07-2018 / 10:34:11 / Stefan Vogel"
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2649
    "Modified (comment): / 26-02-2019 / 14:02:13 / Claus Gittinger"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2650
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2651
13200
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2652
roundedToSecond
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2653
    "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
  2654
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2655
    |offs|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2656
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2657
    offs := (self milliseconds / 1000) rounded.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2658
    ^ self class basicNew setSeconds:(self getSeconds + offs).
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2659
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2660
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2661
     |t1 t2|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2662
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2663
     t1 := Timestamp now.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2664
     t2 := t1 roundedToSecond.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2665
     self halt
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2666
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2667
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2668
    "Created: / 08-01-2011 / 16:24:12 / cg"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2669
!
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2670
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2671
secondDeltaFrom:aTimestamp
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2672
    "return the delta in (truncated) seconds between 2 timestamps.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2673
     The argument is supposed to be BEFORE the receiver,
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2674
        computes self - aTimestamp"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2675
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2676
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2677
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2678
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2679
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2680
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2681
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2682
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2683
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2684
     t2 secondDeltaFrom:t1
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2685
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2686
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2687
    "Modified: / 10-07-2010 / 09:37:24 / cg"
23776
8ab5e2adcf65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23565
diff changeset
  2688
    "Modified (comment): / 26-02-2019 / 14:02:09 / Claus Gittinger"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2689
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2690
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2691
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2692
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2693
hash
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2694
    "return an integer useful for hashing on time stamps"
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2695
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2696
    ^ osTime "// 1000" - why ignore the millis?
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2697
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2698
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2699
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2700
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2701
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2702
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2703
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2704
    "return a Date object from the receiver.
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2705
     The returned date will only represent the day - not the timeOfDay.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2706
     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
  2707
     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
  2708
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2709
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2710
	|milliDelta dayDelta|
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2711
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2712
	"/ 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
  2713
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2714
	milliDelta := osTime - (1000 * self utcOffsetWithoutDst).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2715
	dayDelta := milliDelta // (24 * 3600 * 1000).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2716
	^ Epoch asDate addDays:dayDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2717
    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2718
    ^ self timeInfo asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2719
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2720
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2721
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2722
     Timestamp now asDate
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2723
     (Timestamp now addTime:3600) asDate
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2724
     (Timestamp now addTime:3600) asTime
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2725
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2726
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2727
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2728
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2729
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2730
asLocalTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2731
    "represent myself as a timestamp in the local timezone"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2732
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2733
    ^ self
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2734
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2735
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2736
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2737
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2738
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2739
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2740
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2741
asTZTimestamp
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2742
    "return a timestamp which represents the very same time,
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2743
     but will represent itself as a timestamp with the local utcOffset.
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2744
     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
  2745
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2746
    ^ self asTZTimestamp:self utcOffset
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2747
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2748
    "see the different printStrings of:
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2749
         Timestamp now
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2750
     and
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2751
         Timestamp now asTZTimestamp
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2752
     and
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2753
         Timestamp now asUtcTimestamp
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2754
    "
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2755
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  2756
    "Modified (comment): / 24-05-2018 / 17:31:26 / Claus Gittinger"
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2757
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2758
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2759
asTZTimestamp:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2760
    "return a timestamp which represents the very same time,
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2761
     but will represent itself as a timestamp with the given utcOffset"
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2762
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2763
    ^ (TZTimestamp fromOSTime:osTime) utcOffset:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2764
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2765
    "what is the time now in NewYork?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2766
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2767
     Timestamp now asTZTimestampInZone:'EST'
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2768
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2769
     what is the time now in Stuttgart?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2770
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2771
     Timestamp now asTZTimestampInZone:'MEZ'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2772
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2773
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2774
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2775
asTZTimestampInZone:timeZoneName
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2776
    "return a timestamp which represents the very same time,
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2777
     but will represent itself as a timestamp in the given timezone.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2778
     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
  2779
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2780
    |utcOffset|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2781
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2782
    utcOffset := self class utcOffsetFrom:timeZoneName.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2783
    utcOffset isNil ifTrue:[
17132
01e2272e7912 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17131
diff changeset
  2784
        ^ TimeConversionError raiseRequestWith:self errorString:(' - Invalid/unknown timzone: %1' bindWith:timeZoneName)
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2785
    ].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2786
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2787
    ^ self asTZTimestamp:utcOffset
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2788
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2789
    "what is the time now in NewYork?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2790
       Timestamp now asTZTimestampInZone:'EST'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2791
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2792
     what is the time now in Stuttgart?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2793
       Timestamp now asTZTimestampInZone:'MEZ'
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2794
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2795
     an error os raised for any unknown/invalid timezone:
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2796
       Timestamp now asTZTimestampInZone:'BlaBla'
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2797
    "
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2798
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2799
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2800
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2801
    "return a Time object from the receiver.
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  2802
     The returned time will only represent the timeOfDay - not the day,
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2803
     and does not include the milliseconds."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2804
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2805
    |secondDelta|
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2806
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2807
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2808
	secondDelta := osTime // 1000.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2809
	"/ 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
  2810
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2811
	secondDelta := (secondDelta - self utcOffsetWithoutDst) \\ (24*3600).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2812
	^ Epoch asTime addSeconds:secondDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2813
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2814
    ^ self timeInfo asTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2815
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2816
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2817
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2818
     Timestamp now asTime
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2819
     UtcTimestamp now asTime
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2820
     (Timestamp now addTime:3600) asTime
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2821
     (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
  2822
     (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
  2823
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2824
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2825
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2826
asTimeWithMilliseconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2827
    "return a Time object from the receiver.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2828
     The returned time will only represent the timeOfDay - not the day,
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2829
     it will include the milliseconds."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2830
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2831
    |milliSecondDelta|
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2832
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2833
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2834
	milliSecondDelta := osTime - (self utcOffset * 1000).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2835
	^ self class epoch asTime addMilliseconds:milliSecondDelta.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2836
    ].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2837
    ^ self timeInfo asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2838
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2839
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2840
     Timestamp now
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2841
     Timestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2842
     UtcTimestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2843
     (Timestamp now addTime:3600) asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2844
     (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
  2845
     (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
  2846
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2847
!
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2848
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2849
asTimestamp
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2850
    "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
  2851
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2852
    ^ self
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2853
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2854
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2855
asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2856
    ^ self asUtcTimestamp
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2857
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2858
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2859
     Timestamp now
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2860
     Timestamp now asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2861
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2862
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2863
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2864
asUtcTimestamp
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2865
    "return a timestamp which represents the very same timestamp,
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2866
     but will represent itself as a timestamp in the UTC timezone"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2867
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2868
    ^ UtcTimestamp fromOSTime:osTime
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2869
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2870
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2871
     Timestamp now asUtcTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2872
     Timestamp now asUtcTimestamp asLocalTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2873
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2874
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2875
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2876
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2877
    "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
  2878
     can be reconstructed with #decodeAsLiteralArray.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2879
     The encoding is:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2880
        (#Timestamp YYYYMMDDhhmmss.iiiZ)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2881
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2882
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2883
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2884
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2885
    s := WriteStream on:(String new:18).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2886
    self printGeneralizedOn:s isLocal:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2887
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2888
    ^ Array
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2889
        with:self class name
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2890
        with:s contents
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2891
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2892
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  2893
      Timestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2894
        decodeAsLiteralArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2895
      UtcTimestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2896
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2897
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2898
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2899
24163
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
  2900
utcOffset:secondsOrTimeDuration
22890
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2901
   "answer a DateTime equivalent to the receiver but offset from UTC by offset.
0401fecb9c89 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22885
diff changeset
  2902
     If utcOffset is negative, the local timezone is east of Greenwich (Russia, Asia).
24163
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
  2903
     If utcOffset is positive, the local timezone is west of Greenwich (USA).
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
  2904
     If utcOffset is zero, you effectively get UTC time."
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2905
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2906
    ^ TZTimestamp new 
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2907
        osTime:osTime;
24163
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
  2908
        utcOffset:(secondsOrTimeDuration asTimeDuration);
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2909
        yourself.
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2910
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2911
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2912
     Timestamp now  -- now as local time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2913
     Timestamp now asTZTimestamp -- now in your local timezone
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2914
     Timestamp now asUtcTimestamp -- now in greenwich
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2915
     UtcTimestamp now -- now in greenwich
22894
81be3c10fb6c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22890
diff changeset
  2916
     Timestamp now utcOffset:(-2 hours) -- now in East Europe
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2917
     Timestamp now utcOffset:(5 hours) -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2918
     Timestamp now asTZTimestampInZone:'EST' -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2919
    "
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2920
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2921
    "Modified: / 27-07-2018 / 11:54:45 / Stefan Vogel"
24163
b50d5ba0d03b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24160
diff changeset
  2922
    "Modified: / 26-05-2019 / 12:54:56 / Claus Gittinger"
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2923
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2924
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2925
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2926
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2927
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2928
"
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2929
    secondsBetween1901and1970 :=
23559
82d98769fd95 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23239
diff changeset
  2930
        ((Date year:1970 month:1 day:1) subtractDate:(Date year:1901  month:1 day:1))
82d98769fd95 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23239
diff changeset
  2931
        *  (24 * 60 * 60)
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  2932
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2933
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2934
    ^ self utcSecondsSince1970 + 2177452800.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2935
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2936
    "
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2937
     Timestamp now utcSecondsSince1901
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2938
    "
23559
82d98769fd95 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23239
diff changeset
  2939
82d98769fd95 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23239
diff changeset
  2940
    "Modified (comment): / 10-12-2018 / 20:37:38 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2941
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2942
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2943
!Timestamp methodsFor:'double dispatching'!
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2944
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2945
differenceFromTimestamp:aTimestamp
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2946
    |newMillis newPicos|
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2947
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2948
    newMillis := aTimestamp getMilliseconds - osTime.
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2949
    newPicos := (aTimestamp additionalPicoseconds) - (additionalPicoseconds ? 0).
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2950
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2951
    ^ TimeDuration basicNew
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2952
        setMilliseconds:newMillis additionalPicoseconds:newPicos.
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2953
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2954
    "Created: / 27-07-2018 / 08:45:22 / Stefan Vogel"
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2955
    "Modified (format): / 27-07-2018 / 10:50:05 / Stefan Vogel"
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2956
! !
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  2957
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2958
!Timestamp methodsFor:'initialization'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2959
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2960
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
  2961
    "private: ask the operating system to compute the internal osTime (based on the epoch),
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2962
     given y,m,d and h,m,s in my time.
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2963
     All arguments MUST be integral (for now)"
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2964
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2965
    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
  2966
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2967
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2968
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2969
    "private: ask the operating system to compute the internal osTime (based on the epoch),
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2970
     given y,m,d and h,m,s in my time.
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  2971
     All arguments MUST be integral (for now)"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2972
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2973
    self setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2974
    additionalPicoseconds := picos.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2975
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  2976
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2977
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
  2978
    "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
  2979
     given y,m,d and h,m,s in local time"
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2980
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2981
    Error handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2982
        "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
  2983
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2984
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2985
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2986
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2987
        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
  2988
        "/ 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
  2989
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2990
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2991
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2992
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2993
        osTime := osTime + millis.
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2994
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2995
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2996
                computeOSTimeFromUTCYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2997
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2998
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2999
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3000
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3001
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3002
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
  3003
    "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
  3004
     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
  3005
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3006
    TimeConversionError handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3007
        "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
  3008
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3009
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3010
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3011
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3012
        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
  3013
        "/ 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
  3014
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3015
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3016
        osTime := osTime + self utcOffset.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3017
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3018
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3019
        osTime := osTime + millis.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3020
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3021
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3022
                computeOSTimeFromYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3023
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  3024
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3025
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3026
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3027
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3028
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
  3029
    "private: ask the operating system to compute the internal osTime (based on the epoch),
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  3030
     given y,m,d and h,m,s in my time.
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  3031
     All arguments MUST be integral (for now)"
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3032
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  3033
    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
  3034
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  3035
    "
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  3036
     self basicNew
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  3037
         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
  3038
    "
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3039
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3040
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3041
year:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3042
    "private: ask the operating system to compute the internal osTime (based on the epoch),
22885
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  3043
     given y,m,d and h,m,s in my time.
9617f4a45cdb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22873
diff changeset
  3044
     All arguments MUST be integral (for now)"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3045
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3046
    self setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3047
    additionalPicoseconds := picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3048
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3049
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3050
     self basicNew
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3051
         year:2016 month:4 day:16 hour:17 minute:21 second:13 millisecond:726
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3052
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3053
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3054
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  3055
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3056
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3057
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3058
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3059
    "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
  3060
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  3061
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3062
    |date|
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3063
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3064
    date := self asDate.
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3065
    date addPrintBindingsTo:dict language:languageOrNil.
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  3066
    super addPrintBindingsTo:dict language:languageOrNil.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3067
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  3068
    date year == Date today year ifTrue:[
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3069
        dict at:#yearOrTime put:('%h:%m' expandPlaceholdersWith:dict).
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  3070
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  3071
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  3072
    "
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3073
     |d|
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3074
     d := Dictionary new.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3075
     Timestamp now addPrintBindingsTo:d language:nil.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3076
     d inspect.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3077
    "
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3078
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3079
    "used by:
22331
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  3080
        Timestamp now printStringFormat:'%y-%(mon)-%d'
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  3081
        Timestamp now printStringFormat:'%(dayOfYear)'
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  3082
    "
22331
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  3083
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  3084
    "Modified (comment): / 03-11-2017 / 10:54:30 / cg"
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  3085
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  3086
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3087
printGeneralizedOn:aStream
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3088
    "append a representation of the receiver to aStream in a general format,
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3089
     top-down, without separators: 'yyyymmddHHMMSS.mmmZ'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3090
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3091
     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
  3092
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3093
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3094
    ^ self printGeneralizedOn:aStream isLocal:false short:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3095
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3096
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3097
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3098
    "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
  3099
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3100
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3101
     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
  3102
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3103
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3104
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3105
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  3106
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3107
    self printGeneralizedOn:aStream isLocal:isLocal short:false
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3108
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3109
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3110
    "Modified: / 1.7.1996 / 15:20:59 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3111
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3112
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3113
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3114
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3115
    "append a representation of the receiver to aStream in a general format,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3116
     top-down, without separators;
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3117
        long format:  'yyyymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3118
        short format: 'yymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3119
     Using the short format is strictly discouraged!!
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3120
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3121
     This format is used for the ASN.1 GeneralizedTime and UTCTime
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3122
     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
  3123
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3124
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3125
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3126
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3127
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3128
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  3129
    isLocal ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3130
        t := self timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3131
        off := t utcOffset.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  3132
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3133
        t := self asUtcTimestamp timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3134
        off := 0.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  3135
    ].
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  3136
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3137
    shortFormat ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3138
        self assert:(t year between:1951 and:2049).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3139
        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3140
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3141
        t year    printOn:aStream leftPaddedTo:4 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  3142
    ].
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  3143
    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
  3144
    t day     printOn:aStream leftPaddedTo:2 with:$0.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3145
    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
  3146
    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
  3147
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3148
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  3149
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3150
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3151
    (self isUtcTimestamp or:[off == 0]) ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3152
        aStream nextPut:$Z.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3153
    ] ifFalse:[ |min|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3154
        off < 0 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3155
            aStream nextPut:$+.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3156
            off := off negated.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3157
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3158
            aStream nextPut:$-.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3159
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3160
        min := off // 60.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3161
        min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3162
        min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3163
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3164
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3165
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3166
     Timestamp now printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3167
     Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3168
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3169
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3170
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3171
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3172
     Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3173
     Timestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3174
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  3175
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3176
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3177
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3178
     Date today printOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3179
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3180
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3181
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3182
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3183
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  3184
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3185
printISO8601
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3186
    "obsoleted due to uc/lc and print vs. printString confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3187
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3188
    <resource: #obsolete>
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3189
    "print in a format like 2014-10-17T17:08:44Z"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3190
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3191
    ^ self printStringIso8601
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3192
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3193
    "Created: / 16-06-2005 / 16:11:15 / masca"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3194
    "Modified (comment): / 25-05-2018 / 12:00:52 / Claus Gittinger"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3195
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3196
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3197
printISO8601Compressed
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3198
    "obsoleted due to uc/lc and print vs. printString confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3199
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3200
    <resource: #obsolete>
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3201
    "return a printString in a format like 20141017T170939Z"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3202
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3203
    ^ self printStringIso8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3204
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3205
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3206
     Timestamp now printISO8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3207
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3208
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3209
    "Created: / 16-06-2005 / 16:11:31 / masca"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3210
    "Modified (comment): / 25-05-2018 / 12:00:47 / Claus Gittinger"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3211
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3212
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3213
printISO8601CompressedOn: aStream
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3214
    "obsoleted due to uc/lc confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3215
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3216
    <resource: #obsolete>
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3217
    "print in a format like 20141017T170939Z on aStream"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3218
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3219
    self printIso8601CompressedOn: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3220
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3221
    "Created: / 16-06-2005 / 16:11:50 / masca"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3222
    "Modified (comment): / 25-05-2018 / 12:00:42 / Claus Gittinger"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3223
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3224
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3225
printISO8601On: aStream
22840
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3226
    "obsoleted due to uc/lc confusion"
7069c0491453 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22837
diff changeset
  3227
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3228
    <resource: #obsolete>
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3229
    "print in a format like 2014-10-17T17:08:44Z on aStream"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3230
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3231
    self printIso8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3232
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3233
    "Created: / 16-06-2005 / 16:11:07 / masca"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3234
    "Modified (comment): / 25-05-2018 / 12:00:37 / Claus Gittinger"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3235
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3236
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3237
printIso8601CompressedOn: aStream
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3238
    "print in a format like 20141017T170939Z on aStream"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3239
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3240
    self printIso8601FormatOn:aStream compressed:true timeSeparator:$T
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3241
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3242
    "Created: / 16-06-2005 / 16:11:50 / masca"
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3243
    "Modified: / 24-05-2018 / 17:33:12 / Claus Gittinger"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3244
    "Modified (comment): / 25-05-2018 / 12:00:30 / Claus Gittinger"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3245
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3246
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3247
printIso8601FormatOn:aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3248
    "append the iso8601 representation of the receiver to aStream.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3249
     This format looks like:
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3250
        1999-01-01T24:00:00
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3251
     or, for zero hr:min:sec,
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3252
        1999-01-01
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3253
     Of course, a 24 hour clock is used.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3254
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3255
     Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, 
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3256
     otherwise the reader will read as local time."
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3257
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3258
    self printIso8601FormatOn:aStream compressed:false timeSeparator:$T
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3259
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3260
    "
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3261
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3262
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3263
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3264
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3265
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3266
    "
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3267
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3268
    "Modified: / 24-05-2018 / 17:28:36 / Claus Gittinger"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3269
    "Modified (comment): / 25-05-2018 / 12:00:23 / Claus Gittinger"
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3270
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3271
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3272
printIso8601FormatOn:aStream compressed:compact timeSeparator:sepChar
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3273
    "append the iso8601 representation of the receiver to aStream.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3274
     This format looks like:
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3275
        1999-01-01T24:00:00
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3276
     or, for zero hr:min:sec,
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3277
        1999-01-01
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3278
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3279
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3280
     Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, 
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3281
     otherwise the reader will read as local time."
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3282
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3283
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3284
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3285
    self isUtcTimestamp ifTrue:[
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3286
        asUTC := true. asLocal := false.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3287
    ] ifFalse:[
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3288
        asUTC := false.
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3289
        asLocal := self isLocalTimestamp.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3290
    ].
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3291
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3292
    Timestamp::TimestampISO8601Builder
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3293
        print:self compact:compact
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3294
        asLocal:asLocal asUTC:asUTC withMilliseconds:true
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3295
        timeSeparator:sepChar
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3296
        on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3297
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3298
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3299
"/    |format|
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3300
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3301
"/    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3302
"/    self milliseconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3303
"/        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3304
"/        self seconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3305
"/            format := '%(year)-%(month)-%(day)T%h:%m'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3306
"/            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3307
"/                format := '%(year)-%(month)-%(day)'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3308
"/            ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3309
"/        ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3310
"/    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3311
"/    self printOn:aStream format:format
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3312
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3313
    "
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3314
     Timestamp now printStringIso8601Format.
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  3315
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3316
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3317
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3318
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3319
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  3320
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3321
    "
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3322
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3323
    "Created: / 24-05-2018 / 17:28:25 / Claus Gittinger"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3324
    "Modified (comment): / 25-05-2018 / 12:00:14 / Claus Gittinger"
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3325
    "Modified: / 27-07-2018 / 11:57:21 / Stefan Vogel"
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3326
!
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3327
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3328
printIso8601FormatOn:aStream timeSeparator:sepChar
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3329
    "append the iso8601 representation of the receiver to aStream.
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3330
     This format looks like:
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3331
        1999-01-01T24:00:00
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3332
     or, for zero hr:min:sec,
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3333
        1999-01-01
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3334
     Of course, a 24 hour clock is used.
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3335
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3336
     Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, 
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3337
     otherwise, the reader will read as local time."
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3338
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3339
    self printIso8601FormatOn:aStream compressed:false timeSeparator:sepChar
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3340
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3341
    "
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3342
     Timestamp now printStringIso8601Format.
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3343
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3344
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3345
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3346
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3347
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3348
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3349
    "
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3350
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3351
    "Modified: / 24-05-2018 / 17:28:28 / Claus Gittinger"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3352
    "Modified (comment): / 25-05-2018 / 11:59:57 / Claus Gittinger"
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3353
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  3354
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3355
printIso8601On: aStream
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3356
    "print in a format like 2014-10-17T17:08:44Z on aStream"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3357
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3358
    TimestampISO8601Builder print: self on: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3359
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3360
    "Created: / 16-06-2005 / 16:11:07 / masca"
23023
0833f0a1e701 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23003
diff changeset
  3361
    "Modified (comment): / 25-05-2018 / 11:59:22 / Claus Gittinger"
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3362
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3363
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3364
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3365
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3366
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3367
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3368
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3369
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3370
    self isUtcTimestamp ifTrue:[
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3371
        asUTC := true. asLocal := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3372
    ] ifFalse:[
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3373
        asLocal := self isLocalTimestamp.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3374
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3375
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3376
    Timestamp::TimestampISO8601Builder
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3377
        print:self compact:false
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3378
        asLocal:asLocal asUTC:asUTC withMilliseconds:true
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3379
        timeSeparator:(Character space)
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3380
        on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3381
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3382
"/    self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3383
"/    self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3384
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3385
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3386
    "
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3387
     |tHere tNewYork|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3388
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3389
     Timestamp now printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3390
     Timestamp now asUtcTimestamp printOn:Transcript. Transcript cr.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3391
     (Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')) printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3392
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3393
     tHere := Timestamp now.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3394
     tNewYork := tHere asTZTimestamp:(Timestamp utcOffsetFrom:'EST').
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3395
     tHere printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3396
     tNewYork printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3397
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3398
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3399
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3400
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3401
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3402
     Time now asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3403
     Timestamp now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3404
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3405
     Date today asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3406
     Date today printOn:Transcript. Transcript cr.
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3407
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3408
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3409
    "Modified: / 01-07-1996 / 15:20:59 / cg"
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3410
    "Modified: / 27-07-2018 / 11:58:58 / Stefan Vogel"
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  3411
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3412
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3413
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3414
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3415
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3416
	'Fri, 04 Jul 2003 15:56:11 GMT'
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3417
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3418
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3419
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3420
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3421
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3422
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3423
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3424
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3425
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3426
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3427
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3428
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3429
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3430
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3431
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3432
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3433
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3434
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3435
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3436
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3437
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3438
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3439
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3440
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3441
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3442
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3443
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3444
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3445
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3446
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3447
    timeInfo := self asUtcTimestamp timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3448
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3449
    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
  3450
	    nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3451
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  3452
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3453
    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
  3454
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3455
    "/ the following is too slow for heavy use
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3456
    "/    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
  3457
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3458
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3459
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3460
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3461
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3462
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3463
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3464
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3465
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3466
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3467
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3468
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3469
     String streamContents:[:s| Timestamp now printRFC1123FormatOn:s]
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3470
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3471
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3472
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3473
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3474
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3475
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3476
	'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3477
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3478
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3479
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3480
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3481
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3482
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3483
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3484
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3485
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3486
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3487
    "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
  3488
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3489
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3490
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3491
    aStream nextPut:$(;
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3492
	    nextPutAll:self storeStringClass name;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3493
	    nextPutAll:' readIso8601FormatFrom:'''.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3494
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3495
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  3496
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3497
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3498
     Timestamp now storeString
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3499
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3500
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3501
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3502
    "
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3503
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3504
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3505
storeStringClass
24879
9ec224d47bc0 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 24850
diff changeset
  3506
    "my storeString will ask Timestamp to read the instance"
9ec224d47bc0 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 24850
diff changeset
  3507
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3508
    ^ self class
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3509
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3510
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3511
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3512
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3513
additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3514
    "return the additional picoseconds (0..999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3515
     These must alwyas be smaller than 1000*1000*1000 (i.e. 1ms),
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3516
     to avoid overflow into the millis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3517
     These are to be added to any milliseconds"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3518
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3519
    ^ additionalPicoseconds ? 0.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3520
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3521
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3522
     Timestamp now picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3523
     Timestamp nowWithMicroseconds picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3524
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3525
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3526
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3527
additionalPicoseconds:anInteger
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3528
    "set the additional picoseconds (0..999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3529
     These must alwyas be smaller than 1000*1000*1000 (i.e. 1ms),
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3530
     to avoid overflow into the millis."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3531
22842
c09377000ff0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22840
diff changeset
  3532
    self assert:(anInteger isInteger).
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3533
    self assert:(anInteger < (1000*1000*1000)).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3534
    additionalPicoseconds:= anInteger
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3535
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3536
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3537
     Timestamp now picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3538
     Timestamp now additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3539
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3540
     Timestamp nowWithMicroseconds picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3541
     Timestamp nowWithMicroseconds additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3542
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3543
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3544
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3545
computeTimeInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3546
    |d t info|
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3547
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3548
    "/ fake an info which the OS cannot give me
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3549
    d := self asDate.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3550
    t := self asTime.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3551
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3552
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3553
	 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
  3554
	 utcOffset:(self utcOffset) dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3555
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3556
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3557
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3558
	(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
  3559
	(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
  3560
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3561
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3562
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3563
computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3564
    |utcTimestamp d t info|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3565
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3566
    "/ fake an info which the OS cannot give me
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3567
    utcTimestamp := self asUtcTimestamp.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3568
    d := utcTimestamp asDate.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3569
    t := utcTimestamp asTime.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3570
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3571
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3572
	 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
  3573
	 utcOffset:0 dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3574
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3575
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3576
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3577
	(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
  3578
	(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
  3579
	(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
  3580
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3581
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3582
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3583
fromOSTime:anUninterpretedOSTime
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3584
    "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
  3585
     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
  3586
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3587
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3588
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3589
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3590
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3591
16942
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3592
fromOSTimeWithMilliseconds:anUninterpretedOSTime
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3593
    "strictly private: set the milliseconds from an OS time (since the epoch).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3594
     Notice: timestamps always have millisecond precision (in contrast to Time, where it is optional)"
16942
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3595
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3596
    osTime := anUninterpretedOSTime
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3597
!
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3598
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3599
fromOSTimeWithMilliseconds:anUninterpretedOSTime additionalPicoseconds:picos
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3600
    "strictly private: set the milliseconds and picoSeconds from an OS time (since the epoch)"
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3601
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3602
    osTime := anUninterpretedOSTime.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3603
    additionalPicoseconds := picos
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3604
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3605
    "
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3606
     Timestamp nowWithMicroseconds
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3607
    "
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3608
!
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3609
22940
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3610
getMicroseconds
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3611
    "strictly private: return the truncated microseconds (since the epoch) in utc"
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3612
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3613
    |millisAsMicros|
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3614
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3615
    millisAsMicros := osTime * 1000.
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3616
    additionalPicoseconds notNil ifTrue:[
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3617
        ^ millisAsMicros + (additionalPicoseconds // (1000 * 1000)).   
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3618
    ].
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3619
    ^ millisAsMicros
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3620
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3621
    "Created: 1.7.1996 / 14:33:56 / cg"
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3622
!
92a205803803 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22926
diff changeset
  3623
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3624
getMilliseconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3625
    "strictly private: return the truncated milliseconds (since the epoch) in utc"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3626
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3627
    ^ osTime
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3628
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3629
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3630
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3631
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3632
getSeconds
22280
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3633
    "strictly private: return the (truncated) seconds (since the epoch) in utc"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3634
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3635
    ^ osTime // 1000
22280
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3636
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3637
    "Modified (comment): / 21-09-2017 / 18:50:23 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3638
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3639
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3640
osTime:aTime
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3641
    "set the internal representation of the time"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3642
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3643
    osTime := aTime.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3644
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3645
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3646
setMicrosecond:aNumber
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3647
    "change the sub-second fractional part only (leaves everything above seconds unchanged)"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3648
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3649
    self 
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3650
        setMilliseconds:(osTime // 1000) * 1000   "/ strip off any sub-second part 
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3651
        additionalPicoseconds:(aNumber * 1000000) truncated.    "/ set picos 
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3652
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3653
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3654
     Timestamp now setMicrosecond:15    - 15 microseconds after the current second's start 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3655
     Timestamp now setMicrosecond:0.1   - 100 nanoseconds after the current second's start 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3656
    "
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3657
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3658
    "Modified: / 27-07-2018 / 10:34:18 / Stefan Vogel"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3659
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3660
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3661
setMillisecond:aNumber
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3662
    "change the sub-second fractional part only (leaves everything above seconds unchanged)"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3663
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3664
    self 
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3665
        setMilliseconds:(osTime // 1000) * 1000       "/ strip off any sub-second part 
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3666
        additionalPicoseconds:(aNumber * 1000000000) truncated.     "/ set picos 
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3667
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3668
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3669
     Timestamp now setMillisecond:15    - 15 milliseconds after the current second's start
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3670
     Timestamp now setMillisecond:0.05  - 50 microseconds after the current second's start
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3671
    "
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3672
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3673
    "Modified: / 27-07-2018 / 10:34:42 / Stefan Vogel"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3674
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3675
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3676
setMilliseconds:millis
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3677
    "strictly private: set the milliseconds (since the epoch)"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3678
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3679
    osTime := millis.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3680
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3681
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3682
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3683
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3684
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3685
setMilliseconds:millis additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3686
    "strictly private: set the milliseconds (since the epoch) and additional picos"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3687
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3688
    |rest newMillis newPicos|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3689
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3690
    millis isInteger ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3691
        newMillis := millis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3692
        newPicos := 0.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3693
    ] ifFalse:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3694
        newMillis := millis truncated.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3695
        rest := millis - newMillis.
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3696
        newPicos := (rest * 1000000000) truncated.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3697
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3698
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3699
    picos ~~ 0 ifTrue:[
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3700
        newPicos := newPicos + picos.
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3701
        newMillis := newMillis + (newPicos // 1000000000).
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3702
        newPicos := (newPicos \\ 1000000000) truncated.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3703
    ].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3704
    osTime := newMillis.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3705
    additionalPicoseconds := newPicos.
22989
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3706
9bd6b9704250 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22946
diff changeset
  3707
    "Modified: / 22-05-2018 / 16:50:34 / Stefan Vogel"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3708
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3709
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3710
setNanosecond:aNumber
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3711
    "change the sub-second fractional part only (leaves everything above seconds unchanged)"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3712
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3713
    self 
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3714
        setMilliseconds:(osTime // 1000) * 1000   "/ strip off any sub-second part
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3715
        additionalPicoseconds:(aNumber * 1000) rounded.         "/ set picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3716
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3717
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3718
     Timestamp now setNanosecond:15     - 15 nanoseconds after the current second's start
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3719
     Timestamp now setNanosecond:0.1    - 10 picoseconds after the current second's start
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3720
    "
23239
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3721
d04302832bfb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23028
diff changeset
  3722
    "Modified: / 27-07-2018 / 10:34:52 / Stefan Vogel"
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3723
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3724
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3725
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3726
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3727
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3728
    osTime := (secs * 1000).
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3729
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3730
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3731
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3732
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3733
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3734
timeInfo
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3735
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3736
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3737
	^ self computeTimeInfo
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3738
    ].
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3739
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3740
    ^ OperatingSystem computeTimeAndDateFrom:osTime
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3741
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3742
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3743
	(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
  3744
	(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
  3745
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3746
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3747
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3748
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3749
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3750
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  3751
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3752
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3753
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3754
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3755
    "
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3756
!
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3757
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3758
utcTimeInfo
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3759
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3760
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3761
	^ self computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3762
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3763
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3764
    ^ OperatingSystem computeUTCTimeAndDateFrom:osTime
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3765
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3766
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3767
	(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
  3768
	(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
  3769
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3770
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3771
22914
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3772
!Timestamp methodsFor:'queries'!
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3773
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3774
speciesForCompare
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3775
    "all of my subclass instances can be compared,
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3776
     because they all hold the UTC time internally"
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3777
     
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3778
    ^ Timestamp
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3779
! !
1bb3760b2967 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22894
diff changeset
  3780
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3781
!Timestamp methodsFor:'testing'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3782
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3783
isLocalTimestamp
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3784
    "return true, if I am a local timestamp (i.e. with no TZ info)"
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3785
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3786
    ^ true
23003
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3787
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3788
    "Modified (comment): / 24-05-2018 / 17:29:32 / Claus Gittinger"
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3789
!
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3790
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3791
isTZTimestamp
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3792
    "return true, if I am a timestamp with TZ info"
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3793
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3794
    ^ false
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3795
f43fb9a64745 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22989
diff changeset
  3796
    "Created: / 24-05-2018 / 17:30:25 / Claus Gittinger"
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3797
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3798
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3799
isTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3800
    "return true, if I am a timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3801
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3802
    ^ true
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3803
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3804
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3805
isUtcTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3806
    "return true, if I am a utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3807
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3808
    ^ false
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3809
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3810
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3811
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3812
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3813
acceptVisitor:aVisitor with:aParameter
16718
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3814
    "dispatch for visitor pattern; send #visitTimestamp:with: to aVisitor."
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3815
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3816
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3817
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3818
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3819
!Timestamp::TimestampBuilderAbstract class methodsFor:'documentation'!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3820
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3821
documentation
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3822
"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3823
    documentation to be added.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3824
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3825
    [author:]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3826
        cg
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3827
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3828
    [instance variables:]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3829
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3830
    [class variables:]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3831
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3832
    [see also:]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3833
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3834
"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3835
!
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3836
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3837
examples
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3838
"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3839
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3840
  more examples to be added:
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3841
                                                                [exBegin]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3842
    ... add code fragment for 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3843
    ... executable example here ...
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3844
                                                                [exEnd]
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3845
"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3846
! !
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3847
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3848
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3849
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3850
malformed:aString
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3851
    TimeConversionError raiseErrorString:(' - ', aString)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3852
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3853
    "Created: / 15-06-2005 / 15:54:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3854
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3855
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3856
!Timestamp::TimestampBuilderAbstract methodsFor:'support'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3857
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3858
addHoursAndMinutes: arrayWithHoursAndMinutes
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3859
    "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
  3860
    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
  3861
    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
  3862
    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
  3863
    one day forward or backward)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3864
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3865
    | hours minutes |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3866
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3867
    hours := arrayWithHoursAndMinutes first.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3868
    minutes := arrayWithHoursAndMinutes second.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3869
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3870
    utcOffset := (((hours * 60) + minutes) * 60).
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3871
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3872
    minutes isZero ifFalse: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3873
        minute := minute + minutes.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3874
        minute >= 60 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3875
            hours := hours + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3876
            minute := minute - 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3877
        ].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3878
        minute < 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3879
            hours := hours - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3880
            minute := minute + 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3881
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3882
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3883
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3884
    "Hours may get zero by time zone specification or by minutes modifications above."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3885
    hours isZero ifTrue: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3886
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3887
    "Add or subtract the hour and make date corrections if necessary."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3888
    hour := hour + hours.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3889
    hour < 0 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3890
        "Oops, got to previous day, must adjust even the date."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3891
        hour := 24 - ((hour negated) \\ 24).
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3892
        day := day - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3893
        day <= 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3894
            "Go to previous month..."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3895
            month := month - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3896
            month <= 0 ifTrue: [year := year - 1. month := 12].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3897
            day := self lastDayInMonth: month
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3898
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3899
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3900
    hour >= 24 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3901
        hour := hour \\ 24.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3902
        day := day + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3903
        day > (self lastDayInMonth: month) ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3904
            month := month + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3905
            month > 12 ifTrue: [year := year + 1. month := 1].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3906
            day := 1
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3907
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3908
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3909
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3910
    "Created: / 15-06-2005 / 16:45:49 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3911
    "Modified: / 16-06-2005 / 15:04:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3912
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3913
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3914
dateFromDayNumber: dayInYear
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3915
    "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
  3916
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3917
    |monthAndDay|
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3918
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3919
    (dayInYear between: 1 and: 365) ifFalse: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3920
	(dayInYear = 366 and:[self leapYear: year])
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3921
	    ifFalse: [self malformed: 'Bad day number: ' , dayInYear printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3922
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3923
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3924
    monthAndDay := Date monthAndDayFromDayInYear:dayInYear forYear:year.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3925
    month := monthAndDay at:1.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3926
    day := monthAndDay at:2
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3927
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3928
    "Created: / 15-06-2005 / 11:27:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3929
    "Modified: / 16-06-2005 / 12:31:37 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3930
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3931
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3932
dateFromWeek: weekInteger andWeekday: dayInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3933
    "Compute the month and day. Find the first day (weekday) in the year, maybe even
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3934
    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
  3935
    with thursday (or the one containing 4.1.)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3936
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3937
    |tmpDate|
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3938
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3939
    "Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3940
    (dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3941
    (weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3942
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3943
    tmpDate := Date newDayInWeek:dayInteger week:weekInteger year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3944
    day := tmpDate day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3945
    month := tmpDate month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3946
    year := tmpDate year.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3947
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3948
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3949
isAllowedDay: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3950
    "Answer whether the given day is allowed in the current month."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3951
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3952
    ^anInteger between: 1 and: (self lastDayInMonth: month)
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3953
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3954
    "Created: / 15-06-2005 / 16:22:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3955
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3956
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3957
lastDayInMonth: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3958
    "Answer the number of the last day of the given month in the current year."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3959
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3960
    ^ anInteger = 2
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3961
	ifTrue: [(self leapYear: year) ifTrue: [29] ifFalse: [28]]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3962
	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
  3963
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3964
    "Created: / 15-06-2005 / 17:12:31 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3965
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3966
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3967
leapYear: anInteger
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3968
    ^ Date leapYear:anInteger.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3969
!
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3970
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3971
timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3972
    "Answer the timestamp as it has been parsed."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3973
    "Notes:
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3974
     - 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
  3975
       or is a local time stamp.
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3976
     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
  3977
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3978
    (timestampClass == UtcTimestamp) ifTrue:[
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3979
        ^ UtcTimestamp
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3980
            UTCYear:year month:month day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3981
            hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3982
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3983
    (timestampClass == TZTimestamp) ifTrue:[
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3984
        "/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3985
        ^ ((TZTimestamp
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3986
            UTCYear:year month:month day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3987
            hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3988
           ) utcOffset:utcOffset)
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3989
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3990
16989
de9bc5f12297 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16988
diff changeset
  3991
    (isUtcTime or:[hasTimezone and:[utcOffset == 0]]) ifTrue:[
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3992
        ^ ((timestampClass == Timestamp) ifTrue:UtcTimestamp ifFalse:timestampClass)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3993
            UTCYear:year month:month day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3994
            hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3995
    ].
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3996
    hasTimezone ifTrue:[
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3997
        "/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3998
        ^ (((timestampClass == Timestamp) ifTrue:TZTimestamp ifFalse:timestampClass)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  3999
            UTCYear:year month:month day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4000
            hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4001
          ) utcOffset:utcOffset
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  4002
    ].
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4003
    "/ there was no timezone info, so make it a local timestamp again.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4004
    ^ timestampClass
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4005
        year:year month:month day:day
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4006
        hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4007
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4008
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4009
yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4010
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4011
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4012
    year := yearArg.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4013
    yearAlreadyRead := true.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4014
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4015
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4016
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4017
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4018
documentation
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4019
"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4020
    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4021
    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
  4022
    It has been written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  4023
    (which was now changed to call this as well).
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  4024
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  4025
    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
  4026
    (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
  4027
    broken years, incomplete times and timezones. All times read with timezone difference are recomputed
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4028
    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
  4029
    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
  4030
    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
  4031
    possible.
16915
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  4032
    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
  4033
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4034
    [author:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4035
	Martin Dvorak (masca@volny.cz)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4036
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4037
    [instance variables:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4038
	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
  4039
			so the builder instance can be reused (by at most one thread).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4040
	year            Current timestamp year. No default value, date must be present.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4041
	month           Current timestamp month. May change during parsing. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4042
	day             Current timestamp day. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4043
	hour            Current timestamp hour. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4044
	minute          Current timestamp minute. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4045
	second          Current timestamp second. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4046
	millisecond     Current timestamp millisecond. Defaults to 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4047
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4048
    [see also:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4049
	Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4050
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4051
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4052
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4053
examples
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4054
"
21999
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  4055
    See the unit tests in stx/goodies:regression >> RegressionTests::timeAndDateTest
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4056
    It covers the main features this builder has.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4057
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4058
    Just to introduce some coding examples, try:
21999
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  4059
        Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  4060
        UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  4061
        Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  4062
        Timestamp readISO8601From: (TimestampISO8601Builder print: TZTimestamp now).
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4063
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4064
    Timestamp readISO8601From:'fooBar' onError:[ Timestamp now ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4065
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4066
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4067
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4068
history
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4069
    "Created: / 16-06-2005 / 16:28:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4070
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4071
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4072
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4073
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4074
print: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4075
    "Returns the printString of the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4076
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4077
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4078
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4079
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4080
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4081
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4082
    self print: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4083
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4084
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4085
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4086
     self print:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4087
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4088
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4089
    "Created: / 15-06-2005 / 17:52:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4090
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4091
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4092
print:aTimestamp asLocal:asLocal on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4093
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4094
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4095
     The time is always printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4096
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4097
    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
  4098
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4099
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4100
     self print:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4101
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4102
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4103
    "Created: / 15-06-2005 / 17:56:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4104
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4105
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4106
print:aTimestamp on:aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4107
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4108
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4109
     The time is printed as UTC time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4110
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4111
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4112
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4113
        compact:false asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4114
        withMilliseconds:true timeSeparator:$T timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4115
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4116
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4117
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4118
     self print:(Timestamp now) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4119
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4120
     self print:(Time now) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4121
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4122
     self print:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4123
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4124
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4125
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4126
    "Created: / 15-06-2005 / 17:56:51 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4127
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4128
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4129
printAsLocalTime: aTimestamp on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4130
    "Print the given timestamp in general ISO8601 format,
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  4131
     such as '2014-11-06T11:48:09+01'.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4132
     The time is printed as local time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4133
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4134
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4135
        print:aTimestamp compact:false asLocal:true asUTC:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4136
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4137
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4138
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4139
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4140
     self printAsLocalTime:(Timestamp now) on:Transcript
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4141
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4142
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4143
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4144
printCompressed: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4145
    "Return a printString in compressed format such as '20141106T114636Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4146
     (for example, for timestamp interchange with mobile devices).
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4147
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4148
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4149
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4150
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4151
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4152
    self printCompressed: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4153
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4154
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4155
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4156
     self printCompressed:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4157
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4158
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4159
    "Created: / 15-06-2005 / 17:52:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4160
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4161
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4162
printCompressed:aTimestamp asLocal:asLocal on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4163
    "generates a compressed string representation, 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4164
     (optionally as localtime) such as '20141106T114636Z'"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4165
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4166
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4167
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4168
        compact:true asLocal:asLocal asUTC:asLocal not 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4169
        withMilliseconds:true timeSeparator:$T timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4170
        on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4171
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4172
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4173
     self printCompressed:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4174
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4175
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4176
    "Created: / 15-06-2005 / 17:54:17 / masca"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4177
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4178
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4179
printCompressed:aTimestamp on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4180
    "generates a compressed string representation, such as '20141106T114636Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4181
     The time is printed as UTC time"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4182
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4183
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4184
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4185
        compact:true asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4186
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4187
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4188
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4189
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4190
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4191
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4192
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4193
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4194
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4195
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4196
printCompressedAsLocalTime:aTimestamp on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4197
    "generates a compressed string representation, such as '20141106T114636Z'.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4198
     The time is printed as local time"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4199
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4200
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4201
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4202
        compact:true asLocal:true asUTC:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4203
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4204
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4205
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4206
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4207
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4208
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4209
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4210
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4211
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4212
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4213
printTime:aTimeOrTimestamp on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4214
    "Print the given time in general ISO8601 format,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4215
     such as 'T11:48:09Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4216
     The time is printed as UTC time.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4217
     No date is printed."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4218
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4219
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4220
        print:aTimeOrTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4221
        compact:false asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4222
        withMilliseconds:true timeSeparator:$T timeOnly:true
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4223
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4224
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4225
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4226
     self print:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4227
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4228
     self printTime:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4229
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4230
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4231
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4232
    "Created: / 15-06-2005 / 17:56:51 / masca"
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4233
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4234
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4235
printTimeZone:tzOffsetArg on: aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4236
    "Print the timezone delta"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4237
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4238
    |tzOffset tzHours tzMinutes|
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4239
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4240
    tzOffset := tzOffsetArg.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  4241
    tzOffset == 0 ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4242
	aStream nextPutAll:'+00'.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  4243
    ] ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4244
	tzOffset := tzOffset // 60.     "/ convert from seconds to minutes
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4245
	tzOffset < 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4246
	    tzOffset := tzOffset negated.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4247
	    aStream nextPut:$+
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4248
	] ifFalse:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4249
	    aStream nextPut:$-.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4250
	].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4251
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4252
	tzHours := tzOffset // 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4253
	tzMinutes := tzOffset \\ 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4254
	(tzHours ~= 0 or:[tzMinutes ~= 0]) ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4255
	    aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4256
		nextPutAll:(tzHours printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4257
	    tzMinutes ~= 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4258
		aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4259
		    nextPut: $:;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4260
		    nextPutAll: (tzMinutes printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4261
	    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4262
	].
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4263
    ].
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4264
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4265
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4266
     self print:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4267
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4268
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4269
     self print:(Timestamp now) asLocal:false on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4270
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4271
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4272
     self printCompressed:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4273
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4274
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4275
     self printCompressed:(Timestamp now) asLocal:false on:Transcript.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4276
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  4277
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4278
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4279
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4280
!Timestamp::TimestampISO8601Builder class methodsFor:'printing - basic'!
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4281
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4282
print:aTimeOrTimestamp compact:compact asLocal:asLocal asUTC:asUTC 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4283
    subSecondDigits:numDigits
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4284
    suppressZeroSubSecondDigits:suppressZeroSubSecondDigits
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4285
    timeSeparator:tSep timeOnly:timeOnly on:aStream
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4286
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4287
    "Print the given timestamp in general ISO8601 format,
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4288
     such as '2014-11-06T11:48:09Z'.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4289
        compact: if true, the compact format (without separating dashes and colons is generated)
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4290
        asLocal: if true, generates a localtime string (without any timezone info)
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4291
        asUTC: if true, generates a utc string
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4292
            if both are false:
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4293
                generate a string depending on the type of timestamp:
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4294
                    if local: generate a local timezone string
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4295
                    if utc: generate a utc string
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4296
                    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4297
        numDigits: nr of post-second fractional part (i.e. 3 for millis, 6 for micros, 0 for none, #variable for as-required);
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4298
        suppressZeroSubSecondDigits: to suppress zeros (i.e. the old behavior).
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4299
     if timeOnly is true, only the time is printed."
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4300
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4301
    |aTimestamp timeInfo picos picosString |
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4302
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4303
    aTimestamp := aTimeOrTimestamp asTimestamp.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4304
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4305
    asLocal ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4306
        "/ force local
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4307
        timeInfo := aTimestamp asLocalTimestamp timeInfo.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4308
    ] ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4309
        asUTC ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4310
            "/ force utc
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4311
            timeInfo := aTimestamp asUtcTimestamp timeInfo.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4312
        ] ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4313
            "/ in the timestamps own format
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4314
            timeInfo := aTimestamp timeInfo.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4315
        ]
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4316
    ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4317
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4318
    timeOnly ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4319
        timeInfo year printOn:aStream leftPaddedTo:4 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4320
        compact ifFalse:[ aStream nextPut: $- ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4321
        timeInfo month printOn:aStream leftPaddedTo:2 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4322
        compact ifFalse:[ aStream nextPut: $- ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4323
        timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
23028
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4324
        aStream nextPut:tSep.
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4325
    ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4326
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4327
    compact ifFalse:[ aStream nextPut: $:].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4328
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4329
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4330
    "always print the seconds, even if 0. 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4331
     According to http://www.w3.org/TR/xmlschema11-2/#dateTime  this is mandatory"
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4332
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4333
    compact ifFalse:[ aStream nextPut: $:].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4334
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4335
22946
80d58e6fcf9f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22940
diff changeset
  4336
    (numDigits == 3 and:[suppressZeroSubSecondDigits not]) ifTrue:[
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4337
        "/ special case, because it is so common
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4338
        aStream nextPut: $..
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4339
        aTimestamp milliseconds printOn:aStream leftPaddedTo:3 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4340
    ] ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4341
        numDigits ~~ 0 ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4342
            picos := aTimestamp picoseconds.    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4343
            (suppressZeroSubSecondDigits and:[picos = 0]) ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4344
                "/ not suppressed    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4345
                picosString := picos printStringLeftPaddedTo:12 with:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4346
                numDigits == #variable ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4347
                    picosString := picosString withoutTrailing:$0.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4348
                ] ifFalse:[    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4349
                    numDigits > 12 ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4350
                        picosString := picosString paddedTo:numDigits with:$0
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4351
                    ] ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4352
                        picosString := picosString copyTo:numDigits.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4353
                    ].                
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4354
                ].    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4355
                aStream nextPut: $..
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4356
                aStream nextPutAll:picosString.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4357
            ]    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4358
        ].    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4359
    ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4360
    
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4361
    asUTC ifTrue:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4362
        aStream nextPut: $Z
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4363
    ] ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4364
        asLocal ifFalse:[
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4365
            self printTimeZone:aTimestamp utcOffset on:aStream.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4366
        ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4367
    ].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4368
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4369
    "
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4370
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4371
        print:(Timestamp nowWithMicroseconds) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4372
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4373
        subSecondDigits:3
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4374
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4375
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4376
        
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4377
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4378
        print:(Timestamp nowWithMicroseconds) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4379
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4380
        subSecondDigits:6
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4381
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4382
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4383
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4384
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4385
        print:(Timestamp nowWithMicroseconds) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4386
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4387
        subSecondDigits:#variable
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4388
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4389
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4390
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4391
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4392
        print:(Timestamp now) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4393
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4394
        subSecondDigits:#variable
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4395
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4396
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4397
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4398
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4399
        print:(Timestamp now) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4400
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4401
        subSecondDigits:1
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4402
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4403
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4404
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4405
     Transcript cr. self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4406
        print:(Timestamp now) 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4407
        compact:false asLocal:false asUTC:true 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4408
        subSecondDigits:0
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4409
        suppressZeroSubSecondDigits:false
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4410
        timeSeparator:$T timeOnly:false on:Transcript
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4411
    "
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4412
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4413
    "Created: / 15-06-2005 / 17:56:51 / masca"
23028
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4414
    "Modified: / 26-05-2018 / 13:43:00 / Claus Gittinger"
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4415
!
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4416
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4417
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
  4418
    "Print the given timestamp in general ISO8601 format,
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4419
     such as '2014-11-06T11:48:09Z'.
23028
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4420
        compact: if true, the compact format (without separating dashes and colons is generated)
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4421
        asLocal: if true, generates a localtime string (with the machine's current timezone setting)
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4422
        asUTC: if true, generates a utc string
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4423
            if both are false:
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4424
                generate a string depending on the type of timestamp:
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4425
                    if local: generate a local timezone string
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4426
                    if utc: generate a utc string
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4427
                    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4428
        withMilliseconds: if false, no milliseconds are generated"
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4429
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4430
    self
23028
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4431
        print:aTimestamp
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4432
        compact:compact asLocal:asLocal asUTC:asUTC
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4433
        withMilliseconds:withMillis
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4434
        timeSeparator:$T timeOnly:false
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4435
        on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4436
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4437
    "
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4438
     self print:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4439
     self printAsLocalTime:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4440
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4441
    "
23028
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4442
d93aefb6e389 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23023
diff changeset
  4443
    "Modified: / 26-05-2018 / 13:43:39 / Claus Gittinger"
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4444
!
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4445
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4446
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
  4447
    "Print the given timestamp in general ISO8601 format,
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4448
     such as '2014-11-06T11:48:09Z'.
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4449
        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
  4450
        asLocal: if true, generates a localtime string (without any timezone info)
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4451
        asUTC: if true, generates a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4452
            if both are false:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4453
                generate a string depending on the type of timestamp:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4454
                    if local: generate a local timezone string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4455
                    if utc: generate a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4456
                    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
  4457
        withMilliseconds: if false, no milliseconds are generated"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  4458
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4459
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4460
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4461
        compact:compact asLocal:asLocal asUTC:asUTC 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4462
        withMilliseconds:withMillis timeSeparator:tSep timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4463
        on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4464
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4465
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4466
     self print:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4467
     self printAsLocalTime:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4468
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4469
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4470
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4471
    "Created: / 15-06-2005 / 17:56:51 / masca"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4472
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4473
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4474
print:aTimeOrTimestamp compact:compact asLocal:asLocal asUTC:asUTC 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4475
    withMilliseconds:withMillis timeSeparator:tSep timeOnly:timeOnly on:aStream
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4476
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4477
    "Print the given timestamp in general ISO8601 format,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4478
     such as '2014-11-06T11:48:09Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4479
        compact: if true, the compact format (without separating dashes and colons is generated)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4480
        asLocal: if true, generates a localtime string (without any timezone info)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4481
        asUTC: if true, generates a utc string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4482
            if both are false:
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4483
                generate a string depending on the type of timestamp:
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4484
                    if local: generate a local timezone string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4485
                    if utc: generate a utc string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4486
                    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4487
        withMilliseconds: if false, no milliseconds are generated.
22926
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4488
     if timeOnly is true, only the time is printed.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4489
     Warning: this has a feature (a bug) of implicitly suppressing fractional seconds, if the millis are zero.
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4490
              this is strange, but for backward compatibility, left as is
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4491
              (in case some printout depends on it)"
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4492
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4493
    |nDigits|
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4494
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4495
    nDigits := withMillis ifTrue:[3] ifFalse:[0].
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4496
    self 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4497
        print:aTimeOrTimestamp 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4498
        compact:compact asLocal:asLocal asUTC:asUTC 
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4499
        subSecondDigits:nDigits
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4500
        suppressZeroSubSecondDigits:true
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4501
        timeSeparator:tSep timeOnly:timeOnly on:aStream
663fa103b1e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22914
diff changeset
  4502
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4503
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4504
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4505
     self print:(Timestamp now) on:Transcript
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  4506
     self print:(Time now) on:Transcript
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4507
     self printAsLocalTime:(Timestamp now) on:Transcript
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  4508
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4509
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4510
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4511
    "Created: / 15-06-2005 / 17:56:51 / masca"
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4512
! !
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  4513
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4514
!Timestamp::TimestampISO8601Builder class methodsFor:'public parsing'!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4515
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4516
read: stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4517
    ^ self new read:stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4518
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4519
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4520
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4521
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4522
read: stringOrStream withClass:timestampClass yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4523
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4524
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  4525
    ^ self new
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4526
	yearAlreadyReadAs:yearArg;
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4527
	read:stringOrStream withClass:timestampClass
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4528
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4529
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4530
! !
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4531
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4532
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4533
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4534
nextDigit
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4535
    | char |
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4536
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4537
    char := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4538
    char isNil ifTrue: [^-1].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4539
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4540
    char isDigit ifTrue: [
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4541
	stream next.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4542
	^ char codePoint - $0 codePoint
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4543
    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4544
    ^ -1
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4545
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4546
    "Created: / 14-06-2005 / 11:48:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4547
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4548
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4549
nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4550
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4551
    | digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4552
    digit := self nextDigit.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4553
    ^ digit < 0
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4554
	ifTrue: [self malformed: 'No digit found']
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4555
	ifFalse: [digit]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4556
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4557
    "Created: / 15-06-2005 / 10:57:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4558
    "Modified: / 15-06-2005 / 17:22:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4559
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4560
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4561
nextDigits:anInteger
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4562
    ^ self nextDigitsAtLeast:anInteger atMost:anInteger
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4563
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4564
!
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4565
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4566
nextDigitsAtLeast:minCount atMost:maxCount
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4567
    |count char number|
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4568
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4569
    number := 0.
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4570
    count := 0.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4571
    [
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4572
        char := stream peekOrNil.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4573
        (char notNil and:[char isDigit]) ifFalse:[
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4574
            count < minCount ifTrue:[
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4575
                self malformed:('Stream does not contain at least %1 digits' bindWith:minCount)
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4576
            ].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4577
            ^ number
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4578
        ].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4579
        stream next.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4580
        number := (number * 10) + char digitValue.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4581
        count := count + 1.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4582
        count == maxCount ifTrue:[
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4583
            ^ number
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4584
        ].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4585
    ] loop.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4586
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4587
    "Created: / 14-06-2005 / 11:57:22 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4588
    "Modified: / 15-06-2005 / 15:54:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4589
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4590
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4591
!Timestamp::TimestampISO8601Builder methodsFor:'public processing'!
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4592
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4593
read:stringOrStream withClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4594
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4595
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4596
    stream := stringOrStream readStream.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4597
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4598
    month := day := 1.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4599
    hour := minute := second := millisecond := 0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4600
    isUtcTime := hasTimezone := false.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4601
    utcOffset := 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4602
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  4603
    yearAlreadyRead ~~ true ifTrue:[
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4604
        "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
  4605
        self readYear.
16923
719c8a7b1cdd class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16922
diff changeset
  4606
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4607
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4608
    "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
  4609
    There is possible inconsistency - a dash may be read followed by T, which is not
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4610
    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
  4611
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4612
    peek ifNil: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4613
        "End of stream, only year has been read."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4614
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  4615
    peek == $- ifTrue: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4616
        "Skip the dash after year, if present."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4617
        stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4618
        peek := stream peekOrNil].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4619
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4620
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4621
    (peek == $T or: [peek == Character space])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4622
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4623
            "Got time signature. Skip the signature, read time and answer the timestamp."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4624
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4625
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4626
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4627
            self readTimezone.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4628
            ^ self timestampWithClass:timestampClass
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4629
        ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4630
        ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4631
            "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
  4632
            peek == $W
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4633
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4634
                    "Parse week number and (possibly) day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4635
                    stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4636
                    self readWeekNumber]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4637
                ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4638
                    "Got digit, read month number followed by day or day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4639
                    self readMonthOrDay]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4640
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4641
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4642
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4643
    peek ifNil: [
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4644
        "End of stream, only date has been read."
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4645
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  4646
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  4647
    (peek asUppercase == $T or: [peek == Character space])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4648
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4649
            "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
  4650
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4651
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4652
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4653
            self readTimezone
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4654
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4655
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4656
    ^ self timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4657
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4658
    "Created: / 14-06-2005 / 11:45:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4659
    "Modified: / 16-06-2005 / 10:15:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4660
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4661
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4662
!Timestamp::TimestampISO8601Builder methodsFor:'reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4663
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4664
readFraction
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4665
    "Read an arbitrary number of digits representing a fraction."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4666
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4667
    ^ Fraction readDecimalFractionFrom:stream onError:[self malformed: 'Missing digits after fraction separator'].
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4668
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4669
    "
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4670
     (Fraction readDecimalFractionFrom:'12345' readStream onError:nil)
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4671
    "
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4672
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4673
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4674
readMilliseconds
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4675
    "Read an arbitrary number of digits representing the fractional part
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4676
     (used to be milliseconds, but now we can represent anything down to pico seconds"
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4677
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4678
    |fraction ms|
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4679
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4680
    fraction := self readFraction.  "/ 0 .. 0.99999...
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4681
    ms := (fraction * 1000).        "/ 0 .. 999.999999
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4682
    millisecond := (ms // 1).       "/ 0 .. 999
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4683
    picos := (ms \\ 1) * (1000 * 1000 * 1000).
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4684
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4685
    "Created: / 15-06-2005 / 15:25:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4686
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4687
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4688
readMonthOrDay
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4689
    "Read month number, optionally followed by day, or absolute day number (three digit)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4690
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4691
    | dayDigit1 dayDigit2 |
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4692
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4693
    month := self nextDigitsAtLeast:1 atMost:2.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4694
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4695
    stream peekOrNil == $- ifTrue: [
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4696
        "Got dash. Day number must follow."
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4697
        stream next.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4698
        day := self nextDigitsAtLeast:1 atMost:2.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4699
        (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4700
        ^ self
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4701
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4702
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4703
    dayDigit1 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4704
    dayDigit1 < 0 ifTrue: [
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4705
        "No more digits than month, leave day unspecified."
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4706
        (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4707
        ^self
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4708
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4709
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4710
    dayDigit2 := self nextDigit.
24597
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4711
    dayDigit2 < 0 ifTrue: [
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4712
        "Read only three digits, this is absolute day number in a year."
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4713
        self dateFromDayNumber: month * 10 + dayDigit1
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4714
    ] ifFalse: [
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4715
        "Read four digits. So there's month and day."
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4716
        (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4717
        day := dayDigit1 * 10 + dayDigit2.
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4718
        (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]
435fc9fbc45e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24404
diff changeset
  4719
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4720
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4721
    "Created: / 15-06-2005 / 11:12:02 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4722
    "Modified: / 16-06-2005 / 11:47:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4723
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4724
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4725
readTime
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4726
    "Date already read, don't mind it. 
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4727
     Read only the time value."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4728
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4729
    | peek f |
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4730
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4731
    hour := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4732
    (hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4733
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4734
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4735
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4736
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4737
        "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4738
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4739
        minute := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4740
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4741
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4742
            "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4743
            minute := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4744
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4745
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4746
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4747
                minute := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4748
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4749
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4750
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4751
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4752
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4753
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4754
    minute isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4755
        f := minute.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4756
        minute := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4757
        second := (f - minute) * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4758
        second isInteger ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4759
            f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4760
            second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4761
            millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4762
            millisecond := millisecond rounded.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4763
        ].
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4764
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4765
    (minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4766
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4767
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4768
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4769
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4770
        "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4771
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4772
        second := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4773
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4774
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4775
            "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4776
            second := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4777
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4778
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4779
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4780
                second := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4781
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4782
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4783
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4784
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4785
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4786
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4787
    second isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4788
        f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4789
        second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4790
        millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4791
        millisecond := millisecond rounded.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4792
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4793
    (second between: 0 and: 59) ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4794
        "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
  4795
        second <= 61
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4796
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4797
                "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
  4798
                as it's not deterministic."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4799
                (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
  4800
                    ifFalse: [self malformed: 'Bad leap second']]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4801
            ifFalse: [self malformed: 'Bad second: ' , second printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4802
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4803
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4804
    "Hour, minute and second read. Read appendices."
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4805
    ((peek := stream peekOrNil) == $. or:[peek == $,])
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4806
        ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4807
            "Read dot. Skip it and read milliseconds."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4808
            stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4809
            self readMilliseconds].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4810
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4811
    hour = 24 ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4812
        (minute = 0 and: [second = 0 and: [millisecond = 0]])
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4813
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4814
                "On 24 hour, advance to the next day."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4815
                "hour := 0.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4816
                self addMinutes: 1440"]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4817
            ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4818
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4819
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4820
    "Created: / 14-06-2005 / 17:27:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4821
    "Modified: / 30-06-2005 / 11:34:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4822
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4823
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4824
readTimezone
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4825
    "Read time zone information. There are three possibilities of what can occur.
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4826
     If there is nothing more to read, the offset is unknown - this is treated as
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4827
     Zulu time as this may not be true."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4828
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4829
    | peek tzOffset |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4830
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4831
    peek := stream peek.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4832
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4833
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4834
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4835
    "If the time is in Zulu, don't modify the timestamp. This makes the machine
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4836
     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
  4837
    peek == $Z ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4838
        "Time read, skip Zulu signature and exit."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4839
        isUtcTime := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4840
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4841
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4842
    ].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4843
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4844
    (peek == $+ or:[peek == $-]) ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4845
        "Read a plus/minus, expect a negative/positive time zone difference."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4846
        hasTimezone := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4847
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4848
        tzOffset := self readTimezoneOffset.
19917
b273314a4ef7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19916
diff changeset
  4849
        peek == $+ ifTrue:[
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4850
            tzOffset := tzOffset collect: [:e | e negated].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4851
        ].    
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4852
        self addHoursAndMinutes: tzOffset.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4853
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4854
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4855
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4856
    "This is local time"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4857
    isUtcTime := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4858
    hasTimezone := false.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4859
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4860
    "Created: / 16-06-2005 / 09:54:21 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4861
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4862
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4863
readTimezoneOffset
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4864
    "Read time zone offset as a number minutes. Generally, there should be hours only
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4865
     but as the format introduces minutes in offsets, we must accept them.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4866
     (actually: there are countries with half-hour offsets!!)"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4867
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4868
    | hours digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4869
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4870
    "Read hours."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4871
    hours := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4872
    (hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4873
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4874
    stream peekOrNil = $:
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4875
        ifTrue: [
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4876
            "Colon read, minutes must follow."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4877
            stream next.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4878
            digit := self nextDigits: 2.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4879
            (digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4880
            ^Array with: hours with: digit].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4881
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4882
    "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
  4883
     check boundaries."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4884
    digit := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4885
    digit < 0 ifTrue: [^Array with: hours with: 0].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4886
    digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4887
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4888
    "Read the last digit of offset, it must be present."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4889
    ^Array with: hours with: digit * 10 + self nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4890
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4891
    "Created: / 15-06-2005 / 15:35:41 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4892
    "Modified: / 15-06-2005 / 17:45:58 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4893
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4894
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4895
readWeekNumber
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4896
    "Read week number. It is always two digits long."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4897
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4898
    | week dayInWeek digit |
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4899
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4900
    week := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4901
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4902
    stream peekOrNil = $-
22873
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4903
        ifTrue: [
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4904
            "Got dash, day number must follow."
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4905
            stream next.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4906
            digit := self nextDigit.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4907
            digit < 0 ifTrue: [self malformed: 'Bad weekday number'].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4908
            digit > 7 ifTrue: [self malformed: 'Bad weekday number'].
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4909
            self dateFromWeek: week andWeekday: digit.
cc5d5daffdfa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22867
diff changeset
  4910
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4911
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4912
    "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
  4913
    dayInWeek := self nextDigit.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4914
    dayInWeek <= 0 ifTrue: [dayInWeek := 1].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4915
    dayInWeek > 7 ifTrue: [self malformed: 'Bad weekday number'].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4916
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4917
    self dateFromWeek: week andWeekday: dayInWeek
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4918
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4919
    "Created: / 14-06-2005 / 12:06:47 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4920
    "Modified: / 15-06-2005 / 15:53:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4921
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4922
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4923
readYear
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4924
    "Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4925
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4926
    | read peek |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4927
    stream peekOrNil = $:
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4928
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4929
            "Broken two digit year > 1999 follows."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4930
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4931
            year := self nextDigitOrError + 2000.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4932
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4933
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4934
    "Expecting two-, three- or four-digit year"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4935
    "Read the first two digits. They must be there."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4936
    read := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4937
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4938
    "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
  4939
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4940
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4941
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4942
    ((peek == $-) or:[peek == $W])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4943
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4944
            "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
  4945
            year := read < 70
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4946
                ifTrue: [read + 2000]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4947
                ifFalse: [read + 1900]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4948
        ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4949
            "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
  4950
             read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4951
             peek := stream peekOrNil.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4952
             (peek isNil or: [peek == $-])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4953
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4954
                    "Read three digit year, return it."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4955
                    year :=  read + 1900
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4956
                ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4957
                    "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
  4958
                    two-digit year format is deprecated anyway."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4959
                    read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4960
                    year :=  read.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4961
                ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4962
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4963
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4964
    "Created: / 14-06-2005 / 12:01:11 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4965
    "Modified: / 15-06-2005 / 17:31:56 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4966
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4967
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4968
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4969
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4970
version
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4971
    ^ '$Header$'
12164
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4972
!
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4973
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4974
version_CVS
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4975
    ^ '$Header$'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4976
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4977
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  4978
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4979
Timestamp initialize!