We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 490fadc commit e8bef75Copy full SHA for e8bef75
sciencedates/__init__.py
@@ -169,8 +169,14 @@ def datetime2yeardec(t):
169
time distances should be preserved: If bdate-adate=ddate-cdate then
170
dt2t(bdate)-dt2t(adate) = dt2t(ddate)-dt2t(cdate)
171
"""
172
+
173
if isinstance(t,str):
174
t = parse(t)
175
+ elif isinstance(t, datetime.datetime):
176
+ pass
177
+ elif isinstance(t, datetime.date):
178
+ t = datetime.datetime.combine(t, datetime.time.min)
179
180
181
t = forceutc(t)
182
@@ -179,6 +185,7 @@ def datetime2yeardec(t):
185
year = t.year
186
boy = datetime.datetime(year, 1, 1,tzinfo=UTC)
187
eoy = datetime.datetime(year + 1, 1, 1, tzinfo=UTC)
188
189
return year + ((t - boy).total_seconds() / ((eoy - boy).total_seconds()))
183
190
184
191
setup.py
@@ -6,7 +6,7 @@
6
7
setup(name='sciencedates',
8
packages=find_packages(),
9
- version = '1.3.1',
+ version = '1.3.2',
10
description='Date conversions used in the sciences.',
11
long_description=open('README.rst').read(),
12
author = 'Michael Hirsch, Ph.D.',
tests/test.py
@@ -17,11 +17,11 @@ def test_yearint(self):
17
assert utsec==utsec2
18
19
def test_yeardec(self):
20
- adatetime = datetime.datetime(2013,7,2,12,0,0,tzinfo=UTC)
21
- yeardec = sd.datetime2yeardec(adatetime)
+ t0 = datetime.datetime(2013,7,2,12,0,0,tzinfo=UTC)
+ yeardec = sd.datetime2yeardec(t0)
22
23
- assert_allclose(yeardec,2013.5)
24
- assert sd.yeardec2datetime(yeardec) == adatetime
+ assert_allclose(yeardec, 2013.5)
+ assert sd.yeardec2datetime(yeardec) == t0
25
26
def test_utc(self):
27
t0 = datetime.datetime(2013,7,2,12,0,0)
@@ -36,8 +36,8 @@ def test_utc(self):
36
assert sd.forceutc(d0) == d0
37
38
def test_gtd(self):
39
- adatetime = datetime.datetime(2013,7,2,12,0,0)
40
- iyd,utsec,stl= sd.datetime2gtd(adatetime,glon=42)
+ t0 = datetime.datetime(2013,7,2,12,0,0)
+ iyd,utsec,stl= sd.datetime2gtd(t0,glon=42)
41
42
assert iyd[0]==183
43
assert_allclose(utsec[0],43200)
0 commit comments