@bbn/bbn 2.0.178 → 2.0.179
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/classes/dt.js +7 -2
- package/dist/dt/vars/units.js +12 -5
- package/package.json +1 -1
package/dist/dt/classes/dt.js
CHANGED
|
@@ -978,13 +978,18 @@ export class bbnDt {
|
|
|
978
978
|
if (!chosenUnit) {
|
|
979
979
|
throw new Error('Cannot guess unit for fromNow');
|
|
980
980
|
}
|
|
981
|
-
|
|
981
|
+
let diff = this.diff(temp, chosenUnit);
|
|
982
982
|
const rtf = new Intl.RelativeTimeFormat([bbn.env.lang, ...navigator.languages], { numeric: 'auto' });
|
|
983
983
|
const match = getRow(units, d => d[0] === chosenUnit);
|
|
984
984
|
if (!match) {
|
|
985
985
|
throw new Error('Invalid unit for fromNow: ' + unit);
|
|
986
986
|
}
|
|
987
|
-
|
|
987
|
+
let [, rtfUnit] = match; // [shortUnit, rtfUnit, ms]
|
|
988
|
+
if (rtfUnit === 'millisecond') {
|
|
989
|
+
rtfUnit = 'second';
|
|
990
|
+
diff = Math.round(diff / 1000);
|
|
991
|
+
}
|
|
992
|
+
bbn.fn.log("FROM NOW", diff, rtfUnit, rtf);
|
|
988
993
|
return rtf.format(diff, rtfUnit);
|
|
989
994
|
}
|
|
990
995
|
from(date, unit = '') {
|
package/dist/dt/vars/units.js
CHANGED
|
@@ -6,7 +6,7 @@ const units = [
|
|
|
6
6
|
['h', "hour", 60 * 60 * 1000],
|
|
7
7
|
['i', "minute", 60 * 1000],
|
|
8
8
|
['s', "second", 1000],
|
|
9
|
-
['
|
|
9
|
+
['x', "millisecond", 1]
|
|
10
10
|
];
|
|
11
11
|
const unitsCorrespondence = {
|
|
12
12
|
'years': 'y',
|
|
@@ -50,6 +50,12 @@ const unitsCorrespondence = {
|
|
|
50
50
|
'HH': 'h',
|
|
51
51
|
'hr': 'h',
|
|
52
52
|
'hh': 'h',
|
|
53
|
+
'milliseconds': 'x',
|
|
54
|
+
'millisecond': 'x',
|
|
55
|
+
'Milliseconds': 'x',
|
|
56
|
+
'Millisecond': 'x',
|
|
57
|
+
'MILLISECONDS': 'x',
|
|
58
|
+
'MILLISECOND': 'x',
|
|
53
59
|
'minutes': 'i',
|
|
54
60
|
'minute': 'i',
|
|
55
61
|
'Minutes': 'i',
|
|
@@ -61,9 +67,9 @@ const unitsCorrespondence = {
|
|
|
61
67
|
'mn': 'i',
|
|
62
68
|
'mm': 'i',
|
|
63
69
|
'min': 'i',
|
|
64
|
-
'ms': '
|
|
65
|
-
'SSS': '
|
|
66
|
-
'sss': '
|
|
70
|
+
'ms': 'x',
|
|
71
|
+
'SSS': 'x',
|
|
72
|
+
'sss': 'x',
|
|
67
73
|
'SS': 's',
|
|
68
74
|
'ss': 's',
|
|
69
75
|
'seconds': 's',
|
|
@@ -101,7 +107,7 @@ const unitsMap = {
|
|
|
101
107
|
'h': 'Hours',
|
|
102
108
|
'i': 'Minutes',
|
|
103
109
|
's': 'Seconds',
|
|
104
|
-
'
|
|
110
|
+
'x': 'Milliseconds',
|
|
105
111
|
'z': 'Offset'
|
|
106
112
|
};
|
|
107
113
|
const formatsMap = {
|
|
@@ -113,6 +119,7 @@ const formatsMap = {
|
|
|
113
119
|
'h': 'HH',
|
|
114
120
|
'i': 'II',
|
|
115
121
|
's': 'SS',
|
|
122
|
+
'x': 'SSS',
|
|
116
123
|
'z': 'Z'
|
|
117
124
|
};
|
|
118
125
|
export { units, unitsCorrespondence, unitsMap, formatsMap };
|