@yuneta/gobj-ui 7.26.51 → 7.26.52
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 +88 -2
- package/dist/gobj-ui.cjs.js +1267 -1025
- package/dist/gobj-ui.es.js +1258 -1017
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/c_yui_form.js +48 -5
- package/src/c_yui_json.js +36 -3
- package/src/c_yui_treedb_topic_with_form.js +13 -28
- package/src/c_yui_uplot.js +51 -2
- package/src/fmt_date_time.test.js +138 -0
- package/src/form_table_rows.wiring.test.js +5 -4
- package/src/form_time_value.js +9 -6
- package/src/form_time_value.test.js +1 -1
- package/src/json_view_helpers.js +8 -3
- package/src/time_text.wiring.test.js +489 -0
- package/src/yui_time.js +37 -0
- package/src/yui_uplot_time.js +142 -0
package/index.js
CHANGED
package/package.json
CHANGED
package/src/c_yui_form.js
CHANGED
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
gobj_unsubscribe_event,
|
|
53
53
|
} from "@yuneta/gobj-js";
|
|
54
54
|
|
|
55
|
-
import {t} from "i18next";
|
|
55
|
+
import i18next, {t} from "i18next";
|
|
56
56
|
|
|
57
57
|
import {
|
|
58
58
|
yui_tabulator_name_row_selects,
|
|
@@ -100,6 +100,7 @@ import {
|
|
|
100
100
|
time_value_to_text
|
|
101
101
|
} from "./form_time_value.js";
|
|
102
102
|
import {form_time_cell_editor} from "./form_time_cell_editor.js";
|
|
103
|
+
import {safe_locale} from "./yui_time.js";
|
|
103
104
|
import {parse_json_field, json_editor_value} from "./form_json_field.js";
|
|
104
105
|
import {
|
|
105
106
|
json_editor_menu_items,
|
|
@@ -2605,6 +2606,48 @@ function table_column_titles(template)
|
|
|
2605
2606
|
return titles;
|
|
2606
2607
|
}
|
|
2607
2608
|
|
|
2609
|
+
/* The formatters of the time cells, so a language change finds them. */
|
|
2610
|
+
const TIME_CELL_FORMATTERS = new WeakSet();
|
|
2611
|
+
|
|
2612
|
+
/******************************************************************
|
|
2613
|
+
* The formatter of a time cell: the local clock, 24 hours, in the
|
|
2614
|
+
* APP's language (fmt_date_time of yui_time.js, as the cells of
|
|
2615
|
+
* C_YUI_TREEDB_TOPIC_WITH_FORM): es "14 oct 2026, 15:05:09".
|
|
2616
|
+
******************************************************************/
|
|
2617
|
+
function time_cell_formatter(real_type)
|
|
2618
|
+
{
|
|
2619
|
+
let formatter = function(cell) {
|
|
2620
|
+
return text_node(time_value_to_text(
|
|
2621
|
+
cell.getValue(), real_type, safe_locale(i18next.language)
|
|
2622
|
+
));
|
|
2623
|
+
};
|
|
2624
|
+
TIME_CELL_FORMATTERS.add(formatter);
|
|
2625
|
+
return formatter;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
/******************************************************************
|
|
2629
|
+
* Draw the time cells of a table again, in the current language.
|
|
2630
|
+
* Cell by cell, never a redraw of the rows: a row's formatter
|
|
2631
|
+
* builds its nested tables anew -- empty. A cell being edited is
|
|
2632
|
+
* its editor's; Tabulator formats it again when the editor closes.
|
|
2633
|
+
******************************************************************/
|
|
2634
|
+
function reformat_time_cells(tabulator)
|
|
2635
|
+
{
|
|
2636
|
+
for(let column of tabulator.getColumns()) {
|
|
2637
|
+
let formatter = column.getDefinition().formatter;
|
|
2638
|
+
if(!TIME_CELL_FORMATTERS.has(formatter)) {
|
|
2639
|
+
continue;
|
|
2640
|
+
}
|
|
2641
|
+
for(let cell of column.getCells()) {
|
|
2642
|
+
let $cell = cell.getElement();
|
|
2643
|
+
if($cell.classList.contains("tabulator-editing")) {
|
|
2644
|
+
continue;
|
|
2645
|
+
}
|
|
2646
|
+
$cell.replaceChildren(formatter(cell));
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2608
2651
|
/******************************************************************
|
|
2609
2652
|
* Convert a template's items in tabulator columns
|
|
2610
2653
|
******************************************************************/
|
|
@@ -2808,9 +2851,7 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2808
2851
|
};
|
|
2809
2852
|
/* The clock, not the epoch: up to 7.26.46 the cell showed
|
|
2810
2853
|
* the raw number. */
|
|
2811
|
-
column.formatter =
|
|
2812
|
-
return text_node(time_value_to_text(cell.getValue(), field_desc.real_type));
|
|
2813
|
-
};
|
|
2854
|
+
column.formatter = time_cell_formatter(field_desc.real_type);
|
|
2814
2855
|
break;
|
|
2815
2856
|
|
|
2816
2857
|
case "color":
|
|
@@ -4346,11 +4387,13 @@ function ac_language_changed(gobj, event, kw, src)
|
|
|
4346
4387
|
* form was built in. Through the table's LOCALE, never by
|
|
4347
4388
|
* updateDefinition(): rebuilding a column re-renders every row, and
|
|
4348
4389
|
* a row's formatter builds its nested tables anew -- empty. A table
|
|
4349
|
-
* not built yet is drawn in the current language when it is.
|
|
4390
|
+
* not built yet is drawn in the current language when it is. The
|
|
4391
|
+
* time cells write their month in the language too. */
|
|
4350
4392
|
for(let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) {
|
|
4351
4393
|
let tabulator = $table.tabulator;
|
|
4352
4394
|
if(tabulator && tabulator.initialized && $table.template) {
|
|
4353
4395
|
yui_tabulator_relocalize(tabulator, t, table_column_titles($table.template));
|
|
4396
|
+
reformat_time_cells(tabulator);
|
|
4354
4397
|
}
|
|
4355
4398
|
}
|
|
4356
4399
|
return 0;
|
package/src/c_yui_json.js
CHANGED
|
@@ -68,6 +68,8 @@ import {
|
|
|
68
68
|
gobj_read_pointer_attr,
|
|
69
69
|
gobj_parent,
|
|
70
70
|
gobj_subscribe_event,
|
|
71
|
+
gobj_unsubscribe_event,
|
|
72
|
+
gobj_is_destroying,
|
|
71
73
|
gobj_create_pure_child,
|
|
72
74
|
gobj_start,
|
|
73
75
|
gobj_stop,
|
|
@@ -106,9 +108,11 @@ import {
|
|
|
106
108
|
|
|
107
109
|
import {yui_toolbar, yui_toolbar_icon} from "./yui_toolbar.js";
|
|
108
110
|
import {register_c_yui_json_graph} from "./c_yui_json_graph.js";
|
|
111
|
+
import {yui_shell_of} from "./c_yui_shell.js";
|
|
109
112
|
import {attach_clear} from "./yui_inputs.js";
|
|
110
113
|
|
|
111
|
-
import {t} from "i18next";
|
|
114
|
+
import i18next, {t} from "i18next";
|
|
115
|
+
import {safe_locale} from "./yui_time.js";
|
|
112
116
|
|
|
113
117
|
import "./c_yui_json.css";
|
|
114
118
|
import {text_node} from "./yui_text.js";
|
|
@@ -197,6 +201,7 @@ let PRIVATE_DATA = {
|
|
|
197
201
|
$expand_btn: null, // "expand loaded" button (hidden in text view)
|
|
198
202
|
$collapse_btn: null,// "collapse all" button (hidden in text view)
|
|
199
203
|
$mode_btns: null, // Map<mode, HTMLElement> of the view switch
|
|
204
|
+
lang_shell: null, // the shell whose EV_LANGUAGE_CHANGED we hear
|
|
200
205
|
};
|
|
201
206
|
|
|
202
207
|
let __gclass__ = null;
|
|
@@ -255,6 +260,17 @@ function mt_start(gobj)
|
|
|
255
260
|
if(priv.root !== null) {
|
|
256
261
|
gobj_change_state(gobj, "ST_READY");
|
|
257
262
|
}
|
|
263
|
+
|
|
264
|
+
/* The reading beside a time field is written in the app's language
|
|
265
|
+
* when the tree is drawn: the shell's language switch draws it again
|
|
266
|
+
* (ac_language_changed). No host forwarded the event, so up to
|
|
267
|
+
* gobj-ui 7.26.51 that action never ran. */
|
|
268
|
+
let shell = yui_shell_of(gobj);
|
|
269
|
+
if(shell) {
|
|
270
|
+
gobj_subscribe_event(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
271
|
+
priv.lang_shell = shell;
|
|
272
|
+
}
|
|
273
|
+
|
|
258
274
|
render_view(gobj);
|
|
259
275
|
}
|
|
260
276
|
|
|
@@ -263,6 +279,15 @@ function mt_start(gobj)
|
|
|
263
279
|
***************************************************************/
|
|
264
280
|
function mt_stop(gobj)
|
|
265
281
|
{
|
|
282
|
+
let priv = gobj.priv;
|
|
283
|
+
|
|
284
|
+
/* The shell it subscribed to, if it is still there: a logout may
|
|
285
|
+
* have destroyed it, and its subscriptions with it. */
|
|
286
|
+
if(priv.lang_shell && !gobj_is_destroying(priv.lang_shell)) {
|
|
287
|
+
gobj_unsubscribe_event(priv.lang_shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
288
|
+
}
|
|
289
|
+
priv.lang_shell = null;
|
|
290
|
+
|
|
266
291
|
/*
|
|
267
292
|
* The graph child dies with the parent's RUNNING state, not with
|
|
268
293
|
* its destruction, and the difference is not cosmetic:
|
|
@@ -1001,7 +1026,7 @@ function leaf_row(key, value, depth)
|
|
|
1001
1026
|
body.push(['span', {class: 'JSON_VALUE JSON_TYPE_' + type.toUpperCase()}, text_node(text)]);
|
|
1002
1027
|
|
|
1003
1028
|
if(key !== null && is_time_field(String(key))) {
|
|
1004
|
-
let wall = format_epoch(value);
|
|
1029
|
+
let wall = format_epoch(value, safe_locale(i18next.language));
|
|
1005
1030
|
if(wall) {
|
|
1006
1031
|
body.push(['span', {class: 'JSON_TIME is-size-7 yui-text-quiet ml-2'}, wall]);
|
|
1007
1032
|
}
|
|
@@ -1337,6 +1362,12 @@ function ac_json_item_clicked(gobj, event, kw, src)
|
|
|
1337
1362
|
|
|
1338
1363
|
/************************************************************
|
|
1339
1364
|
* EV_LANGUAGE_CHANGED — re-translate chrome + re-render
|
|
1365
|
+
*
|
|
1366
|
+
* Only the TREE is drawn again: it writes the reading of a
|
|
1367
|
+
* time field in the language of the moment it was drawn. The
|
|
1368
|
+
* text view carries its keys (refresh_language reaches them),
|
|
1369
|
+
* and loading the graph again would throw away the reader's
|
|
1370
|
+
* camera for nothing.
|
|
1340
1371
|
************************************************************/
|
|
1341
1372
|
function ac_language_changed(gobj, event, kw, src)
|
|
1342
1373
|
{
|
|
@@ -1349,7 +1380,9 @@ function ac_language_changed(gobj, event, kw, src)
|
|
|
1349
1380
|
}
|
|
1350
1381
|
apply_view_mode(gobj);
|
|
1351
1382
|
}
|
|
1352
|
-
|
|
1383
|
+
if(current_view_mode(gobj) === "tree") {
|
|
1384
|
+
render_tree(gobj);
|
|
1385
|
+
}
|
|
1353
1386
|
return 0;
|
|
1354
1387
|
}
|
|
1355
1388
|
|
|
@@ -98,7 +98,8 @@ import {
|
|
|
98
98
|
} from "./lib_icons.js";
|
|
99
99
|
import {row_matches} from "./yui_row_search.js";
|
|
100
100
|
|
|
101
|
-
import {t} from "i18next";
|
|
101
|
+
import i18next, {t} from "i18next";
|
|
102
|
+
import {safe_locale} from "./yui_time.js";
|
|
102
103
|
|
|
103
104
|
import {yui_toolbar_icon} from "./yui_toolbar.js";
|
|
104
105
|
|
|
@@ -123,7 +124,7 @@ import {cell_text, hook_cell_spec} from "./table_cell_text.js";
|
|
|
123
124
|
|
|
124
125
|
import { TabulatorFull as Tabulator } from "tabulator-tables";
|
|
125
126
|
import {text_node, text_list_item_formatter} from "./yui_text.js";
|
|
126
|
-
import {
|
|
127
|
+
import {time_value_to_text} from "./form_time_value.js";
|
|
127
128
|
|
|
128
129
|
/***************************************************************
|
|
129
130
|
* Constants
|
|
@@ -2271,33 +2272,17 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field)
|
|
|
2271
2272
|
case "string":
|
|
2272
2273
|
case "integer":
|
|
2273
2274
|
/* An ISO text for a string column (up to 7.26.46 read
|
|
2274
|
-
* with parseInt, as 2026 seconds), none for no time.
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2275
|
+
* with parseInt, as 2026 seconds), none for no time.
|
|
2276
|
+
* The APP's language and 24 hours, as C_YUI_FORM's
|
|
2277
|
+
* cells (up to 7.26.51 the browser's language, 12
|
|
2278
|
+
* hours). A language change re-runs setColumns(),
|
|
2279
|
+
* which re-runs this. */
|
|
2280
|
+
value = time_value_to_text(
|
|
2281
|
+
value, field_desc.real_type, safe_locale(i18next.language)
|
|
2282
|
+
);
|
|
2283
|
+
if(value) {
|
|
2284
|
+
value = createElement2(['span', {class: 'is-size-7'}, text_node(value)]);
|
|
2279
2285
|
}
|
|
2280
|
-
|
|
2281
|
-
const rawLocale = navigator.language;
|
|
2282
|
-
// Playwright Firefox without locale config and some embedded
|
|
2283
|
-
// webviews report navigator.language as the literal string
|
|
2284
|
-
// "undefined" — would throw RangeError in Intl.DateTimeFormat.
|
|
2285
|
-
const userLocale = (typeof rawLocale === "string" && rawLocale && rawLocale !== "undefined")
|
|
2286
|
-
? rawLocale
|
|
2287
|
-
: undefined;
|
|
2288
|
-
const opts = {
|
|
2289
|
-
day: 'numeric',
|
|
2290
|
-
month: 'short', // 'long' for full month name, 'short' for abbreviated, 'narrow' for shortest
|
|
2291
|
-
year: 'numeric',
|
|
2292
|
-
hour: '2-digit',
|
|
2293
|
-
minute: '2-digit',
|
|
2294
|
-
second: '2-digit',
|
|
2295
|
-
hour12: true, // Use true for AM/PM or false for 24-hour format, depending on locale preference
|
|
2296
|
-
// timeZoneName: 'short' // Options are 'short' or 'long'
|
|
2297
|
-
};
|
|
2298
|
-
|
|
2299
|
-
const formatter = new Intl.DateTimeFormat(userLocale, opts);
|
|
2300
|
-
value = createElement2(['span', {class: 'is-size-7'}, formatter.format(value)]);
|
|
2301
2286
|
break;
|
|
2302
2287
|
}
|
|
2303
2288
|
break;
|
package/src/c_yui_uplot.js
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Graphics, Charts with uPlot
|
|
5
5
|
*
|
|
6
|
+
* A moment uPlot writes -- a tick of a time axis, the reading of
|
|
7
|
+
* the legend -- is in the app's language with a clock of 24 hours
|
|
8
|
+
* (yui_uplot_time.js), and is written again on the shell's
|
|
9
|
+
* EV_LANGUAGE_CHANGED.
|
|
10
|
+
*
|
|
6
11
|
* Copyright (c) 2025-2026, ArtGins.
|
|
7
12
|
* All Rights Reserved.
|
|
8
13
|
***********************************************************************/
|
|
@@ -18,6 +23,8 @@ import {
|
|
|
18
23
|
gobj_read_pointer_attr,
|
|
19
24
|
gobj_parent,
|
|
20
25
|
gobj_subscribe_event,
|
|
26
|
+
gobj_unsubscribe_event,
|
|
27
|
+
gobj_is_destroying,
|
|
21
28
|
gobj_read_attr,
|
|
22
29
|
gobj_read_str_attr,
|
|
23
30
|
gobj_write_attr,
|
|
@@ -34,6 +41,9 @@ import {yui_watch_theme} from "./yui_theme.js";
|
|
|
34
41
|
/* The ink of the axes -- the X and the Y -- and the palette of the
|
|
35
42
|
* series, on both schemes: see yui_uplot_ink.js. */
|
|
36
43
|
import {yui_uplot_axes, YUI_UPLOT_PALETTE} from "./yui_uplot_ink.js";
|
|
44
|
+
import {yui_uplot_fmt_date} from "./yui_uplot_time.js";
|
|
45
|
+
import {yui_shell_of} from "./c_yui_shell.js";
|
|
46
|
+
import i18next from "i18next";
|
|
37
47
|
|
|
38
48
|
|
|
39
49
|
/***************************************************************
|
|
@@ -66,6 +76,7 @@ SDATA_END()
|
|
|
66
76
|
|
|
67
77
|
let PRIVATE_DATA = {
|
|
68
78
|
theme_observer: null, /* the DOM's data-theme, as an EV_THEME */
|
|
79
|
+
lang_shell: null, /* the shell whose EV_LANGUAGE_CHANGED we hear */
|
|
69
80
|
};
|
|
70
81
|
|
|
71
82
|
let __gclass__ = null;
|
|
@@ -107,6 +118,13 @@ function mt_create(gobj)
|
|
|
107
118
|
***************************************************************/
|
|
108
119
|
function mt_start(gobj)
|
|
109
120
|
{
|
|
121
|
+
let priv = gobj.priv;
|
|
122
|
+
|
|
123
|
+
let shell = yui_shell_of(gobj);
|
|
124
|
+
if(shell) {
|
|
125
|
+
gobj_subscribe_event(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
126
|
+
priv.lang_shell = shell;
|
|
127
|
+
}
|
|
110
128
|
}
|
|
111
129
|
|
|
112
130
|
/***************************************************************
|
|
@@ -114,6 +132,14 @@ function mt_start(gobj)
|
|
|
114
132
|
***************************************************************/
|
|
115
133
|
function mt_stop(gobj)
|
|
116
134
|
{
|
|
135
|
+
let priv = gobj.priv;
|
|
136
|
+
|
|
137
|
+
/* The shell it subscribed to, if it is still there: a logout may
|
|
138
|
+
* have destroyed it, and its subscriptions with it. */
|
|
139
|
+
if(priv.lang_shell && !gobj_is_destroying(priv.lang_shell)) {
|
|
140
|
+
gobj_unsubscribe_event(priv.lang_shell, "EV_LANGUAGE_CHANGED", {}, gobj);
|
|
141
|
+
}
|
|
142
|
+
priv.lang_shell = null;
|
|
117
143
|
}
|
|
118
144
|
|
|
119
145
|
/***************************************************************
|
|
@@ -172,6 +198,7 @@ function build_ui(gobj)
|
|
|
172
198
|
series: gobj_read_attr(gobj, "series"),
|
|
173
199
|
axes: yui_uplot_axes(gobj_read_attr(gobj, "axes")),
|
|
174
200
|
scales: gobj_read_attr(gobj, "scales"),
|
|
201
|
+
fmtDate: yui_uplot_fmt_date(() => i18next.language),
|
|
175
202
|
};
|
|
176
203
|
let uplot = new uPlot(
|
|
177
204
|
uPlot_options,
|
|
@@ -437,6 +464,26 @@ function ac_theme(gobj, event, kw, src)
|
|
|
437
464
|
return 0;
|
|
438
465
|
}
|
|
439
466
|
|
|
467
|
+
/******************************************************
|
|
468
|
+
* The language changed: the ticks of a time axis and the
|
|
469
|
+
* reading of the legend ask for it when they are written,
|
|
470
|
+
* so they are written again.
|
|
471
|
+
******************************************************/
|
|
472
|
+
function ac_language_changed(gobj, event, kw, src)
|
|
473
|
+
{
|
|
474
|
+
let uplot = gobj_read_attr(gobj, "uplot");
|
|
475
|
+
if(!uplot) {
|
|
476
|
+
return 0;
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
uplot.redraw(true, true);
|
|
480
|
+
uplot.setLegend(null, false);
|
|
481
|
+
} catch(e) {
|
|
482
|
+
log_error(`${gobj_short_name(gobj)}: cannot redraw the chart: ${e}`);
|
|
483
|
+
}
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
|
|
440
487
|
/******************************************************
|
|
441
488
|
*
|
|
442
489
|
******************************************************/
|
|
@@ -511,7 +558,8 @@ function create_gclass(gclass_name)
|
|
|
511
558
|
["EV_ADD_SERIE", ac_add_serie, null],
|
|
512
559
|
["EV_DEL_SERIE", ac_del_serie, null],
|
|
513
560
|
["EV_CLEAR", ac_clear, null],
|
|
514
|
-
["EV_THEME", ac_theme, null]
|
|
561
|
+
["EV_THEME", ac_theme, null],
|
|
562
|
+
["EV_LANGUAGE_CHANGED", ac_language_changed, null]
|
|
515
563
|
]]
|
|
516
564
|
];
|
|
517
565
|
|
|
@@ -523,7 +571,8 @@ function create_gclass(gclass_name)
|
|
|
523
571
|
["EV_ADD_SERIE", 0],
|
|
524
572
|
["EV_DEL_SERIE", 0],
|
|
525
573
|
["EV_CLEAR", 0],
|
|
526
|
-
["EV_THEME", 0]
|
|
574
|
+
["EV_THEME", 0],
|
|
575
|
+
["EV_LANGUAGE_CHANGED", 0]
|
|
527
576
|
];
|
|
528
577
|
|
|
529
578
|
__gclass__ = gclass_create(
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* fmt_date_time.test.js
|
|
3
|
+
*
|
|
4
|
+
* fmt_date_time() of yui_time.js: a moment as a view shows it as
|
|
5
|
+
* text -- day, short month, year, and a clock of 24 hours with its
|
|
6
|
+
* seconds -- in the language it is given (the app's), and the two
|
|
7
|
+
* readers built on it: time_value_to_text() (the time cells of the
|
|
8
|
+
* forms and the treedb tables) and format_epoch() (the reading
|
|
9
|
+
* C_YUI_JSON writes beside a time field).
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect} from "vitest";
|
|
15
|
+
import {fmt_date_time, safe_locale} from "./yui_time.js";
|
|
16
|
+
import {time_value_to_text} from "./form_time_value.js";
|
|
17
|
+
import {format_epoch} from "./json_view_helpers.js";
|
|
18
|
+
import {yui_uplot_fmt_date} from "./yui_uplot_time.js";
|
|
19
|
+
|
|
20
|
+
const D = new Date(2026, 9, 14, 15, 5, 9);
|
|
21
|
+
|
|
22
|
+
describe("fmt_date_time", () => {
|
|
23
|
+
test("es and en, 24 hours", () => {
|
|
24
|
+
expect(fmt_date_time(D, "es")).toBe("14 oct 2026, 15:05:09");
|
|
25
|
+
expect(fmt_date_time(D, "en")).toBe("Oct 14, 2026, 15:05:09");
|
|
26
|
+
/* A region does not bring back the 12 hours of en-US. */
|
|
27
|
+
expect(fmt_date_time(D, "en-US")).toBe("Oct 14, 2026, 15:05:09");
|
|
28
|
+
expect(fmt_date_time(D, "es-ES")).toBe("14 oct 2026, 15:05:09");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("midnight is 00, never 24 nor 12 a. m.; noon is 12, with no p. m.", () => {
|
|
32
|
+
const midnight = new Date(2026, 9, 14, 0, 0, 0);
|
|
33
|
+
const noon = new Date(2026, 9, 14, 12, 0, 0);
|
|
34
|
+
const last = new Date(2026, 9, 14, 23, 59, 59);
|
|
35
|
+
expect(fmt_date_time(midnight, "es")).toBe("14 oct 2026, 00:00:00");
|
|
36
|
+
expect(fmt_date_time(midnight, "en")).toBe("Oct 14, 2026, 00:00:00");
|
|
37
|
+
expect(fmt_date_time(noon, "es")).toBe("14 oct 2026, 12:00:00");
|
|
38
|
+
expect(fmt_date_time(noon, "en")).toBe("Oct 14, 2026, 12:00:00");
|
|
39
|
+
expect(fmt_date_time(last, "en")).toBe("Oct 14, 2026, 23:59:59");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("the hour that repeats in autumn reads 02:30 in both passes", () => {
|
|
43
|
+
const tz = process.env.TZ;
|
|
44
|
+
process.env.TZ = "Europe/Madrid";
|
|
45
|
+
try {
|
|
46
|
+
/* 00:30Z and 01:30Z on 2026-10-25 are both 02:30 in Madrid. */
|
|
47
|
+
expect(fmt_date_time(new Date(1792888200 * 1000), "es")).toBe("25 oct 2026, 02:30:00");
|
|
48
|
+
expect(fmt_date_time(new Date(1792891800 * 1000), "es")).toBe("25 oct 2026, 02:30:00");
|
|
49
|
+
expect(fmt_date_time(new Date(1792895400 * 1000), "es")).toBe("25 oct 2026, 03:30:00");
|
|
50
|
+
} finally {
|
|
51
|
+
if(tz === undefined) {
|
|
52
|
+
delete process.env.TZ;
|
|
53
|
+
} else {
|
|
54
|
+
process.env.TZ = tz;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("no date is no text", () => {
|
|
60
|
+
expect(fmt_date_time(null, "es")).toBe("");
|
|
61
|
+
expect(fmt_date_time(undefined, "es")).toBe("");
|
|
62
|
+
expect(fmt_date_time(new Date("not a date"), "es")).toBe("");
|
|
63
|
+
expect(fmt_date_time(1792888200, "es")).toBe("");
|
|
64
|
+
expect(fmt_date_time("2026-10-14", "es")).toBe("");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("no language, or Firefox's literal \"undefined\", is the fallback of safe_locale", () => {
|
|
68
|
+
const fallback = fmt_date_time(D, safe_locale(undefined));
|
|
69
|
+
expect(fallback).toMatch(/15:05:09/);
|
|
70
|
+
expect(fmt_date_time(D, undefined)).toBe(fallback);
|
|
71
|
+
expect(fmt_date_time(D, "undefined")).toBe(fallback);
|
|
72
|
+
expect(fmt_date_time(D, "")).toBe(fallback);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a locale Intl refuses gives the language-free clock, not a broken screen", () => {
|
|
76
|
+
expect(fmt_date_time(D, "xx_YY")).toBe("2026-10-14 15:05:09");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("what the views read through it", () => {
|
|
81
|
+
const epoch = Math.floor(D.getTime() / 1000);
|
|
82
|
+
|
|
83
|
+
test("time_value_to_text: an epoch, an ISO text, no time, not a time", () => {
|
|
84
|
+
expect(time_value_to_text(epoch, "integer", "es")).toBe("14 oct 2026, 15:05:09");
|
|
85
|
+
expect(time_value_to_text(D.toISOString(), "string", "en")).toBe("Oct 14, 2026, 15:05:09");
|
|
86
|
+
expect(time_value_to_text(null, "integer", "es")).toBe("");
|
|
87
|
+
expect(time_value_to_text(undefined, "integer", "es")).toBe("");
|
|
88
|
+
expect(time_value_to_text("", "string", "es")).toBe("");
|
|
89
|
+
expect(time_value_to_text("garbage", "string", "es")).toBe("garbage");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("format_epoch: seconds and milliseconds read the same", () => {
|
|
93
|
+
expect(format_epoch(epoch, "es")).toBe("14 oct 2026, 15:05:09");
|
|
94
|
+
expect(format_epoch(epoch * 1000 + 999, "en")).toBe("Oct 14, 2026, 15:05:09");
|
|
95
|
+
expect(format_epoch(0, "es")).toBe(null);
|
|
96
|
+
expect(format_epoch(null, "es")).toBe(null);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("the moments uPlot writes (yui_uplot_time.js)", () => {
|
|
101
|
+
let lng = "es";
|
|
102
|
+
const fmt = (tpl) => yui_uplot_fmt_date(() => lng)(tpl);
|
|
103
|
+
const AFTERNOON = new Date(2026, 9, 14, 15, 5, 9, 374);
|
|
104
|
+
const MIDNIGHT = new Date(2026, 9, 14, 0, 0, 0);
|
|
105
|
+
|
|
106
|
+
test("the legend reads as every other view: fmt_date_time()", () => {
|
|
107
|
+
const legend = fmt("{YYYY}-{MM}-{DD} {h}:{mm}{aa}");
|
|
108
|
+
lng = "es";
|
|
109
|
+
expect(legend(AFTERNOON)).toBe("14 oct 2026, 15:05:09");
|
|
110
|
+
lng = "en";
|
|
111
|
+
expect(legend(AFTERNOON)).toBe("Oct 14, 2026, 15:05:09");
|
|
112
|
+
expect(legend(MIDNIGHT)).toBe("Oct 14, 2026, 00:00:00");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("the ticks of uPlot's own templates: 24 hours, the language's names and order", () => {
|
|
116
|
+
lng = "es";
|
|
117
|
+
expect(fmt("{h}{aa}")(AFTERNOON)).toBe("15:00");
|
|
118
|
+
expect(fmt("{h}{aa}")(MIDNIGHT)).toBe("00:00");
|
|
119
|
+
expect(fmt("{h}:{mm}{aa}")(AFTERNOON)).toBe("15:05");
|
|
120
|
+
expect(fmt(":{ss}")(AFTERNOON)).toBe(":09");
|
|
121
|
+
expect(fmt(":{ss}.{fff}")(AFTERNOON)).toBe(":09.374");
|
|
122
|
+
expect(fmt("{M}/{D}")(AFTERNOON)).toBe("14/10");
|
|
123
|
+
expect(fmt("\n{M}/{D}/{YY} {h}:{mm}{aa}")(AFTERNOON)).toBe("\n14/10/26 15:05");
|
|
124
|
+
expect(fmt("{MMM}")(AFTERNOON)).toBe("oct");
|
|
125
|
+
expect(fmt("\n{YYYY}")(AFTERNOON)).toBe("\n2026");
|
|
126
|
+
lng = "en";
|
|
127
|
+
expect(fmt("{M}/{D}")(AFTERNOON)).toBe("10/14");
|
|
128
|
+
expect(fmt("{MMM}")(AFTERNOON)).toBe("Oct");
|
|
129
|
+
expect(fmt("{h}:{mm}{aa}")(AFTERNOON)).toBe("15:05");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("an unknown token is left as text; Firefox's \"undefined\" is no language", () => {
|
|
133
|
+
lng = "es";
|
|
134
|
+
expect(fmt("{nope} {HH}")(AFTERNOON)).toBe("{nope} 15");
|
|
135
|
+
lng = "undefined";
|
|
136
|
+
expect(fmt("{h}:{mm}{aa}")(AFTERNOON)).toBe("15:05");
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -869,8 +869,9 @@ describe("a time column of a table", () => {
|
|
|
869
869
|
expect(errors()).toEqual([]);
|
|
870
870
|
});
|
|
871
871
|
|
|
872
|
-
/* Up to 7.26.46 the cell showed the raw epoch (1700000000)
|
|
873
|
-
|
|
872
|
+
/* Up to 7.26.46 the cell showed the raw epoch (1700000000); up
|
|
873
|
+
* to 7.26.51 "2026-03-14 09:26:53". The app's language is "en". */
|
|
874
|
+
test("shows its time as the local clock, in the app's language, not the epoch", async () => {
|
|
874
875
|
const first = tables.length;
|
|
875
876
|
const app = gobj_create_pure_child(`trapp${++seq}`, "C_TEST_TR_APP", {}, yuno);
|
|
876
877
|
gobj_start(app);
|
|
@@ -898,8 +899,8 @@ describe("a time column of a table", () => {
|
|
|
898
899
|
};
|
|
899
900
|
const wall = "2026-03-14T09:26:53";
|
|
900
901
|
const epoch = Math.floor(new Date(wall).getTime() / 1000);
|
|
901
|
-
expect(text("when", epoch)).toBe("
|
|
902
|
-
expect(text("at", new Date(epoch * 1000).toISOString())).toBe("
|
|
902
|
+
expect(text("when", epoch)).toBe("Mar 14, 2026, 09:26:53");
|
|
903
|
+
expect(text("at", new Date(epoch * 1000).toISOString())).toBe("Mar 14, 2026, 09:26:53");
|
|
903
904
|
expect(text("when", null)).toBe("");
|
|
904
905
|
expect(text("at", "not a time")).toBe("not a time");
|
|
905
906
|
gobj_stop(form);
|
package/src/form_time_value.js
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
* Copyright (c) 2026, ArtGins.
|
|
36
36
|
* All Rights Reserved.
|
|
37
37
|
****************************************************************************/
|
|
38
|
+
import {fmt_date_time} from "./yui_time.js";
|
|
38
39
|
|
|
39
40
|
/************************************************************
|
|
40
41
|
* A Date -> the value of a `datetime-local` input, in local time,
|
|
@@ -110,18 +111,20 @@ function epoch_to_time_value(epoch, real_type)
|
|
|
110
111
|
|
|
111
112
|
/************************************************************
|
|
112
113
|
* The value of a time column as a table cell shows it: the
|
|
113
|
-
* local clock
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
114
|
+
* local clock, 24 hours, in the APP's language `locale`
|
|
115
|
+
* (fmt_date_time() of yui_time.js: es "14 oct 2026, 15:05:09").
|
|
116
|
+
* Up to gobj-ui 7.26.51 the form wrote "2026-10-14 15:05:09" and
|
|
117
|
+
* the treedb table "14 oct 2026, 03:05:09 p. m.", in the
|
|
118
|
+
* browser's language. "" for no time; a value that is not one is
|
|
119
|
+
* shown as it is, so the reader sees what the column holds.
|
|
117
120
|
************************************************************/
|
|
118
|
-
function time_value_to_text(value, real_type)
|
|
121
|
+
function time_value_to_text(value, real_type, locale)
|
|
119
122
|
{
|
|
120
123
|
let date = time_value_to_date(value, real_type);
|
|
121
124
|
if(!date) {
|
|
122
125
|
return (value === null || value === undefined)? "" : String(value);
|
|
123
126
|
}
|
|
124
|
-
return
|
|
127
|
+
return fmt_date_time(date, locale);
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
export {
|
|
@@ -40,7 +40,7 @@ describe("form_time_value", () => {
|
|
|
40
40
|
it("a time cell shows the local clock, and what is not a time as it is", () => {
|
|
41
41
|
const wall = "2026-03-14T09:26:53";
|
|
42
42
|
const epoch = Math.floor(new Date(wall).getTime() / 1000);
|
|
43
|
-
expect(time_value_to_text(epoch, "integer")).toBe("
|
|
43
|
+
expect(time_value_to_text(epoch, "integer", "es")).toBe("14 mar 2026, 09:26:53");
|
|
44
44
|
expect(time_value_to_text(null, "integer")).toBe("");
|
|
45
45
|
expect(time_value_to_text("garbage", "string")).toBe("garbage");
|
|
46
46
|
});
|
package/src/json_view_helpers.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* All Rights Reserved.
|
|
17
17
|
***********************************************************************/
|
|
18
18
|
import {json2flat, flat_diff} from "@yuneta/gobj-js";
|
|
19
|
+
import {fmt_date_time} from "./yui_time.js";
|
|
19
20
|
|
|
20
21
|
/*
|
|
21
22
|
* Path delimiter, identical to the kernel's `delimiter` in kwid.c.
|
|
@@ -214,11 +215,15 @@ export function is_time_field(field)
|
|
|
214
215
|
export {TIME_FIELDS};
|
|
215
216
|
|
|
216
217
|
/************************************************************
|
|
217
|
-
* Format an epoch value as a local wall-clock string
|
|
218
|
+
* Format an epoch value as a local wall-clock string, 24
|
|
219
|
+
* hours, in the APP's language `locale` (fmt_date_time() of
|
|
220
|
+
* yui_time.js, as the time cells of the forms and tables;
|
|
221
|
+
* up to gobj-ui 7.26.51 it was toLocaleString(): the
|
|
222
|
+
* browser's language, and 12 hours in English).
|
|
218
223
|
* Accepts seconds or milliseconds; returns null when the
|
|
219
224
|
* value is not a usable positive timestamp (0 == "unset").
|
|
220
225
|
************************************************************/
|
|
221
|
-
export function format_epoch(value)
|
|
226
|
+
export function format_epoch(value, locale)
|
|
222
227
|
{
|
|
223
228
|
if(typeof value !== "number" || !isFinite(value) || value <= 0) {
|
|
224
229
|
return null;
|
|
@@ -228,7 +233,7 @@ export function format_epoch(value)
|
|
|
228
233
|
if(isNaN(d.getTime())) {
|
|
229
234
|
return null;
|
|
230
235
|
}
|
|
231
|
-
return d
|
|
236
|
+
return fmt_date_time(d, locale);
|
|
232
237
|
}
|
|
233
238
|
|
|
234
239
|
|