asab_webui_components 25.2.6-alpha.1 → 25.2.6-alpha.2
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.
|
@@ -9,6 +9,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _timeToString = _interopRequireDefault(require("./timeToString.js"));
|
|
10
10
|
var _useDateFNSLocale = _interopRequireDefault(require("./useDateFNSLocale.js"));
|
|
11
11
|
var _InvalidDate = require("./InvalidDate.js");
|
|
12
|
+
var _splDatetimeToIso = require("./splDatetimeToIso");
|
|
12
13
|
// Component that displays the absolute time and shows the relative time on hover
|
|
13
14
|
function DateTime(props) {
|
|
14
15
|
if (props.value == undefined) {
|
|
@@ -19,10 +20,11 @@ function DateTime(props) {
|
|
|
19
20
|
|
|
20
21
|
// Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
|
|
21
22
|
var locale = (0, _useDateFNSLocale["default"])();
|
|
22
|
-
|
|
23
|
+
var datetime = validateDateTime(props.value);
|
|
24
|
+
if (datetime.toString() === 'Invalid Date') {
|
|
23
25
|
return /*#__PURE__*/_react["default"].createElement(_InvalidDate.InvalidDate, null);
|
|
24
26
|
}
|
|
25
|
-
var date = (0, _timeToString["default"])(
|
|
27
|
+
var date = (0, _timeToString["default"])(datetime, props.dateTimeFormat, locale);
|
|
26
28
|
|
|
27
29
|
// Check for invalid date from timeToString method
|
|
28
30
|
if (date === 'Invalid Date') {
|
|
@@ -34,4 +36,25 @@ function DateTime(props) {
|
|
|
34
36
|
}, /*#__PURE__*/_react["default"].createElement("i", {
|
|
35
37
|
className: "bi bi-clock pe-1"
|
|
36
38
|
}), date.date);
|
|
39
|
+
}
|
|
40
|
+
function validateDateTime(value) {
|
|
41
|
+
if (value == null) return 'Invalid Date';
|
|
42
|
+
|
|
43
|
+
// Reject non-numeric values
|
|
44
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return new Date(value);
|
|
45
|
+
|
|
46
|
+
// Reject negative numbers (timestamps are always positive)
|
|
47
|
+
if (value < 0) return 'Invalid Date';
|
|
48
|
+
|
|
49
|
+
// SP-Lang datetime (BigInt or number >= 10^17)
|
|
50
|
+
if (typeof value === 'bigint' || value >= Math.pow(10n, 17n)) {
|
|
51
|
+
return (0, _splDatetimeToIso.splDatetimeToIso)(BigInt(value));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Defining the time format by range
|
|
55
|
+
if (value < 1e10) return new Date(value * 1000); // Seconds → milliseconds
|
|
56
|
+
if (value < 1e13) return new Date(value); // Milliseconds
|
|
57
|
+
if (value < 1e16) return new Date(value / 1000); // Microseconds
|
|
58
|
+
|
|
59
|
+
return 'Invalid Date';
|
|
37
60
|
}
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import timeToString from './timeToString.js';
|
|
4
4
|
import useDateFNSLocale from './useDateFNSLocale.js';
|
|
5
5
|
import { InvalidDate } from './InvalidDate.jsx';
|
|
6
|
+
import { splDatetimeToIso } from './splDatetimeToIso';
|
|
6
7
|
|
|
7
8
|
// Component that displays the absolute time and shows the relative time on hover
|
|
8
9
|
export function DateTime(props) {
|
|
@@ -14,13 +15,16 @@ export function DateTime(props) {
|
|
|
14
15
|
|
|
15
16
|
// Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
|
|
16
17
|
const locale = useDateFNSLocale();
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
const datetime = validateDateTime(props.value);
|
|
20
|
+
|
|
21
|
+
if (datetime.toString() === 'Invalid Date') {
|
|
18
22
|
return (
|
|
19
23
|
<InvalidDate />
|
|
20
24
|
);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
const date = timeToString(
|
|
27
|
+
const date = timeToString(datetime, props.dateTimeFormat, locale);
|
|
24
28
|
|
|
25
29
|
// Check for invalid date from timeToString method
|
|
26
30
|
if (date === 'Invalid Date') {
|
|
@@ -39,3 +43,25 @@ export function DateTime(props) {
|
|
|
39
43
|
</span>
|
|
40
44
|
);
|
|
41
45
|
}
|
|
46
|
+
|
|
47
|
+
function validateDateTime(value) {
|
|
48
|
+
if (value == null) return 'Invalid Date';
|
|
49
|
+
|
|
50
|
+
// Reject non-numeric values
|
|
51
|
+
if ((typeof value !== 'number') || !Number.isFinite(value)) return new Date(value);
|
|
52
|
+
|
|
53
|
+
// Reject negative numbers (timestamps are always positive)
|
|
54
|
+
if (value < 0) return 'Invalid Date';
|
|
55
|
+
|
|
56
|
+
// SP-Lang datetime (BigInt or number >= 10^17)
|
|
57
|
+
if (typeof value === 'bigint' || value >= 10n ** 17n) {
|
|
58
|
+
return splDatetimeToIso(BigInt(value));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Defining the time format by range
|
|
62
|
+
if (value < 1e10) return new Date(value * 1000); // Seconds → milliseconds
|
|
63
|
+
if (value < 1e13) return new Date(value); // Milliseconds
|
|
64
|
+
if (value < 1e16) return new Date(value / 1000); // Microseconds
|
|
65
|
+
|
|
66
|
+
return 'Invalid Date';
|
|
67
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.splDatetimeToIso = splDatetimeToIso;
|
|
7
|
+
function splDatetimeToIso(datetime) {
|
|
8
|
+
// Check if datetime is a number or BigInt
|
|
9
|
+
if (typeof datetime !== 'bigint' && typeof datetime !== 'number') {
|
|
10
|
+
return 'Invalid Date';
|
|
11
|
+
}
|
|
12
|
+
var BigIntDatetime = BigInt(datetime); // Convert to BigInt for correct bitwise operations
|
|
13
|
+
|
|
14
|
+
// Year extraction (bits 46-60)
|
|
15
|
+
var year = Number(BigIntDatetime >> BigInt(46) & BigInt(4095)); // 14 bits
|
|
16
|
+
if (year >= 8192) {
|
|
17
|
+
year -= 8192; // Adjust for sign bit if necessary
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Month extraction (bits 42-46)
|
|
21
|
+
var month = Number(BigIntDatetime >> BigInt(42) & BigInt(15)); // 4 bits
|
|
22
|
+
|
|
23
|
+
// Day extraction (bits 37-42)
|
|
24
|
+
var day = Number(BigIntDatetime >> BigInt(37) & BigInt(31)); // 5 bits
|
|
25
|
+
|
|
26
|
+
// Hour extraction (bits 32-37)
|
|
27
|
+
var hour = Number(BigIntDatetime >> BigInt(32) & BigInt(31)); // 5 bits
|
|
28
|
+
|
|
29
|
+
// Minute extraction (bits 26-32)
|
|
30
|
+
var minute = Number(BigIntDatetime >> BigInt(26) & BigInt(63)); // 6 bits
|
|
31
|
+
|
|
32
|
+
// Second extraction (bits 20-26)
|
|
33
|
+
var second = Number(BigIntDatetime >> BigInt(20) & BigInt(63)); // 6 bits
|
|
34
|
+
|
|
35
|
+
// Microsecond extraction (bits 0-20)
|
|
36
|
+
var microsecond = Number(BigIntDatetime & BigInt(2097151)); // 20 bits
|
|
37
|
+
|
|
38
|
+
// Adjust for zero-based month
|
|
39
|
+
month += 1;
|
|
40
|
+
|
|
41
|
+
// Check if the values are correct
|
|
42
|
+
if (year < 0 || month < 1 || month > 12 || day < 1 || day > 31 || hour > 23 || minute > 59 || second > 59) {
|
|
43
|
+
return 'Invalid Date';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Format date string
|
|
47
|
+
return "".concat(year.toString().padStart(4, '0'), "-").concat(month.toString().padStart(2, '0'), "-").concat(day.toString().padStart(2, '0'), "T").concat(hour.toString().padStart(2, '0'), ":").concat(minute.toString().padStart(2, '0'), ":").concat(second.toString().padStart(2, '0'), ".").concat(microsecond.toString().padStart(6, '0'), "Z");
|
|
48
|
+
}
|