Skip to content

Commit

Permalink
Implement RFC_1123_DATE_TIME formatter
Browse files Browse the repository at this point in the history
Fix #549
  • Loading branch information
pithu committed Oct 9, 2021
1 parent 505ce24 commit 76ca881
Show file tree
Hide file tree
Showing 18 changed files with 13,171 additions and 1,798 deletions.
983 changes: 727 additions & 256 deletions docs/ast/source/locale/src/_init.js.json

Large diffs are not rendered by default.

12,781 changes: 11,510 additions & 1,271 deletions docs/ast/source/locale/src/format/LocaleDateTimeFormatter.js.json

Large diffs are not rendered by default.

533 changes: 515 additions & 18 deletions docs/ast/source/locale/src/plug.js.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
</nav>

<div class="content" data-ice="content"><div class="header-notice">
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import LocaleDateTimeFormatter from &apos;<span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber12">@js-joda/root/packages/locale/src/format/LocaleDateTimeFormatter.js</a></span>&apos;</code></pre></div>
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import LocaleDateTimeFormatter from &apos;<span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber19">@js-joda/root/packages/locale/src/format/LocaleDateTimeFormatter.js</a></span>&apos;</code></pre></div>
<span data-ice="access">public</span>
<span data-ice="kind">class</span>



<span data-ice="source">| <span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber12">source</a></span></span>
<span data-ice="source">| <span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber19">source</a></span></span>
</div>

<div class="self-detail detail">
Expand Down Expand Up @@ -204,7 +204,7 @@ <h3 data-ice="anchor" id="instance-method-withLocale">
<span class="right-info">


<span data-ice="source"><span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber25">source</a></span></span>
<span data-ice="source"><span><a href="file/packages/locale/src/format/LocaleDateTimeFormatter.js.html#lineNumber32">source</a></span></span>
</span>
</h3>

Expand Down
15 changes: 8 additions & 7 deletions docs/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"coverage": "70.97%",
"expectCount": 1850,
"coverage": "70.93%",
"expectCount": 1851,
"actualCount": 1313,
"files": {
"packages/core/src/Clock.js": {
Expand Down Expand Up @@ -882,16 +882,17 @@
"expectCount": 2,
"actualCount": 0,
"undocumentLines": [
9,
11
10,
12
]
},
"packages/locale/src/format/LocaleDateTimeFormatter.js": {
"expectCount": 3,
"expectCount": 4,
"actualCount": 1,
"undocumentLines": [
10,
12
17,
19,
41
]
},
"packages/locale/src/format/LocaleStore.js": {
Expand Down
2 changes: 2 additions & 0 deletions docs/file/packages/locale/src/_init.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

import { _init as localeInit } from &apos;./Locale&apos;;
import { _init as weekFieldsInit } from &apos;./temporal/WeekFields&apos;;
import { _init as dateTimeFormatterInit } from &apos;./format/LocaleDateTimeFormatter&apos;;

let isInit = false;

Expand All @@ -125,6 +126,7 @@

localeInit();
weekFieldsInit();
dateTimeFormatterInit();
}

init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,16 @@
* @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
*/

import { _ as jodaInternal, DateTimeFormatter } from &apos;@js-joda/core&apos;;
import {
_ as jodaInternal,
DateTimeFormatter,
ChronoField,
ResolverStyle,
IsoChronology,
} from &apos;@js-joda/core&apos;;
// eslint-disable-next-line no-unused-vars
import Locale from &apos;../Locale&apos;;
import CldrDateTimeFormatterBuilder from &apos;./cldr/CldrDateTimeFormatterBuilder&apos;;

const { assert: { requireNonNull } } = jodaInternal;

Expand All @@ -136,8 +143,57 @@
}
return new DateTimeFormatter(this._printerParser, locale, this._decimalStyle, this._resolverStyle, this._resolverFields, this._chrono, this._zone);
}
}

export function _init() {
const dow = {
1: &apos;Mon&apos;,
2: &apos;Tue&apos;,
3: &apos;Wed&apos;,
4: &apos;Thu&apos;,
5: &apos;Fri&apos;,
6: &apos;Sat&apos;,
7: &apos;Sun&apos;,
};

const moy = {
1: &apos;Jan&apos;,
2: &apos;Feb&apos;,
3: &apos;Mar&apos;,
4: &apos;Apr&apos;,
5: &apos;May&apos;,
6: &apos;Jun&apos;,
7: &apos;Jul&apos;,
8: &apos;Aug&apos;,
9: &apos;Sep&apos;,
10: &apos;Oct&apos;,
11: &apos;Nov&apos;,
12: &apos;Dec&apos;,
};

LocaleDateTimeFormatter.RFC_1123_DATE_TIME = new CldrDateTimeFormatterBuilder()
.parseCaseInsensitive()
.parseLenient()
.optionalStart()
.appendText(ChronoField.DAY_OF_WEEK, dow)
.appendLiteral(&apos;, &apos;)
.optionalEnd()
.appendValue(ChronoField.DAY_OF_MONTH, 2)
.appendLiteral(&apos; &apos;)
.appendText(ChronoField.MONTH_OF_YEAR, moy)
.appendLiteral(&apos; &apos;)
.appendValue(ChronoField.YEAR, 4) // 2 digit year not handled
.appendLiteral(&apos; &apos;)
.appendValue(ChronoField.HOUR_OF_DAY, 2)
.appendLiteral(&apos;:&apos;)
.appendValue(ChronoField.MINUTE_OF_HOUR, 2)
.optionalStart()
.appendLiteral(&apos;:&apos;)
.appendValue(ChronoField.SECOND_OF_MINUTE, 2)
.optionalEnd()
.appendLiteral(&apos; &apos;)
.appendZoneId()
.toFormatter(ResolverStyle.SMART).withChronology(IsoChronology.INSTANCE);
}
</code></pre>

Expand Down
2 changes: 2 additions & 0 deletions docs/file/packages/locale/src/plug.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
jsJoda.DateTimeFormatter.prototype[prop] = LocaleDateTimeFormatter.prototype[prop];
}
});
// copy statics manually
jsJoda.DateTimeFormatter.RFC_1123_DATE_TIME = LocaleDateTimeFormatter.RFC_1123_DATE_TIME;
}
</code></pre>

Expand Down
7 changes: 6 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ <h3 id="additional-value-types">Additional value types</h3><ul>
const date = LocalDate.parse(&apos;4/28/2018&apos;);
console.log(date.toString()); // 2018-04-28</code>
</code></pre><h3>http date parser example</h3><p>Example for an HTTP dates formatter as specified in RFC 7321,
like returned by javascript native <code>Date</code> <code>toUTCString</code> method.</p><p>This formatter requires the <code>@js-joda/locale</code> package.</p><pre><code class="lang-javascript"><code class="source-code prettyprint">import { DateTimeFormatter, ZonedDateTime } from &apos;@js-joda/core&apos;;
like returned by javascript native <code>Date</code> <code>toUTCString</code> method.</p><p>This formatter requires the <code>@js-joda/locale</code> package.
This formatter is built-in since @<a href="./manual/mailto:js-joda/locale@4.2.0">js-joda/locale@4.2.0</a> -&gt; RFC_1123_DATE_TIME</p><pre><code class="lang-javascript"><code class="source-code prettyprint">import { DateTimeFormatter, ZonedDateTime } from &apos;@js-joda/core&apos;;
import &apos;@js-joda/timezone&apos;
import { Locale } from &apos;@js-joda/locale&apos;;

Expand Down Expand Up @@ -1281,6 +1282,10 @@ <h3 id="additional-value-types">Additional value types</h3><ul>
<td>ISO_DATE_TIME</td>
<td>&apos;2011-12-03T10:15:30+01:00[Europe/Paris]&apos;</td>
</tr>
<tr>
<td>RFC_1123_DATE_TIME</td>
<td>&apos;Tue, 05 Oct 2021 17:08:24 GMT&apos;<br>requires @js-joda/locale</td>
</tr>
</tbody>
</table><p>Usage example for a built-in DateTimeFormatter</p><pre><code class="lang-javascript"><code class="source-code prettyprint">const localDate = LocalDate.parse(&apos;2012-12-12&apos;, DateTimeFormatter.ISO_LOCAL_DATE);
const dateAsString = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);</code>
Expand Down

0 comments on commit 76ca881

Please sign in to comment.