36
36
#include "shared-bindings/time/__init__.h"
37
37
#include "supervisor/shared/translate.h"
38
38
39
- //| :mod:`time` --- time and timing related functions
39
+ //| """ :mod:`time` --- time and timing related functions
40
40
//| ========================================================
41
41
//|
42
42
//| .. module:: time
45
45
//|
46
46
//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
47
47
//| written in MicroPython will work in CPython but not necessarily the other
48
- //| way around.
48
+ //| way around."""
49
49
//|
50
- //| .. function:: monotonic()
50
+ //| def monotonic() -> Any:
51
+ //| """Returns an always increasing value of time with an unknown reference
52
+ //| point. Only use it to compare against other values from `monotonic`.
51
53
//|
52
- //| Returns an always increasing value of time with an unknown reference
53
- //| point. Only use it to compare against other values from `monotonic`.
54
- //|
55
- //| :return: the current monotonic time
56
- //| :rtype: float
54
+ //| :return: the current monotonic time
55
+ //| :rtype: float"""
56
+ //| ...
57
57
//|
58
58
STATIC mp_obj_t time_monotonic (void ) {
59
59
uint64_t time64 = common_hal_time_monotonic ();
@@ -62,11 +62,11 @@ STATIC mp_obj_t time_monotonic(void) {
62
62
}
63
63
MP_DEFINE_CONST_FUN_OBJ_0 (time_monotonic_obj , time_monotonic );
64
64
65
- //| .. function:: sleep(seconds)
66
- //|
67
- //| Sleep for a given number of seconds.
65
+ //| def sleep(seconds: float) -> Any:
66
+ //| """Sleep for a given number of seconds.
68
67
//|
69
- //| :param float seconds: the time to sleep in fractional seconds
68
+ //| :param float seconds: the time to sleep in fractional seconds"""
69
+ //| ...
70
70
//|
71
71
STATIC mp_obj_t time_sleep (mp_obj_t seconds_o ) {
72
72
#if MICROPY_PY_BUILTINS_FLOAT
@@ -97,21 +97,22 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp
97
97
return namedtuple_make_new (type , 9 , tuple -> items , NULL );
98
98
}
99
99
100
- //| .. class:: struct_time(time_tuple)
100
+ //| class struct_time:
101
+ //| def __init__(self, time_tuple: Any):
102
+ //| """Structure used to capture a date and time. Note that it takes a tuple!
101
103
//|
102
- //| Structure used to capture a date and time. Note that it takes a tuple!
104
+ //| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
103
105
//|
104
- //| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
105
- //|
106
- //| * ``tm_year``: the year, 2017 for example
107
- //| * ``tm_month``: the month, range [1, 12]
108
- //| * ``tm_mday``: the day of the month, range [1, 31]
109
- //| * ``tm_hour``: the hour, range [0, 23]
110
- //| * ``tm_minute``: the minute, range [0, 59]
111
- //| * ``tm_sec``: the second, range [0, 61]
112
- //| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
113
- //| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
114
- //| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown.
106
+ //| * ``tm_year``: the year, 2017 for example
107
+ //| * ``tm_month``: the month, range [1, 12]
108
+ //| * ``tm_mday``: the day of the month, range [1, 31]
109
+ //| * ``tm_hour``: the hour, range [0, 23]
110
+ //| * ``tm_minute``: the minute, range [0, 59]
111
+ //| * ``tm_sec``: the second, range [0, 61]
112
+ //| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
113
+ //| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
114
+ //| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown."""
115
+ //| ...
115
116
//|
116
117
const mp_obj_namedtuple_type_t struct_time_type_obj = {
117
118
.base = {
@@ -194,12 +195,12 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
194
195
mp_raise_RuntimeError (translate ("RTC is not supported on this board" ));
195
196
}
196
197
197
- //| .. function:: time()
198
- //|
199
- //| Return the current time in seconds since since Jan 1, 1970.
198
+ //| def time() -> Any:
199
+ //| """Return the current time in seconds since since Jan 1, 1970.
200
200
//|
201
- //| :return: the current time
202
- //| :rtype: int
201
+ //| :return: the current time
202
+ //| :rtype: int"""
203
+ //| ...
203
204
//|
204
205
STATIC mp_obj_t time_time (void ) {
205
206
timeutils_struct_time_t tm ;
@@ -210,28 +211,28 @@ STATIC mp_obj_t time_time(void) {
210
211
}
211
212
MP_DEFINE_CONST_FUN_OBJ_0 (time_time_obj , time_time );
212
213
213
- //| .. function:: monotonic_ns()
214
+ //| def monotonic_ns() -> Any:
215
+ //| """Return the time of the specified clock clk_id in nanoseconds.
214
216
//|
215
- //| Return the time of the specified clock clk_id in nanoseconds.
216
- //|
217
- //| :return: the current time
218
- //| :rtype: int
217
+ //| :return: the current time
218
+ //| :rtype: int"""
219
+ //| ...
219
220
//|
220
221
STATIC mp_obj_t time_monotonic_ns (void ) {
221
222
uint64_t time64 = common_hal_time_monotonic_ns ();
222
223
return mp_obj_new_int_from_ll ((long long ) time64 );
223
224
}
224
225
MP_DEFINE_CONST_FUN_OBJ_0 (time_monotonic_ns_obj , time_monotonic_ns );
225
226
226
- //| .. function:: localtime([secs])
227
- //|
228
- //| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
229
- //| local time. If secs is not provided or None, the current time as returned
230
- //| by time() is used.
231
- //| The earliest date for which it can generate a time is Jan 1, 2000.
227
+ //| def localtime(secs: Any) -> Any:
228
+ //| """Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
229
+ //| local time. If secs is not provided or None, the current time as returned
230
+ //| by time() is used.
231
+ //| The earliest date for which it can generate a time is Jan 1, 2000.
232
232
//|
233
- //| :return: the current time
234
- //| :rtype: time.struct_time
233
+ //| :return: the current time
234
+ //| :rtype: time.struct_time"""
235
+ //| ...
235
236
//|
236
237
STATIC mp_obj_t time_localtime (size_t n_args , const mp_obj_t * args ) {
237
238
if (n_args == 0 || args [0 ] == mp_const_none ) {
@@ -256,15 +257,15 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
256
257
}
257
258
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (time_localtime_obj , 0 , 1 , time_localtime );
258
259
259
- //| .. function:: mktime(t)
260
- //|
261
- //| This is the inverse function of localtime(). Its argument is the
262
- //| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
263
- //| dst flag if it is unknown) which expresses the time in local time, not UTC.
264
- //| The earliest date for which it can generate a time is Jan 1, 2000.
260
+ //| def mktime(t: Any) -> Any:
261
+ //| """This is the inverse function of localtime(). Its argument is the
262
+ //| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
263
+ //| dst flag if it is unknown) which expresses the time in local time, not UTC.
264
+ //| The earliest date for which it can generate a time is Jan 1, 2000.
265
265
//|
266
- //| :return: seconds
267
- //| :rtype: int
266
+ //| :return: seconds
267
+ //| :rtype: int"""
268
+ //| ...
268
269
//|
269
270
STATIC mp_obj_t time_mktime (mp_obj_t t ) {
270
271
mp_obj_t * elem ;
0 commit comments