##// END OF EJS Templates
Moved format date into common space
Jonathan Frederic -
Show More
@@ -33,7 +33,7 b' from IPython.config import Config'
33 from IPython.nbformat import current as nbformat
33 from IPython.nbformat import current as nbformat
34 from IPython.utils.traitlets import MetaHasTraits, DottedObjectName, Unicode, List, Dict, Any
34 from IPython.utils.traitlets import MetaHasTraits, DottedObjectName, Unicode, List, Dict, Any
35 from IPython.utils.importstring import import_item
35 from IPython.utils.importstring import import_item
36 from IPython.utils.text import indent
36 from IPython.utils.text import indent, format_date
37 from IPython.utils import py3compat
37 from IPython.utils import py3compat
38
38
39 from IPython.nbconvert import preprocessors as nbpreprocessors
39 from IPython.nbconvert import preprocessors as nbpreprocessors
@@ -282,7 +282,7 b' class Exporter(LoggingConfigurable):'
282 resources['metadata']['name'] = notebook_name
282 resources['metadata']['name'] = notebook_name
283
283
284 modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
284 modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
285 resources['metadata']['modified_date'] = modified_date.strftime("%B %d, %Y")
285 resources['metadata']['modified_date'] = format_date(modified_date)
286
286
287 with io.open(filename) as f:
287 with io.open(filename) as f:
288 return self.from_notebook_node(nbformat.read(f, 'json'), resources=resources,**kw)
288 return self.from_notebook_node(nbformat.read(f, 'json'), resources=resources,**kw)
@@ -30,6 +30,7 b' from pygments.formatters import LatexFormatter'
30 # Our own imports
30 # Our own imports
31 # Configurable traitlets
31 # Configurable traitlets
32 from IPython.utils.traitlets import Unicode, Bool
32 from IPython.utils.traitlets import Unicode, Bool
33 from IPython.utils.text import format_date
33
34
34 # Needed to override preprocessor
35 # Needed to override preprocessor
35 from .base import (Preprocessor)
36 from .base import (Preprocessor)
@@ -158,10 +159,7 b' class SphinxPreprocessor(Preprocessor):'
158 if self.publish_date:
159 if self.publish_date:
159 resources["sphinx"]["date"] = self.publish_date
160 resources["sphinx"]["date"] = self.publish_date
160 elif len(resources['metadata']['modified_date'].strip()) == 0:
161 elif len(resources['metadata']['modified_date'].strip()) == 0:
161 if sys.platform == 'win32':
162 resources["sphinx"]["date"] = format_date(date.today())
162 resources["sphinx"]["date"] = date.today().strftime("%B %d, %Y")
163 else:
164 resources["sphinx"]["date"] = date.today().strftime("%B %-d, %Y")
165 else:
163 else:
166 resources["sphinx"]["date"] = resources['metadata']['modified_date']
164 resources["sphinx"]["date"] = resources['metadata']['modified_date']
167
165
@@ -223,10 +221,7 b' class SphinxPreprocessor(Preprocessor):'
223 if resources['metadata']['modified_date']:
221 if resources['metadata']['modified_date']:
224 default_date = resources['metadata']['modified_date']
222 default_date = resources['metadata']['modified_date']
225 else:
223 else:
226 if sys.platform == 'win32':
224 default_date = format_date(date.today())
227 default_date = date.today().strftime("%B %d, %Y")
228 else:
229 default_date = date.today().strftime("%B %-d, %Y")
230
225
231 user_date = console.input("Date (deafults to \"" + default_date + "\"): ")
226 user_date = console.input("Date (deafults to \"" + default_date + "\"): ")
232 if len(user_date.strip()) == 0:
227 if len(user_date.strip()) == 0:
@@ -21,6 +21,7 b' Inheritance diagram:'
21
21
22 import os
22 import os
23 import re
23 import re
24 import sys
24 import textwrap
25 import textwrap
25 from string import Formatter
26 from string import Formatter
26
27
@@ -711,3 +712,21 b" def columnize(items, separator=' ', displaywidth=80):"
711 fmatrix = [filter(None, x) for x in matrix]
712 fmatrix = [filter(None, x) for x in matrix]
712 sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['columns_width'])])
713 sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['columns_width'])])
713 return '\n'.join(map(sjoin, fmatrix))+'\n'
714 return '\n'.join(map(sjoin, fmatrix))+'\n'
715
716
717 def format_date(date):
718 """ Format a datetime object as a string.
719
720 Parameters
721 ----------
722 date : datetime object
723 Date to be formatted.
724
725 Returns
726 -------
727 The formatted date string (ie "July 1, 1990")
728 """
729 if sys.platform == 'win32':
730 return date.strftime("%B {0}, %Y").format(date.day)
731 else:
732 return date.strftime("%B %-d, %Y") No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now