@rr0/cms 0.3.69 → 0.3.71

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);
@@ -30,7 +30,9 @@ export class TimeTextBuilder {
30
30
  printOptions.weekday = options.weekday;
31
31
  }
32
32
  const hour = time.getHour();
33
- if (hour) {
33
+ // Hour 0 counts only with minutes (00:38): a bare 0 is also what a date without time (from a Date) carries
34
+ const hasHour = Boolean(hour) || (hour === 0 && Boolean(time.getMinutes()));
35
+ if (hasHour) {
34
36
  date.setHours(hour);
35
37
  printOptions.hour = options.hour;
36
38
  }
@@ -54,7 +56,7 @@ export class TimeTextBuilder {
54
56
  printOptions.day = this.options.day;
55
57
  printOptions.weekday = this.options.weekday;
56
58
  }
57
- if (hour) {
59
+ if (hasHour) {
58
60
  printOptions.hour = this.options.hour;
59
61
  }
60
62
  if (minutes) {
@@ -43,6 +43,15 @@ describe("timeTextBuilder", () => {
43
43
  expect(timeTextBuilder.build(context)).toBe("Tuesday, September 23, 2003");
44
44
  }
45
45
  });
46
+ test("prints midnight hour (0) instead of dropping it", () => {
47
+ const context = new RR0ContextImpl("fr", new TimeContext(), config);
48
+ context.time.setYear(1991);
49
+ context.time.setMonth(9);
50
+ context.time.setDayOfMonth(18);
51
+ context.time.setHour(0);
52
+ context.time.setMinutes(38);
53
+ expect(timeTextBuilder.build(context)).toBe("mercredi 18 septembre 1991 à 00:38");
54
+ });
46
55
  test("prints hour", () => {
47
56
  {
48
57
  const context = new RR0ContextImpl("fr", new TimeContext(), config);
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.71",
6
6
  "description": "RR0 Content Management System (CMS)",
7
7
  "exports": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",