@yuneta/gobj-ui 7.26.52 → 7.26.53
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/dist/gobj-ui.cjs.js +664 -647
- package/dist/gobj-ui.es.js +664 -647
- package/package.json +1 -1
- package/src/c_yui_form.js +1 -1
- package/src/c_yui_json.js +1 -1
- package/src/c_yui_treedb_topic_with_form.js +1 -1
- package/src/form_time_value.js +1 -1
- package/src/json_view_helpers.js +1 -1
- package/src/yui_date_text.js +82 -0
- package/src/yui_time.js +5 -58
- package/src/yui_uplot_time.js +1 -1
package/dist/gobj-ui.es.js
CHANGED
|
@@ -9677,169 +9677,22 @@ function yui_icons_list() {
|
|
|
9677
9677
|
return list;
|
|
9678
9678
|
}
|
|
9679
9679
|
//#endregion
|
|
9680
|
-
//#region src/
|
|
9680
|
+
//#region src/yui_date_text.js
|
|
9681
9681
|
/***********************************************************************
|
|
9682
|
-
*
|
|
9683
|
-
*
|
|
9684
|
-
* Time, without a DOM: epochs, and the algebra of PERIODS.
|
|
9685
|
-
*
|
|
9686
|
-
* Two things live here, and they are the two halves of every date
|
|
9687
|
-
* UI the projects keep rewriting:
|
|
9688
|
-
*
|
|
9689
|
-
* 1) EPOCH <-> the local wall clock. A timestamp travels in the
|
|
9690
|
-
* producer's own unit — seconds, or milliseconds when a topic
|
|
9691
|
-
* says so — and every conversion crosses that `ms` flag. Getting
|
|
9692
|
-
* it wrong puts the same instant on two different clocks in one
|
|
9693
|
-
* screen (it did: a picker asking "from 18:55" local returned
|
|
9694
|
-
* rows a table labelled 16:55).
|
|
9695
|
-
*
|
|
9696
|
-
* 2) The PERIOD. A period is not an enum of five names: it is a
|
|
9697
|
-
* BUCKET, and a bucket is `count` of a `unit`:
|
|
9698
|
-
*
|
|
9699
|
-
* {id: "day", unit: "day", count: 1}
|
|
9700
|
-
* {id: "week", unit: "week", count: 1} ISO, Mon-first
|
|
9701
|
-
* {id: "bimester", unit: "month", count: 2}
|
|
9702
|
-
* {id: "quarter", unit: "month", count: 3}
|
|
9703
|
-
* {id: "semester", unit: "month", count: 6}
|
|
9704
|
-
* {id: "decade", unit: "year", count: 10}
|
|
9705
|
-
* {id: "15min", unit: "minute", count: 15}
|
|
9706
|
-
*
|
|
9707
|
-
* Given that pair, ONE implementation answers every question a
|
|
9708
|
-
* date navigator asks — where does the bucket holding this
|
|
9709
|
-
* instant start and end, what is the previous/next one, what do
|
|
9710
|
-
* I call it — so an app that wants quarters declares a quarter
|
|
9711
|
-
* instead of asking for a new component.
|
|
9712
|
-
*
|
|
9713
|
-
* Buckets are ALIGNED, never "count back from now": months align to
|
|
9714
|
-
* the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
|
|
9715
|
-
* boundaries), weeks to Monday, hours to local midnight. "Last 7
|
|
9716
|
-
* days" is a different animal — a rolling window — and it is not a
|
|
9717
|
-
* period: see `rolling_bounds()`.
|
|
9682
|
+
* yui_date_text.js
|
|
9718
9683
|
*
|
|
9719
|
-
*
|
|
9720
|
-
*
|
|
9721
|
-
*
|
|
9684
|
+
* A moment as a VIEW shows it as text, and the locale to show it
|
|
9685
|
+
* in. A module of its own, with no i18n key, on purpose: the views
|
|
9686
|
+
* that show a time (C_YUI_FORM, C_YUI_TREEDB_TOPIC_WITH_FORM,
|
|
9687
|
+
* C_YUI_JSON, C_YUI_UPLOT) import it, and validate-locales follows
|
|
9688
|
+
* the modules an app mounts -- importing yui_time.js for this made
|
|
9689
|
+
* every app that shows a time owe the keys of the period picker
|
|
9690
|
+
* (gobj-ui 7.26.52). yui_time.js re-exports both.
|
|
9722
9691
|
*
|
|
9723
9692
|
* Copyright (c) 2026, ArtGins.
|
|
9724
9693
|
* All Rights Reserved.
|
|
9725
9694
|
***********************************************************************/
|
|
9726
9695
|
/***************************************************************
|
|
9727
|
-
* Constants
|
|
9728
|
-
***************************************************************/
|
|
9729
|
-
var MS_DAY = 864e5;
|
|
9730
|
-
var PERIOD_UNITS = [
|
|
9731
|
-
"minute",
|
|
9732
|
-
"hour",
|
|
9733
|
-
"day",
|
|
9734
|
-
"week",
|
|
9735
|
-
"month",
|
|
9736
|
-
"year"
|
|
9737
|
-
];
|
|
9738
|
-
var YUI_PERIODS = {
|
|
9739
|
-
minute: {
|
|
9740
|
-
id: "minute",
|
|
9741
|
-
unit: "minute",
|
|
9742
|
-
count: 1
|
|
9743
|
-
},
|
|
9744
|
-
"5min": {
|
|
9745
|
-
id: "5min",
|
|
9746
|
-
unit: "minute",
|
|
9747
|
-
count: 5
|
|
9748
|
-
},
|
|
9749
|
-
"15min": {
|
|
9750
|
-
id: "15min",
|
|
9751
|
-
unit: "minute",
|
|
9752
|
-
count: 15
|
|
9753
|
-
},
|
|
9754
|
-
hour: {
|
|
9755
|
-
id: "hour",
|
|
9756
|
-
unit: "hour",
|
|
9757
|
-
count: 1
|
|
9758
|
-
},
|
|
9759
|
-
day: {
|
|
9760
|
-
id: "day",
|
|
9761
|
-
unit: "day",
|
|
9762
|
-
count: 1
|
|
9763
|
-
},
|
|
9764
|
-
week: {
|
|
9765
|
-
id: "week",
|
|
9766
|
-
unit: "week",
|
|
9767
|
-
count: 1
|
|
9768
|
-
},
|
|
9769
|
-
fortnight: {
|
|
9770
|
-
id: "fortnight",
|
|
9771
|
-
unit: "week",
|
|
9772
|
-
count: 2
|
|
9773
|
-
},
|
|
9774
|
-
month: {
|
|
9775
|
-
id: "month",
|
|
9776
|
-
unit: "month",
|
|
9777
|
-
count: 1
|
|
9778
|
-
},
|
|
9779
|
-
bimester: {
|
|
9780
|
-
id: "bimester",
|
|
9781
|
-
unit: "month",
|
|
9782
|
-
count: 2
|
|
9783
|
-
},
|
|
9784
|
-
quarter: {
|
|
9785
|
-
id: "quarter",
|
|
9786
|
-
unit: "month",
|
|
9787
|
-
count: 3
|
|
9788
|
-
},
|
|
9789
|
-
semester: {
|
|
9790
|
-
id: "semester",
|
|
9791
|
-
unit: "month",
|
|
9792
|
-
count: 6
|
|
9793
|
-
},
|
|
9794
|
-
year: {
|
|
9795
|
-
id: "year",
|
|
9796
|
-
unit: "year",
|
|
9797
|
-
count: 1
|
|
9798
|
-
},
|
|
9799
|
-
decade: {
|
|
9800
|
-
id: "decade",
|
|
9801
|
-
unit: "year",
|
|
9802
|
-
count: 10
|
|
9803
|
-
}
|
|
9804
|
-
};
|
|
9805
|
-
var YUI_PERIODS_DEFAULT = [
|
|
9806
|
-
"hour",
|
|
9807
|
-
"day",
|
|
9808
|
-
"week",
|
|
9809
|
-
"month",
|
|
9810
|
-
"year"
|
|
9811
|
-
];
|
|
9812
|
-
var YUI_ROLLING = {
|
|
9813
|
-
"1h": {
|
|
9814
|
-
id: "1h",
|
|
9815
|
-
secs: 3600,
|
|
9816
|
-
label: "last hour"
|
|
9817
|
-
},
|
|
9818
|
-
"6h": {
|
|
9819
|
-
id: "6h",
|
|
9820
|
-
secs: 21600,
|
|
9821
|
-
label: "last 6h"
|
|
9822
|
-
},
|
|
9823
|
-
"24h": {
|
|
9824
|
-
id: "24h",
|
|
9825
|
-
secs: 86400,
|
|
9826
|
-
label: "last 24h"
|
|
9827
|
-
},
|
|
9828
|
-
"7d": {
|
|
9829
|
-
id: "7d",
|
|
9830
|
-
secs: 604800,
|
|
9831
|
-
label: "last 7 days"
|
|
9832
|
-
},
|
|
9833
|
-
"30d": {
|
|
9834
|
-
id: "30d",
|
|
9835
|
-
secs: 2592e3,
|
|
9836
|
-
label: "last 30 days"
|
|
9837
|
-
}
|
|
9838
|
-
};
|
|
9839
|
-
/***************************
|
|
9840
|
-
* Locale / i18n
|
|
9841
|
-
***************************/
|
|
9842
|
-
/***************************************************************
|
|
9843
9696
|
* The locale to format with.
|
|
9844
9697
|
*
|
|
9845
9698
|
* NEVER at module top level, and never `navigator.language` raw:
|
|
@@ -9854,78 +9707,6 @@ function safe_locale(locale) {
|
|
|
9854
9707
|
if (typeof nav === "string" && nav && nav !== "undefined") return nav;
|
|
9855
9708
|
return "en";
|
|
9856
9709
|
}
|
|
9857
|
-
/***************************************************************
|
|
9858
|
-
* Translate through the APP's translator when it gave us one, and
|
|
9859
|
-
* degrade to the key itself otherwise — interpolating `{{x}}` by hand,
|
|
9860
|
-
* so a label never renders raw mustaches at a caller that has no i18n.
|
|
9861
|
-
***************************************************************/
|
|
9862
|
-
function tr(t, key, params) {
|
|
9863
|
-
if (typeof t === "function") return t(key, params);
|
|
9864
|
-
let s = key;
|
|
9865
|
-
for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
|
|
9866
|
-
return s;
|
|
9867
|
-
}
|
|
9868
|
-
/***************************************************************
|
|
9869
|
-
* Intl formatters, built PER CALL (see safe_locale). They are cheap
|
|
9870
|
-
* next to a repaint, and caching them would need a locale-change hook
|
|
9871
|
-
* the library has no business owning.
|
|
9872
|
-
***************************************************************/
|
|
9873
|
-
function fmt_intl(date, locale, opts) {
|
|
9874
|
-
try {
|
|
9875
|
-
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
9876
|
-
} catch (e) {
|
|
9877
|
-
return date.toDateString();
|
|
9878
|
-
}
|
|
9879
|
-
}
|
|
9880
|
-
/***************************
|
|
9881
|
-
* Epoch <-> clock
|
|
9882
|
-
***************************/
|
|
9883
|
-
/***************************************************************
|
|
9884
|
-
* Epoch in the producer's unit -> milliseconds, and back.
|
|
9885
|
-
* `ms` true means the value already IS milliseconds.
|
|
9886
|
-
***************************************************************/
|
|
9887
|
-
function epoch_to_ms(value, ms) {
|
|
9888
|
-
if (!value) return 0;
|
|
9889
|
-
return ms ? value : value * 1e3;
|
|
9890
|
-
}
|
|
9891
|
-
function ms_to_epoch(value_ms, ms) {
|
|
9892
|
-
if (!value_ms) return 0;
|
|
9893
|
-
return ms ? value_ms : Math.floor(value_ms / 1e3);
|
|
9894
|
-
}
|
|
9895
|
-
/***************************************************************
|
|
9896
|
-
* The LOCAL wall-clock string an `<input type="datetime-local">` takes
|
|
9897
|
-
* ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
|
|
9898
|
-
* the parse back. Empty / unparseable -> 0, which is exactly how a
|
|
9899
|
-
* match condition reads an absent bound.
|
|
9900
|
-
***************************************************************/
|
|
9901
|
-
function epoch_to_local_input(value, ms) {
|
|
9902
|
-
if (!value) return "";
|
|
9903
|
-
let d = new Date(epoch_to_ms(value, ms));
|
|
9904
|
-
let pad = (n) => String(n).padStart(2, "0");
|
|
9905
|
-
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
9906
|
-
}
|
|
9907
|
-
function local_input_to_epoch(v, ms) {
|
|
9908
|
-
if (!v) return 0;
|
|
9909
|
-
let parsed = Date.parse(v);
|
|
9910
|
-
if (Number.isNaN(parsed)) return 0;
|
|
9911
|
-
return ms_to_epoch(parsed, ms);
|
|
9912
|
-
}
|
|
9913
|
-
/***************************************************************
|
|
9914
|
-
* A timestamp for a table cell: the local wall clock, space-separated,
|
|
9915
|
-
* keeping the milliseconds when the producer bothered to send them (a
|
|
9916
|
-
* topic that sets sf_t_ms usually appends several records inside the
|
|
9917
|
-
* same second, and a column that hides that shows a column of ties).
|
|
9918
|
-
***************************************************************/
|
|
9919
|
-
function fmt_epoch(value, ms) {
|
|
9920
|
-
if (!value) return "";
|
|
9921
|
-
try {
|
|
9922
|
-
let s = epoch_to_local_input(value, ms).replace("T", " ");
|
|
9923
|
-
if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
|
|
9924
|
-
return s;
|
|
9925
|
-
} catch (e) {
|
|
9926
|
-
return String(value);
|
|
9927
|
-
}
|
|
9928
|
-
}
|
|
9929
9710
|
var DATE_TIME_OPTIONS = {
|
|
9930
9711
|
day: "numeric",
|
|
9931
9712
|
month: "short",
|
|
@@ -9956,439 +9737,105 @@ function fmt_date_time(date, locale) {
|
|
|
9956
9737
|
try {
|
|
9957
9738
|
return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
|
|
9958
9739
|
} catch (e) {
|
|
9959
|
-
|
|
9740
|
+
let pad = (n) => String(n).padStart(2, "0");
|
|
9741
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
9960
9742
|
}
|
|
9961
9743
|
}
|
|
9962
|
-
|
|
9963
|
-
*
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
let d = /* @__PURE__ */ new Date(n * MS_DAY);
|
|
9976
|
-
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
9977
|
-
}
|
|
9978
|
-
/***************************************************************
|
|
9979
|
-
* The Monday of the week a date falls in (ISO: the week starts on
|
|
9980
|
-
* Monday, and Sunday closes it).
|
|
9981
|
-
***************************************************************/
|
|
9982
|
-
function start_of_iso_week(d) {
|
|
9983
|
-
let day = d.getDay();
|
|
9984
|
-
let back = day === 0 ? 6 : day - 1;
|
|
9985
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
|
|
9986
|
-
}
|
|
9987
|
-
/***************************************************************
|
|
9988
|
-
* The ISO week a date belongs to: {week, year}. The YEAR is the ISO
|
|
9989
|
-
* week-year, not the calendar year — 2026-12-31 lives in week 1 of
|
|
9990
|
-
* 2027, and a label that said "week 1 2026" would name a week six
|
|
9991
|
-
* months away.
|
|
9992
|
-
***************************************************************/
|
|
9993
|
-
function iso_week(d) {
|
|
9994
|
-
let monday = start_of_iso_week(d);
|
|
9995
|
-
let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
|
|
9996
|
-
let jan1 = new Date(thursday.getFullYear(), 0, 1);
|
|
9997
|
-
return {
|
|
9998
|
-
week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
|
|
9999
|
-
year: thursday.getFullYear()
|
|
10000
|
-
};
|
|
10001
|
-
}
|
|
10002
|
-
/***************************************************************
|
|
10003
|
-
* The index of the ISO week a date falls in, counting weeks from the
|
|
10004
|
-
* Monday of the epoch week. It is what aligns a MULTI-week bucket (a
|
|
10005
|
-
* fortnight) to a Monday instead of to whatever day 1970-01-01 was.
|
|
10006
|
-
***************************************************************/
|
|
10007
|
-
function week_index(d) {
|
|
10008
|
-
return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
|
|
10009
|
-
}
|
|
10010
|
-
/***************************
|
|
10011
|
-
* Period algebra
|
|
10012
|
-
***************************/
|
|
10013
|
-
/***************************************************************
|
|
10014
|
-
* Normalize whatever a caller hands us into a spec: an id of the
|
|
10015
|
-
* catalog, or a spec of its own. Returns null for anything that is not
|
|
10016
|
-
* a bucket (a "span" / "custom" mode of a navigator has no algebra).
|
|
10017
|
-
***************************************************************/
|
|
10018
|
-
function period_spec(period) {
|
|
10019
|
-
if (!period) return null;
|
|
10020
|
-
let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
|
|
10021
|
-
if (!spec || !spec.unit) return null;
|
|
10022
|
-
if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
|
|
10023
|
-
let count = parseInt(spec.count, 10);
|
|
10024
|
-
if (!(count > 0)) count = 1;
|
|
10025
|
-
return {
|
|
10026
|
-
id: spec.id || spec.unit,
|
|
10027
|
-
unit: spec.unit,
|
|
10028
|
-
count
|
|
10029
|
-
};
|
|
9744
|
+
/************************************************************
|
|
9745
|
+
* JSON type discriminator (viewer vocabulary)
|
|
9746
|
+
************************************************************/
|
|
9747
|
+
function json_type(value) {
|
|
9748
|
+
if (value === null) return "null";
|
|
9749
|
+
if (Array.isArray(value)) return "array";
|
|
9750
|
+
switch (typeof value) {
|
|
9751
|
+
case "string": return "string";
|
|
9752
|
+
case "number": return "number";
|
|
9753
|
+
case "boolean": return "boolean";
|
|
9754
|
+
case "object": return "object";
|
|
9755
|
+
default: return "unknown";
|
|
9756
|
+
}
|
|
10030
9757
|
}
|
|
10031
|
-
|
|
10032
|
-
*
|
|
9758
|
+
/************************************************************
|
|
9759
|
+
* Detect a kw_collapse() sentinel.
|
|
10033
9760
|
*
|
|
10034
|
-
*
|
|
10035
|
-
*
|
|
10036
|
-
*
|
|
9761
|
+
* The kernel replaces an over-limit dict with:
|
|
9762
|
+
* { "__collapsed__": { "path": ..., "size": N } }
|
|
9763
|
+
* and an over-limit array with:
|
|
9764
|
+
* [ { "__collapsed__": { "path": ..., "size": N } } ]
|
|
10037
9765
|
*
|
|
10038
|
-
*
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
if (!spec) return null;
|
|
10051
|
-
let d = new Date(anchor_ms);
|
|
10052
|
-
let n = spec.count;
|
|
10053
|
-
switch (spec.unit) {
|
|
10054
|
-
case "minute": {
|
|
10055
|
-
let m = Math.floor(d.getMinutes() / n) * n;
|
|
10056
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
|
|
10057
|
-
}
|
|
10058
|
-
case "hour": {
|
|
10059
|
-
let h = Math.floor(d.getHours() / n) * n;
|
|
10060
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
|
|
10061
|
-
}
|
|
10062
|
-
case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
|
|
10063
|
-
case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
|
|
10064
|
-
case "month": {
|
|
10065
|
-
let mi = d.getFullYear() * 12 + d.getMonth();
|
|
10066
|
-
let s = Math.floor(mi / n) * n;
|
|
10067
|
-
return new Date(Math.floor(s / 12), s % 12, 1);
|
|
9766
|
+
* Returns { size, path, is_array } or null.
|
|
9767
|
+
************************************************************/
|
|
9768
|
+
function is_collapsed(value) {
|
|
9769
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
9770
|
+
let keys = Object.keys(value);
|
|
9771
|
+
if (keys.length === 1 && keys[0] === "__collapsed__") {
|
|
9772
|
+
let c = value.__collapsed__ || {};
|
|
9773
|
+
return {
|
|
9774
|
+
size: c.size,
|
|
9775
|
+
path: c.path,
|
|
9776
|
+
is_array: false
|
|
9777
|
+
};
|
|
10068
9778
|
}
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
9779
|
+
return null;
|
|
9780
|
+
}
|
|
9781
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
9782
|
+
let e = value[0];
|
|
9783
|
+
if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
|
|
9784
|
+
let c = e.__collapsed__ || {};
|
|
9785
|
+
return {
|
|
9786
|
+
size: c.size,
|
|
9787
|
+
path: c.path,
|
|
9788
|
+
is_array: true
|
|
9789
|
+
};
|
|
10072
9790
|
}
|
|
10073
|
-
default: return null;
|
|
10074
9791
|
}
|
|
9792
|
+
return null;
|
|
10075
9793
|
}
|
|
10076
|
-
|
|
10077
|
-
*
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
let spec = period_spec(period);
|
|
10084
|
-
if (!spec) return anchor_ms;
|
|
10085
|
-
let s = period_start(spec, anchor_ms);
|
|
10086
|
-
let step = spec.count * (delta || 0);
|
|
10087
|
-
switch (spec.unit) {
|
|
10088
|
-
case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
|
|
10089
|
-
case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
|
|
10090
|
-
case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
|
|
10091
|
-
case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
|
|
10092
|
-
case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
|
|
10093
|
-
case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
|
|
10094
|
-
default: return anchor_ms;
|
|
10095
|
-
}
|
|
9794
|
+
/************************************************************
|
|
9795
|
+
* Join / split absolute path segments (kernel convention)
|
|
9796
|
+
************************************************************/
|
|
9797
|
+
function seg_join(segments) {
|
|
9798
|
+
return segments.map(function(s) {
|
|
9799
|
+
return String(s);
|
|
9800
|
+
}).join("`");
|
|
10096
9801
|
}
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
* `to` is INCLUSIVE — the last millisecond of the bucket, not the first
|
|
10101
|
-
* of the next one. Both ends of a match condition are inclusive, and an
|
|
10102
|
-
* exclusive end handed to one silently swallows the record that landed
|
|
10103
|
-
* exactly on the boundary.
|
|
10104
|
-
***************************************************************/
|
|
10105
|
-
function period_bounds(period, anchor_ms) {
|
|
10106
|
-
let spec = period_spec(period);
|
|
10107
|
-
if (!spec) return {
|
|
10108
|
-
from: 0,
|
|
10109
|
-
to: 0
|
|
10110
|
-
};
|
|
10111
|
-
return {
|
|
10112
|
-
from: period_start(spec, anchor_ms).getTime(),
|
|
10113
|
-
to: period_shift(spec, anchor_ms, 1) - 1
|
|
10114
|
-
};
|
|
9802
|
+
function seg_split(path) {
|
|
9803
|
+
if (path === "" || path === null || path === void 0) return [];
|
|
9804
|
+
return path.split("`");
|
|
10115
9805
|
}
|
|
10116
|
-
|
|
10117
|
-
*
|
|
10118
|
-
*
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
let
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
to: ms_to_epoch(b.to, ms)
|
|
10130
|
-
};
|
|
9806
|
+
/************************************************************
|
|
9807
|
+
* Walk a JSON tree by absolute segments; undefined if the
|
|
9808
|
+
* path does not resolve.
|
|
9809
|
+
************************************************************/
|
|
9810
|
+
function get_by_segments(root, segments) {
|
|
9811
|
+
let v = root;
|
|
9812
|
+
for (let seg of segments) {
|
|
9813
|
+
if (v === null || v === void 0) return;
|
|
9814
|
+
if (Array.isArray(v)) v = v[Number(seg)];
|
|
9815
|
+
else if (typeof v === "object") v = v[seg];
|
|
9816
|
+
else return;
|
|
9817
|
+
}
|
|
9818
|
+
return v;
|
|
10131
9819
|
}
|
|
10132
|
-
|
|
10133
|
-
*
|
|
10134
|
-
* previous and no next, it just ends at `now`.
|
|
9820
|
+
/************************************************************
|
|
9821
|
+
* Set a value at absolute segments (mutates root).
|
|
10135
9822
|
*
|
|
10136
|
-
*
|
|
10137
|
-
*
|
|
10138
|
-
*
|
|
10139
|
-
|
|
10140
|
-
function
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
to: 0
|
|
10149
|
-
};
|
|
10150
|
-
}
|
|
10151
|
-
/***************************************************************
|
|
10152
|
-
* Is this the LAST bucket — the one `now` falls in? It is what greys
|
|
10153
|
-
* out the "next" arrow, and what tells the navigator it is already home.
|
|
10154
|
-
***************************************************************/
|
|
10155
|
-
function is_current_period(period, anchor_ms, now_ms) {
|
|
10156
|
-
let spec = period_spec(period);
|
|
10157
|
-
if (!spec) return false;
|
|
10158
|
-
let now = now_ms === void 0 ? Date.now() : now_ms;
|
|
10159
|
-
let a = period_start(spec, anchor_ms);
|
|
10160
|
-
let b = period_start(spec, now);
|
|
10161
|
-
return !!a && !!b && a.getTime() === b.getTime();
|
|
9823
|
+
* segments == [] means "replace the whole root" — the caller
|
|
9824
|
+
* must use the RETURNED value in that case (a primitive/array
|
|
9825
|
+
* root cannot be mutated in place).
|
|
9826
|
+
************************************************************/
|
|
9827
|
+
function set_by_segments(root, segments, new_value) {
|
|
9828
|
+
if (segments.length === 0) return new_value;
|
|
9829
|
+
let parent = get_by_segments(root, segments.slice(0, -1));
|
|
9830
|
+
if (parent === null || parent === void 0 || typeof parent !== "object") return root;
|
|
9831
|
+
let last = segments[segments.length - 1];
|
|
9832
|
+
if (Array.isArray(parent)) parent[Number(last)] = new_value;
|
|
9833
|
+
else parent[last] = new_value;
|
|
9834
|
+
return root;
|
|
10162
9835
|
}
|
|
10163
|
-
|
|
10164
|
-
*
|
|
10165
|
-
*
|
|
10166
|
-
* as the period the user picked instead of as a hand-typed range.
|
|
10167
|
-
*
|
|
10168
|
-
* `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
|
|
10169
|
-
* comparison — that is the whole trap: a bucket ends on the last
|
|
10170
|
-
* MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
|
|
10171
|
-
* it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
|
|
10172
|
-
* seconds-based topic came back as "no bucket at all", every time.
|
|
10173
|
-
*
|
|
10174
|
-
* Only an EXACT match counts: both ends must land on the bucket's own
|
|
10175
|
-
* boundaries, as that consumer would have written them. `candidates` are
|
|
10176
|
-
* ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
|
|
10177
|
-
* null.
|
|
10178
|
-
***************************************************************/
|
|
10179
|
-
function infer_period(from, to, candidates, ms) {
|
|
10180
|
-
if (!from || !to || to <= from) return null;
|
|
10181
|
-
let from_ms = epoch_to_ms(from, ms);
|
|
10182
|
-
for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
|
|
10183
|
-
let spec = period_spec(candidate);
|
|
10184
|
-
if (!spec) continue;
|
|
10185
|
-
let b = period_bounds_epoch(spec, from_ms, ms);
|
|
10186
|
-
if (b.from === from && b.to === to) return {
|
|
10187
|
-
period: spec,
|
|
10188
|
-
anchor: from_ms
|
|
10189
|
-
};
|
|
10190
|
-
}
|
|
10191
|
-
return null;
|
|
10192
|
-
}
|
|
10193
|
-
/***************************
|
|
10194
|
-
* Period labels
|
|
10195
|
-
***************************/
|
|
10196
|
-
/***************************************************************
|
|
10197
|
-
* The name of a GRANULARITY (what the segmented control shows):
|
|
10198
|
-
* the spec's own id as an i18n key, so an app that declares
|
|
10199
|
-
* {id: "quarter"} gets "Trimestre" the moment it adds the key.
|
|
10200
|
-
***************************************************************/
|
|
10201
|
-
function period_name(period, t) {
|
|
10202
|
-
let spec = period_spec(period);
|
|
10203
|
-
if (!spec) return tr(t, String(period && period.id || period || ""));
|
|
10204
|
-
return tr(t, spec.id);
|
|
10205
|
-
}
|
|
10206
|
-
/***************************************************************
|
|
10207
|
-
* The name of the bucket a navigator is PARKED on: what goes between
|
|
10208
|
-
* the two arrows.
|
|
10209
|
-
*
|
|
10210
|
-
* day -> "Today" / "Yesterday" / "13 jul 2026"
|
|
10211
|
-
* week -> "Week 27" (+ year when it is not this one)
|
|
10212
|
-
* month -> "July" (+ year when it is not this one)
|
|
10213
|
-
* quarter -> "Q3 2026" (unit month, count 3)
|
|
10214
|
-
* semester -> "H2 2026" (unit month, count 6)
|
|
10215
|
-
* year -> "2026"
|
|
10216
|
-
* decade -> "2020 – 2029"
|
|
10217
|
-
* any other -> the bucket's own edges: "1 jul – 31 aug 2026"
|
|
10218
|
-
*
|
|
10219
|
-
* The named ones are named because a range reads worse than a name;
|
|
10220
|
-
* everything an app invents falls back to the range, which is always
|
|
10221
|
-
* true and never wrong.
|
|
10222
|
-
***************************************************************/
|
|
10223
|
-
function period_label(period, anchor_ms, t, locale) {
|
|
10224
|
-
let spec = period_spec(period);
|
|
10225
|
-
if (!spec) return "";
|
|
10226
|
-
let loc = safe_locale(locale);
|
|
10227
|
-
let start = period_start(spec, anchor_ms);
|
|
10228
|
-
let end = new Date(period_bounds(spec, anchor_ms).to);
|
|
10229
|
-
let now = /* @__PURE__ */ new Date();
|
|
10230
|
-
let this_year = start.getFullYear() === now.getFullYear();
|
|
10231
|
-
if (spec.unit === "day" && spec.count === 1) {
|
|
10232
|
-
let diff = day_number(start) - day_number(now);
|
|
10233
|
-
if (diff === 0) return tr(t, "today");
|
|
10234
|
-
if (diff === -1) return tr(t, "yesterday");
|
|
10235
|
-
if (diff === 1) return tr(t, "tomorrow");
|
|
10236
|
-
return fmt_intl(start, loc, this_year ? {
|
|
10237
|
-
day: "numeric",
|
|
10238
|
-
month: "short"
|
|
10239
|
-
} : {
|
|
10240
|
-
day: "numeric",
|
|
10241
|
-
month: "short",
|
|
10242
|
-
year: "numeric"
|
|
10243
|
-
});
|
|
10244
|
-
}
|
|
10245
|
-
if (spec.unit === "hour" && spec.count === 1) {
|
|
10246
|
-
let hh = fmt_intl(start, loc, {
|
|
10247
|
-
hour: "2-digit",
|
|
10248
|
-
minute: "2-digit"
|
|
10249
|
-
});
|
|
10250
|
-
if (day_number(start) === day_number(now)) return hh;
|
|
10251
|
-
return `${hh} · ${fmt_intl(start, loc, {
|
|
10252
|
-
day: "numeric",
|
|
10253
|
-
month: "short"
|
|
10254
|
-
})}`;
|
|
10255
|
-
}
|
|
10256
|
-
if (spec.unit === "week" && spec.count === 1) {
|
|
10257
|
-
let away = week_index(start) - week_index(now);
|
|
10258
|
-
if (away === 0) return tr(t, "this week");
|
|
10259
|
-
if (away === -1) return tr(t, "last week");
|
|
10260
|
-
let w = iso_week(start);
|
|
10261
|
-
return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
|
|
10262
|
-
n: w.week,
|
|
10263
|
-
y: w.year
|
|
10264
|
-
});
|
|
10265
|
-
}
|
|
10266
|
-
if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
|
|
10267
|
-
month: "long",
|
|
10268
|
-
year: "numeric"
|
|
10269
|
-
});
|
|
10270
|
-
if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
|
|
10271
|
-
let n = Math.floor(start.getMonth() / spec.count) + 1;
|
|
10272
|
-
return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
|
|
10273
|
-
n,
|
|
10274
|
-
y: start.getFullYear()
|
|
10275
|
-
});
|
|
10276
|
-
}
|
|
10277
|
-
if (spec.unit === "year") {
|
|
10278
|
-
if (spec.count === 1) return String(start.getFullYear());
|
|
10279
|
-
return `${start.getFullYear()} – ${end.getFullYear()}`;
|
|
10280
|
-
}
|
|
10281
|
-
let opts = spec.unit === "minute" || spec.unit === "hour" ? {
|
|
10282
|
-
day: "numeric",
|
|
10283
|
-
month: "short",
|
|
10284
|
-
hour: "2-digit",
|
|
10285
|
-
minute: "2-digit"
|
|
10286
|
-
} : {
|
|
10287
|
-
day: "numeric",
|
|
10288
|
-
month: "short"
|
|
10289
|
-
};
|
|
10290
|
-
if (start.getFullYear() !== end.getFullYear()) {
|
|
10291
|
-
let y_opts = Object.assign({ year: "numeric" }, opts);
|
|
10292
|
-
return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
|
|
10293
|
-
}
|
|
10294
|
-
let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
|
|
10295
|
-
return this_year ? span : `${span} ${start.getFullYear()}`;
|
|
10296
|
-
}
|
|
10297
|
-
/************************************************************
|
|
10298
|
-
* JSON type discriminator (viewer vocabulary)
|
|
10299
|
-
************************************************************/
|
|
10300
|
-
function json_type(value) {
|
|
10301
|
-
if (value === null) return "null";
|
|
10302
|
-
if (Array.isArray(value)) return "array";
|
|
10303
|
-
switch (typeof value) {
|
|
10304
|
-
case "string": return "string";
|
|
10305
|
-
case "number": return "number";
|
|
10306
|
-
case "boolean": return "boolean";
|
|
10307
|
-
case "object": return "object";
|
|
10308
|
-
default: return "unknown";
|
|
10309
|
-
}
|
|
10310
|
-
}
|
|
10311
|
-
/************************************************************
|
|
10312
|
-
* Detect a kw_collapse() sentinel.
|
|
10313
|
-
*
|
|
10314
|
-
* The kernel replaces an over-limit dict with:
|
|
10315
|
-
* { "__collapsed__": { "path": ..., "size": N } }
|
|
10316
|
-
* and an over-limit array with:
|
|
10317
|
-
* [ { "__collapsed__": { "path": ..., "size": N } } ]
|
|
10318
|
-
*
|
|
10319
|
-
* Returns { size, path, is_array } or null.
|
|
10320
|
-
************************************************************/
|
|
10321
|
-
function is_collapsed(value) {
|
|
10322
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
10323
|
-
let keys = Object.keys(value);
|
|
10324
|
-
if (keys.length === 1 && keys[0] === "__collapsed__") {
|
|
10325
|
-
let c = value.__collapsed__ || {};
|
|
10326
|
-
return {
|
|
10327
|
-
size: c.size,
|
|
10328
|
-
path: c.path,
|
|
10329
|
-
is_array: false
|
|
10330
|
-
};
|
|
10331
|
-
}
|
|
10332
|
-
return null;
|
|
10333
|
-
}
|
|
10334
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
10335
|
-
let e = value[0];
|
|
10336
|
-
if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
|
|
10337
|
-
let c = e.__collapsed__ || {};
|
|
10338
|
-
return {
|
|
10339
|
-
size: c.size,
|
|
10340
|
-
path: c.path,
|
|
10341
|
-
is_array: true
|
|
10342
|
-
};
|
|
10343
|
-
}
|
|
10344
|
-
}
|
|
10345
|
-
return null;
|
|
10346
|
-
}
|
|
10347
|
-
/************************************************************
|
|
10348
|
-
* Join / split absolute path segments (kernel convention)
|
|
10349
|
-
************************************************************/
|
|
10350
|
-
function seg_join(segments) {
|
|
10351
|
-
return segments.map(function(s) {
|
|
10352
|
-
return String(s);
|
|
10353
|
-
}).join("`");
|
|
10354
|
-
}
|
|
10355
|
-
function seg_split(path) {
|
|
10356
|
-
if (path === "" || path === null || path === void 0) return [];
|
|
10357
|
-
return path.split("`");
|
|
10358
|
-
}
|
|
10359
|
-
/************************************************************
|
|
10360
|
-
* Walk a JSON tree by absolute segments; undefined if the
|
|
10361
|
-
* path does not resolve.
|
|
10362
|
-
************************************************************/
|
|
10363
|
-
function get_by_segments(root, segments) {
|
|
10364
|
-
let v = root;
|
|
10365
|
-
for (let seg of segments) {
|
|
10366
|
-
if (v === null || v === void 0) return;
|
|
10367
|
-
if (Array.isArray(v)) v = v[Number(seg)];
|
|
10368
|
-
else if (typeof v === "object") v = v[seg];
|
|
10369
|
-
else return;
|
|
10370
|
-
}
|
|
10371
|
-
return v;
|
|
10372
|
-
}
|
|
10373
|
-
/************************************************************
|
|
10374
|
-
* Set a value at absolute segments (mutates root).
|
|
10375
|
-
*
|
|
10376
|
-
* segments == [] means "replace the whole root" — the caller
|
|
10377
|
-
* must use the RETURNED value in that case (a primitive/array
|
|
10378
|
-
* root cannot be mutated in place).
|
|
10379
|
-
************************************************************/
|
|
10380
|
-
function set_by_segments(root, segments, new_value) {
|
|
10381
|
-
if (segments.length === 0) return new_value;
|
|
10382
|
-
let parent = get_by_segments(root, segments.slice(0, -1));
|
|
10383
|
-
if (parent === null || parent === void 0 || typeof parent !== "object") return root;
|
|
10384
|
-
let last = segments[segments.length - 1];
|
|
10385
|
-
if (Array.isArray(parent)) parent[Number(last)] = new_value;
|
|
10386
|
-
else parent[last] = new_value;
|
|
10387
|
-
return root;
|
|
10388
|
-
}
|
|
10389
|
-
/************************************************************
|
|
10390
|
-
* Does `value` (or any loaded descendant / its own key)
|
|
10391
|
-
* contain the lower-cased search term?
|
|
9836
|
+
/************************************************************
|
|
9837
|
+
* Does `value` (or any loaded descendant / its own key)
|
|
9838
|
+
* contain the lower-cased search term?
|
|
10392
9839
|
*
|
|
10393
9840
|
* Collapsed (not-yet-loaded) subtrees can't be searched, so
|
|
10394
9841
|
* they never match on content — only their key can match,
|
|
@@ -83540,6 +82987,576 @@ function register_c_yui_schema_editor() {
|
|
|
83540
82987
|
return create_gclass$1(GCLASS_NAME$1);
|
|
83541
82988
|
}
|
|
83542
82989
|
//#endregion
|
|
82990
|
+
//#region src/yui_time.js
|
|
82991
|
+
/***********************************************************************
|
|
82992
|
+
* yui_time.js
|
|
82993
|
+
*
|
|
82994
|
+
* Time, without a DOM: epochs, and the algebra of PERIODS.
|
|
82995
|
+
*
|
|
82996
|
+
* Two things live here, and they are the two halves of every date
|
|
82997
|
+
* UI the projects keep rewriting:
|
|
82998
|
+
*
|
|
82999
|
+
* 1) EPOCH <-> the local wall clock. A timestamp travels in the
|
|
83000
|
+
* producer's own unit — seconds, or milliseconds when a topic
|
|
83001
|
+
* says so — and every conversion crosses that `ms` flag. Getting
|
|
83002
|
+
* it wrong puts the same instant on two different clocks in one
|
|
83003
|
+
* screen (it did: a picker asking "from 18:55" local returned
|
|
83004
|
+
* rows a table labelled 16:55).
|
|
83005
|
+
*
|
|
83006
|
+
* 2) The PERIOD. A period is not an enum of five names: it is a
|
|
83007
|
+
* BUCKET, and a bucket is `count` of a `unit`:
|
|
83008
|
+
*
|
|
83009
|
+
* {id: "day", unit: "day", count: 1}
|
|
83010
|
+
* {id: "week", unit: "week", count: 1} ISO, Mon-first
|
|
83011
|
+
* {id: "bimester", unit: "month", count: 2}
|
|
83012
|
+
* {id: "quarter", unit: "month", count: 3}
|
|
83013
|
+
* {id: "semester", unit: "month", count: 6}
|
|
83014
|
+
* {id: "decade", unit: "year", count: 10}
|
|
83015
|
+
* {id: "15min", unit: "minute", count: 15}
|
|
83016
|
+
*
|
|
83017
|
+
* Given that pair, ONE implementation answers every question a
|
|
83018
|
+
* date navigator asks — where does the bucket holding this
|
|
83019
|
+
* instant start and end, what is the previous/next one, what do
|
|
83020
|
+
* I call it — so an app that wants quarters declares a quarter
|
|
83021
|
+
* instead of asking for a new component.
|
|
83022
|
+
*
|
|
83023
|
+
* Buckets are ALIGNED, never "count back from now": months align to
|
|
83024
|
+
* the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
|
|
83025
|
+
* boundaries), weeks to Monday, hours to local midnight. "Last 7
|
|
83026
|
+
* days" is a different animal — a rolling window — and it is not a
|
|
83027
|
+
* period: see `rolling_bounds()`.
|
|
83028
|
+
*
|
|
83029
|
+
* Everything here is LOCAL time (the user reads a local clock) and
|
|
83030
|
+
* DST-safe: it never adds 86400000 ms to cross a day, it builds the
|
|
83031
|
+
* next date from calendar fields and lets the platform do it.
|
|
83032
|
+
*
|
|
83033
|
+
* Copyright (c) 2026, ArtGins.
|
|
83034
|
+
* All Rights Reserved.
|
|
83035
|
+
***********************************************************************/
|
|
83036
|
+
/***************************************************************
|
|
83037
|
+
* Constants
|
|
83038
|
+
***************************************************************/
|
|
83039
|
+
var MS_DAY = 864e5;
|
|
83040
|
+
var PERIOD_UNITS = [
|
|
83041
|
+
"minute",
|
|
83042
|
+
"hour",
|
|
83043
|
+
"day",
|
|
83044
|
+
"week",
|
|
83045
|
+
"month",
|
|
83046
|
+
"year"
|
|
83047
|
+
];
|
|
83048
|
+
var YUI_PERIODS = {
|
|
83049
|
+
minute: {
|
|
83050
|
+
id: "minute",
|
|
83051
|
+
unit: "minute",
|
|
83052
|
+
count: 1
|
|
83053
|
+
},
|
|
83054
|
+
"5min": {
|
|
83055
|
+
id: "5min",
|
|
83056
|
+
unit: "minute",
|
|
83057
|
+
count: 5
|
|
83058
|
+
},
|
|
83059
|
+
"15min": {
|
|
83060
|
+
id: "15min",
|
|
83061
|
+
unit: "minute",
|
|
83062
|
+
count: 15
|
|
83063
|
+
},
|
|
83064
|
+
hour: {
|
|
83065
|
+
id: "hour",
|
|
83066
|
+
unit: "hour",
|
|
83067
|
+
count: 1
|
|
83068
|
+
},
|
|
83069
|
+
day: {
|
|
83070
|
+
id: "day",
|
|
83071
|
+
unit: "day",
|
|
83072
|
+
count: 1
|
|
83073
|
+
},
|
|
83074
|
+
week: {
|
|
83075
|
+
id: "week",
|
|
83076
|
+
unit: "week",
|
|
83077
|
+
count: 1
|
|
83078
|
+
},
|
|
83079
|
+
fortnight: {
|
|
83080
|
+
id: "fortnight",
|
|
83081
|
+
unit: "week",
|
|
83082
|
+
count: 2
|
|
83083
|
+
},
|
|
83084
|
+
month: {
|
|
83085
|
+
id: "month",
|
|
83086
|
+
unit: "month",
|
|
83087
|
+
count: 1
|
|
83088
|
+
},
|
|
83089
|
+
bimester: {
|
|
83090
|
+
id: "bimester",
|
|
83091
|
+
unit: "month",
|
|
83092
|
+
count: 2
|
|
83093
|
+
},
|
|
83094
|
+
quarter: {
|
|
83095
|
+
id: "quarter",
|
|
83096
|
+
unit: "month",
|
|
83097
|
+
count: 3
|
|
83098
|
+
},
|
|
83099
|
+
semester: {
|
|
83100
|
+
id: "semester",
|
|
83101
|
+
unit: "month",
|
|
83102
|
+
count: 6
|
|
83103
|
+
},
|
|
83104
|
+
year: {
|
|
83105
|
+
id: "year",
|
|
83106
|
+
unit: "year",
|
|
83107
|
+
count: 1
|
|
83108
|
+
},
|
|
83109
|
+
decade: {
|
|
83110
|
+
id: "decade",
|
|
83111
|
+
unit: "year",
|
|
83112
|
+
count: 10
|
|
83113
|
+
}
|
|
83114
|
+
};
|
|
83115
|
+
var YUI_PERIODS_DEFAULT = [
|
|
83116
|
+
"hour",
|
|
83117
|
+
"day",
|
|
83118
|
+
"week",
|
|
83119
|
+
"month",
|
|
83120
|
+
"year"
|
|
83121
|
+
];
|
|
83122
|
+
var YUI_ROLLING = {
|
|
83123
|
+
"1h": {
|
|
83124
|
+
id: "1h",
|
|
83125
|
+
secs: 3600,
|
|
83126
|
+
label: "last hour"
|
|
83127
|
+
},
|
|
83128
|
+
"6h": {
|
|
83129
|
+
id: "6h",
|
|
83130
|
+
secs: 21600,
|
|
83131
|
+
label: "last 6h"
|
|
83132
|
+
},
|
|
83133
|
+
"24h": {
|
|
83134
|
+
id: "24h",
|
|
83135
|
+
secs: 86400,
|
|
83136
|
+
label: "last 24h"
|
|
83137
|
+
},
|
|
83138
|
+
"7d": {
|
|
83139
|
+
id: "7d",
|
|
83140
|
+
secs: 604800,
|
|
83141
|
+
label: "last 7 days"
|
|
83142
|
+
},
|
|
83143
|
+
"30d": {
|
|
83144
|
+
id: "30d",
|
|
83145
|
+
secs: 2592e3,
|
|
83146
|
+
label: "last 30 days"
|
|
83147
|
+
}
|
|
83148
|
+
};
|
|
83149
|
+
/***************************
|
|
83150
|
+
* Locale / i18n
|
|
83151
|
+
***************************/
|
|
83152
|
+
/***************************************************************
|
|
83153
|
+
* Translate through the APP's translator when it gave us one, and
|
|
83154
|
+
* degrade to the key itself otherwise — interpolating `{{x}}` by hand,
|
|
83155
|
+
* so a label never renders raw mustaches at a caller that has no i18n.
|
|
83156
|
+
***************************************************************/
|
|
83157
|
+
function tr(t, key, params) {
|
|
83158
|
+
if (typeof t === "function") return t(key, params);
|
|
83159
|
+
let s = key;
|
|
83160
|
+
for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
|
|
83161
|
+
return s;
|
|
83162
|
+
}
|
|
83163
|
+
/***************************************************************
|
|
83164
|
+
* Intl formatters, built PER CALL (see safe_locale). They are cheap
|
|
83165
|
+
* next to a repaint, and caching them would need a locale-change hook
|
|
83166
|
+
* the library has no business owning.
|
|
83167
|
+
***************************************************************/
|
|
83168
|
+
function fmt_intl(date, locale, opts) {
|
|
83169
|
+
try {
|
|
83170
|
+
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
83171
|
+
} catch (e) {
|
|
83172
|
+
return date.toDateString();
|
|
83173
|
+
}
|
|
83174
|
+
}
|
|
83175
|
+
/***************************
|
|
83176
|
+
* Epoch <-> clock
|
|
83177
|
+
***************************/
|
|
83178
|
+
/***************************************************************
|
|
83179
|
+
* Epoch in the producer's unit -> milliseconds, and back.
|
|
83180
|
+
* `ms` true means the value already IS milliseconds.
|
|
83181
|
+
***************************************************************/
|
|
83182
|
+
function epoch_to_ms(value, ms) {
|
|
83183
|
+
if (!value) return 0;
|
|
83184
|
+
return ms ? value : value * 1e3;
|
|
83185
|
+
}
|
|
83186
|
+
function ms_to_epoch(value_ms, ms) {
|
|
83187
|
+
if (!value_ms) return 0;
|
|
83188
|
+
return ms ? value_ms : Math.floor(value_ms / 1e3);
|
|
83189
|
+
}
|
|
83190
|
+
/***************************************************************
|
|
83191
|
+
* The LOCAL wall-clock string an `<input type="datetime-local">` takes
|
|
83192
|
+
* ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
|
|
83193
|
+
* the parse back. Empty / unparseable -> 0, which is exactly how a
|
|
83194
|
+
* match condition reads an absent bound.
|
|
83195
|
+
***************************************************************/
|
|
83196
|
+
function epoch_to_local_input(value, ms) {
|
|
83197
|
+
if (!value) return "";
|
|
83198
|
+
let d = new Date(epoch_to_ms(value, ms));
|
|
83199
|
+
let pad = (n) => String(n).padStart(2, "0");
|
|
83200
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
83201
|
+
}
|
|
83202
|
+
function local_input_to_epoch(v, ms) {
|
|
83203
|
+
if (!v) return 0;
|
|
83204
|
+
let parsed = Date.parse(v);
|
|
83205
|
+
if (Number.isNaN(parsed)) return 0;
|
|
83206
|
+
return ms_to_epoch(parsed, ms);
|
|
83207
|
+
}
|
|
83208
|
+
/***************************************************************
|
|
83209
|
+
* A timestamp for a table cell: the local wall clock, space-separated,
|
|
83210
|
+
* keeping the milliseconds when the producer bothered to send them (a
|
|
83211
|
+
* topic that sets sf_t_ms usually appends several records inside the
|
|
83212
|
+
* same second, and a column that hides that shows a column of ties).
|
|
83213
|
+
***************************************************************/
|
|
83214
|
+
function fmt_epoch(value, ms) {
|
|
83215
|
+
if (!value) return "";
|
|
83216
|
+
try {
|
|
83217
|
+
let s = epoch_to_local_input(value, ms).replace("T", " ");
|
|
83218
|
+
if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
|
|
83219
|
+
return s;
|
|
83220
|
+
} catch (e) {
|
|
83221
|
+
return String(value);
|
|
83222
|
+
}
|
|
83223
|
+
}
|
|
83224
|
+
/***************************
|
|
83225
|
+
* Calendar atoms
|
|
83226
|
+
***************************/
|
|
83227
|
+
/***************************************************************
|
|
83228
|
+
* The day number of a date, counting local calendar days from
|
|
83229
|
+
* 1970-01-01. Built from the FIELDS (Date.UTC of y/m/d), never from
|
|
83230
|
+
* the timestamp: a DST day is 23 or 25 hours long, so dividing a local
|
|
83231
|
+
* epoch by 86400000 drifts a day twice a year.
|
|
83232
|
+
***************************************************************/
|
|
83233
|
+
function day_number(d) {
|
|
83234
|
+
return Math.floor(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) / MS_DAY);
|
|
83235
|
+
}
|
|
83236
|
+
function date_from_day_number(n) {
|
|
83237
|
+
let d = /* @__PURE__ */ new Date(n * MS_DAY);
|
|
83238
|
+
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
83239
|
+
}
|
|
83240
|
+
/***************************************************************
|
|
83241
|
+
* The Monday of the week a date falls in (ISO: the week starts on
|
|
83242
|
+
* Monday, and Sunday closes it).
|
|
83243
|
+
***************************************************************/
|
|
83244
|
+
function start_of_iso_week(d) {
|
|
83245
|
+
let day = d.getDay();
|
|
83246
|
+
let back = day === 0 ? 6 : day - 1;
|
|
83247
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
|
|
83248
|
+
}
|
|
83249
|
+
/***************************************************************
|
|
83250
|
+
* The ISO week a date belongs to: {week, year}. The YEAR is the ISO
|
|
83251
|
+
* week-year, not the calendar year — 2026-12-31 lives in week 1 of
|
|
83252
|
+
* 2027, and a label that said "week 1 2026" would name a week six
|
|
83253
|
+
* months away.
|
|
83254
|
+
***************************************************************/
|
|
83255
|
+
function iso_week(d) {
|
|
83256
|
+
let monday = start_of_iso_week(d);
|
|
83257
|
+
let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
|
|
83258
|
+
let jan1 = new Date(thursday.getFullYear(), 0, 1);
|
|
83259
|
+
return {
|
|
83260
|
+
week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
|
|
83261
|
+
year: thursday.getFullYear()
|
|
83262
|
+
};
|
|
83263
|
+
}
|
|
83264
|
+
/***************************************************************
|
|
83265
|
+
* The index of the ISO week a date falls in, counting weeks from the
|
|
83266
|
+
* Monday of the epoch week. It is what aligns a MULTI-week bucket (a
|
|
83267
|
+
* fortnight) to a Monday instead of to whatever day 1970-01-01 was.
|
|
83268
|
+
***************************************************************/
|
|
83269
|
+
function week_index(d) {
|
|
83270
|
+
return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
|
|
83271
|
+
}
|
|
83272
|
+
/***************************
|
|
83273
|
+
* Period algebra
|
|
83274
|
+
***************************/
|
|
83275
|
+
/***************************************************************
|
|
83276
|
+
* Normalize whatever a caller hands us into a spec: an id of the
|
|
83277
|
+
* catalog, or a spec of its own. Returns null for anything that is not
|
|
83278
|
+
* a bucket (a "span" / "custom" mode of a navigator has no algebra).
|
|
83279
|
+
***************************************************************/
|
|
83280
|
+
function period_spec(period) {
|
|
83281
|
+
if (!period) return null;
|
|
83282
|
+
let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
|
|
83283
|
+
if (!spec || !spec.unit) return null;
|
|
83284
|
+
if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
|
|
83285
|
+
let count = parseInt(spec.count, 10);
|
|
83286
|
+
if (!(count > 0)) count = 1;
|
|
83287
|
+
return {
|
|
83288
|
+
id: spec.id || spec.unit,
|
|
83289
|
+
unit: spec.unit,
|
|
83290
|
+
count
|
|
83291
|
+
};
|
|
83292
|
+
}
|
|
83293
|
+
/***************************************************************
|
|
83294
|
+
* The START of the bucket that holds `anchor_ms`, as a local Date.
|
|
83295
|
+
*
|
|
83296
|
+
* Alignment is what makes a bucket a bucket. Each unit floors against
|
|
83297
|
+
* the natural origin of the unit above it, so the boundaries are the
|
|
83298
|
+
* ones a human already has in their head:
|
|
83299
|
+
*
|
|
83300
|
+
* minute -> the hour (a 15min bucket starts at :00/:15/:30/:45)
|
|
83301
|
+
* hour -> local midnight (a 6h bucket starts at 00/06/12/18)
|
|
83302
|
+
* day -> 1970-01-01 (count=1 is the plain day; a 10-day
|
|
83303
|
+
* bucket has no calendar origin to
|
|
83304
|
+
* align to, so it aligns to the epoch)
|
|
83305
|
+
* week -> the epoch week, Monday-first (ISO)
|
|
83306
|
+
* month -> January (which is why 2/3/4/6/12 give calendar
|
|
83307
|
+
* bimesters, quarters and semesters)
|
|
83308
|
+
* year -> year 0 (a decade starts at 2020, not 2021)
|
|
83309
|
+
***************************************************************/
|
|
83310
|
+
function period_start(period, anchor_ms) {
|
|
83311
|
+
let spec = period_spec(period);
|
|
83312
|
+
if (!spec) return null;
|
|
83313
|
+
let d = new Date(anchor_ms);
|
|
83314
|
+
let n = spec.count;
|
|
83315
|
+
switch (spec.unit) {
|
|
83316
|
+
case "minute": {
|
|
83317
|
+
let m = Math.floor(d.getMinutes() / n) * n;
|
|
83318
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
|
|
83319
|
+
}
|
|
83320
|
+
case "hour": {
|
|
83321
|
+
let h = Math.floor(d.getHours() / n) * n;
|
|
83322
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
|
|
83323
|
+
}
|
|
83324
|
+
case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
|
|
83325
|
+
case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
|
|
83326
|
+
case "month": {
|
|
83327
|
+
let mi = d.getFullYear() * 12 + d.getMonth();
|
|
83328
|
+
let s = Math.floor(mi / n) * n;
|
|
83329
|
+
return new Date(Math.floor(s / 12), s % 12, 1);
|
|
83330
|
+
}
|
|
83331
|
+
case "year": {
|
|
83332
|
+
let y = Math.floor(d.getFullYear() / n) * n;
|
|
83333
|
+
return new Date(y, 0, 1);
|
|
83334
|
+
}
|
|
83335
|
+
default: return null;
|
|
83336
|
+
}
|
|
83337
|
+
}
|
|
83338
|
+
/***************************************************************
|
|
83339
|
+
* The start of the bucket `delta` buckets away (delta may be negative).
|
|
83340
|
+
* Calendar arithmetic, never millisecond arithmetic: `new Date(y, m+3, 1)`
|
|
83341
|
+
* overflows the year by itself, and stepping a day across a DST change
|
|
83342
|
+
* keeps landing on midnight.
|
|
83343
|
+
***************************************************************/
|
|
83344
|
+
function period_shift(period, anchor_ms, delta) {
|
|
83345
|
+
let spec = period_spec(period);
|
|
83346
|
+
if (!spec) return anchor_ms;
|
|
83347
|
+
let s = period_start(spec, anchor_ms);
|
|
83348
|
+
let step = spec.count * (delta || 0);
|
|
83349
|
+
switch (spec.unit) {
|
|
83350
|
+
case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
|
|
83351
|
+
case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
|
|
83352
|
+
case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
|
|
83353
|
+
case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
|
|
83354
|
+
case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
|
|
83355
|
+
case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
|
|
83356
|
+
default: return anchor_ms;
|
|
83357
|
+
}
|
|
83358
|
+
}
|
|
83359
|
+
/***************************************************************
|
|
83360
|
+
* The bucket holding `anchor_ms`, as {from, to} in MILLISECONDS.
|
|
83361
|
+
*
|
|
83362
|
+
* `to` is INCLUSIVE — the last millisecond of the bucket, not the first
|
|
83363
|
+
* of the next one. Both ends of a match condition are inclusive, and an
|
|
83364
|
+
* exclusive end handed to one silently swallows the record that landed
|
|
83365
|
+
* exactly on the boundary.
|
|
83366
|
+
***************************************************************/
|
|
83367
|
+
function period_bounds(period, anchor_ms) {
|
|
83368
|
+
let spec = period_spec(period);
|
|
83369
|
+
if (!spec) return {
|
|
83370
|
+
from: 0,
|
|
83371
|
+
to: 0
|
|
83372
|
+
};
|
|
83373
|
+
return {
|
|
83374
|
+
from: period_start(spec, anchor_ms).getTime(),
|
|
83375
|
+
to: period_shift(spec, anchor_ms, 1) - 1
|
|
83376
|
+
};
|
|
83377
|
+
}
|
|
83378
|
+
/***************************************************************
|
|
83379
|
+
* The same bucket, in the unit the CONSUMER speaks (a tranger topic
|
|
83380
|
+
* keeps its timestamps in seconds, unless its system_flag says
|
|
83381
|
+
* milliseconds). This is the function a query builder calls.
|
|
83382
|
+
***************************************************************/
|
|
83383
|
+
function period_bounds_epoch(period, anchor_ms, ms) {
|
|
83384
|
+
let b = period_bounds(period, anchor_ms);
|
|
83385
|
+
if (!b.from) return {
|
|
83386
|
+
from: 0,
|
|
83387
|
+
to: 0
|
|
83388
|
+
};
|
|
83389
|
+
return {
|
|
83390
|
+
from: ms_to_epoch(b.from, ms),
|
|
83391
|
+
to: ms_to_epoch(b.to, ms)
|
|
83392
|
+
};
|
|
83393
|
+
}
|
|
83394
|
+
/***************************************************************
|
|
83395
|
+
* A ROLLING window: `secs` back from now. Not a bucket — it has no
|
|
83396
|
+
* previous and no next, it just ends at `now`.
|
|
83397
|
+
*
|
|
83398
|
+
* The `to` end is left OPEN (0). An iterator with no upper bound keeps
|
|
83399
|
+
* matching the records that land while the card is on screen; pinning
|
|
83400
|
+
* it to "now" would freeze the window at the instant the user clicked.
|
|
83401
|
+
***************************************************************/
|
|
83402
|
+
function rolling_bounds(rolling, ms, now_ms) {
|
|
83403
|
+
let r = typeof rolling === "string" ? YUI_ROLLING[rolling] : rolling;
|
|
83404
|
+
if (!r || !r.secs) return {
|
|
83405
|
+
from: 0,
|
|
83406
|
+
to: 0
|
|
83407
|
+
};
|
|
83408
|
+
return {
|
|
83409
|
+
from: ms_to_epoch((now_ms === void 0 ? Date.now() : now_ms) - r.secs * 1e3, ms),
|
|
83410
|
+
to: 0
|
|
83411
|
+
};
|
|
83412
|
+
}
|
|
83413
|
+
/***************************************************************
|
|
83414
|
+
* Is this the LAST bucket — the one `now` falls in? It is what greys
|
|
83415
|
+
* out the "next" arrow, and what tells the navigator it is already home.
|
|
83416
|
+
***************************************************************/
|
|
83417
|
+
function is_current_period(period, anchor_ms, now_ms) {
|
|
83418
|
+
let spec = period_spec(period);
|
|
83419
|
+
if (!spec) return false;
|
|
83420
|
+
let now = now_ms === void 0 ? Date.now() : now_ms;
|
|
83421
|
+
let a = period_start(spec, anchor_ms);
|
|
83422
|
+
let b = period_start(spec, now);
|
|
83423
|
+
return !!a && !!b && a.getTime() === b.getTime();
|
|
83424
|
+
}
|
|
83425
|
+
/***************************************************************
|
|
83426
|
+
* Recognize the bucket a {from, to} pair came from, so a range that
|
|
83427
|
+
* travelled through a URL, a saved view or a backend answer comes back
|
|
83428
|
+
* as the period the user picked instead of as a hand-typed range.
|
|
83429
|
+
*
|
|
83430
|
+
* `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
|
|
83431
|
+
* comparison — that is the whole trap: a bucket ends on the last
|
|
83432
|
+
* MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
|
|
83433
|
+
* it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
|
|
83434
|
+
* seconds-based topic came back as "no bucket at all", every time.
|
|
83435
|
+
*
|
|
83436
|
+
* Only an EXACT match counts: both ends must land on the bucket's own
|
|
83437
|
+
* boundaries, as that consumer would have written them. `candidates` are
|
|
83438
|
+
* ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
|
|
83439
|
+
* null.
|
|
83440
|
+
***************************************************************/
|
|
83441
|
+
function infer_period(from, to, candidates, ms) {
|
|
83442
|
+
if (!from || !to || to <= from) return null;
|
|
83443
|
+
let from_ms = epoch_to_ms(from, ms);
|
|
83444
|
+
for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
|
|
83445
|
+
let spec = period_spec(candidate);
|
|
83446
|
+
if (!spec) continue;
|
|
83447
|
+
let b = period_bounds_epoch(spec, from_ms, ms);
|
|
83448
|
+
if (b.from === from && b.to === to) return {
|
|
83449
|
+
period: spec,
|
|
83450
|
+
anchor: from_ms
|
|
83451
|
+
};
|
|
83452
|
+
}
|
|
83453
|
+
return null;
|
|
83454
|
+
}
|
|
83455
|
+
/***************************
|
|
83456
|
+
* Period labels
|
|
83457
|
+
***************************/
|
|
83458
|
+
/***************************************************************
|
|
83459
|
+
* The name of a GRANULARITY (what the segmented control shows):
|
|
83460
|
+
* the spec's own id as an i18n key, so an app that declares
|
|
83461
|
+
* {id: "quarter"} gets "Trimestre" the moment it adds the key.
|
|
83462
|
+
***************************************************************/
|
|
83463
|
+
function period_name(period, t) {
|
|
83464
|
+
let spec = period_spec(period);
|
|
83465
|
+
if (!spec) return tr(t, String(period && period.id || period || ""));
|
|
83466
|
+
return tr(t, spec.id);
|
|
83467
|
+
}
|
|
83468
|
+
/***************************************************************
|
|
83469
|
+
* The name of the bucket a navigator is PARKED on: what goes between
|
|
83470
|
+
* the two arrows.
|
|
83471
|
+
*
|
|
83472
|
+
* day -> "Today" / "Yesterday" / "13 jul 2026"
|
|
83473
|
+
* week -> "Week 27" (+ year when it is not this one)
|
|
83474
|
+
* month -> "July" (+ year when it is not this one)
|
|
83475
|
+
* quarter -> "Q3 2026" (unit month, count 3)
|
|
83476
|
+
* semester -> "H2 2026" (unit month, count 6)
|
|
83477
|
+
* year -> "2026"
|
|
83478
|
+
* decade -> "2020 – 2029"
|
|
83479
|
+
* any other -> the bucket's own edges: "1 jul – 31 aug 2026"
|
|
83480
|
+
*
|
|
83481
|
+
* The named ones are named because a range reads worse than a name;
|
|
83482
|
+
* everything an app invents falls back to the range, which is always
|
|
83483
|
+
* true and never wrong.
|
|
83484
|
+
***************************************************************/
|
|
83485
|
+
function period_label(period, anchor_ms, t, locale) {
|
|
83486
|
+
let spec = period_spec(period);
|
|
83487
|
+
if (!spec) return "";
|
|
83488
|
+
let loc = safe_locale(locale);
|
|
83489
|
+
let start = period_start(spec, anchor_ms);
|
|
83490
|
+
let end = new Date(period_bounds(spec, anchor_ms).to);
|
|
83491
|
+
let now = /* @__PURE__ */ new Date();
|
|
83492
|
+
let this_year = start.getFullYear() === now.getFullYear();
|
|
83493
|
+
if (spec.unit === "day" && spec.count === 1) {
|
|
83494
|
+
let diff = day_number(start) - day_number(now);
|
|
83495
|
+
if (diff === 0) return tr(t, "today");
|
|
83496
|
+
if (diff === -1) return tr(t, "yesterday");
|
|
83497
|
+
if (diff === 1) return tr(t, "tomorrow");
|
|
83498
|
+
return fmt_intl(start, loc, this_year ? {
|
|
83499
|
+
day: "numeric",
|
|
83500
|
+
month: "short"
|
|
83501
|
+
} : {
|
|
83502
|
+
day: "numeric",
|
|
83503
|
+
month: "short",
|
|
83504
|
+
year: "numeric"
|
|
83505
|
+
});
|
|
83506
|
+
}
|
|
83507
|
+
if (spec.unit === "hour" && spec.count === 1) {
|
|
83508
|
+
let hh = fmt_intl(start, loc, {
|
|
83509
|
+
hour: "2-digit",
|
|
83510
|
+
minute: "2-digit"
|
|
83511
|
+
});
|
|
83512
|
+
if (day_number(start) === day_number(now)) return hh;
|
|
83513
|
+
return `${hh} · ${fmt_intl(start, loc, {
|
|
83514
|
+
day: "numeric",
|
|
83515
|
+
month: "short"
|
|
83516
|
+
})}`;
|
|
83517
|
+
}
|
|
83518
|
+
if (spec.unit === "week" && spec.count === 1) {
|
|
83519
|
+
let away = week_index(start) - week_index(now);
|
|
83520
|
+
if (away === 0) return tr(t, "this week");
|
|
83521
|
+
if (away === -1) return tr(t, "last week");
|
|
83522
|
+
let w = iso_week(start);
|
|
83523
|
+
return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
|
|
83524
|
+
n: w.week,
|
|
83525
|
+
y: w.year
|
|
83526
|
+
});
|
|
83527
|
+
}
|
|
83528
|
+
if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
|
|
83529
|
+
month: "long",
|
|
83530
|
+
year: "numeric"
|
|
83531
|
+
});
|
|
83532
|
+
if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
|
|
83533
|
+
let n = Math.floor(start.getMonth() / spec.count) + 1;
|
|
83534
|
+
return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
|
|
83535
|
+
n,
|
|
83536
|
+
y: start.getFullYear()
|
|
83537
|
+
});
|
|
83538
|
+
}
|
|
83539
|
+
if (spec.unit === "year") {
|
|
83540
|
+
if (spec.count === 1) return String(start.getFullYear());
|
|
83541
|
+
return `${start.getFullYear()} – ${end.getFullYear()}`;
|
|
83542
|
+
}
|
|
83543
|
+
let opts = spec.unit === "minute" || spec.unit === "hour" ? {
|
|
83544
|
+
day: "numeric",
|
|
83545
|
+
month: "short",
|
|
83546
|
+
hour: "2-digit",
|
|
83547
|
+
minute: "2-digit"
|
|
83548
|
+
} : {
|
|
83549
|
+
day: "numeric",
|
|
83550
|
+
month: "short"
|
|
83551
|
+
};
|
|
83552
|
+
if (start.getFullYear() !== end.getFullYear()) {
|
|
83553
|
+
let y_opts = Object.assign({ year: "numeric" }, opts);
|
|
83554
|
+
return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
|
|
83555
|
+
}
|
|
83556
|
+
let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
|
|
83557
|
+
return this_year ? span : `${span} ${start.getFullYear()}`;
|
|
83558
|
+
}
|
|
83559
|
+
//#endregion
|
|
83543
83560
|
//#region src/c_yui_period.js
|
|
83544
83561
|
/***********************************************************************
|
|
83545
83562
|
* c_yui_period.js
|