@fedify/vocab-runtime 2.0.35 → 2.0.36-dev.2530
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/mod.cjs +1 -1
- package/dist/mod.js +1 -1
- package/dist/temporal.cjs +17 -0
- package/dist/temporal.d.cts +11 -1
- package/dist/temporal.d.ts +11 -1
- package/dist/temporal.js +17 -1
- package/dist/tests/{body-Cul4-oB8.cjs → body-KJu7BVrD.cjs} +1 -1
- package/dist/tests/{body-ByUnLtuw.mjs → body-aEN-Jw2f.mjs} +1 -1
- package/dist/tests/body.test.cjs +1 -1
- package/dist/tests/body.test.mjs +1 -1
- package/dist/tests/docloader.test.cjs +2 -2
- package/dist/tests/docloader.test.mjs +2 -2
- package/dist/tests/{request-B7Iyskql.cjs → request-C1QT7ro7.cjs} +1 -1
- package/dist/tests/{request-pGToUa6Q.mjs → request-DMfShbXT.mjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/temporal.test.cjs +60 -0
- package/dist/tests/temporal.test.mjs +60 -0
- package/package.json +1 -1
- package/src/temporal.test.ts +62 -1
- package/src/temporal.ts +18 -0
package/deno.json
CHANGED
package/dist/mod.cjs
CHANGED
|
@@ -4502,7 +4502,7 @@ const preloadedContexts = {
|
|
|
4502
4502
|
//#endregion
|
|
4503
4503
|
//#region deno.json
|
|
4504
4504
|
var name = "@fedify/vocab-runtime";
|
|
4505
|
-
var version = "2.0.
|
|
4505
|
+
var version = "2.0.36-dev.2530+fb03bc56";
|
|
4506
4506
|
//#endregion
|
|
4507
4507
|
//#region src/request.ts
|
|
4508
4508
|
/**
|
package/dist/mod.js
CHANGED
|
@@ -4498,7 +4498,7 @@ const preloadedContexts = {
|
|
|
4498
4498
|
//#endregion
|
|
4499
4499
|
//#region deno.json
|
|
4500
4500
|
var name = "@fedify/vocab-runtime";
|
|
4501
|
-
var version = "2.0.
|
|
4501
|
+
var version = "2.0.36-dev.2530+fb03bc56";
|
|
4502
4502
|
//#endregion
|
|
4503
4503
|
//#region src/request.ts
|
|
4504
4504
|
/**
|
package/dist/temporal.cjs
CHANGED
|
@@ -55,6 +55,23 @@ function isTemporalInstant(value) {
|
|
|
55
55
|
function isTemporalDuration(value) {
|
|
56
56
|
return typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Temporal.Duration]" && "sign" in value && (value.sign === -1 || value.sign === 0 || value.sign === 1) && "toString" in value && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
60
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
61
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
62
|
+
* 2.0 allows, are filled in.
|
|
63
|
+
*
|
|
64
|
+
* @param value The date-time literal to normalize.
|
|
65
|
+
* @returns The normalized literal.
|
|
66
|
+
*/
|
|
67
|
+
function normalizeDateTimeLiteral(value) {
|
|
68
|
+
const timeStart = value.search(/[Tt ]/) + 1;
|
|
69
|
+
if (timeStart < 1) return value;
|
|
70
|
+
const date = value.substring(0, timeStart);
|
|
71
|
+
const time = value.substring(timeStart).replace(/^(\d{2}:\d{2})(?=\.)/, "$1:00");
|
|
72
|
+
return date + (/[Zz+-]/.test(time) ? time : time + "Z");
|
|
73
|
+
}
|
|
58
74
|
//#endregion
|
|
59
75
|
exports.isTemporalDuration = isTemporalDuration;
|
|
60
76
|
exports.isTemporalInstant = isTemporalInstant;
|
|
77
|
+
exports.normalizeDateTimeLiteral = normalizeDateTimeLiteral;
|
package/dist/temporal.d.cts
CHANGED
|
@@ -50,5 +50,15 @@ declare function isTemporalInstant(value: unknown): value is Temporal.Instant;
|
|
|
50
50
|
* and overrides `toString`; `false` otherwise.
|
|
51
51
|
*/
|
|
52
52
|
declare function isTemporalDuration(value: unknown): value is Temporal.Duration;
|
|
53
|
+
/**
|
|
54
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
55
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
56
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
57
|
+
* 2.0 allows, are filled in.
|
|
58
|
+
*
|
|
59
|
+
* @param value The date-time literal to normalize.
|
|
60
|
+
* @returns The normalized literal.
|
|
61
|
+
*/
|
|
62
|
+
declare function normalizeDateTimeLiteral(value: string): string;
|
|
53
63
|
//#endregion
|
|
54
|
-
export { isTemporalDuration, isTemporalInstant };
|
|
64
|
+
export { isTemporalDuration, isTemporalInstant, normalizeDateTimeLiteral };
|
package/dist/temporal.d.ts
CHANGED
|
@@ -50,5 +50,15 @@ declare function isTemporalInstant(value: unknown): value is Temporal.Instant;
|
|
|
50
50
|
* and overrides `toString`; `false` otherwise.
|
|
51
51
|
*/
|
|
52
52
|
declare function isTemporalDuration(value: unknown): value is Temporal.Duration;
|
|
53
|
+
/**
|
|
54
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
55
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
56
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
57
|
+
* 2.0 allows, are filled in.
|
|
58
|
+
*
|
|
59
|
+
* @param value The date-time literal to normalize.
|
|
60
|
+
* @returns The normalized literal.
|
|
61
|
+
*/
|
|
62
|
+
declare function normalizeDateTimeLiteral(value: string): string;
|
|
53
63
|
//#endregion
|
|
54
|
-
export { isTemporalDuration, isTemporalInstant };
|
|
64
|
+
export { isTemporalDuration, isTemporalInstant, normalizeDateTimeLiteral };
|
package/dist/temporal.js
CHANGED
|
@@ -54,5 +54,21 @@ function isTemporalInstant(value) {
|
|
|
54
54
|
function isTemporalDuration(value) {
|
|
55
55
|
return typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Temporal.Duration]" && "sign" in value && (value.sign === -1 || value.sign === 0 || value.sign === 1) && "toString" in value && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
59
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
60
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
61
|
+
* 2.0 allows, are filled in.
|
|
62
|
+
*
|
|
63
|
+
* @param value The date-time literal to normalize.
|
|
64
|
+
* @returns The normalized literal.
|
|
65
|
+
*/
|
|
66
|
+
function normalizeDateTimeLiteral(value) {
|
|
67
|
+
const timeStart = value.search(/[Tt ]/) + 1;
|
|
68
|
+
if (timeStart < 1) return value;
|
|
69
|
+
const date = value.substring(0, timeStart);
|
|
70
|
+
const time = value.substring(timeStart).replace(/^(\d{2}:\d{2})(?=\.)/, "$1:00");
|
|
71
|
+
return date + (/[Zz+-]/.test(time) ? time : time + "Z");
|
|
72
|
+
}
|
|
57
73
|
//#endregion
|
|
58
|
-
export { isTemporalDuration, isTemporalInstant };
|
|
74
|
+
export { isTemporalDuration, isTemporalInstant, normalizeDateTimeLiteral };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require("./chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_request = require("./request-
|
|
2
|
+
const require_request = require("./request-C1QT7ro7.cjs");
|
|
3
3
|
let _logtape_logtape = require("@logtape/logtape");
|
|
4
4
|
//#region src/body.ts
|
|
5
5
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
package/dist/tests/body.test.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require("./chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_body = require("./body-
|
|
2
|
+
const require_body = require("./body-KJu7BVrD.cjs");
|
|
3
3
|
let node_assert_strict = require("node:assert/strict");
|
|
4
4
|
let node_test = require("node:test");
|
|
5
5
|
let node_zlib = require("node:zlib");
|
package/dist/tests/body.test.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as readBoundedText, t as BodyTooLargeError } from "./body-
|
|
1
|
+
import { r as readBoundedText, t as BodyTooLargeError } from "./body-aEN-Jw2f.mjs";
|
|
2
2
|
import { deepStrictEqual, ok, rejects } from "node:assert/strict";
|
|
3
3
|
import { test } from "node:test";
|
|
4
4
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_request = require("./request-
|
|
3
|
-
const require_body = require("./body-
|
|
2
|
+
const require_request = require("./request-C1QT7ro7.cjs");
|
|
3
|
+
const require_body = require("./body-KJu7BVrD.cjs");
|
|
4
4
|
const require_esm = require("./esm-4DuocLvD.cjs");
|
|
5
5
|
const require_link = require("./link-qDTmjPw_.cjs");
|
|
6
6
|
const require_url = require("./url-DLuSj57U.cjs");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as esm_default } from "./esm-CnLt0wAF.mjs";
|
|
2
|
-
import { a as name, i as logRequest, n as createActivityPubRequest, o as version, t as FetchError } from "./request-
|
|
3
|
-
import { n as MAX_BODY_SIZE, r as readBoundedText } from "./body-
|
|
2
|
+
import { a as name, i as logRequest, n as createActivityPubRequest, o as version, t as FetchError } from "./request-DMfShbXT.mjs";
|
|
3
|
+
import { n as MAX_BODY_SIZE, r as readBoundedText } from "./body-aEN-Jw2f.mjs";
|
|
4
4
|
import { t as HttpHeaderLink } from "./link-CYszIegt.mjs";
|
|
5
5
|
import { t as UrlError } from "./url-DjsVF44Q.mjs";
|
|
6
6
|
import { n as openDirectFetch, r as openPublicFetch, t as createPublicFetch } from "./public-fetch-BUSPlh1C.mjs";
|
|
@@ -3,7 +3,7 @@ let node_process = require("node:process");
|
|
|
3
3
|
node_process = require_chunk.__toESM(node_process);
|
|
4
4
|
//#region deno.json
|
|
5
5
|
var name = "@fedify/vocab-runtime";
|
|
6
|
-
var version = "2.0.
|
|
6
|
+
var version = "2.0.36-dev.2530+fb03bc56";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/request.ts
|
|
9
9
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_request = require("./request-
|
|
2
|
+
const require_request = require("./request-C1QT7ro7.cjs");
|
|
3
3
|
let node_test = require("node:test");
|
|
4
4
|
let node_process = require("node:process");
|
|
5
5
|
node_process = require_chunk.__toESM(node_process);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as version, r as getUserAgent } from "./request-
|
|
1
|
+
import { o as version, r as getUserAgent } from "./request-DMfShbXT.mjs";
|
|
2
2
|
import { test } from "node:test";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { deepStrictEqual } from "node:assert";
|
|
@@ -57,6 +57,22 @@ function isTemporalInstant(value) {
|
|
|
57
57
|
function isTemporalDuration(value) {
|
|
58
58
|
return typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Temporal.Duration]" && "sign" in value && (value.sign === -1 || value.sign === 0 || value.sign === 1) && "toString" in value && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
62
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
63
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
64
|
+
* 2.0 allows, are filled in.
|
|
65
|
+
*
|
|
66
|
+
* @param value The date-time literal to normalize.
|
|
67
|
+
* @returns The normalized literal.
|
|
68
|
+
*/
|
|
69
|
+
function normalizeDateTimeLiteral(value) {
|
|
70
|
+
const timeStart = value.search(/[Tt ]/) + 1;
|
|
71
|
+
if (timeStart < 1) return value;
|
|
72
|
+
const date = value.substring(0, timeStart);
|
|
73
|
+
const time = value.substring(timeStart).replace(/^(\d{2}:\d{2})(?=\.)/, "$1:00");
|
|
74
|
+
return date + (/[Zz+-]/.test(time) ? time : time + "Z");
|
|
75
|
+
}
|
|
60
76
|
//#endregion
|
|
61
77
|
//#region src/temporal.test.ts
|
|
62
78
|
(0, node_test.test)("isTemporalInstant() accepts polyfill instances", () => {
|
|
@@ -131,4 +147,48 @@ function isTemporalDuration(value) {
|
|
|
131
147
|
sign: 0
|
|
132
148
|
}), false);
|
|
133
149
|
});
|
|
150
|
+
(0, node_test.test)("normalizeDateTimeLiteral() keeps literals with a UTC offset", () => {
|
|
151
|
+
for (const literal of [
|
|
152
|
+
"2024-01-01T10:00Z",
|
|
153
|
+
"2024-01-01T10:00+09:00",
|
|
154
|
+
"2024-01-01T10:00-05:00",
|
|
155
|
+
"2024-01-01T10:00:00Z",
|
|
156
|
+
"2024-01-01T10:00:00+09:00",
|
|
157
|
+
"2024-01-01T10:00:00-05:00",
|
|
158
|
+
"2024-01-01T10:00:00+0900",
|
|
159
|
+
"2024-01-01T10:00:00.123456789Z",
|
|
160
|
+
"2024-01-01t10:00z",
|
|
161
|
+
"2024-01-01 10:00:00Z"
|
|
162
|
+
]) {
|
|
163
|
+
(0, node_assert.strictEqual)(normalizeDateTimeLiteral(literal), literal);
|
|
164
|
+
(0, node_assert.strictEqual)(typeof _js_temporal_polyfill.Temporal.Instant.from(literal), "object");
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
(0, node_test.test)("normalizeDateTimeLiteral() treats literals without an offset as UTC", () => {
|
|
168
|
+
for (const literal of [
|
|
169
|
+
"2024-01-01T10:00",
|
|
170
|
+
"2024-01-01T10:00:00",
|
|
171
|
+
"2024-01-01T10:00:00.123",
|
|
172
|
+
"2025-01-01 12:34:56"
|
|
173
|
+
]) {
|
|
174
|
+
(0, node_assert.strictEqual)(normalizeDateTimeLiteral(literal), `${literal}Z`);
|
|
175
|
+
(0, node_assert.strictEqual)(typeof _js_temporal_polyfill.Temporal.Instant.from(normalizeDateTimeLiteral(literal)), "object");
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
(0, node_test.test)("normalizeDateTimeLiteral() keeps literals without a time part", () => {
|
|
179
|
+
(0, node_assert.strictEqual)(normalizeDateTimeLiteral("2024-01-01"), "2024-01-01");
|
|
180
|
+
});
|
|
181
|
+
(0, node_test.test)("normalizeDateTimeLiteral() inserts omitted seconds before a fraction", () => {
|
|
182
|
+
for (const [literal, normalized] of [
|
|
183
|
+
["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
|
|
184
|
+
["2024-01-01T10:00.5+09:00", "2024-01-01T10:00:00.5+09:00"],
|
|
185
|
+
["2024-01-01T10:00.5-05:00", "2024-01-01T10:00:00.5-05:00"],
|
|
186
|
+
["2024-01-01T10:00.5", "2024-01-01T10:00:00.5Z"],
|
|
187
|
+
["2024-01-01T10:00.123456789Z", "2024-01-01T10:00:00.123456789Z"]
|
|
188
|
+
]) {
|
|
189
|
+
(0, node_assert.strictEqual)(normalizeDateTimeLiteral(literal), normalized);
|
|
190
|
+
(0, node_assert.strictEqual)(typeof _js_temporal_polyfill.Temporal.Instant.from(normalized), "object");
|
|
191
|
+
}
|
|
192
|
+
(0, node_assert.strictEqual)(normalizeDateTimeLiteral("2024-01-01T10:00:00.5Z"), "2024-01-01T10:00:00.5Z");
|
|
193
|
+
});
|
|
134
194
|
//#endregion
|
|
@@ -56,6 +56,22 @@ function isTemporalInstant(value) {
|
|
|
56
56
|
function isTemporalDuration(value) {
|
|
57
57
|
return typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Temporal.Duration]" && "sign" in value && (value.sign === -1 || value.sign === 0 || value.sign === 1) && "toString" in value && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
61
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
62
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
63
|
+
* 2.0 allows, are filled in.
|
|
64
|
+
*
|
|
65
|
+
* @param value The date-time literal to normalize.
|
|
66
|
+
* @returns The normalized literal.
|
|
67
|
+
*/
|
|
68
|
+
function normalizeDateTimeLiteral(value) {
|
|
69
|
+
const timeStart = value.search(/[Tt ]/) + 1;
|
|
70
|
+
if (timeStart < 1) return value;
|
|
71
|
+
const date = value.substring(0, timeStart);
|
|
72
|
+
const time = value.substring(timeStart).replace(/^(\d{2}:\d{2})(?=\.)/, "$1:00");
|
|
73
|
+
return date + (/[Zz+-]/.test(time) ? time : time + "Z");
|
|
74
|
+
}
|
|
59
75
|
//#endregion
|
|
60
76
|
//#region src/temporal.test.ts
|
|
61
77
|
test("isTemporalInstant() accepts polyfill instances", () => {
|
|
@@ -130,5 +146,49 @@ test("isTemporalDuration() rejects default Object.prototype.toString", () => {
|
|
|
130
146
|
sign: 0
|
|
131
147
|
}), false);
|
|
132
148
|
});
|
|
149
|
+
test("normalizeDateTimeLiteral() keeps literals with a UTC offset", () => {
|
|
150
|
+
for (const literal of [
|
|
151
|
+
"2024-01-01T10:00Z",
|
|
152
|
+
"2024-01-01T10:00+09:00",
|
|
153
|
+
"2024-01-01T10:00-05:00",
|
|
154
|
+
"2024-01-01T10:00:00Z",
|
|
155
|
+
"2024-01-01T10:00:00+09:00",
|
|
156
|
+
"2024-01-01T10:00:00-05:00",
|
|
157
|
+
"2024-01-01T10:00:00+0900",
|
|
158
|
+
"2024-01-01T10:00:00.123456789Z",
|
|
159
|
+
"2024-01-01t10:00z",
|
|
160
|
+
"2024-01-01 10:00:00Z"
|
|
161
|
+
]) {
|
|
162
|
+
strictEqual(normalizeDateTimeLiteral(literal), literal);
|
|
163
|
+
strictEqual(typeof Temporal.Instant.from(literal), "object");
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
test("normalizeDateTimeLiteral() treats literals without an offset as UTC", () => {
|
|
167
|
+
for (const literal of [
|
|
168
|
+
"2024-01-01T10:00",
|
|
169
|
+
"2024-01-01T10:00:00",
|
|
170
|
+
"2024-01-01T10:00:00.123",
|
|
171
|
+
"2025-01-01 12:34:56"
|
|
172
|
+
]) {
|
|
173
|
+
strictEqual(normalizeDateTimeLiteral(literal), `${literal}Z`);
|
|
174
|
+
strictEqual(typeof Temporal.Instant.from(normalizeDateTimeLiteral(literal)), "object");
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
test("normalizeDateTimeLiteral() keeps literals without a time part", () => {
|
|
178
|
+
strictEqual(normalizeDateTimeLiteral("2024-01-01"), "2024-01-01");
|
|
179
|
+
});
|
|
180
|
+
test("normalizeDateTimeLiteral() inserts omitted seconds before a fraction", () => {
|
|
181
|
+
for (const [literal, normalized] of [
|
|
182
|
+
["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
|
|
183
|
+
["2024-01-01T10:00.5+09:00", "2024-01-01T10:00:00.5+09:00"],
|
|
184
|
+
["2024-01-01T10:00.5-05:00", "2024-01-01T10:00:00.5-05:00"],
|
|
185
|
+
["2024-01-01T10:00.5", "2024-01-01T10:00:00.5Z"],
|
|
186
|
+
["2024-01-01T10:00.123456789Z", "2024-01-01T10:00:00.123456789Z"]
|
|
187
|
+
]) {
|
|
188
|
+
strictEqual(normalizeDateTimeLiteral(literal), normalized);
|
|
189
|
+
strictEqual(typeof Temporal.Instant.from(normalized), "object");
|
|
190
|
+
}
|
|
191
|
+
strictEqual(normalizeDateTimeLiteral("2024-01-01T10:00:00.5Z"), "2024-01-01T10:00:00.5Z");
|
|
192
|
+
});
|
|
133
193
|
//#endregion
|
|
134
194
|
export {};
|
package/package.json
CHANGED
package/src/temporal.test.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { strictEqual } from "node:assert";
|
|
3
3
|
import { test } from "node:test";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isTemporalDuration,
|
|
6
|
+
isTemporalInstant,
|
|
7
|
+
normalizeDateTimeLiteral,
|
|
8
|
+
} from "./temporal.ts";
|
|
5
9
|
|
|
6
10
|
test("isTemporalInstant() accepts polyfill instances", () => {
|
|
7
11
|
strictEqual(
|
|
@@ -119,3 +123,60 @@ test("isTemporalDuration() rejects default Object.prototype.toString", () => {
|
|
|
119
123
|
};
|
|
120
124
|
strictEqual(isTemporalDuration(decoy), false);
|
|
121
125
|
});
|
|
126
|
+
|
|
127
|
+
test("normalizeDateTimeLiteral() keeps literals with a UTC offset", () => {
|
|
128
|
+
const literals = [
|
|
129
|
+
"2024-01-01T10:00Z",
|
|
130
|
+
"2024-01-01T10:00+09:00",
|
|
131
|
+
"2024-01-01T10:00-05:00",
|
|
132
|
+
"2024-01-01T10:00:00Z",
|
|
133
|
+
"2024-01-01T10:00:00+09:00",
|
|
134
|
+
"2024-01-01T10:00:00-05:00",
|
|
135
|
+
"2024-01-01T10:00:00+0900",
|
|
136
|
+
"2024-01-01T10:00:00.123456789Z",
|
|
137
|
+
"2024-01-01t10:00z",
|
|
138
|
+
"2024-01-01 10:00:00Z",
|
|
139
|
+
];
|
|
140
|
+
for (const literal of literals) {
|
|
141
|
+
strictEqual(normalizeDateTimeLiteral(literal), literal);
|
|
142
|
+
strictEqual(typeof Temporal.Instant.from(literal), "object");
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("normalizeDateTimeLiteral() treats literals without an offset as UTC", () => {
|
|
147
|
+
const literals = [
|
|
148
|
+
"2024-01-01T10:00",
|
|
149
|
+
"2024-01-01T10:00:00",
|
|
150
|
+
"2024-01-01T10:00:00.123",
|
|
151
|
+
"2025-01-01 12:34:56",
|
|
152
|
+
];
|
|
153
|
+
for (const literal of literals) {
|
|
154
|
+
strictEqual(normalizeDateTimeLiteral(literal), `${literal}Z`);
|
|
155
|
+
strictEqual(
|
|
156
|
+
typeof Temporal.Instant.from(normalizeDateTimeLiteral(literal)),
|
|
157
|
+
"object",
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("normalizeDateTimeLiteral() keeps literals without a time part", () => {
|
|
163
|
+
strictEqual(normalizeDateTimeLiteral("2024-01-01"), "2024-01-01");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("normalizeDateTimeLiteral() inserts omitted seconds before a fraction", () => {
|
|
167
|
+
const literals = [
|
|
168
|
+
["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
|
|
169
|
+
["2024-01-01T10:00.5+09:00", "2024-01-01T10:00:00.5+09:00"],
|
|
170
|
+
["2024-01-01T10:00.5-05:00", "2024-01-01T10:00:00.5-05:00"],
|
|
171
|
+
["2024-01-01T10:00.5", "2024-01-01T10:00:00.5Z"],
|
|
172
|
+
["2024-01-01T10:00.123456789Z", "2024-01-01T10:00:00.123456789Z"],
|
|
173
|
+
] as const;
|
|
174
|
+
for (const [literal, normalized] of literals) {
|
|
175
|
+
strictEqual(normalizeDateTimeLiteral(literal), normalized);
|
|
176
|
+
strictEqual(typeof Temporal.Instant.from(normalized), "object");
|
|
177
|
+
}
|
|
178
|
+
strictEqual(
|
|
179
|
+
normalizeDateTimeLiteral("2024-01-01T10:00:00.5Z"),
|
|
180
|
+
"2024-01-01T10:00:00.5Z",
|
|
181
|
+
);
|
|
182
|
+
});
|
package/src/temporal.ts
CHANGED
|
@@ -72,3 +72,21 @@ export function isTemporalDuration(value: unknown): value is Temporal.Duration {
|
|
|
72
72
|
value.toString !== Object.prototype.toString
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Normalizes an `xsd:dateTime` literal into a form that
|
|
78
|
+
* `Temporal.Instant.from()` accepts. A literal without a UTC offset is
|
|
79
|
+
* treated as UTC, and seconds omitted before a fraction, which Activity Streams
|
|
80
|
+
* 2.0 allows, are filled in.
|
|
81
|
+
*
|
|
82
|
+
* @param value The date-time literal to normalize.
|
|
83
|
+
* @returns The normalized literal.
|
|
84
|
+
*/
|
|
85
|
+
export function normalizeDateTimeLiteral(value: string): string {
|
|
86
|
+
const timeStart = value.search(/[Tt ]/) + 1;
|
|
87
|
+
if (timeStart < 1) return value;
|
|
88
|
+
const date = value.substring(0, timeStart);
|
|
89
|
+
const time = value.substring(timeStart)
|
|
90
|
+
.replace(/^(\d{2}:\d{2})(?=\.)/, "$1:00");
|
|
91
|
+
return date + (/[Zz+-]/.test(time) ? time : time + "Z");
|
|
92
|
+
}
|