@formant/ava 3.5.1-formant → 3.5.2-formant
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/ava.min.js +1 -1
- package/esm/utils/dateFormat.js +13 -2
- package/lib/utils/dateFormat.js +13 -2
- package/package.json +1 -1
package/esm/utils/dateFormat.js
CHANGED
|
@@ -15,13 +15,24 @@ export var parseInsightDate = function (value) {
|
|
|
15
15
|
var date = new Date(value.length === 10 ? "".concat(value, "T00:00:00") : value.replace(' ', 'T'));
|
|
16
16
|
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
// a zone designator means an absolute instant (e.g. an hourly UTC bucket): always show its time
|
|
19
|
+
var ZONED = /\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to print a time of day. Zoned instants always do, so an hourly series reads
|
|
22
|
+
* `Oct 6, 23:00`, `Oct 7, 00:00` rather than switching to a date at local midnight. Zone-less
|
|
23
|
+
* values only do when the clock is not midnight (`2025-03-19 00:00:00` is a daily bucket).
|
|
24
|
+
*/
|
|
25
|
+
var showsTime = function (value, date) {
|
|
26
|
+
return value instanceof Date || (typeof value === 'string' && ZONED.test(value))
|
|
27
|
+
? true
|
|
28
|
+
: date.getHours() !== 0 || date.getMinutes() !== 0;
|
|
29
|
+
};
|
|
19
30
|
/** `Oct 7, 2026`, or `Oct 7, 14:00` when the value carries a time of day; non-dates pass through */
|
|
20
31
|
export var formatInsightDate = function (value) {
|
|
21
32
|
var date = parseInsightDate(value);
|
|
22
33
|
if (!date)
|
|
23
34
|
return String(value);
|
|
24
|
-
return format(date,
|
|
35
|
+
return format(date, showsTime(value, date) ? 'MMM d, HH:mm' : 'MMM d, yyyy');
|
|
25
36
|
};
|
|
26
37
|
/** `Oct 6 - 7, 2026` style range (little-date); non-dates fall back to `start ~ end` */
|
|
27
38
|
export var formatInsightDateRange = function (start, end) {
|
package/lib/utils/dateFormat.js
CHANGED
|
@@ -19,13 +19,24 @@ var parseInsightDate = function (value) {
|
|
|
19
19
|
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
20
20
|
};
|
|
21
21
|
exports.parseInsightDate = parseInsightDate;
|
|
22
|
-
|
|
22
|
+
// a zone designator means an absolute instant (e.g. an hourly UTC bucket): always show its time
|
|
23
|
+
var ZONED = /\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to print a time of day. Zoned instants always do, so an hourly series reads
|
|
26
|
+
* `Oct 6, 23:00`, `Oct 7, 00:00` rather than switching to a date at local midnight. Zone-less
|
|
27
|
+
* values only do when the clock is not midnight (`2025-03-19 00:00:00` is a daily bucket).
|
|
28
|
+
*/
|
|
29
|
+
var showsTime = function (value, date) {
|
|
30
|
+
return value instanceof Date || (typeof value === 'string' && ZONED.test(value))
|
|
31
|
+
? true
|
|
32
|
+
: date.getHours() !== 0 || date.getMinutes() !== 0;
|
|
33
|
+
};
|
|
23
34
|
/** `Oct 7, 2026`, or `Oct 7, 14:00` when the value carries a time of day; non-dates pass through */
|
|
24
35
|
var formatInsightDate = function (value) {
|
|
25
36
|
var date = (0, exports.parseInsightDate)(value);
|
|
26
37
|
if (!date)
|
|
27
38
|
return String(value);
|
|
28
|
-
return (0, date_fns_1.format)(date,
|
|
39
|
+
return (0, date_fns_1.format)(date, showsTime(value, date) ? 'MMM d, HH:mm' : 'MMM d, yyyy');
|
|
29
40
|
};
|
|
30
41
|
exports.formatInsightDate = formatInsightDate;
|
|
31
42
|
/** `Oct 6 - 7, 2026` style range (little-date); non-dates fall back to `start ~ end` */
|