From a625a9f6ea2c332ed77abf1b7662894067563b91 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jul 2009 13:46:23 -0600 Subject: [PATCH] Fix #2737 (Metadata retrieval error: "year out of range") --- src/calibre/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index d7c5f0b223..1c2d780412 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -308,14 +308,25 @@ def walk(dir): yield os.path.join(record[0], f) def strftime(fmt, t=None): - ''' A version of strtime that returns unicode strings. ''' + ''' A version of strtime that returns unicode strings and tries to handle dates + before 1900 ''' if t is None: t = time.localtime() + early_year = t[0] < 1900 + if early_year: + fmt = fmt.replace('%Y', '_early year hack##') + t = list(t) + orig_year = t[0] + t[0] = 1900 + ans = None if iswindows: if isinstance(fmt, unicode): fmt = fmt.encode('mbcs') - return plugins['winutil'][0].strftime(fmt, t) - return time.strftime(fmt, t).decode(preferred_encoding, 'replace') + ans = plugins['winutil'][0].strftime(fmt, t) + ans = time.strftime(fmt, t).decode(preferred_encoding, 'replace') + if early_year: + ans = ans.replace('_early year hack##', str(orig_year)) + return ans def my_unichr(num): try: