Timestamp.st
author Claus Gittinger <cg@exept.de>
Wed, 09 May 2018 16:23:07 +0200
changeset 22837 c8ab3b3ad654
parent 22834 a70e3ac5710e
child 22840 7069c0491453
permissions -rw-r--r--
#BUGFIX by cg class: Timestamp class added: #timestampISO8601Builder hack
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
     1
"{ Encoding: utf8 }"
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
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
d6d98374dd39 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17003
diff changeset
    27
		hasTimezone yearAlreadyRead utcOffset'
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.
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
   117
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
   118
    [author:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   119
        Claus Gittinger
1306
c0189edbd96c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
   120
1282
3f5eda57c516 commentary
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   121
    [See also:]
17131
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   122
        UtcTimestamp Time Date
d950d092d386 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17081
diff changeset
   123
        Delay ProcessorScheduler
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   124
"
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   125
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   126
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   127
!Timestamp class methodsFor:'initialization'!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   128
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   129
initialize
17008
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   130
    MinOSTime := OperatingSystem epochStartOSTime.
b3c0cf461687 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17006
diff changeset
   131
    MaxOSTime := OperatingSystem epochEndOSTime.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   132
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   133
    Epoch := UtcTimestamp basicNew setSeconds:0.
21264
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   134
8a43f4a520e3 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20817
diff changeset
   135
    "Modified: / 19-01-2017 / 17:01:59 / stefan"
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   136
! !
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   137
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   138
!Timestamp class methodsFor:'instance creation'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   139
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   140
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
   141
    "return an instance of the receiver, given individual components,
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   142
     interpreted in the UTC timezone."
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   143
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   144
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   145
	    UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
   146
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
   147
    "
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
   148
     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
   149
     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
   150
     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
   151
     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
   152
     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
   153
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   154
     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
   155
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   156
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   157
    "Modified: / 1.7.1996 / 15:22:07 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   158
    "Created: / 13.7.1999 / 12:34:37 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   159
    "Modified: / 13.7.1999 / 12:42:30 / stefan"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   160
!
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   161
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   162
decodeFromLiteralArray:anArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   163
    "decode a Timestamp literalArray.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   164
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   165
     anArray may be:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   166
        #(Timestamp '200004182000.123')
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   167
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   168
     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
   169
     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
   170
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   171
        #(Timestamp #osTime: 12345678)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   172
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   173
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   174
    (anArray at:2) == #osTime: ifTrue:[
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   175
        ^ self new osTime:(anArray at:3).
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   176
    ].
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   177
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   178
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   179
        readGeneralizedFrom:(anArray at:2)
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   180
        onError:[ self conversionErrorSignal
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   181
                    raiseWith:anArray errorString:' - Timestamp literal array decoding' ]
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   182
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   183
    "
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   184
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   185
        decodeFromLiteralArray:#(Timestamp '20050323175226.014')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   186
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   187
        decodeFromLiteralArray:#(Timestamp '20050323175226.014-01')
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   188
     Timestamp
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
   189
        decodeFromLiteralArray:#(Timestamp '20050323175226.014Z')
8797
820ce611f762 comment
Claus Gittinger <cg@exept.de>
parents: 8479
diff changeset
   190
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   191
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
   192
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   193
epoch
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   194
    "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
   195
     However, we allow negative values to represent timestamps before that"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   196
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   197
    ^ Epoch
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   198
!
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
   199
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   200
fromDate:aDate
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   201
    "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
   202
     object.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   203
     See also `Timestamp now' and other protocol inherited
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   204
     from my superclass."
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   205
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   206
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   207
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   208
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   209
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   210
	hour:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   211
	minute:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   212
	second:0
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   213
	millisecond:0
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   214
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   215
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   216
     Timestamp fromDate:(Date today) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   217
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   218
     Timestamp now
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   219
    "
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   220
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   221
    "Modified: / 8.9.1995 / 15:07:30 / claus"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   222
    "Modified: / 19.4.1996 / 15:25:46 / cg"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   223
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   224
!
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   225
423
claus
parents: 392
diff changeset
   226
fromDate:aDate andTime:aTime
claus
parents: 392
diff changeset
   227
    "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
   228
     object.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   229
     See also `Timestamp now' and other protocol inherited
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   230
     from my superclass."
423
claus
parents: 392
diff changeset
   231
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   232
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   233
	year:aDate year
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   234
	month:aDate month
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   235
	day:aDate day
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   236
	hour:aTime hours
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   237
	minute:aTime minutes
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   238
	second:aTime seconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   239
	millisecond:aTime milliseconds
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   240
423
claus
parents: 392
diff changeset
   241
    "
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   242
     Timestamp fromDate:(Date today) andTime:(Time now)
16946
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   243
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
2380b5217f73 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16945
diff changeset
   244
16950
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   245
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
2cec0be544e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16946
diff changeset
   246
     Timestamp now
423
claus
parents: 392
diff changeset
   247
    "
claus
parents: 392
diff changeset
   248
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   249
    "Modified: / 8.9.1995 / 15:07:30 / claus"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   250
    "Modified: / 19.4.1996 / 15:25:46 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
   251
    "Modified: / 13.7.1999 / 12:30:47 / stefan"
423
claus
parents: 392
diff changeset
   252
!
claus
parents: 392
diff changeset
   253
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   254
newDay:dayInYear year:year
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   255
    "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
   256
     Date protocol compatibility"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   257
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
   258
    ^ self fromDate:(Date newDay:dayInYear year:year)
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   259
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   260
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
   261
     Timestamp newDay:183 year:1996
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   262
     Timestamp newDay:1 year:1996
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   263
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   264
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   265
    "Modified: 2.7.1996 / 09:39:30 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   266
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
   267
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   268
secondsSince1970:secs
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   269
    "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
   270
     This is the format used in the UNIX world.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   271
     Notice that the internal storage is always UTC based."
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   272
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   273
    ^ self basicNew setSeconds:secs.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   274
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   275
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   276
     UtcTimestamp secondsSince1970:0        -> 1970-01-01 00:00:00Z       
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   277
     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
   278
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   279
     Timestamp secondsSince1970:3600
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   280
     Timestamp secondsSince1970:3600*24
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   281
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   282
     (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
   283
       =
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   284
     (Timestamp secondsSince1970:1277935200)
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   285
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   286
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   287
    "Created: / 21-10-1996 / 17:48:30 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   288
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   289
    "Modified: / 08-01-2011 / 16:06:28 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   290
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   291
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   292
utcMillisecondsSince1970:secs
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   293
    "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
   294
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   295
    ^ self basicNew setMilliseconds:secs
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   296
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   297
    "Created: / 08-01-2011 / 16:09:32 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   298
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   299
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   300
utcNow
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   301
    "return now as utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   302
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   303
    ^ UtcTimestamp now
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   304
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   305
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   306
     Timestamp now
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   307
     Timestamp utcNow
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   308
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   309
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   310
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   311
utcSecondsSince1970:secs
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   312
    "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
   313
     This is the format used in the UNIX world.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   314
     Notice that the internal storage is always UTC based."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   315
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   316
    ^ UtcTimestamp secondsSince1970:secs
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   317
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   318
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   319
     UtcTimestamp secondsSince1970:0        -> 1970-01-01 00:00:00Z       
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   320
     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
   321
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   322
     UtcTimestamp secondsSince1970:3600     -> 1970-01-01 01:00:00Z
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   323
     Timestamp secondsSince1970:3600        -> 1970-01-01 02:00:00 (local)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
   324
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   325
     Timestamp secondsSince1970:3600*24
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   326
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   327
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   328
    "Modified: / 13-07-1999 / 12:31:22 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   329
    "Created: / 08-01-2011 / 16:05:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   330
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   331
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   332
year:year month:month day:day  
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   333
    "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
   334
     Date protocol compatibility"
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   335
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   336
    ^ self
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   337
        year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   338
        month:month
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   339
        day:day
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   340
        hour:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   341
        minute:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   342
        second:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   343
        millisecond:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   344
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   345
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   346
     Timestamp year:1996 month:1 day:1 
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   347
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   348
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   349
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   350
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
   351
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   352
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   353
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   354
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   355
    ^ 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
   356
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   357
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   358
     Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   359
     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
   360
     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
   361
     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
   362
     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
   363
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   364
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   365
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   366
    "Created: / 13.7.1999 / 12:06:39 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   367
    "Modified: / 13.7.1999 / 12:27:47 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   368
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   369
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   370
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
   371
    "return an instance of the receiver, given individual components.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   372
     See also `Timestamp now' and other protocol inherited
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   373
     from my superclass."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   374
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   375
    ^ self basicNew
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   376
	    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
   377
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   378
     Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   379
     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
   380
     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
   381
     Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   382
     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
   383
    "
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
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   386
    "Created: / 13.7.1999 / 12:28:44 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   387
    "Modified: / 13.7.1999 / 12:37:57 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   388
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   389
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
   390
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   391
!Timestamp class methodsFor:'Compatibility-Squeak'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   392
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   393
current
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   394
    ^ self now
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   395
!
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   396
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   397
readFrom:aStringOrStream
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   398
    "Answer a new instance for the value given by aStringOrStream"
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   399
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   400
    ^ self
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   401
        readFrom:aStringOrStream
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   402
        onError:[ TimeConversionError raiseRequestWith:aStringOrStream errorString:' - timestamp']
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   403
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   404
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   405
     self readFrom:'23-jun-2000 15:00'
14969
13470ec6f8c8 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 14713
diff changeset
   406
     self fromString:'23-jun-2000 15:00'
13604
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   407
     self readFrom:'23-jun-2000 '
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   408
    "
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   409
3f708df3bf70 added: #readDateTimeFrom:
Claus Gittinger <cg@exept.de>
parents: 13542
diff changeset
   410
    "Modified (comment): / 20-08-2011 / 16:52:10 / cg"
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   411
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   412
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   413
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
   414
    ^ (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
   415
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   416
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   417
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   418
     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
   419
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   420
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   421
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   422
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
   423
    ^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   424
        utcOffset:timeDuration
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   425
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   426
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   427
     Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:(2 hours)
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
   428
    "
13236
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
22837
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   431
!Timestamp class methodsFor:'class access'!
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   432
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   433
timestampISO8601Builder
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   434
    "I hate private class overuse...
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   435
     ... 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
   436
     See Time for such its use"
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   437
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   438
    ^ TimestampISO8601Builder
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   439
! !
c8ab3b3ad654 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22834
diff changeset
   440
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   441
!Timestamp class methodsFor:'format strings'!
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   442
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   443
defaultFormatString
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   444
    "a format string to present times in user interfaces.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   445
     Do not use this to store/retrieve times (use ISO8601 for that).
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
   446
     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
   447
     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
   448
13700
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   449
    ^ '%(year)-%(month)-%(day) %h:%m:%s.%i'
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   450
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   451
    "Created: / 16-01-2011 / 11:23:36 / cg"
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   452
! !
1f020ea6f607 added: #defaultFormatString
ca
parents: 13606
diff changeset
   453
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   454
!Timestamp class methodsFor:'obsolete'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   455
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   456
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
   457
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   458
    "This is obsolete. User #year:month:day:hour:minute:second:"
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
    ^ self
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   461
	year:y month:m day:d hour:h
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   462
	minute:min second:s millisecond:0
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   463
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   464
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   465
    "Modified: / 1.7.1996 / 15:22:26 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   466
    "Modified: / 13.7.1999 / 12:29:56 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   467
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   468
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   469
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
   470
    <resource: #obsolete>
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   471
    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   472
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   473
    ^ 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
   474
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   475
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   476
     Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   477
     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
   478
     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
   479
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   480
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   481
    "Created: / 1.7.1996 / 14:46:09 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   482
    "Modified: / 1.7.1996 / 15:22:07 / cg"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   483
    "Modified: / 13.7.1999 / 12:30:26 / stefan"
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   484
!
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   485
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   486
newDay:day month:month year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   487
    <resource: #obsolete>
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   488
    "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
   489
     Date protocol compatibility"
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   490
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   491
    ^ self
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   492
	year:year
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   493
	month:month
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   494
	day:day
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   495
	hour:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   496
	minute:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   497
	second:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   498
	millisecond:0
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   499
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   500
    "
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   501
     Timestamp newDay:1 month:1 year:1996
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
   502
    "
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   503
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   504
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   505
!Timestamp class methodsFor:'private'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   506
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   507
basicReadFrom:aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   508
    "return a new Timestamp, reading a printed representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   509
     The string is interpreted as 24 hour format, as printed.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   510
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   511
     Notice, that this is NOT the storeString format, which is iso8601
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   512
     This is more or less a heuristic attempt to read any reasonable format.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   513
     If the input starts with an integer > 31,
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   514
     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
   515
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   516
     KLUDGE:
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   517
        us and non-us format have different ordering of day and month;
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   518
        The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   519
        or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   520
     On error, raise an exception"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   521
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   522
    |monthOrYear firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName ch utcOffsetOrNil count|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   523
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   524
    count := 0.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   525
    monthOrYear := aStream throughAnyForWhich:[:ch | count := count+1. ch isDigit and:[count <= 4]].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   526
    firstNumber := Integer readFrom:monthOrYear onError:[TimeConversionError raiseErrorString:' - integer expected'].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   527
    firstNumber > 31 ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   528
        "/ assume iso8601 format;
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   529
        ^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   530
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   531
    aStream skipSeparators.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   532
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   533
    "/ consider this a kludge
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   534
    usFormat := (aStream peek == $/ ).
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   535
22337
9a707f3b74c2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22331
diff changeset
   536
    [(ch := aStream peekOrNil) notNil and:[ch isLetterOrDigit not]] whileTrue:[aStream next].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   537
    (ch notNil and:[ch isDigit]) ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   538
        secondNumber := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   539
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   540
        usFormat ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   541
            month := firstNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   542
            day := secondNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   543
        ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   544
            month := secondNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   545
            day := firstNumber.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   546
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   547
    ] ifFalse:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   548
        possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   549
        month := Date indexOfMonth:possibeMonthName asLowercase.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   550
        day := firstNumber.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   551
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   552
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   553
    (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   554
    (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   555
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   556
    [(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
   557
    year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   558
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   559
    aStream atEnd ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   560
        hour := min := sec := millis := 0.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   561
    ] ifFalse:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   562
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   563
        hour := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   564
        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   565
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   566
        [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   567
        min := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   568
        (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   569
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   570
        aStream atEnd ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   571
            sec := millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   572
        ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   573
            [(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   574
            sec := Integer readFrom:aStream onError:-1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   575
            (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   576
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   577
            aStream peek == $. ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   578
                aStream next.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   579
                millis := Integer readFrom:aStream onError:0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   580
                millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   581
            ] ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   582
                millis := 0.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   583
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   584
            aStream atEnd ifFalse:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   585
                utcOffsetOrNil := self utcOffsetFrom:aStream
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   586
            ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   587
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   588
    ].
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   589
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   590
    "special check - only 24:00:00 is allowed;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   591
     every time after that must wrap"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   592
    hour == 24 ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   593
        (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
   594
    ].
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   595
    utcOffsetOrNil notNil ifTrue:[
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   596
        utcOffsetOrNil = 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   597
            "/ utc timestamp
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   598
            ^ UtcTimestamp year:year month:month day:day hour:hour minute:min second:sec millisecond:millis
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
   599
        ].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   600
        ^ TZTimestamp new 
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   601
                UTCyear:year month:month day:day hour:hour minute:min second:sec millisecond:millis;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   602
                utcOffset:utcOffsetOrNil;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   603
                addSeconds:utcOffsetOrNil.
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   604
    ].
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
   605
    "/ a local timestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   606
    ^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   607
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   608
    "some ad hoc formats:
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   609
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   610
     Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   611
     Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   612
     Timestamp basicReadFrom:'20-feb-1995 13:11:06' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   613
     Timestamp basicReadFrom:'20-foo-1995 13:11:06' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   614
     (Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month    - european
16935
14fe31ad5f88 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16932
diff changeset
   615
     (Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month    - us
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   616
     Timestamp basicReadFrom:'20-2-1995 13:11' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   617
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   618
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100 MESZ' readStream
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   619
     Timestamp basicReadFrom:'20-2-1995 13:11:06.100+0200' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   620
     Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   621
     Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   622
     Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   623
     Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   624
     Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   625
     Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   626
     Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   627
     Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   628
     Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   629
     Timestamp basicReadFrom:'foo' readStream
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   630
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   631
     any iso8601 format:.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   632
     Timestamp basicReadFrom:(Timestamp now printString readStream)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   633
     Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   634
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
   635
     Timestamp basicReadFrom:'1995-10-20 12:10:00.000-0200' readStream
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   636
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   637
     UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   638
    "
22337
9a707f3b74c2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22331
diff changeset
   639
9a707f3b74c2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22331
diff changeset
   640
    "Modified: / 09-11-2017 / 10:10:07 / cg"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   641
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   642
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   643
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   644
    "common helper for read methods.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   645
     Return a new Timestamp, reading an iso8601 representation from aStream.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   646
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   647
     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
   648
     otherwise it is local time.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   649
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   650
     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
   651
     is the same as 1999-01-01T24:00:00.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   652
     Missing minute, second and ms values are replaced with 0;
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   653
     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
   654
     Partial hours, minutes, seconds are allowed at the end,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   655
     decimal separators are both $. and $, .
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   656
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   657
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   658
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   659
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   660
    "/ changed to use the new reader
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   661
    ^ TimestampISO8601Builder
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   662
	read:aStringOrStream withClass:self
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
   663
	yearAlreadyReadAs:yearOrNil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   664
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   665
"/    |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
   666
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   667
"/    str := aStringOrStream readStream.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   668
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   669
"/    month := day := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   670
"/    hour := millis := 0.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   671
"/    isUtcTime := false.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   672
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   673
"/    yearOrNil notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   674
"/        year := yearOrNil
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   675
"/    ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   676
"/        year := Integer readFrom:str onError:nil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   677
"/        year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   678
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   679
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   680
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   681
"/    (((ch := str peek) == $-) or:[ch == $W]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   682
"/        (ch == $-) ifTrue:[ str next ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   683
"/        str peek == $W ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   684
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   685
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   686
"/            "/ week follows
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   687
"/            week := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   688
"/            (week between:1 and:53) ifFalse:[ TimeConversionError raiseErrorString:' - bad week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   689
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   690
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   691
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   692
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   693
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   694
"/                dayInWeek := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   695
"/                (dayInWeek between:1 and:7) ifFalse:[ TimeConversionError raiseErrorString:' - bad day in week' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   696
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   697
"/                dayInWeek := 1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   698
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   699
"/            tmpDay := Date newDayInWeek:dayInWeek week:week year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   700
"/            day := tmpDay day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   701
"/            month := tmpDay month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   702
"/            year := tmpDay year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   703
"/        ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   704
"/            "/ month follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   705
"/            month := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   706
"/            (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   707
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   708
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   709
"/            str peek == $- ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   710
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   711
"/                "/ day follows.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   712
"/                day := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   713
"/                (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   714
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   715
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   716
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   717
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   718
"/    str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   719
"/    str atEnd ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   720
"/        "time follows"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   721
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   722
"/        str peek == $T ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   723
"/            "we treat the T as optional here"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   724
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   725
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   726
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   727
"/        hour := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   728
"/        (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   729
"/        str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   730
"/        str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   731
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   732
"/            "/ minutes follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   733
"/            min := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   734
"/            (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   735
"/            str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   736
"/            str peekOrNil == $: ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   737
"/                str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   738
"/                "/ seconds follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   739
"/                sec := Integer readFrom:str onError:-1.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   740
"/                (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   741
"/                str skipSeparators.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   742
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   743
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   744
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   745
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   746
"/        (peekChar == $. or:[peekChar == $,]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   747
"/            str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   748
"/            "/ decimals follow.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   749
"/            fraction := Number readMantissaFrom:str radix:10.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   750
"/            min isNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   751
"/                min := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   752
"/                fraction := min fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   753
"/                min := min truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   754
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   755
"/            (sec isNil and:[fraction ~= 0])ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   756
"/                sec := 60 * fraction.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   757
"/                fraction := sec fractionPart.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   758
"/                sec := sec truncated.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   759
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   760
"/            fraction ~= 0 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   761
"/                millis := (1000 * fraction) rounded.  "/ mhmh - should it be truncated ?
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   762
"/            ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   763
"/        ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   764
"/
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   765
"/        peekChar := str peekOrNil.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   766
"/        peekChar notNil ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   767
"/            peekChar == $Z ifTrue:[
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   768
"/                str next.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   769
"/                isUtcTime := true.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   770
"/            ] ifFalse:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   771
"/                ((peekChar == $+) or:[peekChar == $- ]) ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   772
"/                    str next.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   773
"/                    self halt.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   774
"/                    isUtcTime := true.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   775
"/                ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   776
"/            ]
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   777
"/        ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   778
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   779
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   780
"/    min isNil ifTrue:[min := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   781
"/    sec isNil ifTrue:[sec := 0].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   782
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   783
"/    "special check - only 24:00:00 is allowed;
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   784
"/     every time after that must wrap"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   785
"/    hour == 24 ifTrue:[
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   786
"/        (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
   787
"/    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   788
"/
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   789
"/    isUtcTime ifTrue:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   790
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   791
"/            UTCYear:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   792
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   793
"/    ] ifFalse:[
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   794
"/        ^ self
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   795
"/            year:year month:month day:day
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   796
"/            hour:hour minute:min second:sec millisecond:millis.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   797
"/    ]
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   798
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   799
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   800
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   801
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   802
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   803
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   804
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   805
     Timestamp readIso8601FormatFrom:'1995T13:11.5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   806
     Timestamp readIso8601FormatFrom:'1995T13:11,5'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   807
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   808
     Timestamp readIso8601FormatFrom:'1995T13.25'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   809
     Timestamp readIso8601FormatFrom:'1995T13.333333'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   810
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   811
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   812
     Timestamp readIso8601FormatFrom:'2014W40'   -> 29.sep.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   813
     Timestamp readIso8601FormatFrom:'2014W44-4' -> 30.oct.2014
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   814
     Timestamp readIso8601FormatFrom:'2014W1'    -> 30.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   815
     Timestamp readIso8601FormatFrom:'2014W1-1'  -> same 30.dec.2013 !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   816
     Timestamp readIso8601FormatFrom:'2014W1-2'  -> 31.dec.2013      !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   817
     Timestamp readIso8601FormatFrom:'2014W1-3'  -> 1.jan.2014       !!!!!! (this week starts in the previous year)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   818
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   819
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   820
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   821
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   822
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   823
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   824
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   825
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   826
     Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00'
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   827
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   828
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   829
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   830
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   831
    "common helper for read methods."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   832
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   833
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   834
        self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   835
    ] on:ConversionError do:exceptionValue.
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   836
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
   837
    "Modified: / 09-02-2017 / 10:01:27 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   838
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   839
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   840
!Timestamp class methodsFor:'reading'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
   841
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   842
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   843
    "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
   844
     The formatString is similar to the one used when printing.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   845
     On error, exceptionalValue is returned.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   846
     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
   847
     Format:
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   848
        %h      hours, 00..23 (i.e. european)  0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   849
        %u      hours, 00..12 (i.e. us)        0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   850
        %m      minutes, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   851
        %s      seconds, 00..59                0-padded to length 2
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   852
        %i      milliseconds, 000..999         0-padded to length 3
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   853
        %f      fractional seconds             any length, but only milliseconds kept
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   854
        %a      am/pm
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   855
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   856
        %d             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   857
        %D             - day
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   858
        %(day)         - day
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   859
        %(dayOfYear)   - 1..365/366
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   860
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   861
        %(month)       - month
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   862
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   863
        %(monthName)   - monthName
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   864
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   865
        %(year)        - year, full 4 digits
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   866
        %Y             - year, last 2 digits only,
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   867
                         0..71 map to 2000..2071;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   868
                         72..99 map to 1972..1999;
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   869
        %Y1900          - year, last 2 digits only, map to 1900..1999
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   870
        %Y2000          - year, last 2 digits only, map to 2000..2099
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   871
        %Y1950          - year, last 2 digits only, map to 1950..2049
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   872
        %Y1980          - year, last 2 digits only, map to 1980..2079
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   873
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   874
     an optional length after the % gives a field length;
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   875
        i.e. %2h%2m%2s parses '123557' as 12:35:37
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   876
        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
   877
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   878
     Please consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
   879
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   880
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   881
    |day month year dayOfYear monthAndDay
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   882
     hour minute second millisecond
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   883
     utcOffset inStream formatStream error fChar format itemHandler
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   884
     len now s fractionString fraction|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   885
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
   886
    error := [:msg |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   887
                exceptionalValue isBlock ifTrue:[
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   888
                    ^ exceptionalValue valueWithOptionalArgument:'format error'
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   889
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   890
                    ^ exceptionalValue value
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   891
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   892
             ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   893
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   894
    itemHandler := [:format |
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   895
        |input|
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   896
        
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   897
        input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   898
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   899
        ( #('d' 'D' 'day' ) includes:format ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   900
            day := Integer readFrom:input onError:[ error value:'invalid day' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   901
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   902
        ] ifFalse:[ ( format = 'month' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   903
            month := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   904
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   905
        ] ifFalse:[ ( format = 'year' or:[ format = 'y' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   906
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   907
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   908
        ] ifFalse:[ ( format = 'Y' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   909
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   910
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
18449
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   911
            (year < 70) ifTrue:[
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   912
                year := year + 2000
48c31fe80359 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18447
diff changeset
   913
            ] ifFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   914
                year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   915
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   916
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   917
        ] ifFalse:[ (format = 'monthName') ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   918
            s := input nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetter].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   919
            month := Date indexOfMonth:s asLowercase language:languageOrNil
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   920
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   921
        ] ifFalse:[ (format = 'dayOfYear') ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   922
            dayOfYear := Integer readFrom:input onError:[ error value:'invalid day of year' ].
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
   923
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   924
        ] ifFalse:[ ( format sameAs: 'Y1900' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   925
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   926
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   927
            year := year + 1900
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   928
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   929
        ] ifFalse:[ ( format sameAs:  'Y1950' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   930
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   931
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   932
            (year between:0 and: 49) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   933
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   934
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   935
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   936
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   937
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   938
        ] ifFalse:[ ( format sameAs:  'Y1980' ) ifTrue:[
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   939
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   940
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   941
            (year between:0 and: 79) ifTrue:[ 
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   942
                year := year + 2000
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   943
            ] ifFalse:[    
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   944
                year := year + 1900
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   945
            ]  
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   946
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   947
        ] ifFalse:[ ( format sameAs:  'Y2000' ) ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   948
            year := Integer readFrom:input onError:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   949
            (year between:0 and: 99) ifFalse:[ error value:'invalid year' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   950
            year := year + 2000
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   951
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   952
        ] ifFalse:[ ( format = 'h' or:[ format = 'H' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   953
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   954
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   955
        ] ifFalse:[ ( format = 'u'  or:[ format = 'U']) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   956
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   957
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   958
        ] ifFalse:[ ( format = 'm'  or:[ format = 'M' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   959
            minute := Integer readFrom:input onError:[ error value:'invalid minute' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   960
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   961
        ] ifFalse:[ ( format = 's'  or:[ format = 'S' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   962
            second := Integer readFrom:input onError:[ error value:'invalid second' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   963
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   964
        ] ifFalse:[ ( format = 'i'  or:[ format = 'I' ]) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   965
            millisecond := Integer readFrom:input onError:[ error value:'invalid month' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   966
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   967
        ] ifFalse:[ ( format = 'f'  or:[ format = 'F' ]) ifTrue:[
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   968
            fractionString := input upToMatching:[:ch | ch isDigit not].
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   969
            fraction := FixedPoint readFrom:'0.',fractionString.
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   970
            millisecond := (fraction * 1000) truncated.
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   971
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   972
        ] ifFalse:[ ( format = 'tz' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   973
            utcOffset := self utcOffsetFrom:input.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   974
            utcOffset isNil ifTrue:[ error value:'invalid timezone' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   975
        ] ifFalse:[ ( format = 'a' ) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   976
            s := (input next:2) asLowercase.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   977
            s = 'am' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   978
                (hour between:0 and:12) ifFalse:[ error value:'invalid hour' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   979
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   980
                s = 'pm' ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   981
                    (hour between:1 and:12) ifFalse:[ error value:'invalid hour' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   982
                    hour := hour + 12.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   983
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   984
                    error value:'invalid am/pm'
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   985
                ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   986
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   987
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   988
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
   989
            error value:'unhandled format:',format
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
   990
        ]]]]]]]]]]]]]]]]]]
18445
6184d4210c89 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18441
diff changeset
   991
    ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   992
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   993
    hour := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   994
    minute := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   995
    second := 0.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   996
    millisecond := 0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
   997
    utcOffset := 0.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   998
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
   999
    inStream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1000
    formatStream := formatString readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1001
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1002
    [formatStream atEnd] whileFalse:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1003
        fChar := formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1004
        fChar = Character space ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1005
            inStream peek isSeparator ifFalse:[ error value: 'format error; space expcected' ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1006
            inStream skipSeparators.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1007
        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1008
            fChar == $% ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1009
                len := nil.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1010
                (formatStream peek isDigit) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1011
                    len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1012
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1013
                (formatStream peek == $() ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1014
                    formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1015
                    format := formatStream upTo:$).
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1016
                ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1017
                    (formatStream peek == ${) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1018
                        formatStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1019
                        format := formatStream upTo:$}.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1020
                    ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1021
                        (formatStream peek isLetter) ifTrue:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1022
                            format := formatStream nextAlphaNumericWord.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1023
                        ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1024
                            error value:'unhandled format:',formatStream peek
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1025
                        ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1026
                    ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1027
                ].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1028
                itemHandler value:format.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1029
            ] ifFalse:[
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1030
                inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected'].
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1031
                inStream next.
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1032
            ]
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1033
        ].
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1034
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1035
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1036
    year isNil ifTrue:[
18441
dc7abfccf547 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17465
diff changeset
  1037
        year := (now := Timestamp now) year
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1038
    ].
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1039
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1040
    dayOfYear notNil ifTrue:[
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1041
        monthAndDay := Date monthAndDayFromDayInYear:dayOfYear forYear:year.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1042
        month := (monthAndDay at:1).
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1043
        day := (monthAndDay at:2).  
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1044
    ].
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  1045
    
18451
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1046
    ^ (self 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1047
        year:year month:month day:day 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1048
        hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) 
b5c5d8653dc8 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18449
diff changeset
  1049
            + utcOffset
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1050
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1051
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1052
     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
  1053
     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
  1054
     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
  1055
     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
  1056
     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
  1057
     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
  1058
     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
  1059
     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
  1060
     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
  1061
     Timestamp readFrom:'2015103' format:'%4y%3dayOfYear' onError:[self halt]
19923
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1062
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1063
     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
  1064
     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
  1065
     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
  1066
93c1e5c6461d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19917
diff changeset
  1067
     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
  1068
     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
  1069
     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
  1070
     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
  1071
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1072
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1073
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1074
readFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1075
    "return a new Timestamp, reading a printed representation from aStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1076
     The string is interpreted as 24 hour format, as printed.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1077
     Notice, that this is not the storeString format and
4898
a7a32af11523 oops - reading was wrong
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  1078
     is different from the format expected by readFrom:.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1079
     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
  1080
     or iso8601 (if the first integer is >31).
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1081
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1082
     Please consider using a standard format, such as iso8601."
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1083
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1084
    |stream newTime|
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1085
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1086
    stream := aStringOrStream readStream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1087
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7058
diff changeset
  1088
    Error handle:[:ex |
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1089
	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
  1090
    ] do:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1091
	newTime := self basicReadFrom:stream.
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1092
    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
  1093
    ^ newTime
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1094
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1095
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1096
     Timestamp readFrom:'20-2-1995 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1097
     Timestamp readFrom:'20-2-1995 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1098
     Timestamp readFrom:'20-2-2001 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1099
     Timestamp readFrom:'20-2-1995 13:11:06.100'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1100
     Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1101
     Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1102
     Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1103
     Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1104
     Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1105
     Timestamp readFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1106
     Timestamp readFrom:(Timestamp now storeString) onError:'wrong'
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1107
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1108
4378
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1109
    "Modified: / 8.10.1996 / 19:25:59 / cg"
8b93493f8d56 New method to set UTC time.
Stefan Vogel <sv@exept.de>
parents: 3995
diff changeset
  1110
    "Modified: / 13.7.1999 / 12:31:14 / stefan"
2311
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1111
!
88b035dd471a New Method: #secondsSince1970.
Stefan Vogel <sv@exept.de>
parents: 1701
diff changeset
  1112
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1113
readGeneralizedFrom:aStringOrStream
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1114
    "return a new Timestamp, reading a printed representation from aStream.
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1115
     The format read here is either
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1116
        yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1117
     or:
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1118
        yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1119
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1120
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1121
     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
  1122
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1123
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1124
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1125
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1126
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1127
     is different from the format expected by readFrom:.
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1128
    "
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1129
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1130
    ^ self
19897
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1131
        readGeneralizedFrom:aStringOrStream
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1132
        short:false
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1133
        onError:[
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1134
            self conversionErrorSignal raiseWith:aStringOrStream errorString:' - Timestamp GeneralizedTime format error'
cb8cea59de5c #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 19771
diff changeset
  1135
        ].
9620
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1136
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1137
    "Created: / 22-08-2006 / 16:05:55 / cg"
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1138
!
85969e75395d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9619
diff changeset
  1139
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1140
readGeneralizedFrom:aStringOrStream onError:exceptionBlock
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1141
    "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
  1142
     The format read here is either
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1143
	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
  1144
     or:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1145
	yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1146
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1147
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1148
     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
  1149
     so read this before changing anything here.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1150
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1151
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1152
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1153
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1154
     is different from the format expected by readFrom:.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1155
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1156
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1157
    ^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1158
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1159
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1160
     |s|
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1161
     s := '' writeStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1162
     Timestamp now printGeneralizedOn:s.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1163
     Timestamp readGeneralizedFrom:s contents onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1164
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1165
 Daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1167
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1168
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1169
     Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1170
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1171
 No daylight saving time:
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1172
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1173
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1174
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1175
     Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[]
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1176
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1177
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1178
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1179
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1180
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1181
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1182
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1183
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1184
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1185
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1186
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1187
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1188
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1189
    "
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1190
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1191
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1192
    "Modified: / 22-08-2006 / 12:30:11 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1193
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1194
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1195
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1196
    "return a new Timestamp, reading a printed representation from aStream.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1197
     The long format read here is either
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1198
            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1199
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1200
            yyyy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1201
     The (not recommended) short forms are:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1202
            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1203
        or:
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1204
            yy-mm-dd HH:MM:SS.iii +uuuu.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1205
     The string is interpreted as 24 hour format, as printed.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1206
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1207
     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
  1208
     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
  1209
     The short form is no longer recommended.
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1210
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1211
     New applications should consider using a standard format, such as iso8601.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1212
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1213
     Notice, that this is not the storeString format and
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1214
     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
  1215
    "
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1216
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1217
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1218
    ^ [
22653
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1219
        |newTime str day month year hour min sec millis c fraction|
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1220
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1221
        sec := millis := 0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1222
        str := aStringOrStream readStream.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1223
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1224
        shortFormat ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1225
            year := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1226
            year < 50 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1227
                year := year + 2000.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1228
            ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1229
                year := year + 1900.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1230
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1231
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1232
            year := Integer readFrom:(str next:4).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1233
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1234
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1235
        month := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1236
        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1237
        str peek == $- ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1238
        day := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1239
        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1240
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1241
        str skipSeparators.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1242
        hour:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1243
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1244
        str peek == $: ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1245
        min:= Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1246
        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1247
        str atEnd ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1248
            str peek == $: ifTrue:[ str next].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1249
            sec := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1250
            (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1251
            str atEnd ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1252
                str peek == $. ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1253
                    str next.
22653
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1254
                    "/ the old code here was wrong in assuming that exactly 3 digits
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1255
                    "/ are coming; thus hh:mm:ss.1 was interpreted as 1ms (instead of 100)
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1256
                    "/ thus: count the zeros...
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1257
                    str peek isDigit ifTrue:[
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1258
                        fraction := Number readMantissaFrom:str radix:10.
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1259
                        fraction isNil ifTrue:[^ exceptionBlock value].
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1260
                        millis := (fraction * 1000) rounded.
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1261
                    ] ifFalse:[
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1262
                        millis := 0
e7112f73582e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22627
diff changeset
  1263
                    ].
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1264
                ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1265
                str skipSeparators.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1266
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1267
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1268
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1269
        str atEnd ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1270
            "/ this is local time
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1271
            newTime := self year:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1272
                            hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1273
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1274
            c := str next.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1275
            c ~~ $Z ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1276
                |tzh tzmin|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1277
                tzh := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1278
                tzmin := Integer readFrom:(str next:2).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1279
                c == $+ ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1280
                    "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
  1281
                    hour := hour - tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1282
                    min := min - tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1283
                ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1284
                    c == $- ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1285
                        "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
  1286
                        hour := hour + tzh.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1287
                        min := min + tzmin.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1288
                    ] ifFalse:exceptionBlock
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1289
                ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1290
            ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1291
            "this is UTC time"
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1292
            newTime := self UTCYear:year month:month day:day
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1293
                              hour:hour minute:min second:sec millisecond:millis.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1294
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  1295
        newTime
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6047
diff changeset
  1296
    ] on:Error do:exceptionBlock.
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1297
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1298
    "
5656
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1299
     |s|
dbc52ea02716 Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents: 5572
diff changeset
  1300
     s := '' writeStream.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1301
     Timestamp now printGeneralizedOn:s.
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1302
     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
  1303
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1304
     Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1305
     Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1306
     Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[]
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  1307
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1308
 Daylight saving time:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1309
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1310
     Timestamp readGeneralizedFrom:'20000718120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1311
     Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1312
     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
  1313
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1314
 No daylight saving time:
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
     Timestamp readGeneralizedFrom:'20000202120000Z' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1317
     Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[]
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  1318
     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
  1319
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1320
     Timestamp readGeneralizedFrom:'19950220131106' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1321
     Timestamp readGeneralizedFrom:'199502201311' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1322
     Timestamp readGeneralizedFrom:'19950220131106.100' onError:[]
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1323
     Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1324
     Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1325
     Timestamp readGeneralizedFrom:'foo' onError:'wrong'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1326
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1327
     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
  1328
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1329
     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
  1330
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[]
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1331
     Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[]
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1332
    "
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1333
9619
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1334
    "Modified: / 13-07-1999 / 12:31:14 / stefan"
6f1fc553757f skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents: 9449
diff changeset
  1335
    "Modified: / 22-08-2006 / 12:30:11 / cg"
5292
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1336
!
a3936f79327b Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 5291
diff changeset
  1337
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1338
readISO8601From:aStringOrStream
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1339
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1340
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1341
    ^ self readIso8601FormatFrom:aStringOrStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1342
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1343
    "Created: / 16-06-2005 / 16:13:36 / masca"
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1344
    "Modified: / 09-02-2017 / 10:04:53 / stefan"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1345
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1346
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1347
readISO8601From:aStringOrStream onError:exceptionValue
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1348
    <resource: #obsolete>
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1349
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1350
    ^ self readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1351
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1352
    "Modified: / 09-02-2017 / 10:05:56 / stefan"
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1353
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1354
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1355
readIso8601FormatFrom:aStringOrStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1356
    "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
  1357
     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
  1358
     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
  1359
     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
  1360
     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
  1361
     Of course, a 24 hour clock is used.
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1362
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1363
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1364
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1365
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1366
    "changed to use the new reader"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1367
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1368
    ^ TimestampISO8601Builder read:aStringOrStream withClass:self
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1369
"/    ^ self
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1370
"/        readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1371
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1372
    "
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1373
     Timestamp readIso8601FormatFrom:'20141106T123843.299Z'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1374
     Timestamp readIso8601FormatFrom:'20141106T123843.299'
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1375
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1376
     Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1377
     Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1378
     Timestamp readIso8601FormatFrom:'1995T13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1379
     Timestamp readIso8601FormatFrom:'1995T13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1380
     Timestamp readIso8601FormatFrom:'1995T13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1381
     Timestamp readIso8601FormatFrom:'1995'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1382
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1383
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1384
     Timestamp readIso8601FormatFrom:'1995-02-20 13:11'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1385
     Timestamp readIso8601FormatFrom:'1995-02-20 13'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1386
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1387
     Timestamp readIso8601FormatFrom:'20141106T122831.894Z'
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  1388
6684
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1389
   24 is allowed with ISO, and is 00:00 of the next day:
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1390
     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
  1391
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1392
    "
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1393
!
1f4d15ab7c4c default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents: 6634
diff changeset
  1394
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1395
readIso8601FormatFrom:aStringOrStream onError:exceptionValue
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1396
    "return a new Timestamp, reading an iso8601 UTC representation from aStream.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1397
     Missing month/day values are replaced with 1; i.e. 1999T24:00
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1398
     is the same as 1999-01-01T24:00:00.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1399
     Missing minute, second and ms values are replaced with 0;
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1400
     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
  1401
     Of course, a 24 hour clock is used.
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1402
     On error, raise an exception.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1403
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1404
     Please use this format for all external representations - it's the standard."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1405
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1406
    "/ changed to use the new reader
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1407
    ^ [
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1408
        TimestampISO8601Builder read:aStringOrStream withClass:self
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1409
    ] on:ConversionError do:exceptionValue.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1410
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1411
"/    ^ self
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1412
"/        readIso8601FormatFrom:aStringOrStream
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1413
"/        yearAlreadyRead:nil
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1414
"/        onError:exceptionValue
21388
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1415
c2cb27ae6231 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21264
diff changeset
  1416
    "Modified: / 09-02-2017 / 10:02:03 / stefan"
8432
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1417
!
c6919af01ed6 + readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 8414
diff changeset
  1418
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1419
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1420
    "please use this only for http-requests.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1421
     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
  1422
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1423
     All HTTP/1.0 date/time stamps must be represented in Universal Time (UT),
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1424
     also known as Greenwich Mean Time (GMT), without exception.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1425
     This is indicated in the first two formats by the inclusion of
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1426
     'GMT' as the three-letter abbreviation for time zone,
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1427
     and should be assumed when reading the asctime format.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1428
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1429
     HTTP-date      = rfc1123-date | rfc850-date | asctime-date
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1430
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1431
     rfc1123-date   = wkday ',' SP date1 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1432
     rfc850-date    = weekday ',' SP date2 SP time SP 'GMT'
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1433
     asctime-date   = wkday SP date3 SP time SP 4DIGIT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1434
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1435
     date1          = 2DIGIT SP month SP 4DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1436
                      ; day month year (e.g., 02 Jun 1982)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1437
     date2          = 2DIGIT '-' month '-' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1438
                      ; day-month-year (e.g., 02-Jun-82)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1439
     date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1440
                      ; month day (e.g., Jun  2)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1441
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1442
     time           = 2DIGIT ':' 2DIGIT ':' 2DIGIT
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1443
                      ; 00:00:00 - 23:59:59
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1444
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1445
     wkday          = 'Mon' | 'Tue' | 'Wed'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1446
                    | 'Thu' | 'Fri' | 'Sat' | 'Sun'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1447
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1448
     weekday        = 'Monday' | 'Tuesday' | 'Wednesday'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1449
                    | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1450
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1451
     month          = 'Jan' | 'Feb' | 'Mar' | 'Apr'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1452
                    | 'May' | 'Jun' | 'Jul' | 'Aug'
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1453
                    | 'Sep' | 'Oct' | 'Nov' | 'Dec'
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1454
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1455
     Mon, 17 Aug 2009 11:11:15 GMT
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1456
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1457
     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
  1458
     thus, this also supports:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1459
         Mon, 17 Aug 2009 11:11:15 +xxxx
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1460
         Mon, 17 Aug 2009 11:11:15 -xxxx
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1461
     and:
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1462
         Mon, 17 Aug 2009 11:11:15 PST
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  1463
    "
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1464
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1465
    |parts indexModifier utcOffsetString utcOffset day year time monthName month|
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1466
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1467
    rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value].
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1468
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1469
    parts := rfc1123String asCollectionOfSubstringsSeparatedBy:Character space.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1470
    parts size == 6 ifTrue:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1471
        indexModifier := 0.
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1472
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1473
        parts size == 5 ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1474
            indexModifier := -1.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1475
        ] ifFalse:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1476
            ^ exceptionBlock value
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1477
        ].
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1478
    ].
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1479
11862
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1480
    day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1481
    year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1482
    time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock].
9c314f3a40df *** empty log message ***
sr
parents: 11857
diff changeset
  1483
    monthName := parts at:3 + indexModifier.
11847
5c7ecb05e744 *** empty log message ***
sr
parents: 11177
diff changeset
  1484
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1485
    month := Date indexOfMonth:monthName language:#en.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1486
    month = 0 ifTrue:[^ exceptionBlock value].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1487
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1488
    utcOffsetString := parts at:6 + indexModifier ifAbsent:nil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1489
    utcOffset := self utcOffsetFrom:utcOffsetString.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1490
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1491
    (utcOffset isNil or:[utcOffset = 0]) ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1492
        ^ 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
  1493
    ].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1494
    ^ TZTimestamp new 
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1495
            setOSTimeFromUTCYear:year month:month day:day hour:time hour minute:time minute second:time second millisecond:0;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1496
            utcOffset:utcOffset;
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1497
            addSeconds:utcOffset.
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1498
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1499
    "
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1500
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 GMT' onError:nil
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1501
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 UTC' onError:nil
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1502
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PST' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1503
     self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PDT' onError:nil
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1504
     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
  1505
     self readRFC1123FormatFrom:'17 Aug 2009 11:11:15 +0100' onError:nil
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1506
    "
13085
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1507
ee5674e04bd6 changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12939
diff changeset
  1508
    "Modified: / 05-10-2010 / 16:05:32 / cg"
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1509
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1510
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1511
timezoneInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1512
    "return a table containing timezone information.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1513
     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
  1514
     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
  1515
     representation, instead of using names.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  1516
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1517
     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
  1518
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1519
    "/ the table below can be customized via a setter,
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1520
    "/ if an application knows better 
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1521
    "/ (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
  1522
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1523
    TimeZoneInfo notNil ifTrue:[^ TimeZoneInfo].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1524
    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1525
    "/ table is name, utcOffset(minutes), DST-flag, startDay, endDay
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1526
    ^ #(
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1527
            'Z'     0   false          "/ zulu
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1528
            'UTC'   0   false    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1529
            'GMT'   0   false    
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1530
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1531
            "/ US
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1532
            'HAST' -600 false          "/ hawai standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1533
            'AKST' -540 false          "/ alaska standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1534
            'YST'  -540 false          "/ yukon standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1535
            'PST'  -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1536
            'PT'   -480 false          "/ pacific standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1537
            'MST'  -420 false          "/ mountain standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1538
            'CST'  -360 false          "/ central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1539
            'EST'  -300 false          "/ eastern standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1540
            'AST'  -240 false          "/ atlantic standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1541
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1542
            'NST'  -210 false          "/ new foundland standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1543
            'PMST' -180 false          "/ pierre & miquelon
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1544
            'WGT'  -180 false          "/ west greenland
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1545
            'EGT'  -60  false          "/ east greenland
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1546
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1547
            "/ europe
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1548
            'CET'   60  false          "/ central european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1549
            'EET'   120 false          "/ east european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1550
            'WET'   0   false          "/ west european
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1551
            "/ conflict with india!!
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1552
            "/ 'IST'   1               "/ irish standard time
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1553
            "/ 'IST'   1               "/ israel standard time
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1554
            'AZOT'   -60 false         "/ azores standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1555
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1556
            'MSK'   240 false          "/ moscow european
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1557
            'MSD'   240 false
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1558
            'BT'    240 false          "/ baghdad
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1559
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1560
            "/ pacific
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1561
            'NZST'  720 false          "/ new zealand standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1562
            'FJT'   720 false          "/ fiji
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1563
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1564
            "/ south america
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1565
            'ART'   -180 false         "/ argentina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1566
            'BOT'   -240 false         "/ bolivia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1567
            'BRT'   -180 false         "/ brasilia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1568
            'CLT'   -240 false         "/ chile
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1569
            'ECT'   -300 false         "/ equador
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1570
            'PET'   -300 false         "/ peru
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1571
            'PYT'   -240 false         "/ paraguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1572
            'UYT'   -180 false         "/ uruguay
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1573
            'VET'   -270 false         "/ venezuela standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1574
            'VST'   -270 false         "/ venezuela standard
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1575
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1576
            "/ africa
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1577
            'CAT'   120 false          "/ central africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1578
            'EAT'   180 false          "/ east africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1579
            'SAST'  120 false          "/ south africa standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1580
            'WAT'   60 false           "/ west africa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1581
            'WT'    0 false            "/ west sahara standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1582
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1583
            'AST'   180 false          "/ arabia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1584
            'IRT'   210 false          "/ iran time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1585
            'AFT'   270 false          "/ afghanistan time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1586
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1587
            'HKT'   480 false          "/ hongkong
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1588
            'IST'   330 false          "/ india standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1589
            'ICT'   420 false          "/ indochina
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1590
            'CNST'  480 false          "/ china standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1591
            'JST'   540 false          "/ japan standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1592
            'KST'   540 false          "/ korea standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1593
            'SGT'   480 false          "/ singapore
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1594
            'MYT'   480 false          "/ malaysia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1595
            'AWST'  480 false          "/ australian west standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1596
            'ACWST' 525 false          "/ australian central western standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1597
            'ACST'  570 false          "/ australian central standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1598
            'AEST'  600 false          "/ australian east standard
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1599
            'NFT'   690 false          "/ norfolk island, australia
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1600
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1601
            'CHAST' 765 false          "/ chatham island standard
20429
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1602
            'WST'   780 false          "/ west samoa - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1603
            'TOT'   780 false          "/ tonga - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1604
            'TKT'   780 false          "/ tokelau - yes that's 13!!
59f334459ad9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19923
diff changeset
  1605
            'LINT'  840 false          "/ line islands - yes that's 14!!
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1606
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1607
            "/ misc
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1608
            'IDLW' -720 false          "/ international date line west
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1609
            'IDLE'  720 false          "/ international date line east
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1610
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  1611
            'MEZ'   60  false           "/ mittel europäische Zeit /  central european (german)
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1612
            'MESZ'  120 true            "/ central european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1613
            'WESZ'  60  true            "/ west european summer (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1614
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1615
            'WEZ'   0   false           "/ west european (german)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1616
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1617
            'HADT'  -540 true           "/ hawaii summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1618
            'ADT'   -180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1619
            'AKDT'  -540 true         "/ alaska summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1620
            'YDT'   -480 true         "/ yukon summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1621
            'PDT'   -420 true         "/ pacific daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1622
            'MDT'   -360 true         "/ mountain daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1623
            'CDT'   -300 true         "/ central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1624
            'EDT'   -240 true         "/ eastern daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1625
            'CLST'  -180 true         "/ chile summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1626
            'NDT'   -150 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1627
            'PMDT'  -120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1628
            'BRST'  -120 true         "/ brasilia summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1629
            'WGST'  -120 true         "/ west greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1630
            'EGST'   0 true           "/ east greenland summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1631
            'AZOST'  0 true           "/ azores summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1632
            'EEST'   180 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1633
            'CEST'   120 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1634
            'WAST'   120 true         "/ west africa summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1635
            "/ 'WST'   60 true        "/ west sahara summer - conflict with west samoa
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1636
            'WEST'  60 true
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1637
            'BST'   60 true           "/ british summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1638
            'IRST'  270 true          "/ iran summer time
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1639
            'AWDT'  540 true          "/ australian west daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1640
            'ACDT'  630 true          "/ australian central daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1641
            'AEDT'  660 true          "/ australian east daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1642
            'CHADT' 825 true          "/ chatham island daylight saving
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1643
            'FJST'  780 true          "/ fiji summer
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1644
            'NZDT'  780 true          "/ new zealand summer
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1645
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1646
            "/ military
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1647
            'A'     60  false          "/ alpha
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1648
            'B'     120 false          "/ bravo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1649
            'C'     180 false          "/ charlie
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1650
            'D'     240 false          "/ delta
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1651
            'E'     300 false          "/ echo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1652
            'F'     360 false          "/ foxtrot
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1653
            'G'     420 false          "/ golf
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1654
            'H'     480 false          "/ hotel
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1655
            'I'     540 false          "/ also called india - how misleading
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1656
            'K'     600 false          "/ kilo
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1657
            'L'     660 false          "/ lima - but not there
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1658
            'M'     720 false          "/ mike
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1659
            'N'     -60  false         "/ november (but also in other months)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1660
            'O'     -120 false         "/ oscar
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1661
            'P'     -180 false         "/ papa (not mama)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1662
            'Q'     -240 false         "/ quebec - really?
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1663
            'R'     -300 false         "/ romeo and juliet
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1664
            'S'     -360 false         "/ sierra
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1665
            'T'     -420 false         "/ tango (& not rumba)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1666
            'U'     -480 false         "/ uniform
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1667
            'V'     -540 false         "/ victor
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1668
            'W'     -600 false         "/ whiskey (scotch?)
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1669
            'X'     -660 false         "/ xray
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1670
            'Y'     -720 false         "/ yankee
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1671
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1672
        ).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1673
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1674
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1675
utcOffsetFrom:aStringOrStream
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1676
    "return the utcOffset (in seconds) for a given time-zone name.
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1677
     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
  1678
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1679
     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
  1680
     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
  1681
     in timeStamp and OperatingSystem-timeInfo will be.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1682
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1683
     If utcOffset is negative, the local timezone is east of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1684
     If utcOffset is positive, the local timezone is west of Greenwich.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1685
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1686
     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
  1687
     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
  1688
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1689
    |ch offset stream|
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1690
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1691
    stream := aStringOrStream readStream.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1692
    stream skipSeparators.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1693
17079
76e263370574 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17071
diff changeset
  1694
    ch := stream peekOrNil.
76e263370574 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17071
diff changeset
  1695
    ch isNil ifTrue:[^ 0].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1696
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1697
    ch isLetter ifTrue:[
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1698
        |table tzName i minuteOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1699
        
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1700
        table := self timezoneInfo.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1701
        tzName := stream upToElementForWhich:[:ch | ch isLetter not].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1702
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1703
        i := table indexOf:tzName.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1704
        i == 0 ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1705
            ^ nil
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1706
        ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1707
        minuteOffset := (table at:i+1).
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  1708
        offset := minuteOffset * 60
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1709
    ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1710
        |sign|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1711
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1712
        sign := 1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1713
        ch == $- ifTrue:[
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1714
            sign := -1.
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1715
            stream next.
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1716
        ] ifFalse:[ch == $+ ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1717
            stream next.
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1718
        ] ifFalse:[
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1719
            stream skipSeparators
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1720
        ]].
17172
86f49d251345 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17142
diff changeset
  1721
        stream peekOrNil isDigit ifFalse:[^ nil].
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1722
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1723
        offset := ((stream next:2) asNumber * 60 * 60).
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1724
        ch := stream peekOrNil.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1725
        ch notNil ifTrue:[
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1726
            ch == $: ifTrue:[ stream next ].
17071
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1727
            offset := offset + ((stream next:2) asNumber * 60).
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1728
        ].
3d4803aa1b4f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17067
diff changeset
  1729
        offset := offset * sign
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1730
    ].
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1731
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  1732
    "/ 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
  1733
    ^ offset negated
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1734
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1735
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1736
     self utcOffsetFrom:'UTC'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1737
     self utcOffsetFrom:'PST'
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1738
     self utcOffsetFrom:'EST'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1739
     self utcOffsetFrom:'CET'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1740
     self utcOffsetFrom:'+0130'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1741
     self utcOffsetFrom:'+01:30'
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  1742
     self utcOffsetFrom:'+1:30'
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1743
     self utcOffsetFrom:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1744
    "
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1745
!
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1746
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1747
utcOffsetFromString:aString
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1748
    <resource: #obsolete>
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1749
    "return the utcOffset (in seconds) for a given time-zone name.
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1750
     Returns nil for invalid formats"
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1751
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  1752
    ^ self utcOffsetFrom:aString
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1753
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1754
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1755
     self utcOffsetFromString:'UTC'
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1756
     self utcOffsetFromString:'+01'
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  1757
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1758
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  1759
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1760
!Timestamp methodsFor:'Compatibility-ST80'!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1761
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1762
hour
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1763
    "return the hour (0..23).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1764
     ST-80 Timestamp compatibility 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1765
     (I'd prefer the name #hours, for Time compatibility)."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1766
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1767
    ^ self hours
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1768
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1769
    "Created: 1.7.1996 / 15:14:50 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1770
    "Modified: 1.7.1996 / 15:15:32 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1771
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1772
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1773
minute
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1774
    "return the minute (0..59).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1775
     ST-80 Timestamp compatibility 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1776
     (I'd prefer the name #minutes, for Time compatibility)."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1777
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1778
    ^ self minutes
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1779
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1780
    "Created: 1.7.1996 / 15:14:29 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1781
    "Modified: 1.7.1996 / 15:15:37 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1782
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1783
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1784
second
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1785
    "return the second (0..59).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1786
     ST-80 Timestamp compatibility 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1787
     (I'd prefer the name #seconds, for Time compatibility)."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1788
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1789
    ^ self seconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1790
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1791
    "Created: 1.7.1996 / 15:14:19 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1792
    "Modified: 1.7.1996 / 15:15:49 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1793
! !
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1794
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1795
!Timestamp methodsFor:'accessing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1796
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1797
day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1798
    "return the day-in-month of the receiver (1..31).
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  1799
     For compatibility, use instances of Date for this."
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  1800
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1801
    ^ self asDate day.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1802
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1803
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1804
     Timestamp now day
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1805
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1806
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1807
    "Modified: 1.7.1996 / 15:23:02 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1808
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1809
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1810
dayInWeek
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  1811
    "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
  1812
     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
  1813
     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
  1814
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1815
    ^ self asDate dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1816
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1817
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1818
     Timestamp now dayInWeek
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1819
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1820
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1821
    "Modified: 2.7.1996 / 09:20:32 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1822
    "Created: 2.7.1996 / 09:35:48 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1823
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1824
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1825
dayInYear
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1826
    "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
  1827
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1828
    ^ self asDate dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1829
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1830
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1831
     Timestamp now dayInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1832
     (Timestamp newDay:184 year:1996) dayInYear
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1833
    "
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1834
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1835
    "Modified: 2.7.1996 / 10:21:02 / cg"
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1836
!
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1837
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1838
dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1839
    "Answer the day of the month represented by me.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1840
     Same as day; for ST-80 compatibility."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1841
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1842
    ^ self asDate dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1843
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1844
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1845
     Timestamp now dayOfMonth
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1846
     (Timestamp newDay:184 year:1996) dayOfMonth
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1847
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1848
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1849
    "Created: / 20-01-2011 / 12:26:54 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1850
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1851
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1852
dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1853
    "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
  1854
     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
  1855
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1856
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1857
    ^ self asDate dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1858
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1859
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1860
     Timestamp now dayOfWeek
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1861
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1862
!
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  1863
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1864
dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1865
    "return the week-day of the receiver as a string.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1866
     The returned string depends on the language setting.
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1867
     Expect things like 'monday', 'tuesday' ..."
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1868
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1869
    ^ self asDate dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1870
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1871
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1872
     Timestamp now dayOfWeekName
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1873
     (Timestamp newDay:184 year:1996) dayOfWeekName
13225
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1874
    "
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1875
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1876
    "Created: / 20-01-2011 / 12:28:46 / cg"
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1877
!
Claus Gittinger <cg@exept.de>
parents: 13200
diff changeset
  1878
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1879
hours
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1880
    "return the hours (0..23)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1881
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1882
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1883
	^ self asTime hours.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1884
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1885
    ^ self timeInfo hours
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  1886
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1887
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1888
     Timestamp now hours
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1889
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1890
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1891
    "Modified: 2.7.1996 / 09:20:32 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1892
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1893
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1894
microseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1895
    "return the microseconds within the stamp's second (0..999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1896
     notice: that is NOT the total number of microseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1897
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1898
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1899
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1900
    |microsFromMillis|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1901
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1902
    microsFromMillis := (osTime \\ 1000) * 1000.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1903
    additionalPicoseconds notNil ifTrue:[
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1904
        ^ microsFromMillis + (additionalPicoseconds // (1000*1000))
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1905
    ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1906
    ^ microsFromMillis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1907
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1908
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1909
     Timestamp now microseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1910
     Timestamp nowWithMicroseconds microseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1911
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1912
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1913
     t1 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1914
     t2 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1915
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1916
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1917
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1918
     t1 := Timestamp now microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1919
     t2 := Timestamp nowWithMicroseconds microseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1920
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1921
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1922
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1923
    "Created: 1.7.1996 / 15:15:02 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1924
    "Modified: 2.7.1996 / 09:21:41 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1925
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1926
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1927
millisecond
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  1928
    "return the millisecond within the stamp's second (0..999).
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1929
     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1930
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1931
    ^ self milliseconds
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1932
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1933
    "Created: 1.7.1996 / 15:14:50 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1934
    "Modified: 1.7.1996 / 15:15:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1935
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1936
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1937
milliseconds
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  1938
    "return the milliseconds within the stamp's second (0..999)"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1939
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1940
    ^ osTime \\ 1000.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1941
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1942
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1943
     Timestamp now milliseconds
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1944
    "
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1945
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1946
    "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
  1947
    "Modified: 2.7.1996 / 09:21:41 / cg"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1948
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1949
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1950
minutes
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1951
    "return the minutes (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1952
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1953
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1954
	^ self asTime minutes.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1955
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1956
    ^ self timeInfo minutes
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1957
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1958
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  1959
     Timestamp now minutes
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  1960
    "
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1961
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  1962
    "Modified: 2.7.1996 / 09:20:49 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1963
!
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  1964
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1965
month
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1966
    "return the month of the receiver (1..12).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1967
     For compatibility, use instances of Date for this."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1968
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1969
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  1970
	^ self asDate month.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  1971
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  1972
    ^ self timeInfo month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1973
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1974
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  1975
     Timestamp now month
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1976
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1977
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1978
    "Modified: 1.7.1996 / 15:23:05 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1979
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1980
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1981
monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1982
    "return the month of the receiver (1..12).
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1983
     For compatibility"
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1984
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1985
    ^ self asDate monthIndex.
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1986
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1987
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1988
     Timestamp now monthIndex
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1989
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1990
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  1991
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1992
nanoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1993
    "return the nanoseconds within the stamp's second (0..999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1994
     notice: that is NOT the total number of nanoseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1995
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1996
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1997
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1998
    |nanosFromMillis|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  1999
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2000
    nanosFromMillis := (osTime \\ 1000) * (1000 * 1000).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2001
    additionalPicoseconds notNil ifTrue:[
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2002
        ^ nanosFromMillis + (additionalPicoseconds // 1000)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2003
    ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2004
    ^ nanosFromMillis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2005
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2006
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2007
     Timestamp now nanoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2008
     Timestamp nowWithMicroseconds nanoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2009
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2010
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2011
     t1 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2012
     t2 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2013
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2014
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2015
     |t1 t2|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2016
     t1 := Timestamp now nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2017
     t2 := Timestamp nowWithMicroseconds nanoseconds.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2018
     t2-t1
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2019
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2020
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2021
    "Created: 1.7.1996 / 15:15:02 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2022
    "Modified: 2.7.1996 / 09:21:41 / cg"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2023
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2024
8286
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2025
osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2026
    "get the internal representation of the time.
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2027
     Warning: do not depend on the value (unix vs. win32 - differences)"
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2028
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2029
    ^ osTime
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2030
!
d4c7d4d34b8b osTime getter
werner
parents: 8271
diff changeset
  2031
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  2032
osTime:aTime
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  2033
    "set the internal representation of the time"
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  2034
4807
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  2035
    osTime := aTime.
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  2036
!
Claus Gittinger <cg@exept.de>
parents: 4679
diff changeset
  2037
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2038
picoseconds
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2039
    "return the picoseconds within the stamp's second (0..999999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2040
     notice: that is NOT the total number of picoseconds,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2041
     but the fractional part (within the second) only. 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2042
     Use this only for printing."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2043
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2044
    |picosFromMillis|
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2045
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2046
    picosFromMillis := (osTime \\ 1000) * (1000 * 1000 * 1000).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2047
    ^ picosFromMillis + (additionalPicoseconds ? 0)
22613
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2048
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2049
    "
875197e3bb08 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22337
diff changeset
  2050
     Timestamp now picoseconds
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  2051
     Timestamp nowWithMicroseconds picoseconds
22614
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2052
    "
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2053
!
369da8fe40ea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22613
diff changeset
  2054
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2055
seconds
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2056
    "return the seconds (0..59)"
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2057
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2058
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2059
	^ self asTime seconds.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2060
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2061
    ^ self timeInfo seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2062
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2063
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2064
     Timestamp now seconds
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2065
    "
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2066
1513
a4b4c4ce039c added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents: 1501
diff changeset
  2067
    "Modified: 2.7.1996 / 09:20:54 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2068
!
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2069
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2070
timeZoneDeltaInMinutes
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2071
    "answer the number of minutes between local time and utc time.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2072
     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
  2073
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2074
    ^ self utcOffset negated // 60
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2075
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2076
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2077
     Timestamp now timeZoneDeltaInMinutes
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2078
     (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
  2079
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2080
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2081
    "Modified: 20.12.1995 / 17:28:49 / stefan"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2082
    "Modified: 1.7.1996 / 15:21:29 / cg"
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2083
!
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2084
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2085
timeZoneName
16990
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2086
    "find the first zone which is in this range.
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2087
     This is a bit naive, but should be sufficient in most cases
749d20608f8d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16989
diff changeset
  2088
     (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
  2089
      of that particular year...)"
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2090
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2091
    |myUtcOffset iAmDST bestNonDST|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2092
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2093
    myUtcOffset := self utcOffset negated.
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2094
    iAmDST := self timeInfo dst ? false.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2095
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2096
    bestNonDST := nil.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2097
    self class timezoneInfo inGroupsOf:3 do:[:name :offsetInMinutes :isDST|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2098
        |thisUtcOffset|
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2099
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2100
        thisUtcOffset := offsetInMinutes * 60.
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2101
        thisUtcOffset = myUtcOffset ifTrue:[
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2102
            isDST == iAmDST ifTrue:[^ name ].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2103
        ].    
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2104
        bestNonDST := name.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2105
    ].
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2106
    bestNonDST notNil ifTrue:[^ bestNonDST].
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2107
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2108
    "/ nothing found - construct a standard offset string
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2109
    ^ ((self utcOffset > 0) ifTrue:['+'] ifFalse:['-'])
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2110
      , ((myUtcOffset abs // 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2111
      , ((myUtcOffset abs \\ 60) printStringLeftPaddedTo:2 with:$0)
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2112
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2113
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2114
     Timestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2115
     UtcTimestamp now timeZoneName
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2116
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2117
     (Timestamp now asTZTimestampInZone:'MEZ') timeZoneName - will find international name
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2118
     (Timestamp now asTZTimestampInZone:'EST') timeZoneName
19624
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2119
     (Timestamp now asTZTimestampInZone:'IDLE') timeZoneName - sorry - will find 'NZST'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2120
     (Timestamp now asTZTimestampInZone:'BRST') timeZoneName - sorry: will find military 'O'
608491d45d05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 18886
diff changeset
  2121
     (Timestamp now asTZTimestampInZone:'MYT') timeZoneName - will find hongkong; same timezone
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2122
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2123
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2124
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2125
utcOffset
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2126
    "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
  2127
     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
  2128
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2129
     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
  2130
     Subtract utcOffset to convert from UTC time to local time.
8886
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2131
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2132
     If utcOffset is negative, the local timezone is east of Greenwich.
89cb1f2de1c7 Comment for #utcOffset
Stefan Vogel <sv@exept.de>
parents: 8822
diff changeset
  2133
     If utcOffset is positive, the local timezone is west of Greenwich."
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2134
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2135
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2136
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2137
	"/ 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
  2138
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2139
	^ self utcOffsetWithoutDst.
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2140
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2141
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2142
    ^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2143
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2144
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2145
     Timestamp now utcOffset
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2146
     (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
  2147
     (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
  2148
     (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
  2149
     (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
  2150
    "
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2151
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2152
    "Modified: 20.12.1995 / 17:28:49 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2153
    "Modified: 1.7.1996 / 15:21:29 / cg"
799
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2154
!
33cf42458eee New Method utcOffset
Stefan Vogel <sv@exept.de>
parents: 795
diff changeset
  2155
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2156
utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2157
    "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
  2158
     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
  2159
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2160
     Add utcOffset to convert from local time to UTC time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2161
     Subtract utcOffset to convert from UTC time to local time.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2162
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2163
     If utcOffset is negative, the local timezone is east of Greenwich.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2164
     If utcOffset is positive, the local timezone is west of Greenwich."
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2165
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2166
    |offset epochInfo|
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2167
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2168
    offset := 0.
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2169
    [
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2170
	"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
  2171
	epochInfo := OperatingSystem timeInfoFromSeconds:offset milliseconds:0 localTime:true.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2172
	offset := offset + (3600 * 24 * 90). "Add about 3 months"
17031
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2173
    ] doWhile:[epochInfo dst and:[offset < (3600 * 24 * 365) "avoid endless loop"]].
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2174
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2175
    ^ epochInfo utcOffset
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2176
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2177
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2178
     Timestamp now utcOffsetWithoutDst
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2179
    "
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2180
!
d443175f7558 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17026
diff changeset
  2181
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2182
weekInYear
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2183
    "return the week number of the receiver - 1 for Jan, 1st."
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2184
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2185
    ^ Date weekInYearOf:self
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2186
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2187
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2188
     (Timestamp newDay:1 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2189
     (Timestamp newDay:2 year:2000) weekInYear
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2190
     (Timestamp newDay:3 year:2000) weekInYear
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2191
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2192
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2193
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2194
weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2195
    "return the week-day of the receiver as a string.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2196
     The returned string depends on the current language setting.
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2197
     Expect things like 'monday', 'tuesday' ...
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2198
     For ST-80 compatibility"
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2199
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2200
    ^ self asDate weekday
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2201
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2202
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2203
     Timestamp now weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2204
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2205
     but maybe a different day there, in the south pacific:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2206
     (Timestamp now asTZTimestampInZone:'LINT') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2207
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2208
     but maybe a different day there, in alaska:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2209
     (Timestamp now asTZTimestampInZone:'AKST') weekday
16993
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2210
    "
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2211
!
ff9bcbfea867 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16992
diff changeset
  2212
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2213
year
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2214
    "return the year of the receiver i.e. 1992.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2215
     For compatibility, use instances of Date for this."
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2216
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2217
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2218
	^ self asDate year.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2219
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2220
    ^ self timeInfo year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2221
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2222
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2223
     Timestamp now year
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2224
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2225
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2226
    "Modified: 1.7.1996 / 15:23:08 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2227
! !
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2228
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2229
!Timestamp methodsFor:'arithmetic'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2230
13199
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2231
ceilingSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2232
    "return a timestamp which represents the next full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2233
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2234
    |offs|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2235
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2236
    offs := (self milliseconds / 1000) ceiling.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2237
    ^ self class basicNew setSeconds:(self getSeconds + offs).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2238
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2239
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2240
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2241
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2242
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2243
     t2 := t1 ceilingSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2244
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2245
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2246
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2247
    "Created: / 08-01-2011 / 16:23:03 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2248
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2249
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2250
floorSecond
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2251
    "return a timestamp truncated to the last full second"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2252
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2253
    ^ self class basicNew setSeconds:(self getSeconds).
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2254
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2255
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2256
     |t1 t2|
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2257
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2258
     t1 := Timestamp now.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2259
     t2 := t1 floorSecond.
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2260
     self halt
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2261
    "
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2262
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2263
    "Created: / 08-01-2011 / 16:20:55 / cg"
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2264
!
Claus Gittinger <cg@exept.de>
parents: 13198
diff changeset
  2265
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2266
millisecondDeltaFrom:aTimestamp
3510
75824285fe74 comment
Claus Gittinger <cg@exept.de>
parents: 3479
diff changeset
  2267
    "return the delta in milliseconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2268
     The argument is supposed to be BEFORE the receiver,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2269
	computes self - aTimestamp"
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2270
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2271
    ^ self getMilliseconds - (aTimestamp getMilliseconds)
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2272
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2273
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2274
     |t1 t2|
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2275
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2276
     t1 := Timestamp now.
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2277
     Delay waitForSeconds:0.5.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2278
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2279
     t2 millisecondDeltaFrom:t1
2623
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2280
    "
593ab389efd1 added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2281
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2282
    "Modified: / 10-07-2010 / 09:37:18 / cg"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2283
!
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2284
13200
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2285
roundedToSecond
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2286
    "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
  2287
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2288
    |offs|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2289
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2290
    offs := (self milliseconds / 1000) rounded.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2291
    ^ self class basicNew setSeconds:(self getSeconds + offs).
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2292
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2293
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2294
     |t1 t2|
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2295
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2296
     t1 := Timestamp now.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2297
     t2 := t1 roundedToSecond.
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2298
     self halt
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2299
    "
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2300
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2301
    "Created: / 08-01-2011 / 16:24:12 / cg"
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2302
!
744f5c0783f7 added: #roundedToSecond
Claus Gittinger <cg@exept.de>
parents: 13199
diff changeset
  2303
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2304
secondDeltaFrom:aTimestamp
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2305
    "return the delta in seconds between 2 absolute times.
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2306
     The argument is supposed to be BEFORE the receiver,
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2307
	computes self - aTimestamp"
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2308
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2309
    ^ self getSeconds - (aTimestamp getSeconds)
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2310
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2311
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2312
     |t1 t2|
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2313
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2314
     t1 := Timestamp now.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2315
     Delay waitForSeconds:5.
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2316
     t2 := Timestamp now.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2317
     t2 secondDeltaFrom:t1
9056
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2318
    "
d284a6514312 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8888
diff changeset
  2319
12939
aa4983b38cbf comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12830
diff changeset
  2320
    "Modified: / 10-07-2010 / 09:37:24 / cg"
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2321
! !
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2322
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2323
!Timestamp methodsFor:'comparing'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2324
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2325
= aTimestamp
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2326
    "return true if the argument, aTime represents the same time.
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2327
     Notice: you can compare timestamps from different timezones for representing the
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2328
     same time, because they all store their milliseconds internally as utc time"
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2329
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2330
    aTimestamp isTimestamp ifFalse:[^ false].
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2331
    ^ (self getMilliseconds = aTimestamp getMilliseconds)
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2332
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2333
    "Modified: 3.7.1996 / 13:10:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2334
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2335
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2336
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2337
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2338
1520
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2339
    ^ osTime // 1000
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2340
da08f8e49e87 fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents: 1513
diff changeset
  2341
    "Modified: 3.7.1996 / 13:10:52 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2342
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2343
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2344
!Timestamp methodsFor:'converting'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2345
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2346
asDate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2347
    "return a Date object from the receiver.
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2348
     The returned date will only represent the day - not the timeOfDay.
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2349
     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
  2350
     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
  2351
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2352
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2353
	|milliDelta dayDelta|
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2354
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2355
	"/ 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
  2356
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2357
	milliDelta := osTime - (1000 * self utcOffsetWithoutDst).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2358
	dayDelta := milliDelta // (24 * 3600 * 1000).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2359
	^ Epoch asDate addDays:dayDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2360
    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2361
    ^ self timeInfo asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2362
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2363
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2364
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2365
     Timestamp now asDate
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2366
     (Timestamp now addTime:3600) asDate
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2367
     (Timestamp now addTime:3600) asTime
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2368
     Timestamp fromSeconds:(Timestamp now asSeconds + 3600)
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2369
     (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2370
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2371
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2372
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2373
asLocalTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2374
    "represent myself as a timestamp in the local timezone"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2375
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2376
    ^ self
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2377
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2378
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2379
     Timestamp now asUtcTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2380
     Timestamp now asUtcTimestamp asLocalTimestamp
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2381
    "
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2382
!
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2383
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2384
asTZTimestamp
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2385
    "return a timestamp which represents the very same time,
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2386
     but will represent itself as a timestamp with the local utcOffset.
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2387
     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
  2388
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2389
    ^ self asTZTimestamp:self utcOffset
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2390
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2391
    "see the different printStrings of:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2392
	 Timestamp now
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2393
     and
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2394
	 Timestamp now asTZTimestamp
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2395
    "
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2396
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2397
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2398
asTZTimestamp:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2399
    "return a timestamp which represents the very same time,
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2400
     but will represent itself as a timestamp with the given utcOffset"
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2401
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2402
    ^ (TZTimestamp fromOSTime:osTime) utcOffset:utcOffset
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2403
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2404
    "what is the time now in NewYork?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2405
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2406
     Timestamp now asTZTimestampInZone:'EST'
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2407
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2408
     what is the time now in Stuttgart?
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2409
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2410
     Timestamp now asTZTimestampInZone:'MEZ'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2411
    "
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2412
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2413
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2414
asTZTimestampInZone:timeZoneName
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2415
    "return a timestamp which represents the very same time,
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2416
     but will represent itself as a timestamp in the given timezone.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2417
     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
  2418
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2419
    |utcOffset|
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2420
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2421
    utcOffset := self class utcOffsetFrom:timeZoneName.
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2422
    utcOffset isNil ifTrue:[
17132
01e2272e7912 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17131
diff changeset
  2423
        ^ TimeConversionError raiseRequestWith:self errorString:(' - Invalid/unknown timzone: %1' bindWith:timeZoneName)
17081
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2424
    ].
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2425
410da5291dea class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17079
diff changeset
  2426
    ^ self asTZTimestamp:utcOffset
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2427
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2428
    "what is the time now in NewYork?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2429
       Timestamp now asTZTimestampInZone:'EST'
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2430
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2431
     what is the time now in Stuttgart?
17133
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2432
       Timestamp now asTZTimestampInZone:'MEZ'
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2433
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2434
     an error os raised for any unknown/invalid timezone:
397cf32b70f2 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17132
diff changeset
  2435
       Timestamp now asTZTimestampInZone:'BlaBla'
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2436
    "
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2437
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2438
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2439
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2440
    "return a Time object from the receiver.
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  2441
     The returned time will only represent the timeOfDay - not the day,
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2442
     and does not include the milliseconds."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2443
16932
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2444
    |secondDelta|
320e471e5dbc class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16930
diff changeset
  2445
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2446
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2447
	secondDelta := osTime // 1000.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2448
	"/ 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
  2449
	"/ Take the utcOffset without DST
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2450
	secondDelta := (secondDelta - self utcOffsetWithoutDst) \\ (24*3600).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2451
	^ Epoch asTime addSeconds:secondDelta.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2452
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2453
    ^ self timeInfo asTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2454
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2455
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2456
     Timestamp now
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2457
     Timestamp now asTime
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2458
     UtcTimestamp now asTime
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2459
     (Timestamp now addTime:3600) asTime
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2460
     (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
  2461
     (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
  2462
    "
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2463
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2464
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2465
asTimeWithMilliseconds
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2466
    "return a Time object from the receiver.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2467
     The returned time will only represent the timeOfDay - not the day,
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2468
     it will include the milliseconds."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2469
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2470
    |milliSecondDelta|
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2471
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2472
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2473
	milliSecondDelta := osTime - (self utcOffset * 1000).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2474
	^ self class epoch asTime addMilliseconds:milliSecondDelta.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2475
    ].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2476
    ^ self timeInfo asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2477
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2478
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2479
     Timestamp now
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2480
     Timestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2481
     UtcTimestamp now asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2482
     (Timestamp now addTime:3600) asTime
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2483
     (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
  2484
     (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
  2485
    "
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2486
!
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2487
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2488
asTimestamp
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2489
    "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
  2490
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2491
    ^ self
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2492
!
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2493
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2494
asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2495
    ^ self asUtcTimestamp
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2496
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2497
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2498
     Timestamp now
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2499
     Timestamp now asUTC
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2500
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2501
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2502
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2503
asUtcTimestamp
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2504
    "return a timestamp which represents the very same timestamp,
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2505
     but will represent itself as a timestamp in the UTC timezone"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2506
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2507
    ^ UtcTimestamp fromOSTime:osTime
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2508
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2509
    "
11003
ffb8be9eb6ac +asLocalTimestamp
Claus Gittinger <cg@exept.de>
parents: 10736
diff changeset
  2510
     Timestamp now asUtcTimestamp
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2511
     Timestamp now asUtcTimestamp asLocalTimestamp
9402
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2512
    "
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2513
!
39ea6523196d new: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 9385
diff changeset
  2514
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2515
literalArrayEncoding
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2516
    "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
  2517
     can be reconstructed with #decodeAsLiteralArray.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2518
     The encoding is:
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2519
        (#Timestamp YYYYMMDDhhmmss.iiiZ)
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2520
    "
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2521
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2522
    |s|
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2523
8223
56da5d8f8bc1 replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents: 8111
diff changeset
  2524
    s := WriteStream on:(String new:18).
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2525
    self printGeneralizedOn:s isLocal:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2526
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2527
    ^ Array
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2528
        with:self class name
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2529
        with:s contents
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2530
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2531
    "
9416
f57d66ea3bae Fix comments.
Stefan Vogel <sv@exept.de>
parents: 9402
diff changeset
  2532
      Timestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2533
        decodeAsLiteralArray
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  2534
      UtcTimestamp now literalArrayEncoding
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2535
        decodeAsLiteralArray
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2536
    "
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2537
!
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2538
18886
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2539
utcOffset:anOffset
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2540
   "answer a DateTime equivalent to the receiver but offset from UTC by offset"
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2541
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2542
    ^ TZTimestamp new 
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2543
        osTime:osTime;
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2544
        utcOffset:(anOffset asTimeDuration)  
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2545
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2546
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2547
     Timestamp now  -- now as local time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2548
     Timestamp now asTZTimestamp -- now in your local timezone
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2549
     Timestamp now asUtcTimestamp -- now in greenwich
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2550
     UtcTimestamp now -- now in greenwich
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2551
     Timestamp now utcOffset:(-2 hours)2015-11-09 17:29:35.803+02 -- now in East Europe
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2552
     Timestamp now utcOffset:(5 hours) -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2553
     Timestamp now asTZTimestampInZone:'EST' -- now in Eastern time
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2554
    "
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2555
!
abf121c38718 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18761
diff changeset
  2556
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2557
utcSecondsSince1901
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2558
    "return the number of seconds elapsed since Jan, 1st 1901"
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2559
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2560
"
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2561
    secondsBetween1901and1970 :=
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2562
	((Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901))
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2563
	*  (24 * 60 * 60)
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  2564
"
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2565
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2566
    ^ self utcSecondsSince1970 + 2177452800.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2567
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2568
    "
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2569
     Timestamp now utcSecondsSince1901
7006
8813a36f7645 checkin from browser
penk
parents: 7004
diff changeset
  2570
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2571
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2572
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2573
!Timestamp methodsFor:'initialization'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2574
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2575
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
  2576
    "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
  2577
     given y,m,d and h,m,s in my time."
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2578
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2579
    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
  2580
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2581
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2582
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
  2583
    "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
  2584
     given y,m,d and h,m,s in local time"
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2585
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2586
    Error handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2587
        "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
  2588
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2589
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2590
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2591
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2592
        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
  2593
        "/ 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
  2594
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2595
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2596
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2597
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2598
        osTime := osTime + millis.
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2599
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2600
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2601
                computeOSTimeFromUTCYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2602
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2603
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2604
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2605
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2606
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2607
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
  2608
    "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
  2609
     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
  2610
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  2611
    TimeConversionError handle:[:ex |
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2612
        "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
  2613
         Then, an out-of-os-range osTime is generated here manually."
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2614
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2615
        |deltaDays|
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2616
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2617
        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
  2618
        "/ 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
  2619
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2620
        osTime := (h * 3600) + (min * 60) + s.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2621
        osTime := osTime + self utcOffset.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2622
        osTime := osTime - (deltaDays * 24 * 3600).
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2623
        osTime := osTime * 1000.
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2624
        osTime := osTime + millis.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2625
    ] do:[
19713
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2626
        osTime := OperatingSystem
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2627
                computeOSTimeFromYear:y month:m day:d
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2628
                hour:h minute:min second:s
856279e7e3e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19652
diff changeset
  2629
                millisecond:millis
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2630
    ]
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2631
!
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2632
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2633
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
  2634
    "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
  2635
     given y,m,d and h,m,s in my time."
16996
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2636
28bdfa0a3f2f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16995
diff changeset
  2637
    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
  2638
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2639
    "
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2640
     self basicNew
d61c80d72507 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19624
diff changeset
  2641
         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
  2642
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2643
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  2644
13541
91828a57f378 added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents: 13236
diff changeset
  2645
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2646
!Timestamp methodsFor:'printing & storing'!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2647
8111
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2648
addPrintBindingsTo:dict language:languageOrNil
67347b7e3e69 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  2649
    "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
  2650
     languageOrNil can only be #en or nil for the current language."
5726
be29c70156c1 comments added
Claus Gittinger <cg@exept.de>
parents: 5719
diff changeset
  2651
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2652
    |date|
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2653
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2654
    date := self asDate.
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2655
    date addPrintBindingsTo:dict language:languageOrNil.
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2656
    super addPrintBindingsTo:dict language:languageOrNil.
16928
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2657
bf6e87aa449b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16923
diff changeset
  2658
    date year == Date today year ifTrue:[
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2659
        dict at:#yearOrTime put:('%h:%m' expandPlaceholdersWith:dict).
6795
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2660
    ].
519894240d97 more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents: 6686
diff changeset
  2661
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2662
    "
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2663
     |d|
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2664
     d := Dictionary new.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2665
     Timestamp now addPrintBindingsTo:d language:nil.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2666
     d inspect.
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2667
    "
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2668
    
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2669
    "used by:
22331
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  2670
        Timestamp now printStringFormat:'%y-%(mon)-%d'
18447
e494a04e3283 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 18445
diff changeset
  2671
        Timestamp now printStringFormat:'%(dayOfYear)'
17003
e73801d8f0cd class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16996
diff changeset
  2672
    "
22331
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  2673
349664f7c110 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22280
diff changeset
  2674
    "Modified (comment): / 03-11-2017 / 10:54:30 / cg"
4843
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2675
!
3a4484b834dd better printing
Claus Gittinger <cg@exept.de>
parents: 4839
diff changeset
  2676
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2677
printGeneralizedOn:aStream
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2678
    "append a representation of the receiver to aStream in a general format,
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2679
     top-down, without separators: 'yyyymmddHHMMSS.mmmZ'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2680
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2681
     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
  2682
     so read this before changing the output format."
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2683
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2684
    ^ self printGeneralizedOn:aStream isLocal:false short:false.
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2685
!
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2686
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2687
printGeneralizedOn:aStream isLocal:isLocal
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2688
    "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
  2689
     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2690
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2691
     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
  2692
     so read this before changing the output format.
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2693
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2694
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2695
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
5379
2cf681402817 Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents: 5376
diff changeset
  2696
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2697
    self printGeneralizedOn:aStream isLocal:isLocal short:false
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2698
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2699
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2700
    "Modified: / 1.7.1996 / 15:20:59 / cg"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2701
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2702
!
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2703
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2704
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2705
    "append a representation of the receiver to aStream in a general format,
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2706
     top-down, without separators;
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2707
        long format:  'yyyymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2708
        short format: 'yymmddHHMMSS.mmm+0100'
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2709
     Using the short format is strictly discouraged!!
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2710
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2711
     This format is used for the ASN.1 GeneralizedTime and UTCTime
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2712
     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
  2713
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2714
     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2715
     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2716
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2717
    |t off|
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2718
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2719
    isLocal ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2720
        t := self timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2721
        off := t utcOffset.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2722
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2723
        t := self asUtcTimestamp timeInfo.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2724
        off := 0.
12819
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2725
    ].
a28ce068acd8 comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents: 12729
diff changeset
  2726
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2727
    shortFormat ifTrue:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2728
        self assert:(t year between:1951 and:2049).
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2729
        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2730
    ] ifFalse:[
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2731
        t year    printOn:aStream leftPaddedTo:4 with:$0.
12166
83f638e6223d code cleanup
Claus Gittinger <cg@exept.de>
parents: 12164
diff changeset
  2732
    ].
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2733
    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
  2734
    t day     printOn:aStream leftPaddedTo:2 with:$0.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2735
    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
  2736
    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
  2737
    t seconds printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2738
    aStream nextPut:$..
7512
07c56e8934f4 OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents: 7474
diff changeset
  2739
    t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2740
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2741
    (self isUtcTimestamp or:[off == 0]) ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2742
        aStream nextPut:$Z.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2743
    ] ifFalse:[ |min|
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2744
        off < 0 ifTrue:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2745
            aStream nextPut:$+.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2746
            off := off negated.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2747
        ] ifFalse:[
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2748
            aStream nextPut:$-.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2749
        ].
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2750
        min := off // 60.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2751
        min // 60 printOn:aStream leftPaddedTo:2 with:$0.
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2752
        min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2753
    ].
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2754
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2755
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2756
     Timestamp now printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2757
     Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr.
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2758
     (Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2759
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2760
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2761
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2762
     Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2763
     Timestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2764
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  2765
     UtcTimestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2766
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2767
     Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2768
     Date today printOn:Transcript. Transcript cr.
5290
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2769
    "
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2770
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2771
    "Modified: / 1.7.1996 / 15:20:59 / cg"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2772
    "Modified: / 17.1.2000 / 15:53:02 / stefan"
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2773
!
f26854f0f074 Add #printGeneralizedOn:
Stefan Vogel <sv@exept.de>
parents: 4930
diff changeset
  2774
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2775
printISO8601
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2776
    <resource: #obsolete>
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2777
    "print as UTC in a format like 2014-10-17T17:08:44Z"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2778
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2779
    ^ self printStringIso8601
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2780
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2781
    "Created: / 16-06-2005 / 16:11:15 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2782
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2783
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2784
printISO8601Compressed
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2785
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2786
    "return a printString as UTC in a format like 20141017T170939Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2787
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2788
    ^ self printStringIso8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2789
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2790
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2791
     Timestamp now printISO8601Compressed
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2792
    "
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2793
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2794
    "Created: / 16-06-2005 / 16:11:31 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2795
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2796
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2797
printISO8601CompressedOn: aStream
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2798
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2799
    "print as UTC in a format like 20141017T170939Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2800
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2801
    self printIso8601CompressedOn: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2802
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2803
    "Created: / 16-06-2005 / 16:11:50 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2804
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2805
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2806
printISO8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2807
    <resource: #obsolete>
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2808
    "print as UTC in a format like 2014-10-17T17:08:44Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2809
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2810
    self printIso8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2811
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2812
    "Created: / 16-06-2005 / 16:11:07 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2813
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2814
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2815
printIso8601CompressedOn: aStream
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2816
    "print as UTC in a format like 20141017T170939Z on aStream"
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2817
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2818
    TimestampISO8601Builder printCompressed: self on: aStream
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2819
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2820
    "Created: / 16-06-2005 / 16:11:50 / masca"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2821
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2822
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2823
printIso8601FormatOn:aStream
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2824
    "append the iso8601 representation of the receiver to aStream.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2825
     This format looks like:
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2826
	1999-01-01T24:00:00
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2827
     or, for zero hr:min:sec,
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  2828
	1999-01-01
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2829
     Of course, a 24 hour clock is used.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2830
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2831
     Timezone information (eg. Z or +0100) is added, so the reader will read as local time."
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2832
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2833
    self printIso8601FormatOn:aStream timeSeparator:$T
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2834
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2835
    "
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2836
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2837
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2838
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2839
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2840
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2841
    "
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2842
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2843
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2844
printIso8601FormatOn:aStream timeSeparator:sepChar
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2845
    "append the iso8601 representation of the receiver to aStream.
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2846
     This format looks like:
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2847
        1999-01-01T24:00:00
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  2848
     or, for zero hr:min:sec,
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2849
        1999-01-01
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2850
     Of course, a 24 hour clock is used.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2851
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  2852
     Timezone information (eg. Z or +0100) is added, so the reader will read as local time."
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2853
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2854
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2855
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2856
    self isUtcTimestamp ifTrue:[
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2857
        asUTC := true. asLocal := false.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2858
    ] ifFalse:[
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2859
        self isLocalTimestamp ifTrue:[
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2860
            asUTC := false. asLocal := false.
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2861
        ] ifFalse:[
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2862
            asUTC := false. asLocal := false.
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2863
        ]
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2864
    ].
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2865
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2866
    Timestamp::TimestampISO8601Builder
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2867
        print:self compact:false
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2868
        asLocal:asLocal asUTC:asUTC withMilliseconds:true
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2869
        timeSeparator:sepChar
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2870
        on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2871
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2872
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2873
"/    |format|
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2874
"/
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2875
"/    format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2876
"/    self milliseconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2877
"/        format := '%(year)-%(month)-%(day)T%h:%m:%s'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2878
"/        self seconds = 0 ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2879
"/            format := '%(year)-%(month)-%(day)T%h:%m'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2880
"/            ((self hours = 0) and:[self minutes = 0]) ifTrue:[
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2881
"/                format := '%(year)-%(month)-%(day)'.
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2882
"/            ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2883
"/        ]
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2884
"/    ].
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2885
"/    self printOn:aStream format:format
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2886
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2887
    "
22827
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2888
     Timestamp now printStringIso8601Format.
9ea9757226e5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22653
diff changeset
  2889
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2890
     Timestamp now printIso8601FormatOn:Transcript. Transcript cr.
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2891
     Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2892
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2893
     UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr.
16920
cc4bb9fbadb4 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16919
diff changeset
  2894
     UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format).
8479
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2895
    "
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2896
!
3eda51fcb74c isoFormat fixes
Claus Gittinger <cg@exept.de>
parents: 8432
diff changeset
  2897
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2898
printIso8601On: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2899
    "print as UTC in a format like 2014-10-17T17:08:44Z on aStream"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2900
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2901
    TimestampISO8601Builder print: self on: aStream
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2902
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2903
    "Created: / 16-06-2005 / 16:11:07 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2904
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  2905
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  2906
printOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2907
    "append a user readable representation of the receiver to aStream.
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2908
     The format is compatible with readFromString:, but not with readFrom:."
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  2909
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2910
    |asUTC asLocal|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2911
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2912
    self isUtcTimestamp ifTrue:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2913
	asUTC := true. asLocal := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2914
    ] ifFalse:[
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2915
	self isLocalTimestamp ifTrue:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2916
	    asUTC := false. asLocal := true.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2917
	] ifFalse:[
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2918
	    asUTC := false. asLocal := false.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2919
	]
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2920
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2921
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2922
    Timestamp::TimestampISO8601Builder
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2923
	print:self compact:false
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2924
	asLocal:asLocal asUTC:asUTC withMilliseconds:true
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2925
	timeSeparator:(Character space)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2926
	on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2927
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2928
"/    self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2929
"/    self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2930
"/    self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i'
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2931
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2932
    "
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2933
     |tHere tNewYork|
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2934
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2935
     Timestamp now printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2936
     Timestamp now asUtcTimestamp printOn:Transcript. Transcript cr.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2937
     (Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')) printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2938
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2939
     tHere := Timestamp now.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2940
     tNewYork := tHere asTZTimestamp:(Timestamp utcOffsetFrom:'EST').
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2941
     tHere printOn:Transcript. Transcript cr.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  2942
     tNewYork printOn:Transcript. Transcript cr.
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  2943
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  2944
     (Timestamp fromSeconds:0) printOn:Transcript. Transcript cr.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2945
     Time now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2946
     Date today printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2947
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2948
     Time now asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2949
     Timestamp now printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2950
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2951
     Date today asTimestamp printOn:Transcript. Transcript cr.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  2952
     Date today printOn:Transcript. Transcript cr.
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2953
    "
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2954
5719
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2955
    "Modified: 1.7.1996 / 15:20:59 / cg"
cf09067dbd1d can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents: 5678
diff changeset
  2956
!
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  2957
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2958
printRFC1123FormatOn:aStream
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2959
    "append the RFC1123 representation of the receiver to aStream.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2960
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  2961
	'Fri, 04 Jul 2003 15:56:11 GMT'
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2962
     (always GMT and all names in english)"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2963
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2964
"/       HTTP-date      = rfc1123-date | rfc850-date | asctime-date
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2965
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2966
"/       rfc1123-date   = wkday "," SP date1 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2967
"/       rfc850-date    = weekday "," SP date2 SP time SP "GMT"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2968
"/       asctime-date   = wkday SP date3 SP time SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2969
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2970
"/       date1          = 2DIGIT SP month SP 4DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2971
"/                        ; day month year (e.g., 02 Jun 1982)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2972
"/       date2          = 2DIGIT "-" month "-" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2973
"/                        ; day-month-year (e.g., 02-Jun-82)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2974
"/       date3          = month SP ( 2DIGIT | ( SP 1DIGIT ))
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2975
"/                        ; month day (e.g., Jun  2)
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2976
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2977
"/       time           = 2DIGIT ":" 2DIGIT ":" 2DIGIT
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2978
"/                        ; 00:00:00 - 23:59:59
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2979
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2980
"/       wkday          = "Mon" | "Tue" | "Wed"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2981
"/                      | "Thu" | "Fri" | "Sat" | "Sun"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2982
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2983
"/       weekday        = "Monday" | "Tuesday" | "Wednesday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2984
"/                      | "Thursday" | "Friday" | "Saturday" | "Sunday"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2985
"/
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2986
"/       month          = "Jan" | "Feb" | "Mar" | "Apr"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2987
"/                      | "May" | "Jun" | "Jul" | "Aug"
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2988
"/                      | "Sep" | "Oct" | "Nov" | "Dec"
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2989
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2990
    |timeInfo|
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2991
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  2992
    timeInfo := self asUtcTimestamp timeInfo.
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  2993
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2994
    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
  2995
	    nextPutAll:', '.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2996
    timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
7671
fc0a27888051 Fix #printRFC1123FormatOn:
Stefan Vogel <sv@exept.de>
parents: 7512
diff changeset
  2997
    aStream space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  2998
    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
  2999
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3000
    "/ the following is too slow for heavy use
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3001
    "/    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
  3002
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3003
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3004
    timeInfo year printOn:aStream.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3005
    aStream nextPut:Character space.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3006
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3007
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3008
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3009
    aStream nextPut:$:.
7734
650ececb37bb tuning printRFC1123FormatOn
penk
parents: 7733
diff changeset
  3010
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
7677
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3011
    aStream nextPutAll:' GMT'.
e2b4eb2824c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7671
diff changeset
  3012
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3013
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3014
     String streamContents:[:s| Timestamp now printRFC1123FormatOn:s]
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3015
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3016
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3017
16988
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3018
printStringIso8601
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3019
    "return a printString as UTC in a format like 2014-10-17T17:08:44Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3020
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3021
    ^ TimestampISO8601Builder print: self
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3022
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3023
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3024
     Timestamp now printStringIso8601
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3025
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3026
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3027
    "Created: / 16-06-2005 / 16:11:15 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3028
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3029
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3030
printStringIso8601Compressed
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3031
    "return a printString as UTC in a format like 20141017T170939Z"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3032
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3033
    ^ TimestampISO8601Builder printCompressed: self
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3034
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3035
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3036
     Timestamp now printStringIso8601Compressed
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3037
    "
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3038
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3039
    "Created: / 16-06-2005 / 16:11:31 / masca"
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3040
!
ce209a206018 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16986
diff changeset
  3041
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3042
printStringRFC1123Format
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3043
    "return the RFC1123 representation of the receiver.
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3044
     This format is used in HTTP requests and looks like:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3045
	'Fri, 04 Jul 2003 15:56:11 GMT'
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3046
     (always GMT)"
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3047
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3048
    ^ String streamContents:[:s | self printRFC1123FormatOn:s]
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3049
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3050
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3051
     Timestamp now printStringRFC1123Format
7474
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3052
    "
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3053
!
e2dbf8bc10ab RFC1123 printing
Claus Gittinger <cg@exept.de>
parents: 7466
diff changeset
  3054
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3055
storeOn:aStream
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3056
    "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
  3057
     receiver via readFrom:
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3058
     Use a OS/architecture independent format"
275
a76029ddaa98 *** empty log message ***
claus
parents: 242
diff changeset
  3059
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3060
    aStream nextPut:$(;
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3061
	    nextPutAll:self storeStringClass name;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3062
	    nextPutAll:' readIso8601FormatFrom:'''.
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3063
    self printIso8601FormatOn:aStream.
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3064
    aStream nextPutAll:''')'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 30
diff changeset
  3065
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3066
    "
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3067
     Timestamp now storeString
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3068
8822
10d99a9248f2 #storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents: 8797
diff changeset
  3069
     Object readFrom:(Timestamp now storeString) readStream
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3070
     Timestamp readFrom:(Timestamp now storeString) readStream
241
6f30be88e314 *** empty log message ***
claus
parents: 213
diff changeset
  3071
    "
17049
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3072
!
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3073
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3074
storeStringClass
6ddd0b99a693 class: Timestamp
ca
parents: 17031
diff changeset
  3075
    ^ self class
30
c5f5604e0c0a Initial revision
claus
parents:
diff changeset
  3076
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3077
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3078
!Timestamp methodsFor:'private'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3079
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3080
additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3081
    "return the additional picoseconds (0..999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3082
     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
  3083
     to avoid overflow into the millis.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3084
     These are to be added to any milliseconds"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3085
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3086
    ^ additionalPicoseconds ? 0.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3087
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3088
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3089
     Timestamp now picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3090
     Timestamp nowWithMicroseconds picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3091
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3092
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3093
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3094
additionalPicoseconds:anInteger
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3095
    "set the additional picoseconds (0..999999999).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3096
     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
  3097
     to avoid overflow into the millis."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3098
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3099
    self assert:(anInteger < (1000*1000*1000)).
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3100
    additionalPicoseconds:= anInteger
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3101
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3102
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3103
     Timestamp now picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3104
     Timestamp now additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3105
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3106
     Timestamp nowWithMicroseconds picoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3107
     Timestamp nowWithMicroseconds additionalPicoseconds
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3108
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3109
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3110
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3111
computeTimeInfo
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3112
    |d t info|
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3113
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3114
    "/ fake an info which the OS cannot give me
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3115
    d := self asDate.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3116
    t := self asTime.
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3117
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3118
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3119
	 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
  3120
	 utcOffset:(self utcOffset) dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3121
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3122
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3123
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3124
	(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
  3125
	(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
  3126
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3127
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3128
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3129
computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3130
    |utcTimestamp d t info|
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3131
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3132
    "/ fake an info which the OS cannot give me
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3133
    utcTimestamp := self asUtcTimestamp.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3134
    d := utcTimestamp asDate.
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3135
    t := utcTimestamp asTime.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3136
    info := OperatingSystem timeInfoClass new.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3137
    info year:d year month:d month day:d day
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3138
	 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
  3139
	 utcOffset:0 dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3140
    ^ info
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3141
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3142
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3143
	(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
  3144
	(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
  3145
	(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
  3146
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3147
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3148
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3149
fromOSTime:anUninterpretedOSTime
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3150
    "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
  3151
     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
  3152
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3153
    osTime := anUninterpretedOSTime
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3154
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3155
    "Created: 1.7.1996 / 14:33:21 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3156
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3157
16942
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3158
fromOSTimeWithMilliseconds:anUninterpretedOSTime
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3159
    "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
  3160
     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
  3161
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3162
    osTime := anUninterpretedOSTime
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3163
!
4cf2c0a1b800 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16939
diff changeset
  3164
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3165
fromOSTimeWithMilliseconds:anUninterpretedOSTime additionalPicoseconds:picos
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3166
    "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
  3167
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3168
    osTime := anUninterpretedOSTime.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3169
    additionalPicoseconds := picos
22627
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3170
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3171
    "
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3172
     Timestamp nowWithMicroseconds
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3173
    "
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3174
!
2b4c63a427fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22614
diff changeset
  3175
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3176
getMilliseconds
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3177
    "strictly private: return the milliseconds (since the epoch) in utc"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3178
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3179
    ^ osTime
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3180
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3181
    "Created: 1.7.1996 / 14:33:56 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3182
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3183
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3184
getSeconds
22280
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3185
    "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
  3186
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3187
    ^ osTime // 1000
22280
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3188
dba489905fcc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21999
diff changeset
  3189
    "Modified (comment): / 21-09-2017 / 18:50:23 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3190
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3191
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3192
setMilliseconds:millis
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3193
    "strictly private: set the milliseconds (since the epoch)"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3194
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3195
    osTime := millis.
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3196
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3197
    "Modified: 20.12.1995 / 11:46:36 / stefan"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3198
    "Created: 1.7.1996 / 14:34:24 / cg"
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3199
!
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3200
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3201
setSeconds:secs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3202
    "strictly private: set the seconds (since whatever)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3203
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3204
    osTime := (secs * 1000).
795
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3205
ff477bad0f2d fix setSeconds:
Stefan Vogel <sv@exept.de>
parents: 699
diff changeset
  3206
    "Modified: 20.12.1995 / 11:46:36 / stefan"
1501
2589005c849d time changes
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  3207
    "Modified: 1.7.1996 / 14:34:10 / cg"
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3208
!
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3209
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3210
timeInfo
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3211
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3212
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3213
	^ self computeTimeInfo
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3214
    ].
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3215
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3216
    ^ OperatingSystem computeTimeAndDateFrom:osTime
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3217
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3218
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3219
	(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
  3220
	(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
  3221
    "
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3222
!
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3223
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3224
utcSecondsSince1970
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3225
    "return the UTC seconds since 1970"
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3226
9430
919e0cb2257c Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents: 9416
diff changeset
  3227
    ^ self getSeconds
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3228
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3229
    "
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  3230
     Timestamp now utcSecondsSince1970
5853
bee515a21a30 added #utcSecondsSince1970
martin
parents: 5839
diff changeset
  3231
    "
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3232
!
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3233
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3234
utcTimeInfo
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3235
    (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3236
	"/ fake an info which the OS cannot give me
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3237
	^ self computeUtcTimeInfo
17026
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3238
    ].
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3239
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3240
    ^ OperatingSystem computeUTCTimeAndDateFrom:osTime
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3241
aa7743e9f351 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 17020
diff changeset
  3242
    "
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3243
	(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
  3244
	(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
  3245
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3246
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3247
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3248
!Timestamp methodsFor:'testing'!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3249
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3250
isLocalTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3251
    "return true, if I am a local timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3252
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3253
    ^ true
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3254
!
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3255
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3256
isTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3257
    "return true, if I am a timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3258
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3259
    ^ true
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3260
!
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3261
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3262
isUtcTimestamp
16986
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3263
    "return true, if I am a utc timestamp"
fafb2758c9f6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16978
diff changeset
  3264
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3265
    ^ false
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3266
! !
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3267
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3268
!Timestamp methodsFor:'visiting'!
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3269
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3270
acceptVisitor:aVisitor with:aParameter
16718
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3271
    "dispatch for visitor pattern; send #visitTimestamp:with: to aVisitor."
1af0186b3feb comment/format only
Claus Gittinger <cg@exept.de>
parents: 16610
diff changeset
  3272
8396
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3273
    ^ aVisitor visitTimestamp:self with:aParameter
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3274
! !
b13503dbc53c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8286
diff changeset
  3275
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3276
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3277
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3278
malformed:aString
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3279
    TimeConversionError raiseErrorString:(' - ', aString)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3280
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3281
    "Created: / 15-06-2005 / 15:54:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3282
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3283
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3284
!Timestamp::TimestampBuilderAbstract methodsFor:'support'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3285
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3286
addHoursAndMinutes: arrayWithHoursAndMinutes
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3287
    "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
  3288
    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
  3289
    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
  3290
    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
  3291
    one day forward or backward)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3292
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3293
    | hours minutes |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3294
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3295
    hours := arrayWithHoursAndMinutes first.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3296
    minutes := arrayWithHoursAndMinutes second.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3297
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3298
    utcOffset := (((hours * 60) + minutes) * 60).
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3299
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3300
    minutes isZero ifFalse: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3301
        minute := minute + minutes.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3302
        minute >= 60 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3303
            hours := hours + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3304
            minute := minute - 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3305
        ].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3306
        minute < 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3307
            hours := hours - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3308
            minute := minute + 60.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3309
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3310
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3311
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3312
    "Hours may get zero by time zone specification or by minutes modifications above."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3313
    hours isZero ifTrue: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3314
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3315
    "Add or subtract the hour and make date corrections if necessary."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3316
    hour := hour + hours.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3317
    hour < 0 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3318
        "Oops, got to previous day, must adjust even the date."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3319
        hour := 24 - ((hour negated) \\ 24).
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3320
        day := day - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3321
        day <= 0 ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3322
            "Go to previous month..."
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3323
            month := month - 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3324
            month <= 0 ifTrue: [year := year - 1. month := 12].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3325
            day := self lastDayInMonth: month
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3326
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3327
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3328
    hour >= 24 ifTrue: [
19915
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3329
        hour := hour \\ 24.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3330
        day := day + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3331
        day > (self lastDayInMonth: month) ifTrue: [
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3332
            month := month + 1.
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3333
            month > 12 ifTrue: [year := year + 1. month := 1].
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3334
            day := 1
1c59f9b8ffc6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19897
diff changeset
  3335
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3336
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3337
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3338
    "Created: / 15-06-2005 / 16:45:49 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3339
    "Modified: / 16-06-2005 / 15:04:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3340
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3341
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3342
dateFromDayNumber: dayInYear
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3343
    "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
  3344
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3345
    |monthAndDay|
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3346
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3347
    (dayInYear between: 1 and: 365) ifFalse: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3348
	(dayInYear = 366 and:[self leapYear: year])
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3349
	    ifFalse: [self malformed: 'Bad day number: ' , dayInYear printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3350
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3351
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3352
    monthAndDay := Date monthAndDayFromDayInYear:dayInYear forYear:year.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3353
    month := monthAndDay at:1.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3354
    day := monthAndDay at:2
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3355
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3356
    "Created: / 15-06-2005 / 11:27:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3357
    "Modified: / 16-06-2005 / 12:31:37 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3358
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3359
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3360
dateFromWeek: weekInteger andWeekday: dayInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3361
    "Compute the month and day. Find the first day (weekday) in the year, maybe even
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3362
    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
  3363
    with thursday (or the one containing 4.1.)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3364
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3365
    |tmpDate|
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3366
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3367
    "Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3368
    (dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3369
    (weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3370
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3371
    tmpDate := Date newDayInWeek:dayInteger week:weekInteger year:year.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3372
    day := tmpDate day.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3373
    month := tmpDate month.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3374
    year := tmpDate year.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3375
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3376
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3377
isAllowedDay: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3378
    "Answer whether the given day is allowed in the current month."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3379
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3380
    ^anInteger between: 1 and: (self lastDayInMonth: month)
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3381
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3382
    "Created: / 15-06-2005 / 16:22:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3383
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3384
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3385
lastDayInMonth: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3386
    "Answer the number of the last day of the given month in the current year."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3387
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3388
    ^ anInteger = 2
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3389
	ifTrue: [(self leapYear: year) ifTrue: [29] ifFalse: [28]]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3390
	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
  3391
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3392
    "Created: / 15-06-2005 / 17:12:31 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3393
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3394
16836
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3395
leapYear: anInteger
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3396
    ^ Date leapYear:anInteger.
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3397
!
62f28e466c23 class: Timestamp
Stefan Vogel <sv@exept.de>
parents: 16718
diff changeset
  3398
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3399
timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3400
    "Answer the timestamp as it has been parsed."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3401
    "Notes:
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3402
     - 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
  3403
       or is a local time stamp.
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3404
     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
  3405
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3406
    (timestampClass == UtcTimestamp) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3407
	^ UtcTimestamp
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3408
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3409
	    hour: hour minute: minute second: second millisecond: millisecond
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3410
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3411
    (timestampClass == TZTimestamp) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3412
	"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3413
	^ ((TZTimestamp
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3414
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3415
	    hour: hour minute: minute second: second millisecond: millisecond) utcOffset:utcOffset)
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3416
    ].
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3417
16989
de9bc5f12297 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16988
diff changeset
  3418
    (isUtcTime or:[hasTimezone and:[utcOffset == 0]]) ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3419
	^ ((timestampClass == Timestamp) ifTrue:UtcTimestamp ifFalse:timestampClass)
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3420
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3421
	    hour: hour minute: minute second: second millisecond: millisecond
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3422
    ].
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3423
    hasTimezone ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3424
	"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values."
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3425
	^ (((timestampClass == Timestamp) ifTrue:TZTimestamp ifFalse:timestampClass)
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3426
	    UTCYear: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3427
	    hour: hour minute: minute second: second millisecond: millisecond) utcOffset:utcOffset
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3428
    ].
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3429
    "/ there was no timezone info, so make it a local timestamp again.
17016
da04a2484c16 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17014
diff changeset
  3430
    ^ (timestampClass
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3431
	year: year month: month day: day
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3432
	hour: hour minute: minute second: second millisecond: millisecond)
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3433
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3434
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3435
yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3436
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3437
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3438
    year := yearArg.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3439
    yearAlreadyRead := true.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3440
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3441
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3442
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3443
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3444
documentation
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3445
"
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3446
    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp.
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3447
    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
  3448
    It has been written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3449
    (which was now changed to call this as well).
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3450
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3451
    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
  3452
    (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
  3453
    broken years, incomplete times and timezones. All times read with timezone difference are recomputed
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3454
    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
  3455
    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
  3456
    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
  3457
    possible.
16915
2174b3784836 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16914
diff changeset
  3458
    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
  3459
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3460
    [author:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3461
	Martin Dvorak (masca@volny.cz)
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3462
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3463
    [instance variables:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3464
	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
  3465
			so the builder instance can be reused (by at most one thread).
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3466
	year            Current timestamp year. No default value, date must be present.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3467
	month           Current timestamp month. May change during parsing. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3468
	day             Current timestamp day. Defaults to 1.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3469
	hour            Current timestamp hour. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3470
	minute          Current timestamp minute. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3471
	second          Current timestamp second. Defaults to 0.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3472
	millisecond     Current timestamp millisecond. Defaults to 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3473
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3474
    [see also:]
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3475
	Timestamp
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3476
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3477
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3478
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3479
examples
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3480
"
21999
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  3481
    See the unit tests in stx/goodies:regression >> RegressionTests::timeAndDateTest
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3482
    It covers the main features this builder has.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3483
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3484
    Just to introduce some coding examples, try:
21999
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  3485
        Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  3486
        UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  3487
        Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now).
1f634836c816 #OTHER by mawalch
mawalch
parents: 21699
diff changeset
  3488
        Timestamp readISO8601From: (TimestampISO8601Builder print: TZTimestamp now).
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3489
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3490
    Timestamp readISO8601From:'fooBar' onError:[ Timestamp now ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3491
"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3492
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3493
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3494
history
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3495
    "Created: / 16-06-2005 / 16:28:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3496
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3497
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3498
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3499
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3500
print: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3501
    "Returns the printString of the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3502
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3503
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3504
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3505
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3506
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3507
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3508
    self print: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3509
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3510
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3511
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3512
     self print:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3513
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3514
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3515
    "Created: / 15-06-2005 / 17:52:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3516
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3517
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3518
print:aTimestamp asLocal:asLocal on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3519
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3520
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3521
     The time is always printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3522
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3523
    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
  3524
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3525
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3526
     self print:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3527
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3528
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3529
    "Created: / 15-06-2005 / 17:56:51 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3530
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3531
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3532
print:aTimestamp on:aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3533
    "Print the given timestamp in general ISO8601 format,
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3534
     such as '2014-11-06T11:48:09Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3535
     The time is printed as UTC time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3536
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3537
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3538
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3539
        compact:false asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3540
        withMilliseconds:true timeSeparator:$T timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3541
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3542
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3543
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3544
     self print:(Timestamp now) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3545
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3546
     self print:(Time now) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3547
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3548
     self print:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3549
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3550
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3551
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3552
    "Created: / 15-06-2005 / 17:56:51 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3553
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3554
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3555
printAsLocalTime: aTimestamp on: aStream
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3556
    "Print the given timestamp in general ISO8601 format,
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3557
     such as '2014-11-06T11:48:09+01'.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3558
     The time is printed as local time"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3559
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3560
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3561
        print:aTimestamp compact:false asLocal:true asUTC:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3562
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3563
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3564
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3565
    "
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3566
     self printAsLocalTime:(Timestamp now) on:Transcript
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3567
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3568
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3569
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3570
printCompressed: aTimestamp
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3571
    "Return a printString in compressed format such as '20141106T114636Z'.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3572
     (for example, for timestamp interchange with mobile devices).
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3573
     The time is printed as UTC time"
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3574
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3575
    | stream |
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3576
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3577
    stream := '' writeStream.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3578
    self printCompressed: aTimestamp on: stream.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3579
    ^ stream contents
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3580
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3581
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3582
     self printCompressed:(Timestamp now)
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3583
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3584
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3585
    "Created: / 15-06-2005 / 17:52:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3586
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3587
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3588
printCompressed:aTimestamp asLocal:asLocal on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3589
    "generates a compressed string representation, 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3590
     (optionally as localtime) such as '20141106T114636Z'"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3591
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3592
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3593
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3594
        compact:true asLocal:asLocal asUTC:asLocal not 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3595
        withMilliseconds:true timeSeparator:$T timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3596
        on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3597
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3598
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3599
     self printCompressed:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3600
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3601
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3602
    "Created: / 15-06-2005 / 17:54:17 / masca"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3603
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3604
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3605
printCompressed:aTimestamp on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3606
    "generates a compressed string representation, such as '20141106T114636Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3607
     The time is printed as UTC time"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3608
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3609
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3610
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3611
        compact:true asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3612
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3613
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3614
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3615
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3616
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3617
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3618
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3619
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3620
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3621
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3622
printCompressedAsLocalTime:aTimestamp on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3623
    "generates a compressed string representation, such as '20141106T114636Z'.
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3624
     The time is printed as local time"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3625
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3626
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3627
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3628
        compact:true asLocal:true asUTC:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3629
        withMilliseconds:true timeSeparator:$T timeOnly:false 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3630
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3631
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3632
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3633
     self printCompressed:(Timestamp now) on:Transcript
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3634
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3635
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3636
    "Created: / 15-06-2005 / 17:54:17 / masca"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3637
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3638
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3639
printTime:aTimeOrTimestamp on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3640
    "Print the given time in general ISO8601 format,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3641
     such as 'T11:48:09Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3642
     The time is printed as UTC time.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3643
     No date is printed."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3644
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3645
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3646
        print:aTimeOrTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3647
        compact:false asLocal:false asUTC:true 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3648
        withMilliseconds:true timeSeparator:$T timeOnly:true
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3649
        on:aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3650
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3651
    "
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3652
     self print:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3653
     Transcript cr.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3654
     self printTime:(Time nowWithMilliseconds) on:Transcript.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3655
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3656
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3657
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3658
    "Created: / 15-06-2005 / 17:56:51 / masca"
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3659
!
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3660
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3661
printTimeZone:tzOffsetArg on: aStream
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3662
    "Print the timezone delta"
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3663
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3664
    |tzOffset tzHours tzMinutes|
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3665
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3666
    tzOffset := tzOffsetArg.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  3667
    tzOffset == 0 ifTrue:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3668
	aStream nextPutAll:'+00'.
17020
c995597a75c1 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17016
diff changeset
  3669
    ] ifFalse:[
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3670
	tzOffset := tzOffset // 60.     "/ convert from seconds to minutes
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3671
	tzOffset < 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3672
	    tzOffset := tzOffset negated.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3673
	    aStream nextPut:$+
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3674
	] ifFalse:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3675
	    aStream nextPut:$-.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3676
	].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3677
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3678
	tzHours := tzOffset // 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3679
	tzMinutes := tzOffset \\ 60.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3680
	(tzHours ~= 0 or:[tzMinutes ~= 0]) ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3681
	    aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3682
		nextPutAll:(tzHours printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3683
	    tzMinutes ~= 0 ifTrue:[
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3684
		aStream
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3685
		    nextPut: $:;
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3686
		    nextPutAll: (tzMinutes printStringRadix: 10 size: 2 fill: $0).
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3687
	    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3688
	].
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3689
    ].
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3690
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3691
    "
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3692
     self print:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3693
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3694
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3695
     self print:(Timestamp now) asLocal:false on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3696
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3697
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3698
     self printCompressed:(Timestamp now) asLocal:true on:Transcript.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3699
     Transcript cr.
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3700
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3701
     self printCompressed:(Timestamp now) asLocal:false on:Transcript.
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3702
     Transcript cr.
16919
80445b2bec64 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16915
diff changeset
  3703
    "
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3704
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3705
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3706
!Timestamp::TimestampISO8601Builder class methodsFor:'printing - basic'!
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3707
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3708
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
  3709
    "Print the given timestamp in general ISO8601 format,
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3710
     such as '2014-11-06T11:48:09Z'.
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3711
	compact: if true, the compact format (without separating dashes and colons is generated)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3712
	asLocal: if true, generates a localtime string (with the machine's current timezone setting)
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3713
	asUTC: if true, generates a utc string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3714
	    if both are false:
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3715
		generate a string depending on the type of timestamp:
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3716
		    if local: generate a local timezone string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3717
		    if utc: generate a utc string
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3718
		    otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3719
	withMilliseconds: if false, no milliseconds are generated"
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3720
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3721
    self
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3722
	print:aTimestamp
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3723
	compact:compact asLocal:asLocal asUTC:asUTC
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3724
	withMilliseconds:withMillis
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3725
	timeSeparator:$T
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3726
	on:aStream
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3727
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3728
    "
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3729
     self print:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3730
     self printAsLocalTime:(Timestamp now) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3731
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3732
    "
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3733
!
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3734
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3735
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
  3736
    "Print the given timestamp in general ISO8601 format,
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3737
     such as '2014-11-06T11:48:09Z'.
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3738
        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
  3739
        asLocal: if true, generates a localtime string (without any timezone info)
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3740
        asUTC: if true, generates a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3741
            if both are false:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3742
                generate a string depending on the type of timestamp:
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3743
                    if local: generate a local timezone string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3744
                    if utc: generate a utc string
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3745
                    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
  3746
        withMilliseconds: if false, no milliseconds are generated"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3747
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3748
    self 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3749
        print:aTimestamp 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3750
        compact:compact asLocal:asLocal asUTC:asUTC 
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3751
        withMilliseconds:withMillis timeSeparator:tSep timeOnly:false
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3752
        on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3753
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3754
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3755
     self print:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3756
     self printAsLocalTime:(Timestamp now) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3757
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3758
    "
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3759
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3760
    "Created: / 15-06-2005 / 17:56:51 / masca"
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3761
!
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3762
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3763
print:aTimeOrTimestamp compact:compact asLocal:asLocal asUTC:asUTC withMilliseconds:withMillis timeSeparator:tSep timeOnly:timeOnly on:aStream
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3764
    "Print the given timestamp in general ISO8601 format,
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3765
     such as '2014-11-06T11:48:09Z'.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3766
        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
  3767
        asLocal: if true, generates a localtime string (without any timezone info)
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3768
        asUTC: if true, generates a utc string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3769
            if both are false:
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3770
                generate a string depending on the type of timestamp:
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3771
                    if local: generate a local timezone string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3772
                    if utc: generate a utc string
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3773
                    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
  3774
        withMilliseconds: if false, no milliseconds are generated.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3775
     if timeOnly is true, only the time is printed."
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3776
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3777
    |aTimestamp timeInfo millis |
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3778
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3779
    aTimestamp := aTimeOrTimestamp asTimestamp.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3780
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3781
    asLocal ifTrue:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3782
        "/ force local
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3783
        timeInfo := aTimestamp asLocalTimestamp timeInfo.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3784
    ] ifFalse:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3785
        asUTC ifTrue:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3786
            "/ force utc
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3787
            timeInfo := aTimestamp asUtcTimestamp timeInfo.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3788
        ] ifFalse:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3789
            "/ in the timestamps own format
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3790
            timeInfo := aTimestamp timeInfo.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3791
        ]
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3792
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3793
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3794
    timeOnly ifFalse:[
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3795
        timeInfo year printOn:aStream leftPaddedTo:4 with:$0.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3796
        compact ifFalse:[ aStream nextPut: $- ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3797
        timeInfo month printOn:aStream leftPaddedTo:2 with:$0.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3798
        compact ifFalse:[ aStream nextPut: $- ].
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3799
        timeInfo day printOn:aStream leftPaddedTo:2 with:$0.
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3800
    ].
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3801
    aStream nextPut:tSep.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3802
    timeInfo hours printOn:aStream leftPaddedTo:2 with:$0.
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3803
    compact ifFalse:[ aStream nextPut: $:].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3804
    timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0.
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3805
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3806
    "always print the seconds, even if 0. 
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3807
     According to http://www.w3.org/TR/xmlschema11-2/#dateTime  this is mandatory"
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3808
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3809
    compact ifFalse:[ aStream nextPut: $:].
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3810
    timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3811
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3812
    millis := withMillis ifTrue:[timeInfo milliseconds] ifFalse:[0].
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3813
    millis ~= 0 ifTrue:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3814
        aStream nextPut: $..
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3815
        millis printOn:aStream leftPaddedTo:3 with:$0.
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3816
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3817
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3818
    asUTC ifTrue:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3819
        aStream nextPut: $Z
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3820
    ] ifFalse:[
17422
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3821
        asLocal ifFalse:[
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3822
            self printTimeZone:aTimestamp utcOffset on:aStream.
0a01cd7cf5f2 class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents: 17172
diff changeset
  3823
        ].
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3824
    ].
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3825
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3826
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3827
     self print:(Timestamp now) on:Transcript
22834
a70e3ac5710e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22827
diff changeset
  3828
     self print:(Time now) on:Transcript
16967
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3829
     self printAsLocalTime:(Timestamp now) on:Transcript
4640b54ab64a class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16955
diff changeset
  3830
     self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript
16921
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3831
    "
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3832
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3833
    "Created: / 15-06-2005 / 17:56:51 / masca"
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3834
! !
8b4c683d9d5b class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16920
diff changeset
  3835
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3836
!Timestamp::TimestampISO8601Builder class methodsFor:'public parsing'!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3837
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3838
read: stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3839
    ^ self new read:stringOrStream withClass:timestampClass
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3840
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3841
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3842
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3843
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3844
read: stringOrStream withClass:timestampClass yearAlreadyReadAs:yearArg
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3845
    "support for readers which may have already preread the year"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3846
16945
Claus Gittinger <cg@exept.de>
parents: 16943
diff changeset
  3847
    ^ self new
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3848
	yearAlreadyReadAs:yearArg;
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3849
	read:stringOrStream withClass:timestampClass
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3850
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3851
    "Created: / 15-06-2005 / 17:52:03 / masca"
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3852
! !
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3853
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3854
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3855
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3856
nextDigit
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3857
    | char |
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3858
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3859
    char := stream peekOrNil.
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3860
    char isNil ifTrue: [^-1].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3861
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3862
    char isDigit ifTrue: [
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3863
	stream next.
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3864
	^ char codePoint - $0 codePoint
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3865
    ].
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  3866
    ^ -1
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3867
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3868
    "Created: / 14-06-2005 / 11:48:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3869
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3870
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3871
nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3872
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3873
    | digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3874
    digit := self nextDigit.
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3875
    ^ digit < 0
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3876
	ifTrue: [self malformed: 'No digit found']
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3877
	ifFalse: [digit]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3878
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3879
    "Created: / 15-06-2005 / 10:57:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3880
    "Modified: / 15-06-2005 / 17:22:52 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3881
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3882
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3883
nextDigits: anInteger
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3884
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3885
    | char number |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3886
    number := 0.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3887
    anInteger timesRepeat: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3888
	char := stream peekOrNil.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3889
	char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3890
	char isDigit
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3891
	    ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3892
		stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3893
		number := number * 10 + char codePoint - $0 codePoint]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  3894
	    ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3895
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3896
    ^ number
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3897
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3898
    "Created: / 14-06-2005 / 11:57:22 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3899
    "Modified: / 15-06-2005 / 15:54:29 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3900
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3901
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3902
!Timestamp::TimestampISO8601Builder methodsFor:'public processing'!
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3903
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3904
read:stringOrStream withClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3905
    | peek |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3906
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3907
    stream := stringOrStream readStream.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3908
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3909
    month := day := 1.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3910
    hour := minute := second := millisecond := 0.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3911
    isUtcTime := hasTimezone := false.
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  3912
    utcOffset := 0.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3913
16936
cf59a3abe590 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16935
diff changeset
  3914
    yearAlreadyRead ~~ true ifTrue:[
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3915
        "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
  3916
        self readYear.
16923
719c8a7b1cdd class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16922
diff changeset
  3917
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3918
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3919
    "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
  3920
    There is possible inconsistency - a dash may be read followed by T, which is not
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3921
    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
  3922
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3923
    peek ifNil: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3924
        "End of stream, only year has been read."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3925
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3926
    peek == $- ifTrue: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3927
        "Skip the dash after year, if present."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3928
        stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3929
        peek := stream peekOrNil].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3930
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3931
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3932
    (peek == $T or: [peek == Character space])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3933
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3934
            "Got time signature. Skip the signature, read time and answer the timestamp."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3935
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3936
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3937
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3938
            self readTimezone.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3939
            ^ self timestampWithClass:timestampClass
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3940
        ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3941
        ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3942
            "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
  3943
            peek == $W
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3944
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3945
                    "Parse week number and (possibly) day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3946
                    stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3947
                    self readWeekNumber]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3948
                ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3949
                    "Got digit, read month number followed by day or day number."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3950
                    self readMonthOrDay]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3951
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3952
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3953
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3954
    peek ifNil: [
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3955
        "End of stream, only year has been read."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3956
        ^ self timestampWithClass:timestampClass].
16955
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3957
2c49b8f7fc7f class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16950
diff changeset
  3958
    (peek asUppercase == $T or: [peek == Character space])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3959
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3960
            "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
  3961
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3962
            peek == Character space ifTrue:[stream skipSeparators].
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3963
            self readTime.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3964
            self readTimezone
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  3965
        ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3966
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  3967
    ^ self timestampWithClass:timestampClass
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3968
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3969
    "Created: / 14-06-2005 / 11:45:04 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3970
    "Modified: / 16-06-2005 / 10:15:35 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3971
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3972
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3973
!Timestamp::TimestampISO8601Builder methodsFor:'reading'!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  3974
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3975
readFraction
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3976
    "Read an arbitrary number of digits representing a fraction."
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3977
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3978
    ^ Fraction readDecimalFractionFrom:stream onError:[self malformed: 'Missing digits after fraction separator'].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3979
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3980
"/    | anyDigit digit factor fraction |
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3981
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3982
"/    factor := (1 / 10).
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3983
"/    fraction := 0.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3984
"/    anyDigit := false.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3985
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3986
"/    [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3987
"/        digit := self nextDigit.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3988
"/        digit >= 0
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3989
"/    ] whileTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3990
"/        anyDigit := true.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3991
"/        fraction := digit * factor + fraction.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3992
"/        factor := (factor / 10)
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3993
"/    ].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3994
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3995
"/    anyDigit ifFalse: [self malformed: 'Missing digits after fraction separator'].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3996
"/    ^ fraction
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  3997
"/
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3998
!
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  3999
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4000
readMilliseconds
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4001
    "Read an arbitrary number of digits representing milliseconds. As the timestamp can
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4002
    hold only integer amounts of milliseconds, don't mind the rest of the digits."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4003
16939
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4004
    millisecond := (self readFraction * 1000) asInteger
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4005
"/    | digit factor |
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4006
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4007
"/    factor := 100.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4008
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4009
"/    [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4010
"/        digit := self nextDigit.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4011
"/        digit >= 0
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4012
"/    ] whileTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4013
"/        factor > 0 ifTrue: [
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4014
"/            "Factor still > 0, did not read all three digits of mantissa."
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4015
"/            millisecond := digit * factor + millisecond.
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4016
"/            factor := (factor / 10) integerPart
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4017
"/        ]
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4018
"/    ].
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4019
"/
1c51cd6660e5 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16936
diff changeset
  4020
"/    factor = 100 ifTrue: [self malformed: 'No digits after millisecond separator']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4021
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4022
    "Created: / 15-06-2005 / 15:25:45 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4023
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4024
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4025
readMonthOrDay
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4026
    "Read month number, optionally followed by day, or absolute day number (three digit)."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4027
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4028
    | dayDigit1 dayDigit2 |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4029
    month := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4030
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4031
    stream peekOrNil = $-
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4032
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4033
	    "Got dash. Day number must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4034
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4035
	    day := self nextDigits: 2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4036
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4037
	    ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4038
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4039
    dayDigit1 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4040
    dayDigit1 < 0 ifTrue: [
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4041
	"No more digits than month, leave day unspecified."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4042
	(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4043
	^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4044
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4045
    dayDigit2 := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4046
    dayDigit2 < 0
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4047
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4048
	    "Read only three digits, this is absolute day number in a year."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4049
	    self dateFromDayNumber: month * 10 + dayDigit1]
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4050
	ifFalse: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4051
	    "Read four digits. So there's month and day."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4052
	    (month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4053
	    day := dayDigit1 * 10 + dayDigit2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4054
	    (self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4055
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4056
    "Created: / 15-06-2005 / 11:12:02 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4057
    "Modified: / 16-06-2005 / 11:47:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4058
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4059
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4060
readTime
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4061
    "Date read, don't mind it. Read only the time value."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4062
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4063
    | peek f |
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4064
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4065
    hour := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4066
    (hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4067
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4068
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4069
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4070
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4071
        "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4072
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4073
        minute := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4074
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4075
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4076
            "/ read minutes
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4077
            minute := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4078
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4079
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4080
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4081
                minute := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4082
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4083
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4084
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4085
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4086
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4087
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4088
    minute isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4089
        f := minute.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4090
        minute := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4091
        second := (f - minute) * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4092
        second isInteger ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4093
            f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4094
            second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4095
            millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4096
            millisecond := millisecond rounded.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4097
        ].
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4098
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4099
    (minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4100
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4101
    peek := stream peekOrNil.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4102
    peek isNil ifTrue: [^self].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4103
    (peek == $:) ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4104
        "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4105
        stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4106
        second := self nextDigits: 2.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4107
    ] ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4108
        peek isDigit ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4109
            "/ read seconds
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4110
            second := self nextDigits: 2.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4111
        ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4112
            (peek == $. or:[peek == $,]) ifTrue:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4113
                stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4114
                second := self readFraction * 60.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4115
            ] ifFalse:[
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4116
                ^ self.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4117
            ].
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4118
        ]
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4119
    ].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4120
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4121
    second isInteger ifFalse:[
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4122
        f := second.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4123
        second := f truncated.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4124
        millisecond := (f - second) * 1000.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4125
        millisecond := millisecond rounded.
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4126
    ].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4127
    (second between: 0 and: 59) ifFalse: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4128
        "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
  4129
        second <= 61
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4130
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4131
                "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
  4132
                as it's not deterministic."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4133
                (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
  4134
                    ifFalse: [self malformed: 'Bad leap second']]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4135
            ifFalse: [self malformed: 'Bad second: ' , second printString]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4136
    ].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4137
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4138
    "Hour, minute and second read. Read appendices."
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4139
    ((peek := stream peekOrNil) == $. or:[peek == $,])
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4140
        ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4141
            "Read dot. Skip it and read milliseconds."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4142
            stream next.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4143
            self readMilliseconds].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4144
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4145
    hour = 24 ifTrue: [
20817
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4146
        (minute = 0 and: [second = 0 and: [millisecond = 0]])
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4147
            ifTrue: [
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4148
                "On 24 hour, advance to the next day."
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4149
                "hour := 0.
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4150
                self addMinutes: 1440"]
f85fbb0ac273 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20616
diff changeset
  4151
            ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)']
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4152
    ]
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4153
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4154
    "Created: / 14-06-2005 / 17:27:00 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4155
    "Modified: / 30-06-2005 / 11:34:38 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4156
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4157
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4158
readTimezone
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4159
    "Read time zone information. There are three possibilities of what can occur.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4160
    If there is nothing more to read, the offset is unknown - this is treated as
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4161
    Zulu time as this may not be true."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4162
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4163
    | peek tzOffset |
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4164
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4165
    peek := stream peek.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4166
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4167
    peek := peek asUppercase.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4168
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4169
    "If the time is in Zulu, don't modify the timestamp. This makes the machine
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4170
    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
  4171
    peek == $Z ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4172
        "Time read, skip Zulu signature and exit."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4173
        isUtcTime := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4174
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4175
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4176
    ].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4177
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4178
    (peek == $+ or:[peek == $-]) ifTrue: [
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4179
        "Read a plus/minus, expect a negative/positive time zone difference."
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4180
        hasTimezone := true.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4181
        stream next.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4182
        tzOffset := self readTimezoneOffset.
19917
b273314a4ef7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19916
diff changeset
  4183
        peek == $+ ifTrue:[
19916
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4184
            tzOffset := tzOffset collect: [:e | e negated].
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4185
        ].    
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4186
        self addHoursAndMinutes: tzOffset.
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4187
        ^ self
e8c8589b1928 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19915
diff changeset
  4188
    ].
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4189
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4190
    "This is local time"
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4191
    isUtcTime := false.
16975
7b1b852a393e class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16973
diff changeset
  4192
    hasTimezone := false.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4193
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4194
    "Created: / 16-06-2005 / 09:54:21 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4195
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4196
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4197
readTimezoneOffset
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4198
    "Read time zone offset as a number minutes. Generally, there should be hours only
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4199
    but as the format introduces minutes in offsets, we must accept them."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4200
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4201
    | hours digit |
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4202
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4203
    "Read hours."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4204
    hours := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4205
    (hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4206
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4207
    stream peekOrNil = $:
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4208
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4209
	    "Colon read, minutes must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4210
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4211
	    digit := self nextDigits: 2.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4212
	    (digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4213
	    ^Array with: hours with: digit].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4214
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4215
    "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
  4216
     check boundaries."
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4217
    digit := self nextDigit.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4218
    digit < 0 ifTrue: [^Array with: hours with: 0].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4219
    digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4220
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4221
    "Read the last digit of offset, it must be present."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4222
    ^Array with: hours with: digit * 10 + self nextDigitOrError
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4223
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4224
    "Created: / 15-06-2005 / 15:35:41 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4225
    "Modified: / 15-06-2005 / 17:45:58 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4226
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4227
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4228
readWeekNumber
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4229
16914
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4230
    | week dayInWeek digit |
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4231
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4232
    "Read week number. It is always two digits long."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4233
    week := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4234
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4235
    stream peekOrNil = $-
17006
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4236
	ifTrue: [
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4237
	    "Got dash, day number must follow."
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4238
	    stream next.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4239
	    digit := self nextDigit.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4240
	    digit < 0 ifTrue: [self malformed: 'Bad weekday number'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4241
	    digit > 7 ifTrue: [self malformed: 'Bad weekday number'].
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4242
	    self dateFromWeek: week andWeekday: digit.
d6ec5e448ac5 timestamp changes
Claus Gittinger <cg@exept.de>
parents: 17005
diff changeset
  4243
	    ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4244
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4245
    "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
  4246
    dayInWeek := self nextDigit.
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4247
    dayInWeek <= 0 ifTrue: [dayInWeek := 1].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4248
    dayInWeek > 7 ifTrue: [self malformed: 'Bad weekday number'].
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4249
c550a2e2359d class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 16901
diff changeset
  4250
    self dateFromWeek: week andWeekday: dayInWeek
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4251
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4252
    "Created: / 14-06-2005 / 12:06:47 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4253
    "Modified: / 15-06-2005 / 15:53:34 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4254
!
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4255
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4256
readYear
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4257
    "Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4258
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4259
    | read peek |
13236
74872163b47b Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents: 13225
diff changeset
  4260
    stream peekOrNil = $:
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4261
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4262
            "Broken two digit year > 1999 follows."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4263
            stream next.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4264
            year := self nextDigitOrError + 2000.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4265
            ^self].
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4266
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4267
    "Expecting two-, three- or four-digit year"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4268
    "Read the first two digits. They must be there."
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4269
    read := self nextDigits: 2.
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4270
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4271
    "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
  4272
    peek := stream peekOrNil.
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4273
    peek ifNil: [^self].
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4274
17067
b32e90d1cc4d simplified the code
Claus Gittinger <cg@exept.de>
parents: 17049
diff changeset
  4275
    ((peek == $-) or:[peek == $W])
17465
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4276
        ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4277
            "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
  4278
            year := read < 70
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4279
                ifTrue: [read + 2000]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4280
                ifFalse: [read + 1900]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4281
        ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4282
            "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
  4283
             read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4284
             peek := stream peekOrNil.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4285
             (peek isNil or: [peek == $-])
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4286
                ifTrue: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4287
                    "Read three digit year, return it."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4288
                    year :=  read + 1900
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4289
                ] ifFalse: [
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4290
                    "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
  4291
                    two-digit year format is deprecated anyway."
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4292
                    read := read * 10 + self nextDigitOrError.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4293
                    year :=  read.
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4294
                ]
e78bccbfe573 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 17424
diff changeset
  4295
        ]
11993
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4296
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4297
    "Created: / 14-06-2005 / 12:01:11 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4298
    "Modified: / 15-06-2005 / 17:31:56 / masca"
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4299
! !
f303ffa58005 abstract timestamp builder
fm
parents: 11876
diff changeset
  4300
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4301
!Timestamp class methodsFor:'documentation'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4302
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4303
version
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4304
    ^ '$Header$'
12164
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4305
!
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4306
b87f20d77369 added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 11994
diff changeset
  4307
version_CVS
18761
2358ffda3751 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18455
diff changeset
  4308
    ^ '$Header$'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4309
! !
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4310
14713
eb944b3267e6 class: Timestamp
Claus Gittinger <cg@exept.de>
parents: 14428
diff changeset
  4311
8246
7b66fe46e2c3 defined source container
Stefan Vogel <sv@exept.de>
parents: 8223
diff changeset
  4312
Timestamp initialize!