Skip to content

Commit bffacc8

Browse files
authored
Merge pull request #70 from rettinghaus/typehints
style: adding type hints
2 parents 78cb30a + 2e69104 commit bffacc8

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

edtf/convert.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ def dt_to_struct_time(dt):
3939
return struct_time(
4040
[dt.year, dt.month, dt.day] + TIME_EMPTY_TIME + TIME_EMPTY_EXTRAS
4141
)
42-
else:
43-
raise NotImplementedError(f"Cannot convert {type(dt)} to `struct_time`")
42+
raise NotImplementedError(f"Cannot convert {type(dt)} to `struct_time`")
4443

4544

46-
def struct_time_to_date(st):
45+
def struct_time_to_date(st: struct_time) -> date:
4746
"""
4847
Return a `datetime.date` representing the provided `struct_time.
4948
@@ -52,7 +51,7 @@ def struct_time_to_date(st):
5251
return date(*st[:3])
5352

5453

55-
def struct_time_to_datetime(st):
54+
def struct_time_to_datetime(st: struct_time) -> datetime:
5655
"""
5756
Return a `datetime.datetime` representing the provided `struct_time.
5857
@@ -61,7 +60,7 @@ def struct_time_to_datetime(st):
6160
return datetime(*st[:6])
6261

6362

64-
def trim_struct_time(st, strip_time=False):
63+
def trim_struct_time(st: struct_time, strip_time: bool = False) -> struct_time:
6564
"""
6665
Return a `struct_time` based on the one provided but with the extra fields
6766
`tm_wday`, `tm_yday`, and `tm_isdst` reset to default values.
@@ -75,7 +74,7 @@ def trim_struct_time(st, strip_time=False):
7574
return struct_time(list(st[:6]) + TIME_EMPTY_EXTRAS)
7675

7776

78-
def struct_time_to_jd(st):
77+
def struct_time_to_jd(st: struct_time) -> float:
7978
"""
8079
Return a float number representing the Julian Date for the given
8180
`struct_time`.
@@ -91,7 +90,7 @@ def struct_time_to_jd(st):
9190
return jdutil.date_to_jd(year, month, day)
9291

9392

94-
def jd_to_struct_time(jd):
93+
def jd_to_struct_time(jd: float) -> struct_time:
9594
"""
9695
Return a `struct_time` converted from a Julian Date float number.
9796

edtf/jdutil.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# time deltas if one date is from before 10-15-1582.
1919

2020

21-
def mjd_to_jd(mjd):
21+
def mjd_to_jd(mjd: float) -> float:
2222
"""
2323
Convert Modified Julian Day to Julian Day.
2424
@@ -37,7 +37,7 @@ def mjd_to_jd(mjd):
3737
return mjd + 2400000.5
3838

3939

40-
def jd_to_mjd(jd):
40+
def jd_to_mjd(jd: float) -> float:
4141
"""
4242
Convert Julian Day to Modified Julian Day
4343
@@ -55,7 +55,7 @@ def jd_to_mjd(jd):
5555
return jd - 2400000.5
5656

5757

58-
def date_to_jd(year, month, day):
58+
def date_to_jd(year: int, month: int, day: float) -> float:
5959
"""
6060
Convert a date to Julian Day.
6161
@@ -117,7 +117,7 @@ def date_to_jd(year, month, day):
117117
return jd
118118

119119

120-
def jd_to_date(jd):
120+
def jd_to_date(jd: float) -> tuple:
121121
"""
122122
Convert Julian Day to date.
123123
@@ -175,7 +175,7 @@ def jd_to_date(jd):
175175
return year, month, day
176176

177177

178-
def hmsm_to_days(hour=0, min=0, sec=0, micro=0):
178+
def hmsm_to_days(hour: int = 0, min: int = 0, sec: int = 0, micro: int = 0) -> float:
179179
"""
180180
Convert hours, minutes, seconds, and microseconds to fractional days.
181181
@@ -262,7 +262,7 @@ def days_to_hmsm(days):
262262
return int(hour), int(min), int(sec), int(micro)
263263

264264

265-
def datetime_to_jd(date):
265+
def datetime_to_jd(date: dt.datetime) -> float:
266266
"""
267267
Convert a `datetime.datetime` object to Julian Day.
268268
@@ -291,7 +291,7 @@ def datetime_to_jd(date):
291291
return date_to_jd(date.year, date.month, days)
292292

293293

294-
def jd_to_datetime(jd):
294+
def jd_to_datetime(jd: float) -> dt.datetime:
295295
"""
296296
Convert a Julian Day to an `jdutil.datetime` object.
297297
@@ -321,7 +321,7 @@ def jd_to_datetime(jd):
321321
return datetime(year, month, day, hour, min, sec, micro)
322322

323323

324-
def timedelta_to_days(td):
324+
def timedelta_to_days(td: dt.timedelta) -> float:
325325
"""
326326
Convert a `datetime.timedelta` object to a total number of days.
327327

0 commit comments

Comments
 (0)