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