Skip to content

Commit fdffae0

Browse files
add basic unittest for DS1307 module
1 parent d6d2ca9 commit fdffae0

File tree

2 files changed

+371
-5
lines changed

2 files changed

+371
-5
lines changed

ds1307/ds1307.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434

3535
# system packages
3636
from machine import I2C
37-
from micropython import const
37+
try:
38+
from micropython import const
39+
except ImportError:
40+
def const(x):
41+
return x
3842

3943

4044
class _Subscriptable():
@@ -109,8 +113,8 @@ def datetime(self) -> Tuple[int, int, int, int, int, int, int, int]:
109113
"""
110114
Get the current datetime
111115
112-
(2023, 4, 18, 0, 10, 34, 4, 0)
113-
y, m, d,
116+
(2023, 4, 18, 0, 10, 34, 4, 108)
117+
y, m, d, h, m, s, wd, yd
114118
115119
:returns: (year, month, day, hour, minute, second, weekday, yearday)
116120
:rtype: Tuple[int, int, int, int, int, int, int, int]
@@ -240,7 +244,7 @@ def yearday(self) -> int:
240244
:returns: Yearday of RTC
241245
:rtype: int
242246
"""
243-
return self.datetime[6]
247+
return self.datetime[7]
244248

245249
def is_leap_year(self, year: int) -> bool:
246250
"""
@@ -275,7 +279,7 @@ def day_of_year(self, year: int, month: int, day: int) -> int:
275279
for x in range(1, month):
276280
days16 += month_days[x - 1]
277281

278-
if month == 2 and self.is_leap_year(year=year):
282+
if month >= 2 and self.is_leap_year(year=year):
279283
days16 += 1
280284

281285
return days16

0 commit comments

Comments
 (0)