I've ported a package originally written for Python to MicroPython but in order to get it working I had to implement some fixes to datetime package from micropython-lib based on solutions I found online. Datetime installed via upip it does not even import without errors but I had to fix more than that. I found
this issue where someone went through exactly what I needed and I implemented the changes suggested there.
Specifically in
micropython-lib/datetime/datetime.py
- on line 1356 I had to change 1.0 to 1 (float to int)
- replace line 1366 with the following try block:
Code: Select all
try: # fix per https://github.com/smlng/pycayennelpp/issues/53
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
except ValueError:
y, m, d, hh, mm, ss, weekday, jday = converter(t)
- and add to line 917:
Code: Select all
def __new__(cls, *args, **kwargs):
return object.__new__(cls)
This is what a success with my changes looks like:
Code: Select all
MicroPython v1.14 on 2021-02-02; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> ts=1612971162
>>> from datetime import datetime
>>> from datetime import timezone
>>> datetime.fromtimestamp(ts, timezone.utc)
datetime.datetime(2051, 2, 10, 15, 32, 42, tzinfo=datetime.timezone.utc)
>>>
There are some PRs open on GitHub for these changes but they are not being actively merged (e.g.
PR338 that fixes
#319. The question that I have is how should I approach the requirement for the fixes? Should I work to push them into micropython-lib or should I keep my custom version of datetime that is 99.99 % identical? And if I keep my own versions how do I include them in my new package when it comes to licensing? I may have a similar requirement for another MicroPython package or two and they all come with different licenses. Thank you for any advice.