INCOMPATIBLE CHANGE: struct_time(1,2,3,4,5,6,7,8,9) is now _rejected_
just as on standad Python.
This incorrect constructor was added by me in #2327; I assumed
without even checking that the `struct_time` constructor was also
compatible with the `namedtuple` constructor, but it is not and has
always been rejected by standard Python (checked 2.7 and 3.9)
This commit restores the specific error message that we used for this
purpose, which was removed in the previous commit either out of laziness
or out of trying to reduce unneeded error strings. In this case, the
alternate string is too misleading (it refers to arguments, not to
sequence elements) so let's put the better message back.
This is a slight trade-off with code size, in places where a "_varg"
mp_raise variant is now used. The net savings on trinket_m0 is
just 32 bytes.
It also means that the translation will include the original English
text, and cannot be translated. These are usually names of Python
types such as int, set, or dict or special values such as "inf" or
"Nan".
Fix for Issue #2812. Instead of reporting a missing attribute for functions such as time.time() and time.mktime(); platforms that do not have long integer support will raise a NotImplementedError
Whenever there is more than one argument, delegate the operation to
namedtuple_make_new. This allows other circuitpython-compatible
idioms, like with keywords
time.struct_time(tm_year=2000, tm_mon=1, tm_mday=1, tm_hour=0,
tm_min=0, tm_sec=14, tm_wday=5, tm_yday=5, tm_isdst=-1)
with 9 positional arguments, etc.
The only vaguely plausible CPython behavior still not permitted in
CircuitPython that I found is constructing a timetuple from a length-9
list, a la
time.struct_time(list(time.localtime())
Even better, by getting rid of an error message, the build shrinks a
tiny bit.
This doesn't cover ALL the cases that CPython permits for construction
of a struct_time, but it at least makes constructing from any namedtuple
work.
Closes: #2326
It turns out `mp_obj_int_get_checked` is not appropriate to call when
the argument is not of int or long type--the "checked" refers to guarding
against overflow/underflow, not type checking.
For compatibility with CPython, handle float arguments.
Closes: #2069
This is intended to be compatible with Python 3.7's time.monotonic_ns.
The "actual resolution" is 1ms due to this being the unit at which
common_hal_time_monotonic ticks.
Closes#519
Commit 95e70cd0ea 'time: Use 1970 epoch' changed epoch for the time
module, but not for other users. This patch does the same for the only
other core timeutils user: extmod/vfs_fat.c:fat_vfs_stat().
Other timeutils users: cc3200, esp8266 and stm32, are not changed.
Ports that don't use long ints, will still get wrong time values from
os.stat().
Use UNIX epoch to match CPython.
This overflows small int so time.{time,localtime,mktime} is only supported with long int.
Also remove some comment cruft in time_time().
Add an rtc module that provides a singleton RTC class with
- a datetime property to set and get time if the board supports it.
- a calbration property to adjust the clock.
There's also an rtc.set_time_source() method to override this RTC object using pure python.
The time module gets 3 methods:
- time.time()
- time.localtime()
- time.mktime()
The rtc timesource is used to provide time to the time module.
lib/timeutils is used for time conversions and thus only supports dates after 2000.