diff --git a/cli/tests/input/elements.xml b/cli/tests/input/elements.xml
index b757a04ae..8b49cff24 100644
--- a/cli/tests/input/elements.xml
+++ b/cli/tests/input/elements.xml
@@ -899,6 +899,14 @@ the Cherokee block look similar to the ASCII characters "STPETER".]]>
+
+
+ Document with no date
+
+
+
+
+
diff --git a/cli/tests/valid/elements.bom.text b/cli/tests/valid/elements.bom.text
index 221c122de..9bb043982 100644
--- a/cli/tests/valid/elements.bom.text
+++ b/cli/tests/valid/elements.bom.text
@@ -1048,6 +1048,8 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
[FUZZY-DATE]
Mae, J., "Document with fuzzy date", Second quarter 2010.
+ [NO-DATE] Mae, N., "Document with no date".
+
[RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet
host table specification", RFC 952, DOI 10.17487/RFC0952,
October 1985, .
@@ -1059,8 +1061,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
-
-
Author, et al. Expires 13 January 2019 [Page 19]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
diff --git a/cli/tests/valid/elements.pages.text b/cli/tests/valid/elements.pages.text
index f9a5e3448..0890a0911 100644
--- a/cli/tests/valid/elements.pages.text
+++ b/cli/tests/valid/elements.pages.text
@@ -1048,6 +1048,8 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
[FUZZY-DATE]
Mae, J., "Document with fuzzy date", Second quarter 2010.
+ [NO-DATE] Mae, N., "Document with no date".
+
[RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet
host table specification", RFC 952, DOI 10.17487/RFC0952,
October 1985, .
@@ -1059,8 +1061,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
-
-
Author, et al. Expires January 13, 2019 [Page 19]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
diff --git a/cli/tests/valid/elements.prepped.xml b/cli/tests/valid/elements.prepped.xml
index 8eb34ec10..ddc14c31e 100644
--- a/cli/tests/valid/elements.prepped.xml
+++ b/cli/tests/valid/elements.prepped.xml
@@ -1,5 +1,5 @@
-
+
@@ -1257,6 +1257,13 @@ the Cherokee block look similar to the ASCII characters "STPETER".
Second quarter 2010
+
+
+ Document with no date
+
+
+
+ DoD Internet host table specification
diff --git a/cli/tests/valid/elements.text b/cli/tests/valid/elements.text
index 235aa3be1..d63eb7824 100644
--- a/cli/tests/valid/elements.text
+++ b/cli/tests/valid/elements.text
@@ -886,6 +886,8 @@ Table of Contents
[FUZZY-DATE]
Mae, J., "Document with fuzzy date", Second quarter 2010.
+ [NO-DATE] Mae, N., "Document with no date".
+
[RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet
host table specification", RFC 952, DOI 10.17487/RFC0952,
October 1985, .
diff --git a/cli/tests/valid/elements.v3.py27.html b/cli/tests/valid/elements.v3.py27.html
index 5ed46b475..0b283e31d 100644
--- a/cli/tests/valid/elements.v3.py27.html
+++ b/cli/tests/valid/elements.v3.py27.html
@@ -10,7 +10,7 @@
-
+
@@ -1179,6 +1179,9 @@
[FUZZY-DATE]
Mae, J., "Document with fuzzy date", .
+
[NO-DATE]
+
+Mae, N., "Document with no date", .
[RFC0952]
Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet host table specification", RFC 952, DOI 10.17487/RFC0952, , <https://www.rfc-editor.org/info/rfc952>.
diff --git a/cli/tests/valid/elements.wip.text b/cli/tests/valid/elements.wip.text
index 58147edc9..1da2282f0 100644
--- a/cli/tests/valid/elements.wip.text
+++ b/cli/tests/valid/elements.wip.text
@@ -1048,6 +1048,8 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
[FUZZY-DATE]
Mae, J., "Document with fuzzy date", Second quarter 2010.
+ [NO-DATE] Mae, N., "Document with no date".
+
[RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet
host table specification", RFC 952, DOI 10.17487/RFC0952,
October 1985, .
@@ -1059,8 +1061,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
-
-
Author, et al. Expires 13 January 2019 [Page 19]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
diff --git a/cli/xml2rfc/util/date.py b/cli/xml2rfc/util/date.py
index 70d03a52f..c639e54b4 100644
--- a/cli/xml2rfc/util/date.py
+++ b/cli/xml2rfc/util/date.py
@@ -24,16 +24,14 @@ def normalize_month(month):
def extract_date(e, today):
day = e.get('day')
month = e.get('month')
- year = e.get('year', str(today.year))
+ year = e.get('year')
#
- if not year.isdigit():
- xml2rfc.log.warn("Expected a numeric year, but found '%s'" % year)
- year = today.year
- year = int(year)
- if not month:
- if year == today.year:
- month = today.month
- else:
+ if year:
+ if not year.isdigit():
+ xml2rfc.log.warn("Expected a numeric year, but found '%s'" % year)
+ year = today.year
+ year = int(year)
+ if month:
if not month.isdigit():
month = normalize_month(month)
month = int(month)
@@ -44,6 +42,15 @@ def extract_date(e, today):
day = int(day)
return year, month, day
+def augment_date(year, month, day, today):
+ if not year:
+ year = today.year
+ if not month:
+ if year == today.year:
+ month = today.month
+ return year, month, day
+
+
def format_date_iso(year, month, day):
if year and month and day:
return '%4d-%02d-%02d' % (year, month, day)
@@ -62,15 +69,16 @@ def format_date(year, month, day, legacy=False):
date = '%s %s %s' % (day, month, year)
else:
date = '%s %s' % (month, year)
- else:
+ elif year:
date = '%s' % year
+ else:
+ date = ''
return date
def get_expiry_date(tree, today):
year, month, day = extract_date(tree.find('./front/date'), today)
- if not day:
- day = today.day
+ year, month, day = augment_date(year, month, day, today)
exp = datetime.date(year=year, month=month, day=day) + datetime.timedelta(days=185)
return exp
diff --git a/cli/xml2rfc/writers/base.py b/cli/xml2rfc/writers/base.py
index 9e85ca47a..c06867bef 100644
--- a/cli/xml2rfc/writers/base.py
+++ b/cli/xml2rfc/writers/base.py
@@ -21,7 +21,7 @@
pass
from xml2rfc import strings, log
-from xml2rfc.util.date import extract_date, format_date, get_expiry_date
+from xml2rfc.util.date import extract_date, augment_date, format_date, get_expiry_date
from xml2rfc.util.name import short_author_ascii_name_parts, full_author_name_expansion, short_author_name_parts
from xml2rfc.util.unicode import punctuation, unicode_replacements, unicode_content_tags, downcode
from xml2rfc.utils import namespaces, find_duplicate_ids
@@ -1805,8 +1805,9 @@ def page_top_center(self):
def page_top_right(self):
date = self.root.find('./front/date')
- parts = extract_date(date, self.options.date)
- text = format_date(parts[0], parts[1], None, legacy=True)
+ year, month, day = extract_date(date, self.options.date)
+ year, month, day = augment_date(year, month, day, self.options.date)
+ text = format_date(year, month, None, legacy=True)
return text
def page_bottom_left(self):
diff --git a/cli/xml2rfc/writers/html.py b/cli/xml2rfc/writers/html.py
index 045de7fac..1d10ea538 100644
--- a/cli/xml2rfc/writers/html.py
+++ b/cli/xml2rfc/writers/html.py
@@ -33,7 +33,7 @@
from xml2rfc import log, strings
from xml2rfc.writers.base import default_options, BaseV3Writer
from xml2rfc.uniscripts import is_script
-from xml2rfc.util.date import extract_date, format_date, format_date_iso, get_expiry_date
+from xml2rfc.util.date import extract_date, augment_date, format_date, format_date_iso, get_expiry_date
from xml2rfc.util.name import ( full_author_name_expansion, short_author_role,
ref_author_name_first, ref_author_name_last,
short_author_name_set, full_author_name_set,
@@ -1311,9 +1311,13 @@ def render_cref(self, h, x):
#
def render_date(self, h, x):
have_date = x.get('day') or x.get('month') or x.get('year')
- parts = extract_date(x, self.options.date)
- text = format_date(*parts, legacy=self.options.legacy_date_format)
- datetime = format_date_iso(*parts) if have_date else x.text
+ year, month, day = extract_date(x, self.options.date)
+ p = x.getparent()
+ if p==None or p.getparent().tag != 'reference':
+ # don't touch the given date if we're rendering a reference
+ year, month, day = augment_date(year, month, day, self.options.date)
+ text = format_date(year, month, day, legacy=self.options.legacy_date_format)
+ datetime = format_date_iso(year, month, day) if have_date else x.text
if x.text and have_date:
text = "%s (%s)" % (x.text, text)
elif x.text:
diff --git a/cli/xml2rfc/writers/preptool.py b/cli/xml2rfc/writers/preptool.py
index 1fa0ce06c..2bc29ffde 100644
--- a/cli/xml2rfc/writers/preptool.py
+++ b/cli/xml2rfc/writers/preptool.py
@@ -37,7 +37,7 @@
from xml2rfc.boilerplate_tlp import boilerplate_tlp
from xml2rfc.scripts import get_scripts
from xml2rfc.uniscripts import is_script
-from xml2rfc.util.date import extract_date, format_date, normalize_month
+from xml2rfc.util.date import extract_date, augment_date, format_date, normalize_month
from xml2rfc.util.name import full_author_name_expansion
from xml2rfc.util.num import ol_style_formatter
from xml2rfc.util.unicode import unicode_content_tags, bare_unicode_tags, expand_unicode_element, isascii, downcode
@@ -1096,8 +1096,7 @@ def boilerplate_insert_status_of_memo(self, e, p):
else:
year, month, day = extract_date(self.root.find('./front/date'), self.date)
- if not day:
- day = self.date.day
+ year, month, day = augment_date(year, month, day, self.date)
exp = datetime.date(year=year, month=month, day=day) + datetime.timedelta(days=185)
format_dict['expiration_date'] = format_date(exp.year, exp.month, exp.day, legacy=self.options.legacy_date_format)
for para in boilerplate_draft_status_of_memo:
diff --git a/cli/xml2rfc/writers/text.py b/cli/xml2rfc/writers/text.py
index 8cb2c3b91..c591f967a 100644
--- a/cli/xml2rfc/writers/text.py
+++ b/cli/xml2rfc/writers/text.py
@@ -27,7 +27,7 @@
from xml2rfc.writers.base import default_options, BaseV3Writer
from xml2rfc import utils
from xml2rfc.uniscripts import is_script
-from xml2rfc.util.date import extract_date, get_expiry_date, format_date
+from xml2rfc.util.date import extract_date, augment_date, get_expiry_date, format_date
from xml2rfc.util.name import short_author_name, short_author_ascii_name, short_author_name_parts, short_org_name_set
from xml2rfc.util.num import ol_style_formatter, num_width
@@ -434,6 +434,9 @@ def tjoin(self, text, e, width, **kwargs):
if text:
if '\n' in j.join:
text += j.join + itext
+ elif j.join.strip() and not itext.strip():
+ # don't use non-empty joiners with empty content
+ pass
else:
text += j.join + itext.lstrip()
else:
@@ -1217,6 +1220,10 @@ def render_date(self, e, width, **kwargs):
#if pp.tag == 'rfc':
have_date = e.get('day') or e.get('month') or e.get('year')
year, month, day = extract_date(e, self.date)
+ p = e.getparent()
+ if p==None or p.getparent().tag != 'reference':
+ # don't touch the given date if we're rendering a reference
+ year, month, day = augment_date(year, month, day, self.date)
date = format_date(year, month, day, self.options.legacy_date_format)
if e.text and have_date:
date = "%s (%s)" % (e.text, date)