Show More
@@ -33,7 +33,7 b' from IPython.config import Config' | |||
|
33 | 33 | from IPython.nbformat import current as nbformat |
|
34 | 34 | from IPython.utils.traitlets import MetaHasTraits, DottedObjectName, Unicode, List, Dict, Any |
|
35 | 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 | 37 | from IPython.utils import py3compat |
|
38 | 38 | |
|
39 | 39 | from IPython.nbconvert import preprocessors as nbpreprocessors |
@@ -282,7 +282,7 b' class Exporter(LoggingConfigurable):' | |||
|
282 | 282 | resources['metadata']['name'] = notebook_name |
|
283 | 283 | |
|
284 | 284 | modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename)) |
|
285 |
resources['metadata']['modified_date'] = modified_date |
|
|
285 | resources['metadata']['modified_date'] = format_date(modified_date) | |
|
286 | 286 | |
|
287 | 287 | with io.open(filename) as f: |
|
288 | 288 | return self.from_notebook_node(nbformat.read(f, 'json'), resources=resources,**kw) |
@@ -30,6 +30,7 b' from pygments.formatters import LatexFormatter' | |||
|
30 | 30 | # Our own imports |
|
31 | 31 | # Configurable traitlets |
|
32 | 32 | from IPython.utils.traitlets import Unicode, Bool |
|
33 | from IPython.utils.text import format_date | |
|
33 | 34 | |
|
34 | 35 | # Needed to override preprocessor |
|
35 | 36 | from .base import (Preprocessor) |
@@ -158,10 +159,7 b' class SphinxPreprocessor(Preprocessor):' | |||
|
158 | 159 | if self.publish_date: |
|
159 | 160 | resources["sphinx"]["date"] = self.publish_date |
|
160 | 161 | elif len(resources['metadata']['modified_date'].strip()) == 0: |
|
161 | if sys.platform == 'win32': | |
|
162 | resources["sphinx"]["date"] = date.today().strftime("%B %d, %Y") | |
|
163 | else: | |
|
164 | resources["sphinx"]["date"] = date.today().strftime("%B %-d, %Y") | |
|
162 | resources["sphinx"]["date"] = format_date(date.today()) | |
|
165 | 163 | else: |
|
166 | 164 | resources["sphinx"]["date"] = resources['metadata']['modified_date'] |
|
167 | 165 | |
@@ -223,10 +221,7 b' class SphinxPreprocessor(Preprocessor):' | |||
|
223 | 221 | if resources['metadata']['modified_date']: |
|
224 | 222 | default_date = resources['metadata']['modified_date'] |
|
225 | 223 | else: |
|
226 | if sys.platform == 'win32': | |
|
227 | default_date = date.today().strftime("%B %d, %Y") | |
|
228 | else: | |
|
229 | default_date = date.today().strftime("%B %-d, %Y") | |
|
224 | default_date = format_date(date.today()) | |
|
230 | 225 | |
|
231 | 226 | user_date = console.input("Date (deafults to \"" + default_date + "\"): ") |
|
232 | 227 | if len(user_date.strip()) == 0: |
@@ -21,6 +21,7 b' Inheritance diagram:' | |||
|
21 | 21 | |
|
22 | 22 | import os |
|
23 | 23 | import re |
|
24 | import sys | |
|
24 | 25 | import textwrap |
|
25 | 26 | from string import Formatter |
|
26 | 27 | |
@@ -711,3 +712,21 b" def columnize(items, separator=' ', displaywidth=80):" | |||
|
711 | 712 | fmatrix = [filter(None, x) for x in matrix] |
|
712 | 713 | sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['columns_width'])]) |
|
713 | 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