@yuneta/gobj-ui 7.31.7 → 7.31.8
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/README.md +13 -5
- package/dist/gobj-ui.cjs.js +205 -51
- package/dist/gobj-ui.es.js +205 -51
- package/package.json +1 -1
- package/src/c_yui_json_graph.js +247 -76
- package/src/fmt_date_time.test.js +55 -0
- package/src/json_graph_lit_edge.wiring.test.js +90 -4
- package/src/yui_date_text.js +27 -2
package/src/yui_date_text.js
CHANGED
|
@@ -69,6 +69,30 @@ const DATE_TIME_OPTIONS = {
|
|
|
69
69
|
hourCycle: "h23"
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
/* The formatters of fmt_date_time(), by locale and time zone. A
|
|
73
|
+
* filter over a time column formats every row on every keystroke,
|
|
74
|
+
* and building an Intl.DateTimeFormat costs some 20 times what one
|
|
75
|
+
* format() costs. A formatter keeps the time zone it was built in,
|
|
76
|
+
* so the key carries the zone's offsets in January and in July: a
|
|
77
|
+
* zone that changes under the page (TZ in node, the system's in a
|
|
78
|
+
* browser) gets a new one. Plain Dates, not Intl: nothing of Intl
|
|
79
|
+
* is built at module top level (see safe_locale). */
|
|
80
|
+
const __date_time_formatters__ = new Map();
|
|
81
|
+
const JANUARY = new Date(Date.UTC(2026, 0, 1));
|
|
82
|
+
const JULY = new Date(Date.UTC(2026, 6, 1));
|
|
83
|
+
|
|
84
|
+
function date_time_formatter(locale)
|
|
85
|
+
{
|
|
86
|
+
let loc = safe_locale(locale);
|
|
87
|
+
let key = `${loc}|${JANUARY.getTimezoneOffset()}|${JULY.getTimezoneOffset()}`;
|
|
88
|
+
let f = __date_time_formatters__.get(key);
|
|
89
|
+
if(!f) {
|
|
90
|
+
f = date_time_format(loc, DATE_TIME_OPTIONS);
|
|
91
|
+
__date_time_formatters__.set(key, f);
|
|
92
|
+
}
|
|
93
|
+
return f;
|
|
94
|
+
}
|
|
95
|
+
|
|
72
96
|
/***************************************************************
|
|
73
97
|
* A moment as a VIEW shows it as text: the day, the month and the
|
|
74
98
|
* year, then the clock of 24 hours with its seconds, in the APP's
|
|
@@ -79,7 +103,8 @@ const DATE_TIME_OPTIONS = {
|
|
|
79
103
|
* fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
|
|
80
104
|
*
|
|
81
105
|
* "" for anything that is not a valid Date. A locale Intl refuses
|
|
82
|
-
* writes in the environment's (date_time_format).
|
|
106
|
+
* writes in the environment's (date_time_format). The formatter is
|
|
107
|
+
* built once per locale and time zone (date_time_formatter).
|
|
83
108
|
*
|
|
84
109
|
* The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
|
|
85
110
|
* the reading C_YUI_JSON writes beside a time field all come from
|
|
@@ -90,7 +115,7 @@ function fmt_date_time(date, locale)
|
|
|
90
115
|
if(!(date instanceof Date) || isNaN(date.getTime())) {
|
|
91
116
|
return "";
|
|
92
117
|
}
|
|
93
|
-
return
|
|
118
|
+
return date_time_formatter(locale).format(date);
|
|
94
119
|
}
|
|
95
120
|
|
|
96
121
|
|