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