kopia lustrzana https://github.com/micropython/micropython-lib
time: Introduce "real" struct_time.
Implemented using namedtuple and lacks tm_zone, tm_gmtoff fields.pull/121/merge
rodzic
2472ad4e0e
commit
d69aaba546
|
@ -1,4 +1,5 @@
|
|||
from utime import *
|
||||
from ucollections import namedtuple
|
||||
import ustruct
|
||||
import uctypes
|
||||
import ffi
|
||||
|
@ -16,6 +17,8 @@ localtime_ = libc.func("P", "localtime", "P")
|
|||
strftime_ = libc.func("i", "strftime", "sisP")
|
||||
mktime_ = libc.func("i", "mktime", "P")
|
||||
|
||||
_struct_time = namedtuple("struct_time",
|
||||
["tm_year", "tm_mon", "tm_mday", "tm_hour", "tm_min", "tm_sec", "tm_wday", "tm_yday", "tm_isdst"])
|
||||
|
||||
def _tuple_to_c_tm(t):
|
||||
return ustruct.pack("@iiiiiiiii", t[5], t[4], t[3], t[2], t[1] - 1, t[0] - 1900, (t[6] + 1) % 7, t[7] - 1, t[8])
|
||||
|
@ -23,10 +26,10 @@ def _tuple_to_c_tm(t):
|
|||
|
||||
def _c_tm_to_tuple(tm):
|
||||
t = ustruct.unpack("@iiiiiiiii", tm)
|
||||
return tuple([t[5] + 1900, t[4] + 1, t[3], t[2], t[1], t[0], (t[6] - 1) % 7, t[7] + 1, t[8]])
|
||||
return _struct_time(t[5] + 1900, t[4] + 1, t[3], t[2], t[1], t[0], (t[6] - 1) % 7, t[7] + 1, t[8])
|
||||
|
||||
def struct_time(tm):
|
||||
return tm
|
||||
return _struct_time(*tm)
|
||||
|
||||
|
||||
def strftime(format, t=None):
|
||||
|
|
Ładowanie…
Reference in New Issue