@@ -42,65 +42,164 @@ def __init__(self, millis, _jvm=None):
42
42
self ._jduration = _jvm .Duration (millis )
43
43
44
44
def toString (self ):
45
- """ Return duration as string """
45
+ """
46
+ Return duration as string
47
+
48
+ >>> d_10 = Duration(10)
49
+ >>> d_10.toString()
50
+ '10 ms'
51
+ """
46
52
return str (self ._millis ) + " ms"
47
53
48
54
def isZero (self ):
49
- """ Check if millis is zero """
55
+ """
56
+ Check if millis is zero
57
+
58
+ >>> d_10 = Duration(10)
59
+ >>> d_10.isZero()
60
+ False
61
+ >>> d_0 = Duration(0)
62
+ >>> d_0.isZero()
63
+ True
64
+ """
50
65
return self ._millis == 0
51
66
52
67
def prettyPrint (self ):
53
68
"""
54
69
Return a human-readable string representing a duration
70
+
71
+ >>> d_10 = Duration(10)
72
+ >>> d_10.prettyPrint()
73
+ '10 ms'
74
+ >>> d_1sec = Duration(1000)
75
+ >>> d_1sec.prettyPrint()
76
+ '1.0 s'
77
+ >>> d_1min = Duration(60 * 1000)
78
+ >>> d_1min.prettyPrint()
79
+ '1.0 m'
80
+ >>> d_1hour = Duration(60 * 60 * 1000)
81
+ >>> d_1hour.prettyPrint()
82
+ '1.00 h'
55
83
"""
56
84
return utils .msDurationToString (self ._millis )
57
85
58
86
def milliseconds (self ):
59
- """ Return millisecond """
87
+ """
88
+ Return millisecond
89
+
90
+ >>> d_10 = Duration(10)
91
+ >>> d_10.milliseconds()
92
+ 10
93
+
94
+ """
60
95
return self ._millis
61
96
62
97
def toFormattedString (self ):
63
- """ Return millisecond """
98
+ """
99
+ Return millisecond
100
+
101
+ >>> d_10 = Duration(10)
102
+ >>> d_10.toFormattedString()
103
+ '10'
104
+
105
+ """
64
106
return str (self ._millis )
65
107
66
108
def max (self , other ):
67
- """ Return higher Duration """
109
+ """
110
+ Return higher Duration
111
+
112
+ >>> d_10 = Duration(10)
113
+ >>> d_100 = Duration(100)
114
+ >>> d_max = d_10.max(d_100)
115
+ >>> print d_max
116
+ 100 ms
117
+
118
+ """
68
119
Duration ._is_duration (other )
69
120
if self > other :
70
121
return self
71
122
else :
72
123
return other
73
124
74
125
def min (self , other ):
75
- """ Return lower Durattion """
126
+ """
127
+ Return lower Durattion
128
+
129
+ >>> d_10 = Duration(10)
130
+ >>> d_100 = Duration(100)
131
+ >>> d_min = d_10.min(d_100)
132
+ >>> print d_min
133
+ 10 ms
134
+
135
+ """
76
136
Duration ._is_duration (other )
77
137
if self < other :
78
138
return self
79
139
else :
80
140
return other
81
141
82
142
def __str__ (self ):
143
+ """
144
+ >>> d_10 = Duration(10)
145
+ >>> str(d_10)
146
+ '10 ms'
147
+
148
+ """
83
149
return self .toString ()
84
150
85
151
def __add__ (self , other ):
86
- """ Add Duration and Duration """
152
+ """
153
+ Add Duration and Duration
154
+
155
+ >>> d_10 = Duration(10)
156
+ >>> d_100 = Duration(100)
157
+ >>> d_110 = d_10 + d_100
158
+ >>> print d_110
159
+ 110 ms
160
+ """
87
161
Duration ._is_duration (other )
88
162
return Duration (self ._millis + other ._millis )
89
163
90
164
def __sub__ (self , other ):
91
- """ Subtract Duration by Duration """
165
+ """
166
+ Subtract Duration by Duration
167
+
168
+ >>> d_10 = Duration(10)
169
+ >>> d_100 = Duration(100)
170
+ >>> d_90 = d_100 - d_10
171
+ >>> print d_90
172
+ 90 ms
173
+
174
+ """
92
175
Duration ._is_duration (other )
93
176
return Duration (self ._millis - other ._millis )
94
177
95
178
def __mul__ (self , other ):
96
- """ Multiple Duration by Duration """
179
+ """
180
+ Multiple Duration by Duration
181
+
182
+ >>> d_10 = Duration(10)
183
+ >>> d_100 = Duration(100)
184
+ >>> d_1000 = d_10 * d_100
185
+ >>> print d_1000
186
+ 1000 ms
187
+
188
+ """
97
189
Duration ._is_duration (other )
98
190
return Duration (self ._millis * other ._millis )
99
191
100
192
def __div__ (self , other ):
101
193
"""
102
194
Divide Duration by Duration
103
195
for Python 2.X
196
+
197
+ >>> d_10 = Duration(10)
198
+ >>> d_20 = Duration(20)
199
+ >>> d_2 = d_20 / d_10
200
+ >>> print d_2
201
+ 2 ms
202
+
104
203
"""
105
204
Duration ._is_duration (other )
106
205
return Duration (self ._millis / other ._millis )
@@ -109,46 +208,121 @@ def __truediv__(self, other):
109
208
"""
110
209
Divide Duration by Duration
111
210
for Python 3.0
211
+
212
+ >>> d_10 = Duration(10)
213
+ >>> d_20 = Duration(20)
214
+ >>> d_2 = d_20 / d_10
215
+ >>> print d_2
216
+ 2 ms
217
+
112
218
"""
113
219
Duration ._is_duration (other )
114
220
return Duration (self ._millis / other ._millis )
115
221
116
222
def __floordiv__ (self , other ):
117
- """ Divide Duration by Duration """
223
+ """
224
+ Divide Duration by Duration
225
+
226
+ >>> d_10 = Duration(10)
227
+ >>> d_3 = Duration(3)
228
+ >>> d_3 = d_10 // d_3
229
+ >>> print d_3
230
+ 3 ms
231
+
232
+ """
118
233
Duration ._is_duration (other )
119
234
return Duration (self ._millis // other ._millis )
120
235
121
- def __len__ (self ):
122
- """ Length of miilisecond in Duration """
123
- return len (self ._millis )
124
-
125
236
def __lt__ (self , other ):
126
- """ Duration < Duration """
237
+ """
238
+ Duration < Duration
239
+
240
+ >>> d_10 = Duration(10)
241
+ >>> d_20 = Duration(20)
242
+ >>> d_10 < d_20
243
+ True
244
+ >>> d_20 < d_10
245
+ False
246
+
247
+ """
127
248
Duration ._is_duration (other )
128
249
return self ._millis < other ._millis
129
250
130
251
def __le__ (self , other ):
131
- """ Duration <= Duration """
252
+ """
253
+ Duration <= Duration
254
+
255
+ >>> d_10 = Duration(10)
256
+ >>> d_20 = Duration(20)
257
+ >>> d_10 <= d_20
258
+ True
259
+ >>> d_20 <= d_10
260
+ False
261
+
262
+ """
132
263
Duration ._is_duration (other )
133
- return self .millis <= other ._millis
264
+ return self ._millis <= other ._millis
134
265
135
266
def __eq__ (self , other ):
136
- """ Duration == Duration """
267
+ """
268
+ Duration == Duration
269
+
270
+ >>> d_10 = Duration(10)
271
+ >>> d_20 = Duration(20)
272
+ >>> d_10 == d_20
273
+ False
274
+ >>> other_d_10 = Duration(10)
275
+ >>> d_10 == other_d_10
276
+ True
277
+
278
+ """
137
279
Duration ._is_duration (other )
138
280
return self ._millis == other ._millis
139
281
140
282
def __ne__ (self , other ):
141
- """ Duration != Duration """
283
+ """
284
+ Duration != Duration
285
+
286
+ >>> d_10 = Duration(10)
287
+ >>> d_20 = Duration(20)
288
+ >>> d_10 != d_20
289
+ True
290
+ >>> other_d_10 = Duration(10)
291
+ >>> d_10 != other_d_10
292
+ False
293
+
294
+ """
142
295
Duration ._is_duration (other )
143
296
return self ._millis != other ._millis
144
297
145
298
def __gt__ (self , other ):
146
- """ Duration > Duration """
299
+ """
300
+ Duration > Duration
301
+
302
+ >>> d_10 = Duration(10)
303
+ >>> d_20 = Duration(20)
304
+ >>> d_10 > d_20
305
+ False
306
+ >>> d_20 > d_10
307
+ True
308
+
309
+ """
147
310
Duration ._is_duration (other )
148
311
return self ._millis > other ._millis
149
312
150
313
def __ge__ (self , other ):
151
- """ Duration >= Duration """
314
+ """
315
+ Duration >= Duration
316
+
317
+ >>> d_10 = Duration(10)
318
+ >>> d_20 = Duration(20)
319
+ >>> d_10 < d_20
320
+ True
321
+ >>> d_20 < d_10
322
+ False
323
+
324
+
325
+ """
152
326
Duration ._is_duration (other )
153
327
return self ._millis >= other ._millis
154
328
@@ -162,25 +336,37 @@ def Milliseconds(milliseconds):
162
336
"""
163
337
Helper function that creates instance of [[pysparkstreaming.duration]] representing
164
338
a given number of milliseconds.
339
+
340
+ >>> milliseconds = Milliseconds(1)
341
+ >>> d_1 = Duration(1)
342
+ >>> milliseconds == d_1
343
+ True
344
+
165
345
"""
166
346
return Duration (milliseconds )
167
347
168
348
def Seconds (seconds ):
169
349
"""
170
350
Helper function that creates instance of [[pysparkstreaming.duration]] representing
171
351
a given number of seconds.
352
+
353
+ >>> seconds = Seconds(1)
354
+ >>> d_1sec = Duration(1000)
355
+ >>> seconds == d_1sec
356
+ True
357
+
172
358
"""
173
359
return Duration (seconds * 1000 )
174
360
175
- def Minites ( minites ):
361
+ def Minutes ( minutes ):
176
362
"""
177
363
Helper function that creates instance of [[pysparkstreaming.duration]] representing
178
364
a given number of minutes.
179
- """
180
- return Duration (minutes * 60000 )
181
365
182
- if __name__ == "__main__" :
183
- d = Duration (1 )
184
- print d
185
- print d . milliseconds ()
366
+ >>> minutes = Minutes(1)
367
+ >>> d_1min = Duration(60 * 1000 )
368
+ >>> minutes == d_1min
369
+ True
186
370
371
+ """
372
+ return Duration (minutes * 60 * 1000 )
0 commit comments