summaryrefslogtreecommitdiff
path: root/shared-bindings/time
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-07-02 13:56:09 -0700
committerGitHub <noreply@github.com>2020-07-02 13:56:09 -0700
commitc33542f978cc61f0466ff60ea769e3067baca95f (patch)
tree071e8f8a86971f7e947053c3b4fb2ff7da95d223 /shared-bindings/time
parentf572b723060382bbc9ca7a3edc88cb7c30fdcc30 (diff)
parenteec42d4cb53536a75e88f7f9321515bc6dcfeaa7 (diff)
Merge branch 'main' into patch-1
Diffstat (limited to 'shared-bindings/time')
-rw-r--r--shared-bindings/time/__init__.c122
1 files changed, 66 insertions, 56 deletions
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index aa2f4fc6a..d50ce86f6 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -36,24 +36,19 @@
#include "shared-bindings/time/__init__.h"
#include "supervisor/shared/translate.h"
-//| :mod:`time` --- time and timing related functions
-//| ========================================================
-//|
-//| .. module:: time
-//| :synopsis: time and timing related functions
-//| :platform: SAMD21
+//| """time and timing related functions
//|
//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
//| written in MicroPython will work in CPython but not necessarily the other
-//| way around.
-//|
-//| .. function:: monotonic()
+//| way around."""
//|
-//| Returns an always increasing value of time with an unknown reference
-//| point. Only use it to compare against other values from `monotonic`.
+//| def monotonic() -> Any:
+//| """Returns an always increasing value of time with an unknown reference
+//| point. Only use it to compare against other values from `monotonic`.
//|
-//| :return: the current monotonic time
-//| :rtype: float
+//| :return: the current monotonic time
+//| :rtype: float"""
+//| ...
//|
STATIC mp_obj_t time_monotonic(void) {
uint64_t time64 = common_hal_time_monotonic();
@@ -62,11 +57,11 @@ STATIC mp_obj_t time_monotonic(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);
-//| .. function:: sleep(seconds)
-//|
-//| Sleep for a given number of seconds.
+//| def sleep(seconds: float) -> Any:
+//| """Sleep for a given number of seconds.
//|
-//| :param float seconds: the time to sleep in fractional seconds
+//| :param float seconds: the time to sleep in fractional seconds"""
+//| ...
//|
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_PY_BUILTINS_FLOAT
@@ -97,21 +92,22 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp
return namedtuple_make_new(type, 9, tuple->items, NULL);
}
-//| .. class:: struct_time(time_tuple)
+//| class struct_time:
+//| def __init__(self, time_tuple: Any):
+//| """Structure used to capture a date and time. Note that it takes a tuple!
//|
-//| Structure used to capture a date and time. Note that it takes a tuple!
+//| :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)``
//|
-//| :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)``
-//|
-//| * ``tm_year``: the year, 2017 for example
-//| * ``tm_month``: the month, range [1, 12]
-//| * ``tm_mday``: the day of the month, range [1, 31]
-//| * ``tm_hour``: the hour, range [0, 23]
-//| * ``tm_min``: the minute, range [0, 59]
-//| * ``tm_sec``: the second, range [0, 61]
-//| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
-//| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
-//| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown.
+//| * ``tm_year``: the year, 2017 for example
+//| * ``tm_month``: the month, range [1, 12]
+//| * ``tm_mday``: the day of the month, range [1, 31]
+//| * ``tm_hour``: the hour, range [0, 23]
+//| * ``tm_min``: the minute, range [0, 59]
+//| * ``tm_sec``: the second, range [0, 61]
+//| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
+//| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
+//| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown."""
+//| ...
//|
const mp_obj_namedtuple_type_t struct_time_type_obj = {
.base = {
@@ -188,18 +184,26 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) {
tm->tm_yday = mp_obj_get_int(elems[7]);
// elems[8] tm_isdst is not supported
}
+#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
+// Function to return a NotImplementedError on platforms that don't
+// support long integers
+STATIC mp_obj_t time_not_implemented(void) {
+ mp_raise_NotImplementedError(translate("No long integer support"));
+}
+MP_DEFINE_CONST_FUN_OBJ_0(time_not_implemented_obj, time_not_implemented);
+#endif
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
mp_raise_RuntimeError(translate("RTC is not supported on this board"));
}
-//| .. function:: time()
+//| def time() -> Any:
+//| """Return the current time in seconds since since Jan 1, 1970.
//|
-//| Return the current time in seconds since since Jan 1, 1970.
-//|
-//| :return: the current time
-//| :rtype: int
+//| :return: the current time
+//| :rtype: int"""
+//| ...
//|
STATIC mp_obj_t time_time(void) {
timeutils_struct_time_t tm;
@@ -210,12 +214,12 @@ STATIC mp_obj_t time_time(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
-//| .. function:: monotonic_ns()
-//|
-//| Return the time of the specified clock clk_id in nanoseconds.
+//| def monotonic_ns() -> Any:
+//| """Return the time of the specified clock clk_id in nanoseconds.
//|
-//| :return: the current time
-//| :rtype: int
+//| :return: the current time
+//| :rtype: int"""
+//| ...
//|
STATIC mp_obj_t time_monotonic_ns(void) {
uint64_t time64 = common_hal_time_monotonic_ns();
@@ -223,15 +227,15 @@ STATIC mp_obj_t time_monotonic_ns(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_ns_obj, time_monotonic_ns);
-//| .. function:: localtime([secs])
-//|
-//| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
-//| local time. If secs is not provided or None, the current time as returned
-//| by time() is used.
-//| The earliest date for which it can generate a time is Jan 1, 2000.
+//| def localtime(secs: Any) -> Any:
+//| """Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
+//| local time. If secs is not provided or None, the current time as returned
+//| by time() is used.
+//| The earliest date for which it can generate a time is Jan 1, 2000.
//|
-//| :return: the current time
-//| :rtype: time.struct_time
+//| :return: the current time
+//| :rtype: time.struct_time"""
+//| ...
//|
STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
if (n_args == 0 || args[0] == mp_const_none) {
@@ -256,15 +260,15 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime);
-//| .. function:: mktime(t)
+//| def mktime(t: Any) -> Any:
+//| """This is the inverse function of localtime(). Its argument is the
+//| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
+//| dst flag if it is unknown) which expresses the time in local time, not UTC.
+//| The earliest date for which it can generate a time is Jan 1, 2000.
//|
-//| This is the inverse function of localtime(). Its argument is the
-//| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
-//| dst flag if it is unknown) which expresses the time in local time, not UTC.
-//| The earliest date for which it can generate a time is Jan 1, 2000.
-//|
-//| :return: seconds
-//| :rtype: int
+//| :return: seconds
+//| :rtype: int"""
+//| ...
//|
STATIC mp_obj_t time_mktime(mp_obj_t t) {
mp_obj_t *elem;
@@ -307,6 +311,12 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_monotonic_ns_obj) },
#endif
+ #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
+ { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_not_implemented_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_not_implemented_obj) },
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_not_implemented_obj) },
+ { MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_not_implemented_obj) },
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);