author | Claus Gittinger <cg@exept.de> |
Tue, 22 Mar 2016 12:52:45 +0100 | |
changeset 19398 | 7384b2086a5d |
parent 19198 | 9ecddb1c5b63 |
child 19412 | 1e842c25e51e |
child 19654 | f07bf67efc5c |
permissions | -rw-r--r-- |
240 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
7010 | 3 |
All Rights Reserved |
240 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5548 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17400 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
240 | 16 |
Magnitude subclass:#AbstractTime |
7258 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
7672 | 20 |
category:'Magnitude-Time' |
240 | 21 |
! |
22 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
23 |
!AbstractTime class methodsFor:'documentation'! |
240 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
7010 | 28 |
All Rights Reserved |
240 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
41 |
This is an abstract class providing common protocol for Time (time in day) |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
42 |
and Timestamp (time plus day). |
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
43 |
There are no instances of this class in the system. |
275 | 44 |
It is meant as a home for methods common to time handling classes. |
1282 | 45 |
|
1295 | 46 |
[author:] |
47 |
Claus Gittinger |
|
48 |
||
1282 | 49 |
[See also:] |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
50 |
Time Date Timestamp |
1282 | 51 |
Delay ProcessorScheduler |
240 | 52 |
" |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
53 |
! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
54 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
55 |
iso8601Format |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
56 |
" |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
57 |
Abstract |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
58 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
59 |
This document defines a profile of ISO 8601, the International Standard for the representation of dates and times. ISO |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
60 |
8601 describes a large number of date/time formats. To reduce the scope for error and the complexity of software, it is |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
61 |
useful to restrict the supported formats to a small number. This profile defines a few date/time formats, likely to satisfy |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
62 |
most requirements. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
63 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
64 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
65 |
Formats |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
66 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
67 |
Different standards may need different levels of granularity in the date and time, so this profile defines six levels. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
68 |
Standards that reference this profile should specify one or more of these granularities. If a given standard allows more |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
69 |
than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
70 |
of comparing two dates with different precisions. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
71 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
72 |
The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
73 |
that the 'T' appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
74 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
75 |
Year: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
76 |
YYYY (eg 1997) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
77 |
Year and month: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
78 |
YYYY-MM (eg 1997-07) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
79 |
Complete date: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
80 |
YYYY-MM-DD (eg 1997-07-16) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
81 |
Complete date plus hours and minutes: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
82 |
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
83 |
Complete date plus hours, minutes and seconds: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
84 |
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
85 |
Complete date plus hours, minutes, seconds and a decimal fraction of a |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
86 |
second |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
87 |
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
88 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
89 |
where: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
90 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
91 |
YYYY = four-digit year |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
92 |
MM = two-digit month (01=January, etc.) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
93 |
DD = two-digit day of month (01 through 31) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
94 |
hh = two digits of hour (00 through 23) (am/pm NOT allowed) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
95 |
mm = two digits of minute (00 through 59) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
96 |
ss = two digits of second (00 through 59) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
97 |
s = one or more digits representing a decimal fraction of a second |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
98 |
TZD = time zone designator (Z or +hh:mm or -hh:mm) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
99 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
100 |
This profile does not specify how many digits may be used to represent the decimal fraction of a second. An adopting |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
101 |
standard that permits fractions of a second must specify both the minimum number of digits (a number greater than or |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
102 |
equal to one) and the maximum number of digits (the maximum may be stated to be 'unlimited'). |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
103 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
104 |
This profile defines two ways of handling time zone offsets: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
105 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
106 |
1.Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ('Z'). |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
107 |
2.Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
108 |
'+hh:mm' indicates that the date/time uses a local time zone which is 'hh' hours and 'mm' minutes ahead of |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
109 |
UTC. A time zone offset of '-hh:mm' indicates that the date/time uses a local time zone which is 'hh' hours and |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
110 |
'mm' minutes behind UTC. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
111 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
112 |
A standard referencing this profile should permit one or both of these ways of handling time zone offsets. |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
113 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
114 |
The ISO8601 printString are generated with: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
115 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
116 |
Year: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
117 |
YYYY (eg 1997) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
118 |
Date today printStringFormat:'%(year)' |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
119 |
Timestamp now printStringFormat:'%(year)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
120 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
121 |
Year and month: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
122 |
YYYY-MM (eg 1997-07) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
123 |
Date today printStringFormat:'%(year)-%(month)' |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
124 |
Timestamp now printStringFormat:'%(year)-%(month)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
125 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
126 |
Complete date: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
127 |
YYYY-MM-DD (eg 1997-07-16) |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
128 |
Date today printStringFormat:'%(year)-%(month)-%(day)' |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
129 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
130 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
131 |
Complete date plus hours and minutes: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
132 |
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
133 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m%(TZD)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
134 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
135 |
Complete date plus hours, minutes and seconds: |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
136 |
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
137 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s%(TZD)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
138 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
139 |
Complete date plus hours, minutes, seconds and a decimal fraction of a second |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
140 |
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
141 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)' |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
142 |
" |
240 | 143 |
! ! |
144 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
145 |
!AbstractTime class methodsFor:'instance creation'! |
240 | 146 |
|
699 | 147 |
dateAndTimeNow |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
148 |
"return an array filled with the current date and time. |
16982 | 149 |
As these provide no timezone info, this should be only used for user interface purposes. |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
150 |
See also: Date today / Time now / Timestamp now." |
240 | 151 |
|
699 | 152 |
^ Array with:(Date today) with:(Time now) |
240 | 153 |
|
154 |
" |
|
16982 | 155 |
Time dateAndTimeNow |
156 |
Date dateAndTimeNow |
|
240 | 157 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
158 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
159 |
"Modified: 19.4.1996 / 15:23:37 / cg" |
275 | 160 |
! |
240 | 161 |
|
9432 | 162 |
epoch |
163 |
"answer the time when we start counting" |
|
164 |
||
165 |
^ self new setSeconds:0 |
|
166 |
||
167 |
" |
|
16982 | 168 |
Timestamp epoch |
169 |
Time epoch |
|
9432 | 170 |
" |
171 |
! |
|
172 |
||
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
173 |
now |
16982 | 174 |
"return an instance of myself representing this moment with second precision. |
175 |
Timestamps will redefine this to always return millisecond precision." |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
176 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
177 |
^ self basicNew fromOSTime:(OperatingSystem getOSTime) |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
178 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
179 |
" |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
180 |
Timestamp now |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
181 |
Time now |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
182 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
183 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
184 |
"Modified: 1.7.1996 / 15:20:10 / cg" |
13233 | 185 |
! |
186 |
||
16941 | 187 |
nowWithMilliseconds |
16982 | 188 |
"return an instance of myself representing this moment with millisecond precision." |
16941 | 189 |
|
190 |
^ self basicNew fromOSTimeWithMilliseconds:(OperatingSystem getOSTime) |
|
191 |
||
192 |
" |
|
193 |
Timestamp now |
|
194 |
Time now |
|
195 |
Time nowWithMilliseconds |
|
196 |
" |
|
197 |
||
198 |
"Modified: 1.7.1996 / 15:20:10 / cg" |
|
199 |
! |
|
200 |
||
13233 | 201 |
utcNow |
202 |
"return an instance of myself representing this momentin the UTC timezone." |
|
203 |
||
204 |
^ self subclassResponsibility |
|
205 |
||
206 |
" |
|
207 |
Timestamp utcNow |
|
208 |
Timestamp utcNow |
|
209 |
||
210 |
Time now |
|
211 |
Time utcNow |
|
212 |
" |
|
213 |
||
214 |
"Modified: 1.7.1996 / 15:20:10 / cg" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
215 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
216 |
|
7294 | 217 |
!AbstractTime class methodsFor:'Compatibility-Squeak'! |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
218 |
|
9432 | 219 |
dateAndTimeFromSeconds:secondCount |
220 |
"set date and time from seconds since 1901-01-01 00:00 UTC" |
|
221 |
||
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
222 |
|timestamp| |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
223 |
|
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
224 |
" |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
225 |
secondsBetween1901and1970 := |
9432 | 226 |
(Timestamp epoch asDate subtractDate:(Date day:1 month:1 year:1901)) |
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
227 |
* (24 * 60 * 60) |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
228 |
" |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
229 |
|
9432 | 230 |
"stc cannot make large integers" |
9449
6ba774be6aa1
stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents:
9432
diff
changeset
|
231 |
timestamp := Timestamp fromSeconds:secondCount - 2177452800. |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
232 |
^ Array |
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
233 |
with: (timestamp asDate) |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
234 |
with: (timestamp asTime) |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
235 |
|
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
236 |
" |
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
237 |
Timestamp dateAndTimeFromSeconds: (Time primSecondsClock) |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
238 |
Time dateAndTimeFromSeconds: (Time totalSeconds) |
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
239 |
Date dateAndTimeFromSeconds: (Time totalSeconds) |
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
240 |
" |
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
241 |
! |
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
242 |
|
11528 | 243 |
milliseconds:msTime1 since:msTime2 |
244 |
"return the number of milliseconds between two |
|
245 |
millisecond time values, compensating for roll-over. |
|
246 |
The same as millisecondsBetween:and: for Squeak compatibility." |
|
247 |
||
248 |
^ OperatingSystem millisecondTimeDeltaBetween:msTime1 and:msTime2 |
|
249 |
! |
|
250 |
||
9926 | 251 |
millisecondsSince: lastTime |
252 |
"Answer the elapsed time since last recorded in milliseconds. |
|
253 |
Compensate for rollover." |
|
254 |
||
255 |
^self milliseconds: self millisecondClockValue since: lastTime |
|
256 |
! |
|
257 |
||
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
258 |
primSecondsClock |
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
259 |
"returns the number of seconds since 1.1.1901 UTC" |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
260 |
|
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
261 |
^ Timestamp now utcSecondsSince1901 |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
262 |
|
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
263 |
" |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
264 |
Timestamp primSecondsClock |
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
265 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
266 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
267 |
|
7294 | 268 |
!AbstractTime class methodsFor:'Compatibility-VW'! |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
269 |
|
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
270 |
totalSeconds |
9429
173bcd493d7c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
8586
diff
changeset
|
271 |
"returns the number of seconds since 1.1.1901 UTC" |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
272 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
273 |
^ Timestamp now utcSecondsSince1901 |
7007
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
274 |
! ! |
9af8cc2f82a4
totalSeconds returns the number of seconds since 1.1.1901 now
penk
parents:
6888
diff
changeset
|
275 |
|
11130 | 276 |
!AbstractTime class methodsFor:'error handling'! |
277 |
||
278 |
conversionErrorSignal |
|
279 |
"return the signal used for conversion error handling" |
|
280 |
||
281 |
^ TimeConversionError |
|
282 |
! ! |
|
283 |
||
13701 | 284 |
!AbstractTime class methodsFor:'format strings'! |
285 |
||
286 |
defaultFormatString |
|
287 |
^ '%h:%m:%s' |
|
288 |
! ! |
|
289 |
||
18454 | 290 |
|
7258 | 291 |
!AbstractTime class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
292 |
|
275 | 293 |
fromOSTime:osTime |
294 |
"return a time, representing the time given by the operatingSystem time. |
|
295 |
Not meant for public use." |
|
296 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
297 |
^ self basicNew fromOSTime:osTime. |
418 | 298 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
299 |
"Modified: 1.7.1996 / 15:09:54 / cg" |
240 | 300 |
! |
301 |
||
699 | 302 |
fromSeconds:seconds |
303 |
"return an instance that is constructed from seconds. |
|
304 |
This method is only allowed for second values as returned by |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
305 |
getSeconds, possibly adding/subtracting to that. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
306 |
Never depend on any specific interpretation of the seconds, |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
307 |
since it depends on how the OperatingSystem counts time |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
308 |
(some start at 1900, others with 1970 ...)" |
240 | 309 |
|
699 | 310 |
^ self basicNew setSeconds:seconds |
240 | 311 |
|
312 |
" |
|
699 | 313 |
Time fromSeconds:0 should return midnight |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
314 |
Timestamp fromSeconds:0 on UNIX: returns 1st. Jan 1970 |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
315 |
on others: dont know |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
316 |
(Timestamp day:1 month:1 year:1970 hour:1 minutes:0 seconds:0) |
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
317 |
getSeconds on UNIX: returns 0 |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
318 |
on others: dont know |
699 | 319 |
" |
320 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
321 |
"Modified: 1.7.1996 / 13:39:30 / cg" |
240 | 322 |
! ! |
323 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
324 |
!AbstractTime class methodsFor:'queries'! |
275 | 325 |
|
18918 | 326 |
isAbstract |
327 |
^ self == AbstractTime |
|
328 |
! |
|
329 |
||
15684 | 330 |
microsecondClockValue |
331 |
"return microseconds seconds of now" |
|
332 |
||
333 |
^ OperatingSystem getMicrosecondTime |
|
334 |
||
335 |
" |
|
336 |
Time microsecondClockValue |
|
337 |
" |
|
338 |
||
339 |
" |
|
340 |
|t1 t2 overhead| |
|
341 |
||
342 |
t1 := Time microsecondClockValue. |
|
343 |
t2 := Time microsecondClockValue. |
|
344 |
overhead := t2 - t1. |
|
345 |
||
346 |
t1 := Time microsecondClockValue. |
|
347 |
100 factorial. |
|
348 |
t2 := Time microsecondClockValue. |
|
349 |
t2 - t1 - overhead |
|
350 |
" |
|
351 |
! |
|
352 |
||
699 | 353 |
millisecondClockValue |
354 |
"return the millisecond clock - since this one overruns |
|
355 |
regularly, use the value only for short timing deltas. |
|
5730 | 356 |
Also remember that it wraps when comparing these values." |
275 | 357 |
|
699 | 358 |
^ OperatingSystem getMillisecondTime. |
359 |
||
360 |
" |
|
361 |
Time millisecondClockValue |
|
362 |
" |
|
275 | 363 |
! |
364 |
||
699 | 365 |
secondClock |
366 |
"return seconds of now - for GNU-ST compatibility" |
|
367 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
368 |
^ OperatingSystem getOSTime // 1000 |
699 | 369 |
|
370 |
" |
|
371 |
AbstractTime secondClock |
|
372 |
" |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
373 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
374 |
"Modified: 1.7.1996 / 15:20:14 / cg" |
699 | 375 |
! ! |
376 |
||
18454 | 377 |
!AbstractTime class methodsFor:'reading'! |
378 |
||
379 |
readFrom:aStringOrStream format:formatString |
|
380 |
"see format description in readFrom:format:language:onError:" |
|
381 |
||
382 |
^ self |
|
383 |
readFrom:aStringOrStream format:formatString language:nil |
|
384 |
onError:[ |
|
385 |
self conversionErrorSignal raiseErrorString:'Timestamp format error' |
|
386 |
]. |
|
387 |
! |
|
388 |
||
389 |
readFrom:aStringOrStream format:formatString onError:exceptionalValue |
|
390 |
"see format description in readFrom:format:language:onError:" |
|
391 |
||
392 |
^ self readFrom:aStringOrStream format:formatString language:nil onError:exceptionalValue |
|
393 |
! ! |
|
394 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
395 |
!AbstractTime class methodsFor:'timing evaluations'! |
275 | 396 |
|
12831 | 397 |
microsecondsToRun:aBlock |
16673 | 398 |
"evaluate the argument, aBlock; return the number of microseconds it took" |
12831 | 399 |
|
400 |
|startTime endTime| |
|
401 |
||
402 |
startTime := OperatingSystem getMicrosecondTime. |
|
403 |
aBlock value. |
|
404 |
endTime := OperatingSystem getMicrosecondTime. |
|
405 |
^ endTime - startTime |
|
406 |
||
407 |
" |
|
408 |
Time microsecondsToRun:[1000 factorial] |
|
409 |
" |
|
16673 | 410 |
|
411 |
"Modified (comment): / 01-07-2014 / 15:57:13 / az" |
|
12831 | 412 |
! |
413 |
||
699 | 414 |
millisecondsToRun:aBlock |
415 |
"evaluate the argument, aBlock; return the number of milliseconds it took" |
|
416 |
||
417 |
|startTime endTime| |
|
418 |
||
1476 | 419 |
startTime := OperatingSystem getMillisecondTime. |
699 | 420 |
aBlock value. |
1476 | 421 |
endTime := OperatingSystem getMillisecondTime. |
8586
a38e882affa5
take care of time-wrap in #millisecondsToRun:
Stefan Vogel <sv@exept.de>
parents:
8450
diff
changeset
|
422 |
^ self milliseconds:endTime since:startTime |
699 | 423 |
|
424 |
" |
|
8586
a38e882affa5
take care of time-wrap in #millisecondsToRun:
Stefan Vogel <sv@exept.de>
parents:
8450
diff
changeset
|
425 |
Time millisecondsToRun:[1000 factorial] |
699 | 426 |
" |
1476 | 427 |
|
428 |
"Modified: 17.6.1996 / 16:57:37 / cg" |
|
275 | 429 |
! |
430 |
||
699 | 431 |
secondsToRun:aBlock |
432 |
"evaluate the argument, aBlock; return the number of seconds it took" |
|
433 |
||
434 |
|startTime endTime| |
|
360 | 435 |
|
699 | 436 |
startTime := self secondClock. |
437 |
aBlock value. |
|
438 |
endTime := self secondClock. |
|
439 |
^ endTime - startTime |
|
275 | 440 |
|
699 | 441 |
" |
442 |
Time secondsToRun:[1000 factorial] |
|
443 |
" |
|
275 | 444 |
! ! |
445 |
||
7261 | 446 |
!AbstractTime methodsFor:'Compatibility-ANSI'! |
6419 | 447 |
|
448 |
hour12 |
|
449 |
"return the hour (1..12)." |
|
450 |
||
451 |
^ self hours - 1 \\ 12 + 1. |
|
452 |
||
453 |
" |
|
454 |
Time now hour12 |
|
455 |
Time now hour24 |
|
456 |
(Time hours:0 minutes:0 seconds:0) hour24 |
|
457 |
(Time hours:0 minutes:0 seconds:0) hour12 |
|
458 |
(Time hours:1 minutes:0 seconds:0) hour24 |
|
459 |
(Time hours:1 minutes:0 seconds:0) hour12 |
|
460 |
(Time hours:12 minutes:0 seconds:0) hour24 |
|
461 |
(Time hours:12 minutes:0 seconds:0) hour12 |
|
462 |
(Time hours:13 minutes:0 seconds:0) hour24 |
|
463 |
(Time hours:13 minutes:0 seconds:0) hour12 |
|
464 |
(Time hours:23 minutes:0 seconds:0) hour24 |
|
465 |
(Time hours:23 minutes:0 seconds:0) hour12 |
|
466 |
(Time hours:24 minutes:0 seconds:0) hour24 |
|
467 |
(Time hours:24 minutes:0 seconds:0) hour12 |
|
468 |
" |
|
469 |
! |
|
470 |
||
471 |
hour24 |
|
472 |
"return the hour (0..23)." |
|
473 |
||
474 |
^ self hours |
|
475 |
||
476 |
" |
|
477 |
Time now hour12 |
|
478 |
Time now hour24 |
|
479 |
(Time hours:0 minutes:0 seconds:0) hour24 |
|
480 |
(Time hours:0 minutes:0 seconds:0) hour12 |
|
481 |
(Time hours:1 minutes:0 seconds:0) hour24 |
|
482 |
(Time hours:1 minutes:0 seconds:0) hour12 |
|
483 |
(Time hours:12 minutes:0 seconds:0) hour24 |
|
484 |
(Time hours:12 minutes:0 seconds:0) hour12 |
|
485 |
(Time hours:13 minutes:0 seconds:0) hour24 |
|
486 |
(Time hours:13 minutes:0 seconds:0) hour12 |
|
487 |
(Time hours:23 minutes:0 seconds:0) hour24 |
|
488 |
(Time hours:23 minutes:0 seconds:0) hour12 |
|
489 |
(Time hours:24 minutes:0 seconds:0) hour24 |
|
490 |
(Time hours:24 minutes:0 seconds:0) hour12 |
|
491 |
" |
|
492 |
! |
|
493 |
||
494 |
meridianAbbreviation |
|
495 |
"am/pm" |
|
496 |
||
497 |
self hours // 12 == 0 ifTrue:[ |
|
498 |
^ 'am'. |
|
499 |
] ifFalse:[ |
|
8200 | 500 |
(self hours == 12 and:[self minutes == 0 and:[self seconds == 0]]) ifTrue:[ |
501 |
^ 'noon' |
|
502 |
]. |
|
6419 | 503 |
^ 'pm'. |
504 |
]. |
|
505 |
||
506 |
" |
|
507 |
Time now meridianAbbreviation |
|
508 |
(Time hours:0 minutes:0 seconds:0) meridianAbbreviation |
|
509 |
(Time hours:11 minutes:59 seconds:59) meridianAbbreviation |
|
510 |
(Time hours:12 minutes:0 seconds:0) meridianAbbreviation |
|
511 |
(Time hours:12 minutes:0 seconds:1) meridianAbbreviation |
|
512 |
" |
|
513 |
! ! |
|
514 |
||
19398 | 515 |
|
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
516 |
!AbstractTime methodsFor:'abstract'! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
517 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
518 |
hours |
8200 | 519 |
"return the hour of time (0..23)" |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
520 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
521 |
^ self subclassResponsibility |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
522 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
523 |
" |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
524 |
Timestamp now hours |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
525 |
Time now hours |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
526 |
" |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
527 |
! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
528 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
529 |
milliseconds |
8200 | 530 |
"return the milliseconds since the start of the second (0..999)" |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
531 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
532 |
^ self subclassResponsibility |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
533 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
534 |
" |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
535 |
Timestamp now milliseconds |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
536 |
Time now milliseconds |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
537 |
" |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
538 |
! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
539 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
540 |
minutes |
8200 | 541 |
"return the minutes since the start of the hour (0..59)" |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
542 |
|
7672 | 543 |
^ self subclassResponsibility. |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
544 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
545 |
" |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
546 |
Timestamp now minutes |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
547 |
Time now minutes |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
548 |
" |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
549 |
! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
550 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
551 |
seconds |
8200 | 552 |
"return the seconds since the start of the minute (0..59)" |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
553 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
554 |
^ self subclassResponsibility |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
555 |
|
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
556 |
" |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
557 |
Timestamp now seconds. |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
558 |
Time now seconds |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
559 |
" |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
560 |
! ! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
561 |
|
275 | 562 |
!AbstractTime methodsFor:'accessing'! |
563 |
||
564 |
hourInDay |
|
565 |
"return the hours (0..23)" |
|
566 |
||
567 |
^ self hours |
|
568 |
||
569 |
" |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
570 |
Timestamp now hourInDay |
275 | 571 |
Time now hourInDay |
572 |
" |
|
573 |
! |
|
574 |
||
575 |
minuteInDay |
|
576 |
"return the minutes (0..59)" |
|
577 |
||
578 |
^ self minutes. |
|
579 |
||
580 |
" |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
581 |
Timestamp now minuteInDay |
275 | 582 |
Time now minuteInDay |
583 |
" |
|
584 |
! |
|
585 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
586 |
secondInDay |
275 | 587 |
"return the seconds (0..59)" |
588 |
||
589 |
^ self seconds |
|
590 |
||
591 |
" |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
592 |
Timestamp now secondInDay |
275 | 593 |
Time now seconds |
594 |
" |
|
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
595 |
|
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
596 |
"Created: 22.10.1996 / 09:27:47 / stefan" |
5548 | 597 |
! |
598 |
||
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
599 |
timeZoneDeltaInMinutes |
9432 | 600 |
"answer the number of minutes between local time and utc time. |
601 |
Delta is positive if local time is ahead of utc, negative if behind utc." |
|
602 |
||
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
603 |
^ 0 |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
604 |
! |
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
605 |
|
5968 | 606 |
timeZoneName |
16982 | 607 |
^ 'UTC' |
608 |
! |
|
609 |
||
610 |
utcOffset |
|
611 |
^ 0 |
|
275 | 612 |
! ! |
613 |
||
614 |
!AbstractTime methodsFor:'arithmetic'! |
|
615 |
||
10679 | 616 |
+ aNumberOrTimeDuration |
617 |
"Add aNumber numberOfSeconds or, if its a timeDuration, add its value" |
|
8200 | 618 |
|
10679 | 619 |
^ aNumberOrTimeDuration sumFromTimestamp:self. |
620 |
||
17015 | 621 |
"/ ^ self speciesNew |
10679 | 622 |
"/ setMilliseconds:(self getMilliseconds + (aNumberOrTimeDuration * 1000) asInteger) |
8200 | 623 |
|
624 |
" |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
625 |
Timestamp now to:(Timestamp now + 30) by:2 do:[:time| |
8200 | 626 |
Transcript showCR:time. |
627 |
]. |
|
628 |
||
10679 | 629 |
(Timestamp now + 20) - Timestamp now |
630 |
(Timestamp now + 0.5) - Timestamp now |
|
631 |
(Timestamp now + (TimeDuration fromString:'1m 10s')) - Timestamp now |
|
11771 | 632 |
(Timestamp now + (10 seconds)) - Timestamp now |
8200 | 633 |
" |
634 |
! |
|
635 |
||
636 |
- aTimeOrNumberOfSeconds |
|
8244 | 637 |
"return the delta in seconds between 2 times or subtract a number of seconds." |
275 | 638 |
|
11515 | 639 |
^ aTimeOrNumberOfSeconds differenceFromTimestamp:self. |
275 | 640 |
|
641 |
" |
|
11518 | 642 |
Timestamp now - 3600. |
11515 | 643 |
Time now - 3600. |
11518 | 644 |
(Time now addSeconds:10) - Time now |
11515 | 645 |
(TimeDuration fromString:'1.5hr') - 3600. |
646 |
(TimeDuration fromString:'1.5hr') - (TimeDuration fromString:'1hr') |
|
8200 | 647 |
|
275 | 648 |
|t1 t2| |
649 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
650 |
t1 := Timestamp now. |
16407 | 651 |
Delay waitFor:10 seconds. |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
652 |
t2 := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
653 |
Transcript showCR:('seconds passed: ' , (t2 - t1) printString). |
275 | 654 |
" |
655 |
! |
|
656 |
||
6048
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
657 |
addDays:numberOfDays |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
658 |
"return a new instance of myself, numberOfDays afterwards." |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
659 |
|
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
660 |
^ self addSeconds:(numberOfDays * (60 * 60 * 24)) |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
661 |
|
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
662 |
" |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
663 |
|t| |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
664 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
665 |
t := Timestamp now. |
6048
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
666 |
Transcript showCR:t. |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
667 |
Transcript showCR:(t addDays:7) |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
668 |
" |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
669 |
! |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
670 |
|
699 | 671 |
addHours:numberOfHours |
672 |
"return a new instance of myself, numberOfHours afterwards." |
|
275 | 673 |
|
699 | 674 |
^ self addSeconds:(numberOfHours * (60 * 60)) |
275 | 675 |
|
676 |
" |
|
677 |
|t| |
|
678 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
679 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
680 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
681 |
Transcript showCR:(t addHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
682 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
683 |
|
275 | 684 |
" |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
685 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
686 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
687 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
688 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
689 |
Transcript showCR:(t addHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
690 |
" |
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
691 |
! |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
692 |
|
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
693 |
addMilliseconds:numberOfMilliSeconds |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
694 |
"return a new instance of myself, numberOfMilliSeconds afterwards." |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
695 |
|
17015 | 696 |
^ self speciesNew |
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
697 |
setMilliseconds:(self getMilliseconds + numberOfMilliSeconds) |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
698 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
699 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
700 |
|t| |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
701 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
702 |
t := Timestamp now. |
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
703 |
Transcript showCR:t. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
704 |
Transcript showCR:(t addMilliseconds:100). |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
705 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
706 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
707 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
708 |
|t| |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
709 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
710 |
t := Time now. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
711 |
Transcript showCR:t. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
712 |
Transcript showCR:(t addMilliseconds:1000). |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
713 |
" |
275 | 714 |
! |
715 |
||
716 |
addMinutes:numberOfMinutes |
|
717 |
"return a new instance of myself, numberOfMinutes afterwards." |
|
718 |
||
719 |
^ self addSeconds:(numberOfMinutes * 60) |
|
720 |
||
721 |
" |
|
722 |
|t| |
|
723 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
724 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
725 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
726 |
Transcript showCR:(t addMinutes:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
727 |
" |
275 | 728 |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
729 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
730 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
731 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
732 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
733 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
734 |
Transcript showCR:(t addMinutes:60). |
275 | 735 |
" |
736 |
! |
|
737 |
||
699 | 738 |
addSeconds:numberOfSeconds |
739 |
"return a new instance of myself, numberOfSeconds afterwards." |
|
740 |
||
17015 | 741 |
^ self speciesNew |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
742 |
setMilliseconds:(self getMilliseconds + (numberOfSeconds * 1000)) |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
743 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
744 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
745 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
746 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
747 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
748 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
749 |
Transcript showCR:(t addSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
750 |
" |
699 | 751 |
|
752 |
" |
|
753 |
|t| |
|
754 |
||
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
755 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
756 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
757 |
Transcript showCR:(t addSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
758 |
" |
699 | 759 |
! |
760 |
||
761 |
addTime:timeAmount |
|
762 |
"return a new instance of myself, timeAmount seconds afterwards. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
763 |
Provided for ST-80 compatibility. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
764 |
WARNING: |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
765 |
AddTime is a bad name - it does not add a time, but expects |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
766 |
a numberOfSeconds as argument. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
767 |
Use any of addSeconds/addHours etc. to make things clear" |
699 | 768 |
|
6888
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
769 |
timeAmount isNumber ifFalse:[ |
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
770 |
^ self addSeconds:(timeAmount asSeconds). |
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
771 |
]. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
772 |
^ self addSeconds:timeAmount |
699 | 773 |
! |
774 |
||
16475 | 775 |
deltaFrom:aTimeOrInteger |
776 |
"return the delta as a timeDuration between 2 timeStamps. |
|
777 |
The argument is supposed to be BEFORE the receiver, |
|
778 |
computes self - aTimestamp" |
|
779 |
||
780 |
^ aTimeOrInteger differenceFromTimestamp:self |
|
781 |
||
782 |
" |
|
783 |
Time now deltaFrom:10 minutes. |
|
784 |
Time now deltaFrom:3600. |
|
785 |
Time now deltaFrom:3600 seconds. |
|
786 |
||
787 |
Timestamp now deltaFrom:10 minutes. |
|
788 |
Timestamp now deltaFrom:3600. |
|
789 |
Timestamp now deltaFrom:3600 seconds. |
|
790 |
" |
|
791 |
||
792 |
" |
|
793 |
|t1 t2| |
|
794 |
||
795 |
t1 := Timestamp now. |
|
796 |
Delay waitForSeconds:0.5. |
|
797 |
t2 := Timestamp now. |
|
798 |
t2 deltaFrom:t1 |
|
799 |
" |
|
800 |
||
801 |
"Created: / 04-10-2007 / 13:34:28 / cg" |
|
802 |
"Modified: / 10-07-2010 / 09:37:01 / cg" |
|
803 |
! |
|
804 |
||
16505 | 805 |
roundTo:aTimeDuration |
806 |
^ self class new setMilliseconds:(self getMilliseconds roundTo:aTimeDuration getMilliseconds) |
|
807 |
||
808 |
" |
|
809 |
(TimeDuration fromMilliseconds:25234) roundTo:2 seconds |
|
810 |
Time now roundTo:10 minutes |
|
811 |
Timestamp now roundTo:10 minutes |
|
812 |
" |
|
813 |
! |
|
814 |
||
6048
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
815 |
subtractDays:numberOfDays |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
816 |
"return a new instance of myself, numberOfDays before." |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
817 |
|
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
818 |
^ self subtractSeconds:(numberOfDays * (60 * 60 * 24)) |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
819 |
|
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
820 |
" |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
821 |
|t| |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
822 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
823 |
t := Timestamp now. |
6048
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
824 |
Transcript showCR:t. |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
825 |
Transcript showCR:(t subtractDays:50) |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
826 |
" |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
827 |
! |
af4b1127f362
refactored - some methods moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
6043
diff
changeset
|
828 |
|
699 | 829 |
subtractHours:numberOfHours |
830 |
"return a new instance of myself, numberOfHours before." |
|
831 |
||
832 |
^ self subtractSeconds:(numberOfHours * (60 * 60)) |
|
275 | 833 |
|
834 |
" |
|
835 |
|t| |
|
836 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
837 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
838 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
839 |
Transcript showCR:(t subtractHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
840 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
841 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
842 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
843 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
844 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
845 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
846 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
847 |
Transcript showCR:(t subtractHours:12). |
275 | 848 |
" |
849 |
! |
|
850 |
||
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
851 |
subtractMilliseconds:numberOfMilliSeconds |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
852 |
"return a new instance of myself, numberOfMilliSeconds before." |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
853 |
|
17015 | 854 |
^ self speciesNew |
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
855 |
setMilliseconds:(self getMilliseconds - numberOfMilliSeconds) |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
856 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
857 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
858 |
|t| |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
859 |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
860 |
t := Timestamp now. |
6043
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
861 |
Transcript showCR:t. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
862 |
Transcript showCR:(t subtractMilliseconds:100). |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
863 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
864 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
865 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
866 |
|t| |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
867 |
|
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
868 |
t := Time now. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
869 |
Transcript showCR:t. |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
870 |
Transcript showCR:(t subtractMilliseconds:1000). |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
871 |
" |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
872 |
! |
ee486429674b
pushed up addMilliseconds/subtractMilliseconds
Claus Gittinger <cg@exept.de>
parents:
5968
diff
changeset
|
873 |
|
275 | 874 |
subtractMinutes:numberOfMinutes |
875 |
"return a new instance of myself, numberOfMinutes before." |
|
876 |
||
877 |
^ self subtractSeconds:(numberOfMinutes * 60) |
|
878 |
||
879 |
" |
|
880 |
|t| |
|
881 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
882 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
883 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
884 |
Transcript showCR:(t subtractMinutes:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
885 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
886 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
887 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
888 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
889 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
890 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
891 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
892 |
Transcript showCR:(t subtractMinutes:60). |
275 | 893 |
" |
894 |
! |
|
895 |
||
699 | 896 |
subtractSeconds:numberOfSeconds |
897 |
"return a new instance of myself, numberOfSeconds before." |
|
275 | 898 |
|
17015 | 899 |
^ self speciesNew |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
900 |
setMilliseconds:(self getMilliseconds - (numberOfSeconds * 1000)) |
275 | 901 |
|
902 |
" |
|
903 |
|t| |
|
904 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
905 |
t := Timestamp now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
906 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
907 |
Transcript showCR:(t subtractSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
908 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
909 |
|
275 | 910 |
" |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
911 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
912 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
913 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
914 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
915 |
Transcript showCR:(t subtractSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
916 |
" |
275 | 917 |
! |
918 |
||
919 |
subtractTime:timeAmount |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
920 |
"return a new instance of myself, timeAmount seconds before myself. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
921 |
Provided for ST-80 compatibility. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
922 |
WARNING: |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
923 |
SubtractTime is a bad name - it does not add a time, but expects |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
924 |
a numberOfSeconds as argument. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
925 |
Use any of addSeconds/addHours etc. to make things clear" |
275 | 926 |
|
6888
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
927 |
timeAmount isNumber ifFalse:[ |
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
928 |
^ self subtractSeconds:(timeAmount asSeconds). |
d75cbe2e8ef7
addTime / subtractTime handle non-Number argument
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
929 |
]. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
930 |
^ self subtractSeconds:timeAmount |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
931 |
|
16505 | 932 |
! |
933 |
||
934 |
truncateTo:aTimeDuration |
|
935 |
^ self class new setMilliseconds:(self getMilliseconds truncateTo:aTimeDuration getMilliseconds) |
|
936 |
||
937 |
" |
|
938 |
(TimeDuration fromMilliseconds:25234) truncateTo:2 seconds |
|
939 |
Time now truncateTo:10 minutes |
|
940 |
Timestamp now truncateTo:10 minutes |
|
941 |
" |
|
275 | 942 |
! ! |
943 |
||
5573
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
944 |
!AbstractTime methodsFor:'comparing'! |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
945 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
946 |
< aTime |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
947 |
"return true if the receiver is before the argument" |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
948 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
949 |
^ self getMilliseconds < aTime getMilliseconds |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
950 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
951 |
"Modified: 3.7.1996 / 13:10:17 / cg" |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
952 |
! |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
953 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
954 |
> aTime |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
955 |
"return true if the receiver is after the argument" |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
956 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
957 |
^ self getMilliseconds > aTime getMilliseconds |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
958 |
|
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
959 |
"Modified: 1.7.1996 / 15:24:38 / cg" |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
960 |
! ! |
efd0dc6578ac
#-, #< and #> moved from AbsoluteTime
Claus Gittinger <cg@exept.de>
parents:
5548
diff
changeset
|
961 |
|
8200 | 962 |
!AbstractTime methodsFor:'converting'! |
963 |
||
964 |
asAbsoluteTime |
|
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
965 |
"deprecated, use #asTimestamp" |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
966 |
<resource:#obsolete> |
8200 | 967 |
|
12002 | 968 |
self obsoleteMethodWarning:'use #asTimestamp'. |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
969 |
^ self asTimestamp |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
970 |
! |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
971 |
|
13233 | 972 |
asLocalTimestamp |
973 |
"represent myself as a timestamp in the local timezone" |
|
974 |
||
975 |
^ self subclassResponsibility |
|
976 |
! |
|
977 |
||
17140 | 978 |
asMilliseconds |
979 |
"return the number of milliseconds elapsed since midnight" |
|
980 |
||
981 |
^ self getMilliseconds |
|
982 |
||
983 |
" |
|
984 |
Time now asMilliseconds |
|
985 |
Timestamp now asMilliseconds |
|
986 |
(TimeDuration days:1) asMilliseconds |
|
987 |
(TimeDuration hours:1) asMilliseconds |
|
988 |
" |
|
989 |
||
990 |
"Created: / 05-09-2011 / 10:40:15 / cg" |
|
991 |
! |
|
992 |
||
993 |
asSeconds |
|
19398 | 994 |
"get the seconds since some point of time in the past. |
995 |
For Time instances, this is the number of seconds elapsed since midnight; |
|
996 |
For TimeDurations, that is the duration in seconds; |
|
997 |
For TimeStamps, that is the number of seconds since the epoch" |
|
17140 | 998 |
|
999 |
^ self getSeconds |
|
1000 |
||
1001 |
" |
|
1002 |
Timestamp now asSeconds |
|
1003 |
Time now asSeconds |
|
1004 |
(TimeDuration days:1) asSeconds |
|
1005 |
" |
|
1006 |
! |
|
1007 |
||
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1008 |
asTimestamp |
13233 | 1009 |
"represent myself as a Timestamp" |
1010 |
||
1011 |
^ self subclassResponsibility |
|
1012 |
! |
|
1013 |
||
1014 |
asUtcTimestamp |
|
1015 |
"represent myself as a timestamp in the local timezone" |
|
1016 |
||
8200 | 1017 |
^ self subclassResponsibility |
1018 |
! ! |
|
1019 |
||
11518 | 1020 |
!AbstractTime methodsFor:'double dispatching'! |
1021 |
||
1022 |
differenceFromTimestamp:aTimestamp |
|
16365 | 1023 |
"/ the correct thing to do (and I will, in the future) is to |
1024 |
"/ return a TimeDuration: |
|
1025 |
"/ |
|
16934 | 1026 |
^ TimeDuration fromMilliseconds:(aTimestamp getMilliseconds - self getMilliseconds). |
16407 | 1027 |
|
16365 | 1028 |
"/ which is the same as: deltaFrom:aTimestamp |
1029 |
"/ |
|
1030 |
"/ however, there might be old code around, which is not be prepared for |
|
1031 |
"/ getting a non-number (the seconds). Therefore, for the meantime, |
|
1032 |
"/ we return: |
|
1033 |
||
1034 |
"/ ^ aTimestamp getSeconds - self getSeconds |
|
11518 | 1035 |
! ! |
1036 |
||
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1037 |
!AbstractTime methodsFor:'printing & storing'! |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1038 |
|
16829 | 1039 |
addBasicPrintBindingsTo:aDictionary language:languageOrNil |
1040 |
"private print support: add bindings for printing to aDictionary. |
|
1041 |
languageOrNil can be #en, #fr, #de or nil for the current language. |
|
1042 |
Here only basic bindings are added - no timezone am am/pm stuff, |
|
1043 |
which doesn't make sense for TimeDuration. |
|
1044 |
||
1045 |
bindings: |
|
1046 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
|
1047 |
%m minutes, 00..59 0-padded to length 2 |
|
1048 |
%s seconds, 00..59 0-padded to length 2 |
|
1049 |
%i milliseconds, 000..999 0-padded to length 3 |
|
1050 |
||
1051 |
Timestamp only: |
|
1052 |
%(day) day, 00..31 0-padded to length 2 |
|
1053 |
%(month) month, 00..12 0-padded to length 2 |
|
1054 |
%(year) year, 4 digits 0-padded to length 4 |
|
1055 |
||
1056 |
special: |
|
1057 |
%H 24-hours - unpadded |
|
1058 |
%M minutes - unpadded |
|
1059 |
%S seconds - unpadded |
|
1060 |
%I milliseconds, unpadded |
|
1061 |
||
1062 |
%t seconds within hour (unpadded) |
|
1063 |
%T seconds from midNight (unpadded) |
|
1064 |
||
1065 |
%(milli1) milliseconds, truncated to 1/10th of a second 0..9 |
|
1066 |
%(milli2) milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2 |
|
1067 |
%(milli3) milliseconds, same as %i for convenience |
|
1068 |
||
1069 |
Timestamp only: |
|
1070 |
%(Day) - day - unpadded |
|
1071 |
%(Month) - month - unpadded |
|
1072 |
%(yearOrTime) - year or time 5 digits as in unix-ls: |
|
1073 |
year if it is not the current year; |
|
1074 |
time otherwise |
|
1075 |
%(weekDay) - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
1076 |
||
1077 |
%(dayName) - full day name |
|
1078 |
%(DayName) - full day name, first character uppercase |
|
1079 |
%(DAYNAME) - full day name, all uppercase |
|
1080 |
||
1081 |
%(monthName) - full month name |
|
1082 |
%(MonthName) - full month name, first character uppercase |
|
1083 |
%(MONTHNAME) - full month name, all uppercase |
|
1084 |
||
1085 |
%(shortDayName) - short (abbreviated) day name |
|
1086 |
%(ShortDayName) - short (abbreviated) day name, first character uppercase |
|
1087 |
%(SHORTDAYNAME) - short (abbreviated) day name, all uppercase |
|
1088 |
||
1089 |
%(shortMonthName) - short (abbreviated) month name |
|
1090 |
%(ShortMonthName) - short (abbreviated) month name, first character uppercase |
|
1091 |
%(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase |
|
1092 |
||
1093 |
%(nth) - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
1094 |
%(weekDayNth) - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
1095 |
%(weekNth) - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
1096 |
||
1097 |
||
1098 |
The ISO8601 printString are generated with: |
|
1099 |
||
1100 |
Year: |
|
1101 |
YYYY (eg 1997) |
|
1102 |
Date today printStringFormat:'%(year)' |
|
1103 |
Timestamp now printStringFormat:'%(year)' |
|
1104 |
||
1105 |
Year and month: |
|
1106 |
YYYY-MM (eg 1997-07) |
|
1107 |
Date today printStringFormat:'%(year)-%(month)' |
|
1108 |
Timestamp now printStringFormat:'%(year)-%(month)' |
|
1109 |
||
1110 |
Complete date: |
|
1111 |
YYYY-MM-DD (eg 1997-07-16) |
|
1112 |
Date today printStringFormat:'%(year)-%(month)-%(day)' |
|
1113 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)' |
|
1114 |
||
1115 |
Complete date plus hours and minutes: |
|
1116 |
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) |
|
1117 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m%(TZD)' |
|
1118 |
||
1119 |
Complete date plus hours, minutes and seconds: |
|
1120 |
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) |
|
1121 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s%(TZD)' |
|
1122 |
||
1123 |
Complete date plus hours, minutes, seconds and a decimal fraction of a second |
|
1124 |
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) |
|
1125 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)' |
|
1126 |
||
1127 |
" |
|
1128 |
||
16926 | 1129 |
|time hours minutes seconds millis s t| |
16829 | 1130 |
|
16926 | 1131 |
time := self asTime. |
1132 |
hours := time hours. |
|
1133 |
minutes := time minutes. |
|
1134 |
seconds := time seconds. |
|
16829 | 1135 |
millis := self milliseconds. |
1136 |
||
1137 |
aDictionary at:$H put:(s := hours printString). |
|
1138 |
aDictionary at:$h put:(s leftPaddedTo:2 with:$0). |
|
1139 |
||
1140 |
aDictionary at:$M put:(s := minutes printString). |
|
1141 |
aDictionary at:$m put:(s leftPaddedTo:2 with:$0). |
|
1142 |
||
1143 |
aDictionary at:$S put:(s := seconds printString). |
|
1144 |
aDictionary at:$s put:(s leftPaddedTo:2 with:$0). |
|
1145 |
||
1146 |
aDictionary at:$I put:(s := millis printString). |
|
1147 |
aDictionary at:$i put:(t := s leftPaddedTo:3 with:$0). |
|
1148 |
aDictionary at:#milli3 put:t. |
|
1149 |
||
1150 |
aDictionary at:#milli1 put:((millis // 100) printString). |
|
1151 |
aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0). |
|
1152 |
||
1153 |
aDictionary at:$t put:(seconds * minutes) printString. |
|
1154 |
aDictionary at:$T put:(seconds * minutes * hours) printString. |
|
1155 |
||
1156 |
||
1157 |
" |
|
1158 |
|dict| |
|
1159 |
dict := Dictionary new. |
|
1160 |
Timestamp now addBasicPrintBindingsTo:dict language:#en. |
|
1161 |
dict inspect |
|
1162 |
" |
|
1163 |
! |
|
1164 |
||
4844 | 1165 |
addPrintBindingsTo:aDictionary |
16829 | 1166 |
<resource: #obsolete> |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1167 |
|
16829 | 1168 |
self obsoleteMethodWarning:'use #addPrintBindingsTo:language:'. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1169 |
self addPrintBindingsTo:aDictionary language:nil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1170 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1171 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1172 |
addPrintBindingsTo:aDictionary language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7672
diff
changeset
|
1173 |
"private print support: add bindings for printing to aDictionary. |
13175 | 1174 |
languageOrNil can be #en, #fr, #de or nil for the current language. |
1175 |
||
11772 | 1176 |
bindings: |
1177 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
|
1178 |
%u hours, 00..12 (i.e. us) 0-padded to length 2 |
|
1179 |
%m minutes, 00..59 0-padded to length 2 |
|
1180 |
%s seconds, 00..59 0-padded to length 2 |
|
1181 |
%i milliseconds, 000..999 0-padded to length 3 |
|
1182 |
%a am/pm |
|
1183 |
||
1184 |
Timestamp only: |
|
1185 |
%(day) day, 00..31 0-padded to length 2 |
|
1186 |
%(month) month, 00..12 0-padded to length 2 |
|
1187 |
%(year) year, 4 digits 0-padded to length 4 |
|
1188 |
||
1189 |
special: |
|
1190 |
%H 24-hours - unpadded |
|
1191 |
%U 12-hours - unpadded |
|
1192 |
%M minutes - unpadded |
|
1193 |
%S seconds - unpadded |
|
1194 |
%I milliseconds, unpadded |
|
1195 |
%A AM/PM - uppercase |
|
1196 |
||
1197 |
%t seconds within hour (unpadded) |
|
1198 |
%T seconds from midNight (unpadded) |
|
1199 |
||
16982 | 1200 |
%(TZD) timeZone delta of the receiver from UTC in the format +/-hh:mm |
11772 | 1201 |
|
13175 | 1202 |
%(milli1) milliseconds, truncated to 1/10th of a second 0..9 |
1203 |
%(milli2) milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2 |
|
14493
0a3c9081d40a
changed: #addPrintBindingsTo:language:
Claus Gittinger <cg@exept.de>
parents:
13701
diff
changeset
|
1204 |
%(milli3) milliseconds, same as %i for convenience |
11772 | 1205 |
|
1206 |
Timestamp only: |
|
13175 | 1207 |
%(Day) - day - unpadded |
1208 |
%(Month) - month - unpadded |
|
1209 |
%(yearOrTime) - year or time 5 digits as in unix-ls: |
|
1210 |
year if it is not the current year; |
|
1211 |
time otherwise |
|
1212 |
%(weekDay) - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
1213 |
||
1214 |
%(dayName) - full day name |
|
1215 |
%(DayName) - full day name, first character uppercase |
|
1216 |
%(DAYNAME) - full day name, all uppercase |
|
1217 |
||
1218 |
%(monthName) - full month name |
|
1219 |
%(MonthName) - full month name, first character uppercase |
|
1220 |
%(MONTHNAME) - full month name, all uppercase |
|
1221 |
||
1222 |
%(shortDayName) - short (abbreviated) day name |
|
1223 |
%(ShortDayName) - short (abbreviated) day name, first character uppercase |
|
1224 |
%(SHORTDAYNAME) - short (abbreviated) day name, all uppercase |
|
1225 |
||
1226 |
%(shortMonthName) - short (abbreviated) month name |
|
1227 |
%(ShortMonthName) - short (abbreviated) month name, first character uppercase |
|
1228 |
%(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase |
|
1229 |
||
1230 |
%(nth) - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
1231 |
%(weekDayNth) - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
1232 |
%(weekNth) - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
11772 | 1233 |
|
17195 | 1234 |
%(yearRoman) - year, in roman letters |
1235 |
%(monthRoman) - month, in roman letters |
|
1236 |
||
11772 | 1237 |
|
1238 |
The ISO8601 printString are generated with: |
|
1239 |
||
1240 |
Year: |
|
1241 |
YYYY (eg 1997) |
|
1242 |
Date today printStringFormat:'%(year)' |
|
1243 |
Timestamp now printStringFormat:'%(year)' |
|
1244 |
||
1245 |
Year and month: |
|
1246 |
YYYY-MM (eg 1997-07) |
|
1247 |
Date today printStringFormat:'%(year)-%(month)' |
|
1248 |
Timestamp now printStringFormat:'%(year)-%(month)' |
|
1249 |
||
1250 |
Complete date: |
|
1251 |
YYYY-MM-DD (eg 1997-07-16) |
|
1252 |
Date today printStringFormat:'%(year)-%(month)-%(day)' |
|
1253 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)' |
|
1254 |
||
1255 |
Complete date plus hours and minutes: |
|
1256 |
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) |
|
1257 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m%(TZD)' |
|
1258 |
||
1259 |
Complete date plus hours, minutes and seconds: |
|
1260 |
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) |
|
1261 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s%(TZD)' |
|
1262 |
||
1263 |
Complete date plus hours, minutes, seconds and a decimal fraction of a second |
|
1264 |
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) |
|
1265 |
Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)' |
|
1266 |
||
1267 |
" |
|
4844 | 1268 |
|
16829 | 1269 |
|usHours ampm s zone tzDelta| |
4844 | 1270 |
|
16829 | 1271 |
self addBasicPrintBindingsTo:aDictionary language:languageOrNil. |
5968 | 1272 |
zone := self timeZoneName. |
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
1273 |
tzDelta := self timeZoneDeltaInMinutes. |
4844 | 1274 |
|
6419 | 1275 |
ampm := self meridianAbbreviation. |
16829 | 1276 |
usHours := self hour12 printString. |
1277 |
aDictionary at:$U put:usHours. |
|
1278 |
aDictionary at:$u put:(usHours leftPaddedTo:2 with:$0). |
|
14493
0a3c9081d40a
changed: #addPrintBindingsTo:language:
Claus Gittinger <cg@exept.de>
parents:
13701
diff
changeset
|
1279 |
|
0a3c9081d40a
changed: #addPrintBindingsTo:language:
Claus Gittinger <cg@exept.de>
parents:
13701
diff
changeset
|
1280 |
|
12662 | 1281 |
aDictionary at:$a put:ampm. |
1282 |
aDictionary at:$A put:ampm asUppercase. |
|
1283 |
aDictionary at:$z put:zone. |
|
1284 |
aDictionary at:$Z put:zone asUppercase. |
|
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
1285 |
|
9432 | 1286 |
tzDelta == 0 ifTrue:[ |
1287 |
s := 'Z'. |
|
1288 |
] ifFalse:[ |
|
1289 |
s := tzDelta < 0 ifTrue:[ '-' ] ifFalse:[ '+' ]. |
|
1290 |
tzDelta := tzDelta abs. |
|
1291 |
s := s , ((tzDelta // 60) printStringLeftPaddedTo:2 with:$0), |
|
1292 |
':' , ((tzDelta \\ 60) printStringLeftPaddedTo:2 with:$0). |
|
1293 |
]. |
|
6172
a3c88ea5efe9
comment and iso8601 (time/date formats) fixes
Claus Gittinger <cg@exept.de>
parents:
6048
diff
changeset
|
1294 |
aDictionary at:#TZD put:s |
13082 | 1295 |
|
1296 |
||
1297 |
" |
|
1298 |
|dict| |
|
1299 |
dict := Dictionary new. |
|
1300 |
Timestamp now addPrintBindingsTo:dict language:#en. |
|
1301 |
dict inspect |
|
1302 |
" |
|
4844 | 1303 |
! |
1304 |
||
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1305 |
printOn:aStream format:aFormatString |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1306 |
"print using a format string; |
13175 | 1307 |
See #addPrintBindingsTo:language: for allowed format strings" |
7327 | 1308 |
|
13175 | 1309 |
self printOn:aStream format:aFormatString language:nil. |
10907
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1310 |
|
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1311 |
" |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1312 |
Timestamp now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1313 |
Time now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1314 |
Time now printOn:Transcript format:'%H:%m:%s' . Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1315 |
Time now printOn:Transcript format:'%u:%m:%s %a'. Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1316 |
Time now printOn:Transcript format:'%h:%m' . Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1317 |
Time now printOn:Transcript format:'%H:%m %A' . Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1318 |
Time now printOn:Transcript format:'minutes:%M seconds:%S'. Transcript cr. |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1319 |
" |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1320 |
|
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1321 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1322 |
! |
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1323 |
|
13082 | 1324 |
printOn:aStream format:aFormatString language:languageString |
1325 |
"print using a format string; |
|
13175 | 1326 |
See #addPrintBindingsTo:language: for allowed format strings" |
13082 | 1327 |
|
1328 |
|dict| |
|
1329 |
||
1330 |
dict := IdentityDictionary new. |
|
1331 |
self addPrintBindingsTo:dict language:languageString. |
|
1332 |
||
1333 |
aFormatString expandPlaceholdersWith:dict on:aStream |
|
1334 |
||
1335 |
" |
|
1336 |
Timestamp now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
|
1337 |
Time now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
|
1338 |
Time now printOn:Transcript format:'%H:%m:%s' . Transcript cr. |
|
1339 |
Time now printOn:Transcript format:'%u:%m:%s %a'. Transcript cr. |
|
1340 |
Time now printOn:Transcript format:'%h:%m' . Transcript cr. |
|
1341 |
Time now printOn:Transcript format:'%H:%m %A' . Transcript cr. |
|
1342 |
Time now printOn:Transcript format:'minutes:%M seconds:%S'. Transcript cr. |
|
1343 |
" |
|
1344 |
||
1345 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
|
1346 |
! |
|
1347 |
||
10907
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1348 |
printStringFormat:aFormatString |
13175 | 1349 |
"print using a format string. |
1350 |
See #addPrintBindingsTo:language: for allowed format strings" |
|
10907
8b98ba82a46f
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10770
diff
changeset
|
1351 |
|
13175 | 1352 |
^ self printStringFormat:aFormatString language:nil. |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1353 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1354 |
" |
17400 | 1355 |
Timestamp now printStringFormat:'%U:%m:%s %a' |
1356 |
Timestamp now printStringFormat:'%u:%m:%s %a' |
|
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1357 |
Time now printStringFormat:'%U:%m:%s %a' |
17400 | 1358 |
Time now printStringFormat:'%u:%m:%s %a' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1359 |
|
4844 | 1360 |
Time now printStringFormat:'%h:%m:%s' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1361 |
Time now printStringFormat:'%H:%m:%s' |
4844 | 1362 |
Time now printStringFormat:'%H:%m:%s.%i' |
8256
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1363 |
Timestamp now printStringFormat:'%H:%m:%s.%i' |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1364 |
Timestamp now printStringFormat:'%H:%m:%s.%(milli1)' |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1365 |
Timestamp now printStringFormat:'%H:%m:%s.%(milli2)' |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1366 |
Timestamp now printStringFormat:'%(day)-%(month)-%(year) :%m:%s' |
4c3d944ef85a
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8244
diff
changeset
|
1367 |
Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1368 |
Time now printStringFormat:'%u:%m:%s %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1369 |
Time now printStringFormat:'%h:%m' |
4844 | 1370 |
Time now printStringFormat:'%h:%m' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1371 |
Time now printStringFormat:'%H:%m %A' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1372 |
Time now printStringFormat:'%m minutes after %U %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1373 |
Time now printStringFormat:'%t seconds after %U %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1374 |
Time now printStringFormat:'%T seconds from midNight' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1375 |
" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1376 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1377 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
13082 | 1378 |
! |
1379 |
||
1380 |
printStringFormat:aFormatString language:languageString |
|
13175 | 1381 |
"print using a format string. |
1382 |
See #addPrintBindingsTo:language: for allowed format strings" |
|
13082 | 1383 |
|
1384 |
|s| |
|
1385 |
||
16829 | 1386 |
s := CharacterWriteStream on:(String new:20). |
13082 | 1387 |
self printOn:s format:aFormatString language:languageString. |
1388 |
^ s contents. |
|
1389 |
||
1390 |
" |
|
1391 |
Timestamp now printStringFormat:'%U:%m:%s %a |
|
1392 |
Time now printStringFormat:'%U:%m:%s %a' |
|
1393 |
||
1394 |
Time now printStringFormat:'%h:%m:%s' |
|
1395 |
Time now printStringFormat:'%H:%m:%s' |
|
1396 |
Time now printStringFormat:'%H:%m:%s.%i' |
|
1397 |
Timestamp now printStringFormat:'%H:%m:%s.%i' |
|
1398 |
Timestamp now printStringFormat:'%H:%m:%s.%(milli1)' |
|
1399 |
Timestamp now printStringFormat:'%H:%m:%s.%(milli2)' |
|
1400 |
Timestamp now printStringFormat:'%(day)-%(month)-%(year) :%m:%s' |
|
13175 | 1401 |
Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#en |
1402 |
Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#de |
|
1403 |
Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#fr |
|
13082 | 1404 |
Time now printStringFormat:'%u:%m:%s %a' |
1405 |
Time now printStringFormat:'%h:%m' |
|
1406 |
Time now printStringFormat:'%h:%m' |
|
1407 |
Time now printStringFormat:'%H:%m %A' |
|
1408 |
Time now printStringFormat:'%m minutes after %U %a' |
|
1409 |
Time now printStringFormat:'%t seconds after %U %a' |
|
1410 |
Time now printStringFormat:'%T seconds from midNight' |
|
1411 |
" |
|
1412 |
||
1413 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
|
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1414 |
! ! |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
1415 |
|
699 | 1416 |
!AbstractTime methodsFor:'private'! |
240 | 1417 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1418 |
fromOSTime:osTime |
699 | 1419 |
"set my time, from operatingSystems time parts" |
240 | 1420 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1421 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1422 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1423 |
"Modified: 1.7.1996 / 15:09:44 / cg" |
240 | 1424 |
! |
1425 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1426 |
getMilliseconds |
8200 | 1427 |
"get the milliseconds since some point of time in the past. |
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1428 |
Since I am abstract (not knowing how the time is actually |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1429 |
represented), this must be done by a concrete class." |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1430 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1431 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1432 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1433 |
"Created: 1.7.1996 / 14:16:49 / cg" |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1434 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1435 |
|
699 | 1436 |
getSeconds |
8200 | 1437 |
"get the seconds since some point of time in the past. |
699 | 1438 |
Since I am abstract (not knowing how the time is actually |
1439 |
represented), this must be done by a concrete class." |
|
240 | 1440 |
|
699 | 1441 |
^ self subclassResponsibility |
1442 |
! |
|
1443 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1444 |
setMilliseconds:millis |
8200 | 1445 |
"set the milliseconds since some point of time in the past. |
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1446 |
Since I am abstract (not knowing how the time is actually |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1447 |
represented), this must be done by a concrete class." |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1448 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1449 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1450 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1451 |
"Created: 1.7.1996 / 14:17:00 / cg" |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1452 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
1453 |
|
699 | 1454 |
setSeconds:secs |
8200 | 1455 |
"set the seconds since some point of time in the past. |
699 | 1456 |
Since I am abstract (not knowing how the time is actually |
1457 |
represented), this must be done by a concrete class." |
|
1458 |
||
1459 |
^ self subclassResponsibility |
|
17015 | 1460 |
! |
1461 |
||
1462 |
speciesNew |
|
1463 |
^ self species basicNew |
|
240 | 1464 |
! ! |
1465 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
1466 |
!AbstractTime class methodsFor:'documentation'! |
240 | 1467 |
|
699 | 1468 |
version |
18918 | 1469 |
^ '$Header$' |
12660 | 1470 |
! |
1471 |
||
1472 |
version_CVS |
|
18918 | 1473 |
^ '$Header$' |
240 | 1474 |
! ! |
15684 | 1475 |