asab_webui_components 25.2.6 → 25.2.7-alpha.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.
|
@@ -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,58 @@ 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
|
+
// Return 'Invalid Date' if the input is null or undefined
|
|
42
|
+
if (value == null) {
|
|
43
|
+
return 'Invalid Date';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Handle BigInt values explicitly
|
|
47
|
+
if (typeof value === 'bigint') {
|
|
48
|
+
// SP-Lang datetime format is represented as BigInt
|
|
49
|
+
return (0, _splDatetimeToIso.splDatetimeToIso)(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Handle string values
|
|
53
|
+
if (typeof value === 'string') {
|
|
54
|
+
var parsed = new Date(value); // Try to parse the string into a Date object
|
|
55
|
+
// If the parsed date is invalid, return 'Invalid Date'; otherwise, return the date
|
|
56
|
+
return isNaN(parsed.getTime()) ? 'Invalid Date' : parsed;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle number values
|
|
60
|
+
if (typeof value === 'number') {
|
|
61
|
+
// Reject infinite, NaN, or negative numbers
|
|
62
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
63
|
+
return 'Invalid Date';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Consider numbers ≥ 1e17 as SP-Lang datetime format
|
|
67
|
+
if (value >= 1e17) {
|
|
68
|
+
// Convert number to BigInt and parse as SP-Lang datetime
|
|
69
|
+
return (0, _splDatetimeToIso.splDatetimeToIso)(BigInt(value));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Handle Unix timestamp in seconds (less than 1e10)
|
|
73
|
+
if (value < 1e10) {
|
|
74
|
+
return new Date(value * 1000); // Convert seconds to milliseconds
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Handle timestamps in milliseconds (less than 1e13)
|
|
78
|
+
if (value < 1e13) {
|
|
79
|
+
return new Date(value); // Already in milliseconds
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Handle timestamps in microseconds (less than 1e16)
|
|
83
|
+
if (value < 1e16) {
|
|
84
|
+
return new Date(value / 1000); // Convert microseconds to milliseconds
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Numbers that don't fall into any known range are considered invalid
|
|
88
|
+
return 'Invalid Date';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// All other types are unsupported and result in 'Invalid Date'
|
|
92
|
+
return 'Invalid Date';
|
|
37
93
|
}
|
|
@@ -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,58 @@ export function DateTime(props) {
|
|
|
39
43
|
</span>
|
|
40
44
|
);
|
|
41
45
|
}
|
|
46
|
+
|
|
47
|
+
function validateDateTime(value) {
|
|
48
|
+
// Return 'Invalid Date' if the input is null or undefined
|
|
49
|
+
if (value == null) {
|
|
50
|
+
return 'Invalid Date';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Handle BigInt values explicitly
|
|
54
|
+
if (typeof value === 'bigint') {
|
|
55
|
+
// SP-Lang datetime format is represented as BigInt
|
|
56
|
+
return splDatetimeToIso(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle string values
|
|
60
|
+
if (typeof value === 'string') {
|
|
61
|
+
const parsed = new Date(value); // Try to parse the string into a Date object
|
|
62
|
+
// If the parsed date is invalid, return 'Invalid Date'; otherwise, return the date
|
|
63
|
+
return isNaN(parsed.getTime()) ? 'Invalid Date' : parsed;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Handle number values
|
|
67
|
+
if (typeof value === 'number') {
|
|
68
|
+
// Reject infinite, NaN, or negative numbers
|
|
69
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
70
|
+
return 'Invalid Date';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Consider numbers ≥ 1e17 as SP-Lang datetime format
|
|
74
|
+
if (value >= 1e17) {
|
|
75
|
+
// Convert number to BigInt and parse as SP-Lang datetime
|
|
76
|
+
return splDatetimeToIso(BigInt(value));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Handle Unix timestamp in seconds (less than 1e10)
|
|
80
|
+
if (value < 1e10) {
|
|
81
|
+
return new Date(value * 1000); // Convert seconds to milliseconds
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Handle timestamps in milliseconds (less than 1e13)
|
|
85
|
+
if (value < 1e13) {
|
|
86
|
+
return new Date(value); // Already in milliseconds
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Handle timestamps in microseconds (less than 1e16)
|
|
90
|
+
if (value < 1e16) {
|
|
91
|
+
return new Date(value / 1000); // Convert microseconds to milliseconds
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Numbers that don't fall into any known range are considered invalid
|
|
95
|
+
return 'Invalid Date';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// All other types are unsupported and result in 'Invalid Date'
|
|
99
|
+
return 'Invalid Date';
|
|
100
|
+
}
|
|
@@ -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
|
+
}
|