3636#include "shared-bindings/time/__init__.h"
3737#include "supervisor/shared/translate.h"
3838
39- //| :mod:`time` --- time and timing related functions
39+ //| """ :mod:`time` --- time and timing related functions
4040//| ========================================================
4141//|
4242//| .. module:: time
4545//|
4646//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
4747//| written in MicroPython will work in CPython but not necessarily the other
48- //| way around.
48+ //| way around."""
4949//|
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`.
5153//|
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+ //| ...
5757//|
5858STATIC mp_obj_t time_monotonic (void ) {
5959 uint64_t time64 = common_hal_time_monotonic ();
@@ -62,11 +62,11 @@ STATIC mp_obj_t time_monotonic(void) {
6262}
6363MP_DEFINE_CONST_FUN_OBJ_0 (time_monotonic_obj , time_monotonic );
6464
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.
6867//|
69- //| :param float seconds: the time to sleep in fractional seconds
68+ //| :param float seconds: the time to sleep in fractional seconds"""
69+ //| ...
7070//|
7171STATIC mp_obj_t time_sleep (mp_obj_t seconds_o ) {
7272 #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
9797 return namedtuple_make_new (type , 9 , tuple -> items , NULL );
9898}
9999
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!
101103//|
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)``
103105//|
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+ //| ...
115116//|
116117const mp_obj_namedtuple_type_t struct_time_type_obj = {
117118 .base = {
@@ -194,12 +195,12 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
194195 mp_raise_RuntimeError (translate ("RTC is not supported on this board" ));
195196}
196197
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.
200200//|
201- //| :return: the current time
202- //| :rtype: int
201+ //| :return: the current time
202+ //| :rtype: int"""
203+ //| ...
203204//|
204205STATIC mp_obj_t time_time (void ) {
205206 timeutils_struct_time_t tm ;
@@ -210,28 +211,28 @@ STATIC mp_obj_t time_time(void) {
210211}
211212MP_DEFINE_CONST_FUN_OBJ_0 (time_time_obj , time_time );
212213
213- //| .. function:: monotonic_ns()
214+ //| def monotonic_ns() -> Any:
215+ //| """Return the time of the specified clock clk_id in nanoseconds.
214216//|
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+ //| ...
219220//|
220221STATIC mp_obj_t time_monotonic_ns (void ) {
221222 uint64_t time64 = common_hal_time_monotonic_ns ();
222223 return mp_obj_new_int_from_ll ((long long ) time64 );
223224}
224225MP_DEFINE_CONST_FUN_OBJ_0 (time_monotonic_ns_obj , time_monotonic_ns );
225226
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.
232232//|
233- //| :return: the current time
234- //| :rtype: time.struct_time
233+ //| :return: the current time
234+ //| :rtype: time.struct_time"""
235+ //| ...
235236//|
236237STATIC mp_obj_t time_localtime (size_t n_args , const mp_obj_t * args ) {
237238 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) {
256257}
257258MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (time_localtime_obj , 0 , 1 , time_localtime );
258259
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.
265265//|
266- //| :return: seconds
267- //| :rtype: int
266+ //| :return: seconds
267+ //| :rtype: int"""
268+ //| ...
268269//|
269270STATIC mp_obj_t time_mktime (mp_obj_t t ) {
270271 mp_obj_t * elem ;
0 commit comments