@rr0/cms 0.3.69 → 0.3.70

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.
@@ -112,6 +112,11 @@ export class TimeContext {
112
112
  }
113
113
  catch (e) {
114
114
  try {
115
+ // Only a duration starts with P ("P10M", "~P1H"): otherwise EdtfDuration also accepts a date whose
116
+ // time zone contains a P ("21:45PST", "00:38:42PDT") as an empty duration.
117
+ if (!/^\s*~?P/.test(timeStr)) {
118
+ throw new Error("Not a duration");
119
+ }
115
120
  this.duration = EdtfDuration.fromString(timeStr);
116
121
  this.interval = undefined;
117
122
  this.date = undefined;
@@ -59,6 +59,20 @@ describe("TimeContext", () => {
59
59
  expect(timeContext.getHour()).toBe(12);
60
60
  expect(timeContext.getMinutes()).toBe(55);
61
61
  });
62
+ test("updateFromStr with a time zone containing a P is a date, not a duration", () => {
63
+ for (const str of ["1957-02-27 21:45PST", "1991-09-18 00:38:42PDT", "1957-02-27 21:45 (PST)"]) {
64
+ const context = new TimeContext();
65
+ expect(context.updateFromStr(str)).toBe(true);
66
+ expect(context.duration).toBeUndefined();
67
+ expect(context.getYear()).toBeDefined();
68
+ expect(context.getHour()).toBeDefined();
69
+ }
70
+ });
71
+ test("updateFromStr duration", () => {
72
+ const context = new TimeContext();
73
+ expect(context.updateFromStr("~P1H")).toBe(true);
74
+ expect(context.duration).toBeDefined();
75
+ });
62
76
  test("fromDate", () => {
63
77
  const month = 12;
64
78
  const date = new Date(2001, month - 1, 13);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@rr0/cms",
3
3
  "type": "module",
4
4
  "author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
5
- "version": "0.3.69",
5
+ "version": "0.3.70",
6
6
  "description": "RR0 Content Management System (CMS)",
7
7
  "exports": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",