summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Weis <gweis@gmx.at>2011-04-16 12:09:29 +1000
committerGerhard Weis <gweis@gmx.at>2011-04-16 12:09:29 +1000
commit33373b3ddbf7946117b48c5db3c3610c6cb73adf (patch)
tree29fc6ce342159b894104a687c88ab48e95c39548
parentbc1f74552d33a3548242503bf1d40eee5b3902df (diff)
downloadisodate-33373b3ddbf7946117b48c5db3c3610c6cb73adf.tar.gz
* Fixed a formatting of microseconds for datetime objects
* some whitespace cleanup * bumped version to 0.4.4
-rw-r--r--CHANGES.txt6
-rw-r--r--TODO.txt11
-rw-r--r--setup.py30
-rw-r--r--src/isodate/isostrf.py4
-rw-r--r--src/tests/test_datetime.py40
5 files changed, 51 insertions, 40 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 15f20e2..2565f68 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,11 @@
CHANGES
=======
+0.4.4 (2011-04-16)
+------------------
+
+- Fixed formatting of microseconds for datetime objects
+
0.4.3 (2010-10-29)
------------------
@@ -29,4 +34,3 @@ CHANGES
------------------
- Initial release
-
diff --git a/TODO.txt b/TODO.txt
index c733206..6843fa3 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -11,6 +11,8 @@ Missing features:
* time formating does not allow to create fractional representations.
* parser for ISO intervals.
+ * currently microseconds are always padded to a length of 6 characters.
+ trailing 0s should be optional
Documentation:
--------------
@@ -19,20 +21,19 @@ Documentation:
- complete documentation to show what this function allows, but ISO forbids.
and vice verse.
- support other separators between date and time than 'T'
-
+
* parse_date:
- yeardigits should be always greater than 4
- dates before 0001-01-01 are not supported
-
+
* parse_duration:
- alternative formats are not fully supported due to parse_date restrictions
- standard duration format is fully supported but not very restrictive.
-
+
* Duration:
- support fractional years and month in calculations
- implement w3c order relation? (`<http://www.w3.org/TR/xmlschema-2/#duration-order>`_)
- refactor to have duration mathematics only at one place.
- localize __str__ method (does timedelta do this?)
- - when is a Duration negative?
+ - when is a Duration negative?
- normalize Durations. months [00-12] and years ]-inf,+inf[
-
diff --git a/setup.py b/setup.py
index c8cb3ac..9bf49ca 100644
--- a/setup.py
+++ b/setup.py
@@ -35,9 +35,9 @@ def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-setup(name = 'isodate',
- version = '0.4.3',
- packages = find_packages('src', exclude=["tests"]),
+setup(name='isodate',
+ version='0.4.4',
+ packages=find_packages('src', exclude=["tests"]),
package_dir={'': 'src'},
# dependencies:
@@ -47,22 +47,22 @@ setup(name = 'isodate',
author='Gerhard Weis',
author_email='gerhard.weis@proclos.com',
description='An ISO 8601 date/time/duration parser and formater',
- license = 'BSD',
+ license='BSD',
#keywords = '',
url='http://cheeseshop.python.org/pypi/isodate',
long_description=read('README.txt') +
read('CHANGES.txt') +
read('TODO.txt'),
-
- classifiers = ['Development Status :: 4 - Beta',
- # 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: BSD License',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Topic :: Internet',
- 'Topic :: Software Development :: Libraries :: Python Modules',
- ],
- test_suite = "tests.test_suite"
+
+ classifiers=['Development Status :: 4 - Beta',
+ # 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Internet',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ],
+ test_suite="tests.test_suite"
)
diff --git a/src/isodate/isostrf.py b/src/isodate/isostrf.py
index 6ab534b..13480e0 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.microseconds,
+ '%f': lambda tdt, yds: '%d' % tdt.microsecond,
'%H': lambda tdt, yds: '%02d' % tdt.hour,
'%j': lambda tdt, yds: '%03d' % (tdt.toordinal() -
date(tdt.year, 1, 1).toordinal() +
@@ -186,7 +186,7 @@ def strftime(tdt, format, yeardigits=4):
'''
Directive Meaning Notes
%d Day of the month as a decimal number [01,31].
- %f Microsecond as a decimal number [0,999999], zero-padded on the left (1)
+ %f Microsecond as a decimal number [0,999999], zero-padded on the left (1)
%H Hour (24-hour clock) as a decimal number [00,23].
%j Day of the year as a decimal number [001,366].
%m Month as a decimal number [01,12].
diff --git a/src/tests/test_datetime.py b/src/tests/test_datetime.py
index 842f312..fd50039 100644
--- a/src/tests/test_datetime.py
+++ b/src/tests/test_datetime.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -31,8 +31,9 @@ import unittest
from datetime import datetime
from isodate import parse_datetime, UTC, FixedOffset, datetime_isoformat
-from isodate import DATE_BAS_COMPLETE, TIME_BAS_MINUTE, TZ_BAS
-from isodate import DATE_EXT_COMPLETE, TIME_EXT_MINUTE, TZ_EXT, TZ_HOUR
+from isodate import DATE_BAS_COMPLETE, TIME_BAS_MINUTE, TIME_BAS_COMPLETE
+from isodate import DATE_EXT_COMPLETE, TIME_EXT_MINUTE
+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
@@ -47,36 +48,40 @@ TEST_CASES = [('19850412T1015', datetime(1985, 4, 12, 10, 15),
DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS),
('1985-102T10:15Z', datetime(1985, 4, 12, 10, 15, tzinfo=UTC),
DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_EXT),
- ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15,
- tzinfo=FixedOffset(4, 0,
+ ('1985W155T1015+0400', datetime(1985, 4, 12, 10, 15,
+ tzinfo=FixedOffset(4, 0,
'+0400')),
DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_MINUTE + TZ_BAS),
- ('1985-W15-5T10:15+04', datetime(1985, 4, 12, 10, 15,
- tzinfo=FixedOffset(4, 0,
+ ('1985-W15-5T10:15+04', datetime(1985, 4, 12, 10, 15,
+ tzinfo=FixedOffset(4, 0,
'+0400')),
- DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_MINUTE + TZ_HOUR)]
+ 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)]
+
def create_testcase(datetimestring, expectation, format):
- '''
+ """
Create a TestCase class for a specific test.
-
+
This allows having a separate TestCase for each test tuple from the
TEST_CASES list, so that a failed test won't stop other tests.
- '''
-
+ """
+
class TestDateTime(unittest.TestCase):
'''
- A test case template to parse an ISO datetime string into a
+ A test case template to parse an ISO datetime string into a
datetime object.
'''
-
+
def test_parse(self):
'''
Parse an ISO datetime string and compare it to the expected value.
'''
result = parse_datetime(datetimestring)
self.assertEqual(result, expectation)
-
+
def test_format(self):
'''
Take datetime object and create ISO string from it.
@@ -88,9 +93,10 @@ def create_testcase(datetimestring, expectation, format):
else:
self.assertEqual(datetime_isoformat(expectation, format),
datetimestring)
-
+
return unittest.TestLoader().loadTestsFromTestCase(TestDateTime)
+
def test_suite():
'''
Construct a TestSuite instance for all test cases.