micropython-lib
micropython-lib copied to clipboard
time: Add time module to provide strftime.
FYI I've also got a recent open PR to add a time module with monotonic in https://github.com/micropython/micropython-lib/pull/502
It'd certainly be trivial to merge them eventually.
It's probably worth you adding from time import * in __init__.py so this new module transparently includes everything from there too?
It's probably worth you adding
from time import *in__init__.pyso this new module transparently includes everything from there too?
I don't think it should import everything in there.
In micropython, the C implementation of builtins are in the u modules, eg uos, ucollections. These are automatically shadowed to the non-u names if there's no other non-u implementation on path, eg os, collections for compatibility.
If there's a python / frozen version of the non-u version provided however that overrides the shadow; the intention is to allow python modules to extend the built-ins exactly like this PR is doing.
As-is, once this time.py is added to path, import time should no longer include the rest of the built in functionality?
In my understanding the python built-in packages should wrap / override the built-in C u version, see https://github.com/micropython/micropython-lib/blob/70e422dc2e885bbaafe6eb7e3d81118e17d4b555/python-stdlib/collections/collections/init.py#L5
That wayimport time will give access to everything in C utime as well as the new python functionality.
Ah okay, but you said :
It's probably worth you adding from time import * in init.py so this new module transparently includes everything from there too?
I think you meant from utime import * now that makes sense yes.
I think you meant from
utime import *now that makes sense yes.
Ah geez sorry for the confusion, I missed the unwanted autocorrect!
Thanks for updating. Merged, and I removed the import re and associated global variable because it's no longer used.
I also added a unit test (taking out the test from time.py).