@bbn/bbn 1.0.456 → 1.0.458
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/date.d.ts +2 -1
- package/dist/date.js +5 -5
- package/dist/fn/datetime/calendar.d.ts +1 -1
- package/dist/fn/datetime/calendar.js +3 -15
- package/dist/fn/datetime/daysInMonth.d.ts +1 -1
- package/dist/fn/datetime/daysInMonth.js +2 -5
- package/dist/fn/datetime/fdate.d.ts +1 -1
- package/dist/fn/datetime/fdate.js +6 -10
- package/dist/fn/datetime/fdatetime.d.ts +1 -1
- package/dist/fn/datetime/fdatetime.js +3 -15
- package/dist/fn/datetime/formatDate.d.ts +1 -1
- package/dist/fn/datetime/formatDate.js +7 -2
- package/dist/fn/datetime/ftime.js +3 -7
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class bbnDateTool {
|
|
|
32
32
|
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
|
33
33
|
*/
|
|
34
34
|
compare(date: any, unit?: string): -1 | 0 | 1;
|
|
35
|
+
isValid(): boolean;
|
|
35
36
|
isBefore(date: any, unit?: string): Boolean;
|
|
36
37
|
isAfter(date: any, unit?: string): Boolean;
|
|
37
38
|
isSame(date: any, unit?: string): Boolean;
|
|
@@ -42,7 +43,7 @@ declare class bbnDateTool {
|
|
|
42
43
|
guessUnit(valueInMs: number): string | null;
|
|
43
44
|
diff(date: any, unit?: string, abs?: boolean): number;
|
|
44
45
|
calendar(format: string): string;
|
|
45
|
-
get daysInMonth():
|
|
46
|
+
get daysInMonth(): number;
|
|
46
47
|
}
|
|
47
48
|
declare function generatorFunction(value: any, inputFormat?: null | String): bbnDateTool;
|
|
48
49
|
export default generatorFunction;
|
package/dist/date.js
CHANGED
|
@@ -203,7 +203,7 @@ const unitsCorrespondence = {
|
|
|
203
203
|
class bbnDateTool {
|
|
204
204
|
constructor(value, inputFormat = null) {
|
|
205
205
|
_bbnDateTool_value.set(this, void 0);
|
|
206
|
-
_bbnDateTool_daysInMonth.set(this,
|
|
206
|
+
_bbnDateTool_daysInMonth.set(this, 0);
|
|
207
207
|
if (!value) {
|
|
208
208
|
__classPrivateFieldSet(this, _bbnDateTool_value, new Date(), "f");
|
|
209
209
|
}
|
|
@@ -428,6 +428,9 @@ class bbnDateTool {
|
|
|
428
428
|
}
|
|
429
429
|
return 0;
|
|
430
430
|
}
|
|
431
|
+
isValid() {
|
|
432
|
+
return __classPrivateFieldGet(this, _bbnDateTool_value, "f") !== undefined;
|
|
433
|
+
}
|
|
431
434
|
isBefore(date, unit = '') {
|
|
432
435
|
return this.compare(date, unit) === -1;
|
|
433
436
|
}
|
|
@@ -493,10 +496,7 @@ class bbnDateTool {
|
|
|
493
496
|
return str;
|
|
494
497
|
}
|
|
495
498
|
get daysInMonth() {
|
|
496
|
-
if (!__classPrivateFieldGet(this,
|
|
497
|
-
return 0;
|
|
498
|
-
}
|
|
499
|
-
if (!__classPrivateFieldGet(this, _bbnDateTool_daysInMonth, "f")) {
|
|
499
|
+
if (this.isValid && !__classPrivateFieldGet(this, _bbnDateTool_daysInMonth, "f")) {
|
|
500
500
|
switch (__classPrivateFieldGet(this, _bbnDateTool_value, "f").getMonth()) {
|
|
501
501
|
case 1:
|
|
502
502
|
if (__classPrivateFieldGet(this, _bbnDateTool_value, "f").getFullYear() % 4 === 0) {
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
* @param {String | Boolean} wrong_result Whether or not include the time in the date
|
|
17
17
|
* @returns {String}
|
|
18
18
|
*/
|
|
19
|
-
export default function calendar(d: any, wrong_result?: boolean):
|
|
19
|
+
export default function calendar(d: any, wrong_result?: boolean): string | true;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import isLeapYear from 'dayjs/plugin/isLeapYear.js';
|
|
3
3
|
import dayjs_plugin_calendar from 'dayjs/plugin/calendar.js';
|
|
4
|
-
import
|
|
5
|
-
import date from './date.js';
|
|
6
|
-
import isDate from '../type/isDate.js';
|
|
4
|
+
import date from '../../date.js';
|
|
7
5
|
import isString from '../type/isString.js';
|
|
8
6
|
const bbn = {
|
|
9
7
|
_: st => st
|
|
@@ -29,20 +27,10 @@ dayjs.extend(isLeapYear);
|
|
|
29
27
|
* @returns {String}
|
|
30
28
|
*/
|
|
31
29
|
export default function calendar(d, wrong_result = false) {
|
|
32
|
-
if (undefined === dayjs) {
|
|
33
|
-
return fdate(d, wrong_result);
|
|
34
|
-
}
|
|
35
30
|
let r = date(d);
|
|
36
|
-
if (!
|
|
31
|
+
if (!r.isValid) {
|
|
37
32
|
return wrong_result && isString(wrong_result) ? wrong_result : '';
|
|
38
33
|
}
|
|
39
|
-
return
|
|
40
|
-
sameDay: '[' + bbn._('Today') + ']',
|
|
41
|
-
nextDay: '[' + bbn._('Tomorrow') + ']',
|
|
42
|
-
nextWeek: 'ddd D',
|
|
43
|
-
lastDay: '[' + bbn._('Yesterday') + ']',
|
|
44
|
-
lastWeek: 'ddd D',
|
|
45
|
-
sameElse: 'L',
|
|
46
|
-
});
|
|
34
|
+
return r.fdate();
|
|
47
35
|
}
|
|
48
36
|
;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import date from '
|
|
1
|
+
import date from '../../date.js';
|
|
2
2
|
/**
|
|
3
3
|
* Returns the number of days of the month given in the date.
|
|
4
4
|
* @method daysInMonth
|
|
@@ -16,9 +16,6 @@ import date from './date.js';
|
|
|
16
16
|
*/
|
|
17
17
|
export default function daysInMonth(v) {
|
|
18
18
|
let d = date(v);
|
|
19
|
-
|
|
20
|
-
return dayjs(d).daysInMonth();
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
19
|
+
return d.daysInMonth;
|
|
23
20
|
}
|
|
24
21
|
;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import date from './date.js';
|
|
3
|
-
import isDate from '../type/isDate.js';
|
|
1
|
+
import date from '../../date.js';
|
|
4
2
|
import isString from '../type/isString.js';
|
|
5
3
|
/**
|
|
6
4
|
* @method fdate
|
|
@@ -12,17 +10,15 @@ import isString from '../type/isString.js';
|
|
|
12
10
|
* @returns
|
|
13
11
|
*/
|
|
14
12
|
export default function fdate(d, wrong_result = false) {
|
|
13
|
+
let r = date(d);
|
|
14
|
+
let time = false;
|
|
15
15
|
// Retro compatibility
|
|
16
16
|
if (wrong_result === true) {
|
|
17
|
-
|
|
17
|
+
time = true;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
if (!isDate(r)) {
|
|
19
|
+
if (!r.isValid) {
|
|
21
20
|
return wrong_result && isString(wrong_result) ? wrong_result : '';
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
return dayjs(r).format('L');
|
|
25
|
-
}
|
|
26
|
-
return r.toLocaleDateString();
|
|
22
|
+
return r.fdate(true, time);
|
|
27
23
|
}
|
|
28
24
|
;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import date from '
|
|
2
|
-
import isDate from '../type/isDate.js';
|
|
1
|
+
import date from '../../date.js';
|
|
3
2
|
import isString from '../type/isString.js';
|
|
4
3
|
/**
|
|
5
4
|
* @method fdatetime
|
|
@@ -10,20 +9,9 @@ import isString from '../type/isString.js';
|
|
|
10
9
|
*/
|
|
11
10
|
export default function fdatetime(d, wrong_result = false) {
|
|
12
11
|
let r = date(d);
|
|
13
|
-
if (!
|
|
12
|
+
if (!r.isValid) {
|
|
14
13
|
return wrong_result && isString(wrong_result) ? wrong_result : '';
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
return dayjs(r).calendar(null, {
|
|
18
|
-
sameDay: '[' + bbn._('Today') + '] HH:mm',
|
|
19
|
-
nextDay: '[' + bbn._('Tomorrow') + '] HH:mm',
|
|
20
|
-
nextWeek: 'ddd D HH:mm',
|
|
21
|
-
lastDay: '[' + bbn._('Yesterday') + '] HH:mm',
|
|
22
|
-
lastWeek: 'ddd D HH:mm',
|
|
23
|
-
sameElse: 'DD/MM/YYYY HH:mm',
|
|
24
|
-
});
|
|
25
|
-
//return dayjs(r).format("DD/MM/YYYY HH:mm")
|
|
26
|
-
}
|
|
27
|
-
return r.toLocaleDateString();
|
|
15
|
+
return r.fdate(false, true);
|
|
28
16
|
}
|
|
29
17
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function formatDate(
|
|
1
|
+
export default function formatDate(dateToFormat: any, format: any): string;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import date from '../../date.js';
|
|
2
|
+
export default function formatDate(dateToFormat, format) {
|
|
3
|
+
const d = date(dateToFormat);
|
|
4
|
+
if (!d.isValid) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
return d.format(format);
|
|
3
8
|
}
|
|
4
9
|
;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import date from '
|
|
2
|
-
import isDate from '../type/isDate.js';
|
|
1
|
+
import date from '../../date.js';
|
|
3
2
|
import isString from '../type/isString.js';
|
|
4
3
|
/**
|
|
5
4
|
* @method ftime
|
|
@@ -10,12 +9,9 @@ import isString from '../type/isString.js';
|
|
|
10
9
|
*/
|
|
11
10
|
export default function ftime(d, wrong_result) {
|
|
12
11
|
let r = date(d);
|
|
13
|
-
if (!
|
|
12
|
+
if (!r.isValid) {
|
|
14
13
|
return wrong_result && isString(wrong_result) ? wrong_result : '';
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
return dayjs(r).calendar();
|
|
18
|
-
}
|
|
19
|
-
return r.toLocaleDateString();
|
|
15
|
+
return r.ftime();
|
|
20
16
|
}
|
|
21
17
|
;
|