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