@sbb-esta/lyne-elements-experimental 1.10.0 → 1.11.1

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/core/datetime.js CHANGED
@@ -1,156 +1,167 @@
1
- import { i18nDurationDay as p, i18nDurationHour as g, i18nDurationMinute as N } from "@sbb-esta/lyne-elements/core/i18n.js";
2
- import { t as m, c as M, a as d, b as h } from "../constants-DSR8hPvP.js";
3
- import { d as I, i as $ } from "../isValid-DSjxf8eh.js";
4
- import { b as y, c as U, g as C, a as Y, d as F } from "../differenceInMinutes-BhHyuJc4.js";
5
- function x(t, e) {
6
- const n = m(t);
7
- return isNaN(e) ? M(t, NaN) : (e && n.setDate(n.getDate() + e), n);
8
- }
9
- function H(t, e) {
10
- return y(t, e * d);
11
- }
12
- function S(t, e) {
13
- const n = m(t), s = m(e), r = T(n, s), i = Math.abs(I(n, s));
14
- n.setDate(n.getDate() - r * i);
15
- const a = +(T(n, s) === -r), u = r * (i - a);
16
- return u === 0 ? 0 : u;
17
- }
18
- function T(t, e) {
1
+ import { i18nDurationDay as h, i18nDurationHour as T, i18nDurationMinute as p } from "@sbb-esta/lyne-elements/core/i18n.js";
2
+ import { t as d, c as N, a as m, b as w } from "../toDate-DQg4ZFnf.js";
3
+ import { n as I, d as y, i as U } from "../isValid-mroh13Xp.js";
4
+ import { g as C, a as Y, d as F } from "../differenceInMinutes-BI2zjbtS.js";
5
+ function x(t, e, n) {
6
+ const r = d(t, n == null ? void 0 : n.in);
7
+ return isNaN(e) ? N(t, NaN) : (e && r.setDate(r.getDate() + e), r);
8
+ }
9
+ function z(t, e, n) {
10
+ return N(t, +d(t) + e);
11
+ }
12
+ function H(t, e, n) {
13
+ return z(t, e * m);
14
+ }
15
+ function S(t, e, n) {
16
+ const [r, i] = I(
17
+ n == null ? void 0 : n.in,
18
+ t,
19
+ e
20
+ ), s = M(r, i), u = Math.abs(
21
+ y(r, i)
22
+ );
23
+ r.setDate(r.getDate() - s * u);
24
+ const a = +(M(r, i) === -s), c = s * (u - a);
25
+ return c === 0 ? 0 : c;
26
+ }
27
+ function M(t, e) {
19
28
  const n = t.getFullYear() - e.getFullYear() || t.getMonth() - e.getMonth() || t.getDate() - e.getDate() || t.getHours() - e.getHours() || t.getMinutes() - e.getMinutes() || t.getSeconds() - e.getSeconds() || t.getMilliseconds() - e.getMilliseconds();
20
29
  return n < 0 ? -1 : n > 0 ? 1 : n;
21
30
  }
22
- function z(t, e, n) {
23
- const s = U(t, e) / d;
31
+ function Z(t, e, n) {
32
+ const [r, i] = I(
33
+ n == null ? void 0 : n.in,
34
+ t,
35
+ e
36
+ ), s = (+r - +i) / m;
24
37
  return C(n == null ? void 0 : n.roundingMethod)(s);
25
38
  }
26
- function Z(t, e) {
27
- return x(t, -e);
39
+ function v(t, e, n) {
40
+ return x(t, -e, n);
28
41
  }
29
- function b(t, e) {
30
- const s = W(t);
31
- let r;
32
- if (s.date) {
33
- const o = _(s.date, 2);
34
- r = j(o.restDateString, o.year);
42
+ function O(t, e) {
43
+ const n = () => N(e == null ? void 0 : e.in, NaN), i = k(t);
44
+ let s;
45
+ if (i.date) {
46
+ const o = W(i.date, 2);
47
+ s = j(o.restDateString, o.year);
35
48
  }
36
- if (!r || isNaN(r.getTime()))
37
- return /* @__PURE__ */ new Date(NaN);
38
- const i = r.getTime();
39
- let a = 0, u;
40
- if (s.time && (a = A(s.time), isNaN(a)))
41
- return /* @__PURE__ */ new Date(NaN);
42
- if (s.timezone) {
43
- if (u = E(s.timezone), isNaN(u))
44
- return /* @__PURE__ */ new Date(NaN);
49
+ if (!s || isNaN(+s)) return n();
50
+ const u = +s;
51
+ let a = 0, c;
52
+ if (i.time && (a = A(i.time), isNaN(a)))
53
+ return n();
54
+ if (i.timezone) {
55
+ if (c = E(i.timezone), isNaN(c)) return n();
45
56
  } else {
46
- const o = new Date(i + a), c = /* @__PURE__ */ new Date(0);
47
- return c.setFullYear(
57
+ const o = new Date(u + a), D = d(0, e == null ? void 0 : e.in);
58
+ return D.setFullYear(
48
59
  o.getUTCFullYear(),
49
60
  o.getUTCMonth(),
50
61
  o.getUTCDate()
51
- ), c.setHours(
62
+ ), D.setHours(
52
63
  o.getUTCHours(),
53
64
  o.getUTCMinutes(),
54
65
  o.getUTCSeconds(),
55
66
  o.getUTCMilliseconds()
56
- ), c;
67
+ ), D;
57
68
  }
58
- return new Date(i + a + u);
69
+ return d(u + a + c, e == null ? void 0 : e.in);
59
70
  }
60
- const f = {
71
+ const l = {
61
72
  dateTimeDelimiter: /[T ]/,
62
73
  timeZoneDelimiter: /[Z ]/i,
63
74
  timezone: /([Z+-].*)$/
64
- }, O = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/, v = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/, k = /^([+-])(\d{2})(?::?(\d{2}))?$/;
65
- function W(t) {
66
- const e = {}, n = t.split(f.dateTimeDelimiter);
67
- let s;
75
+ }, _ = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/, b = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/, R = /^([+-])(\d{2})(?::?(\d{2}))?$/;
76
+ function k(t) {
77
+ const e = {}, n = t.split(l.dateTimeDelimiter);
78
+ let r;
68
79
  if (n.length > 2)
69
80
  return e;
70
- if (/:/.test(n[0]) ? s = n[0] : (e.date = n[0], s = n[1], f.timeZoneDelimiter.test(e.date) && (e.date = t.split(f.timeZoneDelimiter)[0], s = t.substr(
81
+ if (/:/.test(n[0]) ? r = n[0] : (e.date = n[0], r = n[1], l.timeZoneDelimiter.test(e.date) && (e.date = t.split(l.timeZoneDelimiter)[0], r = t.substr(
71
82
  e.date.length,
72
83
  t.length
73
- ))), s) {
74
- const r = f.timezone.exec(s);
75
- r ? (e.time = s.replace(r[1], ""), e.timezone = r[1]) : e.time = s;
84
+ ))), r) {
85
+ const i = l.timezone.exec(r);
86
+ i ? (e.time = r.replace(i[1], ""), e.timezone = i[1]) : e.time = r;
76
87
  }
77
88
  return e;
78
89
  }
79
- function _(t, e) {
90
+ function W(t, e) {
80
91
  const n = new RegExp(
81
92
  "^(?:(\\d{4}|[+-]\\d{" + (4 + e) + "})|(\\d{2}|[+-]\\d{" + (2 + e) + "})$)"
82
- ), s = t.match(n);
83
- if (!s) return { year: NaN, restDateString: "" };
84
- const r = s[1] ? parseInt(s[1]) : null, i = s[2] ? parseInt(s[2]) : null;
93
+ ), r = t.match(n);
94
+ if (!r) return { year: NaN, restDateString: "" };
95
+ const i = r[1] ? parseInt(r[1]) : null, s = r[2] ? parseInt(r[2]) : null;
85
96
  return {
86
- year: i === null ? r : i * 100,
87
- restDateString: t.slice((s[1] || s[2]).length)
97
+ year: s === null ? i : s * 100,
98
+ restDateString: t.slice((r[1] || r[2]).length)
88
99
  };
89
100
  }
90
101
  function j(t, e) {
91
102
  if (e === null) return /* @__PURE__ */ new Date(NaN);
92
- const n = t.match(O);
103
+ const n = t.match(_);
93
104
  if (!n) return /* @__PURE__ */ new Date(NaN);
94
- const s = !!n[4], r = l(n[1]), i = l(n[2]) - 1, a = l(n[3]), u = l(n[4]), o = l(n[5]) - 1;
95
- if (s)
96
- return B(e, u, o) ? J(e, u, o) : /* @__PURE__ */ new Date(NaN);
105
+ const r = !!n[4], i = f(n[1]), s = f(n[2]) - 1, u = f(n[3]), a = f(n[4]), c = f(n[5]) - 1;
106
+ if (r)
107
+ return G(e, a, c) ? J(e, a, c) : /* @__PURE__ */ new Date(NaN);
97
108
  {
98
- const c = /* @__PURE__ */ new Date(0);
99
- return !V(e, i, a) || !q(e, r) ? /* @__PURE__ */ new Date(NaN) : (c.setUTCFullYear(e, i, Math.max(r, a)), c);
109
+ const o = /* @__PURE__ */ new Date(0);
110
+ return !q(e, s, u) || !B(e, i) ? /* @__PURE__ */ new Date(NaN) : (o.setUTCFullYear(e, s, Math.max(i, u)), o);
100
111
  }
101
112
  }
102
- function l(t) {
113
+ function f(t) {
103
114
  return t ? parseInt(t) : 1;
104
115
  }
105
116
  function A(t) {
106
- const e = t.match(v);
117
+ const e = t.match(b);
107
118
  if (!e) return NaN;
108
- const n = D(e[1]), s = D(e[2]), r = D(e[3]);
109
- return G(n, s, r) ? n * d + s * h + r * 1e3 : NaN;
119
+ const n = g(e[1]), r = g(e[2]), i = g(e[3]);
120
+ return K(n, r, i) ? n * m + r * w + i * 1e3 : NaN;
110
121
  }
111
- function D(t) {
122
+ function g(t) {
112
123
  return t && parseFloat(t.replace(",", ".")) || 0;
113
124
  }
114
125
  function E(t) {
115
126
  if (t === "Z") return 0;
116
- const e = t.match(k);
127
+ const e = t.match(R);
117
128
  if (!e) return 0;
118
- const n = e[1] === "+" ? -1 : 1, s = parseInt(e[2]), r = e[3] && parseInt(e[3]) || 0;
119
- return K(s, r) ? n * (s * d + r * h) : NaN;
129
+ const n = e[1] === "+" ? -1 : 1, r = parseInt(e[2]), i = e[3] && parseInt(e[3]) || 0;
130
+ return P(r, i) ? n * (r * m + i * w) : NaN;
120
131
  }
121
132
  function J(t, e, n) {
122
- const s = /* @__PURE__ */ new Date(0);
123
- s.setUTCFullYear(t, 0, 4);
124
- const r = s.getUTCDay() || 7, i = (e - 1) * 7 + n + 1 - r;
125
- return s.setUTCDate(s.getUTCDate() + i), s;
133
+ const r = /* @__PURE__ */ new Date(0);
134
+ r.setUTCFullYear(t, 0, 4);
135
+ const i = r.getUTCDay() || 7, s = (e - 1) * 7 + n + 1 - i;
136
+ return r.setUTCDate(r.getUTCDate() + s), r;
126
137
  }
127
- const R = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
128
- function w(t) {
138
+ const V = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
139
+ function $(t) {
129
140
  return t % 400 === 0 || t % 4 === 0 && t % 100 !== 0;
130
141
  }
131
- function V(t, e, n) {
132
- return e >= 0 && e <= 11 && n >= 1 && n <= (R[e] || (w(t) ? 29 : 28));
142
+ function q(t, e, n) {
143
+ return e >= 0 && e <= 11 && n >= 1 && n <= (V[e] || ($(t) ? 29 : 28));
133
144
  }
134
- function q(t, e) {
135
- return e >= 1 && e <= (w(t) ? 366 : 365);
145
+ function B(t, e) {
146
+ return e >= 1 && e <= ($(t) ? 366 : 365);
136
147
  }
137
- function B(t, e, n) {
148
+ function G(t, e, n) {
138
149
  return e >= 1 && e <= 53 && n >= 0 && n <= 6;
139
150
  }
140
- function G(t, e, n) {
151
+ function K(t, e, n) {
141
152
  return t === 24 ? e === 0 && n === 0 : n >= 0 && n < 60 && e >= 0 && e < 60 && t >= 0 && t < 25;
142
153
  }
143
- function K(t, e) {
154
+ function P(t, e) {
144
155
  return e >= 0 && e <= 59;
145
156
  }
146
- function P(t, e) {
157
+ function Q(t, e, n) {
147
158
  return H(t, -e);
148
159
  }
149
- function te(t) {
160
+ function ne(t) {
150
161
  if (!t)
151
162
  return;
152
- const e = b(t);
153
- if ($(e)) {
163
+ const e = O(t);
164
+ if (U(e)) {
154
165
  if (t.includes("Z"))
155
166
  return new Date(t.replace("Z", ""));
156
167
  if (t.includes("T")) {
@@ -161,26 +172,26 @@ function te(t) {
161
172
  return new Date(t);
162
173
  }
163
174
  }
164
- const ne = (t, e) => {
165
- const n = [], s = [];
166
- let i = Y(0, t);
167
- const a = S(i, 0);
168
- a > 0 && (n.push(`${a} d`), e && s.push(
169
- `${a} ${a > 1 ? p.multiple.long[e] : p.single.long[e]}`
170
- ), i = Z(i, a));
171
- const u = z(i, 0);
172
- u > 0 && (n.push(`${u} h`), e && s.push(
173
- `${u} ${u > 1 ? g.multiple.long[e] : g.single.long[e]}`
174
- ), i = P(i, u));
175
- const o = F(i, 0);
176
- return o > 0 && (n.push(`${o} min`), e && s.push(
177
- `${o} ${o > 1 ? N.multiple.long[e] : N.single.long[e]}`
175
+ const re = (t, e) => {
176
+ const n = [], r = [];
177
+ let s = Y(0, t);
178
+ const u = S(s, 0);
179
+ u > 0 && (n.push(`${u} d`), e && r.push(
180
+ `${u} ${u > 1 ? h.multiple.long[e] : h.single.long[e]}`
181
+ ), s = v(s, u));
182
+ const a = Z(s, 0);
183
+ a > 0 && (n.push(`${a} h`), e && r.push(
184
+ `${a} ${a > 1 ? T.multiple.long[e] : T.single.long[e]}`
185
+ ), s = Q(s, a));
186
+ const c = F(s, 0);
187
+ return c > 0 && (n.push(`${c} min`), e && r.push(
188
+ `${c} ${c > 1 ? p.multiple.long[e] : p.single.long[e]}`
178
189
  )), {
179
190
  short: n.join(" "),
180
- long: s.join(" ")
191
+ long: r.join(" ")
181
192
  };
182
193
  };
183
194
  export {
184
- ne as durationToTime,
185
- te as removeTimezoneFromISOTimeString
195
+ re as durationToTime,
196
+ ne as removeTimezoneFromISOTimeString
186
197
  };