summaryrefslogtreecommitdiff
path: root/src/isodate
diff options
context:
space:
mode:
Diffstat (limited to 'src/isodate')
-rw-r--r--src/isodate/isostrf.py4
-rw-r--r--src/isodate/tests/test_datetime.py12
-rw-r--r--src/isodate/tests/test_strf.py5
3 files changed, 17 insertions, 4 deletions
diff --git a/src/isodate/isostrf.py b/src/isodate/isostrf.py
index 34785d4..5f3169f 100644
--- a/src/isodate/isostrf.py
+++ b/src/isodate/isostrf.py
@@ -83,7 +83,7 @@ D_ALT_EXT_ORD = 'P' + DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_COMPLETE
D_ALT_BAS_ORD = 'P' + DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_COMPLETE
STRF_DT_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.day,
- '%f': lambda tdt, yds: '%d' % tdt.microsecond,
+ '%f': lambda tdt, yds: '%06d' % tdt.microsecond,
'%H': lambda tdt, yds: '%02d' % tdt.hour,
'%j': lambda tdt, yds: '%03d' % (tdt.toordinal() -
date(tdt.year, 1, 1).toordinal() +
@@ -103,7 +103,7 @@ STRF_DT_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.day,
'%%': lambda tdt, yds: '%'}
STRF_D_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.days,
- '%f': lambda tdt, yds: '%d' % tdt.microseconds,
+ '%f': lambda tdt, yds: '%06d' % tdt.microseconds,
'%H': lambda tdt, yds: '%02d' % (tdt.seconds / 60 / 60),
'%m': lambda tdt, yds: '%02d' % tdt.months,
'%M': lambda tdt, yds: '%02d' % ((tdt.seconds / 60) % 60),
diff --git a/src/isodate/tests/test_datetime.py b/src/isodate/tests/test_datetime.py
index fd50039..339d40a 100644
--- a/src/isodate/tests/test_datetime.py
+++ b/src/isodate/tests/test_datetime.py
@@ -32,7 +32,7 @@ from datetime import datetime
from isodate import parse_datetime, UTC, FixedOffset, datetime_isoformat
from isodate import DATE_BAS_COMPLETE, TIME_BAS_MINUTE, TIME_BAS_COMPLETE
-from isodate import DATE_EXT_COMPLETE, TIME_EXT_MINUTE
+from isodate import DATE_EXT_COMPLETE, TIME_EXT_MINUTE, TIME_EXT_COMPLETE
from isodate import TZ_BAS, TZ_EXT, TZ_HOUR
from isodate import DATE_BAS_ORD_COMPLETE, DATE_EXT_ORD_COMPLETE
from isodate import DATE_BAS_WEEK_COMPLETE, DATE_EXT_WEEK_COMPLETE
@@ -58,7 +58,15 @@ TEST_CASES = [('19850412T1015', datetime(1985, 4, 12, 10, 15),
DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR),
('20110410T101225.123000Z',
datetime(2011, 4, 10, 10, 12, 25, 123000, tzinfo=UTC),
- DATE_BAS_COMPLETE + 'T' + TIME_BAS_COMPLETE + ".%f" + TZ_BAS)]
+ DATE_BAS_COMPLETE + 'T' + TIME_BAS_COMPLETE + ".%f" + TZ_BAS),
+ ('2012-10-12T08:29:46.069178Z',
+ datetime(2012, 10, 12, 8, 29, 46, 69178, tzinfo=UTC),
+ DATE_EXT_COMPLETE + 'T' + TIME_EXT_COMPLETE + ".%f" + TZ_BAS),
+ ('2012-10-12T08:29:46.691780Z',
+ datetime(2012, 10, 12, 8, 29, 46, 691780, tzinfo=UTC),
+ DATE_EXT_COMPLETE + 'T' + TIME_EXT_COMPLETE + ".%f" + TZ_BAS),
+ ]
+
def create_testcase(datetimestring, expectation, format):
diff --git a/src/isodate/tests/test_strf.py b/src/isodate/tests/test_strf.py
index 7d9ba4b..540e0d0 100644
--- a/src/isodate/tests/test_strf.py
+++ b/src/isodate/tests/test_strf.py
@@ -41,6 +41,11 @@ TEST_CASES = ((datetime(2012, 12, 25, 13, 30, 0, 0, LOCAL), DT_EXT_COMPLETE,
# DST ON
(datetime(1999, 12, 25, 13, 30, 0, 0, LOCAL), DT_EXT_COMPLETE,
"1999-12-25T13:30:00+11:00"),
+ # microseconds
+ (datetime(2012, 10, 12, 8, 29, 46, 69178), "%Y-%m-%dT%H:%M:%S.%f",
+ "2012-10-12T08:29:46.069178"),
+ (datetime(2012, 10, 12, 8, 29, 46, 691780), "%Y-%m-%dT%H:%M:%S.%f",
+ "2012-10-12T08:29:46.691780"),
)