Skip to content

Commit

Permalink
Add more date format (#1664)
Browse files Browse the repository at this point in the history
* add date formats

* fix test

* Update lib/rules.json

Co-authored-by: Denis Ah-Kang <[email protected]>

Co-authored-by: Denis Ah-Kang <[email protected]>
  • Loading branch information
jennyliang220 and deniak authored Nov 4, 2022
1 parent e78f96b commit e0b99c8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const messages = {
'Duplicate <code>&lt;hr&gt;</code> at the end of, and right after, <code>div.head</code>.',
// headers/w3c-state
'headers.w3c-state.no-w3c-state':
'Cannot find the <code>&lt;p id="w3c-state"&gt;</code> element for profile and date.<br><br>Please make sure the <code>&lt;p id="w3c-state"&gt;<a href="https://www.w3.org/standards/types#@@Profile">W3C @@Profile</a>, DD Month Year&lt;/p&gt;</code> element can be selected by <code>document.getElementById("w3c-state")</code>; <br>If you are using bikeshed, please update to the latest version.',
'Cannot find the <code>&lt;p id="w3c-state"&gt;</code> element for profile and date.<br><br>Please make sure the <code>&lt;p id="w3c-state"&gt;<a href="https://www.w3.org/standards/types#@@Profile">W3C @@Profile</a>, DD Month YYYY&lt;/p&gt;</code> element can be selected by <code>document.getElementById("w3c-state")</code>; <br>If you are using bikeshed, please update to the latest version.',
'headers.w3c-state.bad-w3c-state':
'Incorrect w3c status element, <code>&lt;p id="w3c-state"&gt;</code>. <code>&lt;p id="w3c-state"&gt;<a href="https://www.w3.org/standards/types#@@Profile">W3C @@Profile</a>, DD Month Year&lt;/p&gt;</code>.',
'Incorrect w3c status element, <code>&lt;p id="w3c-state"&gt;</code>. <code>&lt;p id="w3c-state"&gt;<a href="https://www.w3.org/standards/types#@@Profile">W3C @@Profile</a>, DD Month YYYY&lt;/p&gt;</code>.',
'headers.w3c-state.no-w3c-state-link':
'Cannot find the link of the W3C profile in id="w3c-state" element pointing to "https://www.w3.org/standards/types#xx".',
'headers.w3c-state.wrong-w3c-state-link':
Expand Down
4 changes: 2 additions & 2 deletions lib/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@
"rules": {
"sotd": "There <span class=\"rfc2119\">must</span> be a status section that follows the abstract, labeled with an <code>h2</code> element with content \"Status of This Document\". The Team maintains the status section of a document.",
"boilerplateTRDoc": "It <span class=\"rfc2119\">must</span> begin with the following boilerplate text: <blockquote class=\"boilerplate\"> <p> <em>This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the <a href=\"https://www.w3.org/TR/\">W3C technical reports index</a> at https://www.w3.org/TR/.</em> </p> </blockquote> <div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p&gt;&lt;em&gt;This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the &lt;a href=\"https://www.w3.org/TR/\"&gt;W3C technical reports index&lt;/a&gt; at https://www.w3.org/TR/.&lt;/em&gt;&lt;/p&gt;</code></div>",
"datesFormat": "All dates <span class=\"rfc2119\">must</span> have the form DD Month YYYY. A leading zero in the day is <span class=\"rfc2119\">optional</span>.",
"datesFormat": "All dates <span class=\"rfc2119\">must</span> have one of the following forms:<ol><li>DD Month YYYY : 09 January 2020</li><li>DD-Month-YYYY : 09-January-2020</li><li>DD Mon YYYY : 09 Jan 2020</li><li>DD-Mon-YYYY : 09-Jan-2020</li></ol>A leading zero in the day is <span class=\"rfc2119\">optional</span>.",
"publish": "It <span class=\"rfc2119\">must</span> include the name of the W3C group that produced the document, the type of document and its track. The name <span class=\"rfc2119\">must</span> be a link to a public page for the group.<blockquote><p>This document was published by the <a href=\"https://www.w3.org/groups/(wg|ig)/@@\">@@@ Working/Interest Group</a> as a @{param1} using the @{param2}.</p> </blockquote><div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p&gt;This document was published by the &lt;a href=\"https://www.w3.org/groups/(wg|ig)/@@\"&gt;@@@ Working/Interest Group&lt;/a&gt; as a @{param1} using the @{param3}.&lt;/p&gt;</code></div>",
"customParagraph": "It <span class=\"rfc2119\">must</span> include at least one customized paragraph. This section <span class=\"rfc2119\">should</span> include the title page date (i.e., the one next to the maturity level at the top of the document). These paragraphs <span class=\"rfc2119\">should</span> explain the publication context, including rationale and relationships to other work. See <a href=\"https://www.w3.org/2001/06/manual/#Status\">examples and more discussion in the Manual of Style</a>.",
"changesList": "It <span class=\"rfc2119\">@{param1}</span> include a link to changes since the previous draft (e.g., a list of changes or a diff document or both; see the <a href=\"https://www.w3.org/2007/10/htmldiff\">online HTML diff tool</a>).@{param2}",
Expand Down Expand Up @@ -1656,7 +1656,7 @@
"rec-edit-w3c-state": {
"name": "3. Change the title of the document",
"rules": {
"w3c-state": "In the <code>&lt;p id=\"w3c-state\"&gt;</code> element containing the state and date (\"W3C Recommendation DD MMMMMM YYYY\"), add:<ol><li id='testtest'>a <code>&lt;br&gt;</code> element after the original date</li><li>and \"@{param1} <code>&lt;new date&gt;</code>\" when the @{param1} document gets published by the webmaster</li></ol>"
"w3c-state": "In the <code>&lt;p id=\"w3c-state\"&gt;</code> element containing the state and date (\"W3C Recommendation DD Month YYYY\"), add:<ol><li id='testtest'>a <code>&lt;br&gt;</code> element after the original date</li><li>and \"@{param1} <code>&lt;new date&gt;</code>\" when the @{param1} document gets published by the webmaster</li></ol>"
}
},
"rec-edit-version": {
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/heuristic/date-format.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { possibleMonths } from '../../validator.js';

const self = {
name: 'heuristic.date-format',
section: 'document-status',
Expand All @@ -12,14 +14,12 @@ export const { name } = self;
*/
export function check(sr, done) {
// Pseudo-constants:
const MONTHS =
'jan|january|feb|february|mar|march|apr|april|may|jun|june|jul|july|aug|august|sep|september|oct|october|nov|november|dec|december';
const POSSIBLE_DATE = new RegExp(
`\\b([0123]?\\d|${MONTHS})[\\ \\-\\/–—]([0123]?\\d|${MONTHS})[\\ \\-\\/–—]([\\'‘’]?\\d{2})(\\d\\d)?\\b`,
`\\b([0123]?\\d|${possibleMonths})[\\ \\-\\/–—]([0123]?\\d|${possibleMonths})[\\ \\-\\/–—]([\\'‘’]?\\d{2})(\\d\\d)?\\b`,
'gi'
);
const EXPECTED_DATE_FORMAT = new RegExp(
`[0123]?\\d\\ (${MONTHS})\\ \\d{4}`,
`[0123]?\\d\\ (${possibleMonths})\\ \\d{4}`,
'i'
);

Expand Down
45 changes: 35 additions & 10 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,41 @@ Specberus.prototype.norm = function (str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '').replace(/\s+/g, ' ');
};

const months =
'January February March April May June July August September October November December'.split(
' '
);
Specberus.prototype.dateRegexStrCapturing = `(\\d?\\d) (${months.join(
'|'
)}) (\\d{4})`;
Specberus.prototype.dateRegexStrNonCapturing = `\\d?\\d (?:${months.join(
'|'
)}) \\d{4}`;
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
const abbrMonths = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];

export const possibleMonths = [...months, ...abbrMonths].join('|');

const separator = '[ -]{1}';

Specberus.prototype.dateRegexStrCapturing = `(\\d?\\d)${separator}(${possibleMonths})${separator}(\\d{4})`;
Specberus.prototype.dateRegexStrNonCapturing = `\\d?\\d${separator}(?:${possibleMonths})${separator}\\d{4}`;

Specberus.prototype.stringToDate = function (str) {
const rex = new RegExp(this.dateRegexStrCapturing);
Expand Down
6 changes: 3 additions & 3 deletions test/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function buildHandler(test, mock, done) {
'https://www.w3.org/Consortium/Patent-Policy-20170801/',
},
{
end: '2024-09-30',
end: '2090-09-30',
'doc-licenses': [
{
uri: 'https://www.w3.org/Consortium/Legal/copyright-software',
Expand All @@ -350,7 +350,7 @@ function buildHandler(test, mock, done) {
start: '2010-05-17',
},
83907: {
end: '2023-07-31',
end: '2090-07-31',
'doc-licenses': [
{
uri: 'https://www.w3.org/Consortium/Legal/copyright-documents',
Expand All @@ -366,7 +366,7 @@ function buildHandler(test, mock, done) {
'https://www.w3.org/Consortium/Patent-Policy-20200915/',
},
35422: {
end: '2022-10-31',
end: '2090-10-31',
'doc-licenses': [
{
uri: 'https://www.w3.org/Consortium/Legal/copyright-documents',
Expand Down

0 comments on commit e0b99c8

Please sign in to comment.