@brggroup/share-lib 0.1.16 → 0.1.18
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/fesm2022/brggroup-share-lib.mjs +53 -2
- package/fesm2022/brggroup-share-lib.mjs.map +1 -1
- package/lib/components/extend-date-picker/extend-date-picker.d.ts +4 -1
- package/lib/components/extend-date-picker/extend-date-picker.d.ts.map +1 -1
- package/lib/helper/date.helper.d.ts +9 -1
- package/lib/helper/date.helper.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -2049,6 +2049,51 @@ class DateTimeHelper {
|
|
|
2049
2049
|
}
|
|
2050
2050
|
return d1.getTime() === d2.getTime();
|
|
2051
2051
|
}
|
|
2052
|
+
/**
|
|
2053
|
+
* date1 - date2
|
|
2054
|
+
* @param date1
|
|
2055
|
+
* @param date2
|
|
2056
|
+
* @param unit
|
|
2057
|
+
* @returns
|
|
2058
|
+
*/
|
|
2059
|
+
static dateDiff(date1, date2, unit = 'day') {
|
|
2060
|
+
// 1. Kiểm tra tham số đầu vào
|
|
2061
|
+
if (!date1 || !date2) {
|
|
2062
|
+
return NaN;
|
|
2063
|
+
}
|
|
2064
|
+
const d1 = new Date(date1);
|
|
2065
|
+
const d2 = new Date(date2);
|
|
2066
|
+
if (isNaN(d1.getTime()) || isNaN(d2.getTime())) {
|
|
2067
|
+
throw new Error('Tham số ngày không hợp lệ (Invalid Date)');
|
|
2068
|
+
}
|
|
2069
|
+
// 2. Tính chênh lệch mili-giây mặc định (date1 - date2)
|
|
2070
|
+
let diffMs = d1.getTime() - d2.getTime();
|
|
2071
|
+
// 3. Xử lý chuẩn hóa riêng cho "ngày" để tránh sai lệch múi giờ
|
|
2072
|
+
if (unit === 'day') {
|
|
2073
|
+
const utc1 = Date.UTC(d1.getFullYear(), d1.getMonth(), d1.getDate());
|
|
2074
|
+
const utc2 = Date.UTC(d2.getFullYear(), d2.getMonth(), d2.getDate());
|
|
2075
|
+
diffMs = utc1 - utc2;
|
|
2076
|
+
}
|
|
2077
|
+
// 4. Các hằng số quy đổi từ mili-giây
|
|
2078
|
+
const MS_PER_SECOND = 1000;
|
|
2079
|
+
const MS_PER_MINUTE = MS_PER_SECOND * 60;
|
|
2080
|
+
const MS_PER_HOUR = MS_PER_MINUTE * 60;
|
|
2081
|
+
const MS_PER_DAY = MS_PER_HOUR * 24;
|
|
2082
|
+
// 5. Tính toán và trả về kết quả dựa trên unit
|
|
2083
|
+
// Sử dụng Math.trunc() thay vì Math.floor() để giữ đúng phần nguyên trong trường hợp kết quả âm
|
|
2084
|
+
switch (unit) {
|
|
2085
|
+
case 'day':
|
|
2086
|
+
return Math.trunc(diffMs / MS_PER_DAY);
|
|
2087
|
+
case 'hour':
|
|
2088
|
+
return Math.trunc(diffMs / MS_PER_HOUR);
|
|
2089
|
+
case 'minute':
|
|
2090
|
+
return Math.trunc(diffMs / MS_PER_MINUTE);
|
|
2091
|
+
case 'second':
|
|
2092
|
+
return Math.trunc(diffMs / MS_PER_SECOND);
|
|
2093
|
+
default:
|
|
2094
|
+
throw new Error("Đơn vị tính không hợp lệ. Vui lòng dùng 'day', 'hour', 'minute', hoặc 'second'.");
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2052
2097
|
static lstDate(from, to) {
|
|
2053
2098
|
if (!from || !to) {
|
|
2054
2099
|
return [];
|
|
@@ -2238,8 +2283,12 @@ class ExtendDatePicker {
|
|
|
2238
2283
|
}
|
|
2239
2284
|
return '';
|
|
2240
2285
|
}
|
|
2286
|
+
errorMessages = {
|
|
2287
|
+
required: 'Trường yêu cầu nhập',
|
|
2288
|
+
invalidDate: 'Ngày không hợp lệ',
|
|
2289
|
+
};
|
|
2241
2290
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: ExtendDatePicker, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2242
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.7", type: ExtendDatePicker, isStandalone: true, selector: "extend-date-picker", inputs: { dateFormat: "dateFormat", layOutType: "layOutType", label: "label", placeHolder: "placeHolder", labelAlign: "labelAlign", labelSpan: "labelSpan", labelFlex: "labelFlex", inputFlex: "inputFlex", disabled: "disabled", required: "required", noBottom: "noBottom", selectModeType: "selectModeType", inputWidth: "inputWidth", inputHeight: "inputHeight", borderBottomOnly: "borderBottomOnly", displayInline: "displayInline", size: "size", minDate: "minDate", maxDate: "maxDate", lstItem: "lstItem", displayField: "displayField", valueField: "valueField", formData: "formData", controlName: "controlName", _ngModel: "_ngModel", isTouched: "isTouched" }, outputs: { _ngModelChange: "_ngModelChange" }, ngImport: i0, template: "<div class=\"extend-wrapper\" [ngStyle]=\"{ display: displayInline ? 'inline' : null }\">\n @if (controlName) {\n <div [formGroup]=\"formData\">\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"
|
|
2291
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.7", type: ExtendDatePicker, isStandalone: true, selector: "extend-date-picker", inputs: { dateFormat: "dateFormat", layOutType: "layOutType", label: "label", placeHolder: "placeHolder", labelAlign: "labelAlign", labelSpan: "labelSpan", labelFlex: "labelFlex", inputFlex: "inputFlex", disabled: "disabled", required: "required", noBottom: "noBottom", selectModeType: "selectModeType", inputWidth: "inputWidth", inputHeight: "inputHeight", borderBottomOnly: "borderBottomOnly", displayInline: "displayInline", size: "size", minDate: "minDate", maxDate: "maxDate", lstItem: "lstItem", displayField: "displayField", valueField: "valueField", formData: "formData", controlName: "controlName", _ngModel: "_ngModel", isTouched: "isTouched", errorMessages: "errorMessages" }, outputs: { _ngModelChange: "_ngModelChange" }, ngImport: i0, template: "<div class=\"extend-wrapper\" [ngStyle]=\"{ display: displayInline ? 'inline' : null }\">\n @if (controlName) {\n <div [formGroup]=\"formData\">\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"dynamicErrorTemplate\"\n >\n <nz-date-picker\n class=\"full-width\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [nzSize]=\"size\"\n [formControlName]=\"controlName\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n ></nz-date-picker>\n </nz-form-control>\n </nz-form-item>\n\n <ng-template #dynamicErrorTemplate let-control>\n <ng-container *ngFor=\"let error of errorMessages | keyvalue\">\n <ng-container *ngIf=\"control.hasError(error.key)\">\n {{ error.value }}\n </ng-container>\n </ng-container>\n </ng-template>\n </div>\n } @else {\n @if (label) {\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"errorMessage\"\n [nzValidateStatus]=\"errorMessage ? 'error' : ''\"\n >\n <nz-date-picker\n class=\"full-width\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [nzSize]=\"size\"\n [disabled]=\"disabled\"\n [nzDisabledDate]=\"disabledDate\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n [(ngModel)]=\"_ngModel\"\n (ngModelChange)=\"onNgModelChange($event)\"\n (blur)=\"onBlur()\"\n ></nz-date-picker>\n </nz-form-control>\n </nz-form-item>\n } @else {\n <nz-date-picker\n class=\"full-width\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n [nzSize]=\"size\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [disabled]=\"disabled\"\n [(ngModel)]=\"_ngModel\"\n (ngModelChange)=\"onNgModelChange($event)\"\n ></nz-date-picker>\n }\n }\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1$3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "pipe", type: i1$3.KeyValuePipe, name: "keyvalue" }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i2$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "ngmodule", type: NzFormModule }, { kind: "directive", type: i4.NzColDirective, selector: "[nz-col],nz-col,nz-form-control,nz-form-label", inputs: ["nzFlex", "nzSpan", "nzOrder", "nzOffset", "nzPush", "nzPull", "nzXs", "nzSm", "nzMd", "nzLg", "nzXl", "nzXXl"], exportAs: ["nzCol"] }, { kind: "directive", type: i4.NzRowDirective, selector: "[nz-row],nz-row,nz-form-item", inputs: ["nzAlign", "nzJustify", "nzGutter"], exportAs: ["nzRow"] }, { kind: "component", type: i5.NzFormItemComponent, selector: "nz-form-item", exportAs: ["nzFormItem"] }, { kind: "component", type: i5.NzFormLabelComponent, selector: "nz-form-label", inputs: ["nzFor", "nzRequired", "nzNoColon", "nzTooltipTitle", "nzTooltipIcon", "nzLabelAlign", "nzLabelWrap"], exportAs: ["nzFormLabel"] }, { kind: "component", type: i5.NzFormControlComponent, selector: "nz-form-control", inputs: ["nzSuccessTip", "nzWarningTip", "nzErrorTip", "nzValidatingTip", "nzExtra", "nzAutoTips", "nzDisableAutoTips", "nzHasFeedback", "nzValidateStatus"], exportAs: ["nzFormControl"] }, { kind: "ngmodule", type: NzDatePickerModule }, { kind: "component", type: i5$1.NzDatePickerComponent, selector: "nz-date-picker,nz-week-picker,nz-month-picker,nz-quarter-picker,nz-year-picker,nz-range-picker", inputs: ["nzAllowClear", "nzAutoFocus", "nzDisabled", "nzBorderless", "nzInputReadOnly", "nzInline", "nzOpen", "nzDisabledDate", "nzLocale", "nzPlaceHolder", "nzPopupStyle", "nzDropdownClassName", "nzSize", "nzStatus", "nzFormat", "nzDateRender", "nzDisabledTime", "nzRenderExtraFooter", "nzShowToday", "nzMode", "nzShowNow", "nzRanges", "nzDefaultPickerValue", "nzSeparator", "nzSuffixIcon", "nzBackdrop", "nzId", "nzPlacement", "nzShowWeekNumber", "nzShowTime"], outputs: ["nzOnPanelChange", "nzOnCalendarChange", "nzOnOk", "nzOnOpenChange"], exportAs: ["nzDatePicker"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "directive", type: DateInputParserDirective, selector: "nz-date-picker", inputs: ["format"] }] });
|
|
2243
2292
|
}
|
|
2244
2293
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: ExtendDatePicker, decorators: [{
|
|
2245
2294
|
type: Component,
|
|
@@ -2251,7 +2300,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImpor
|
|
|
2251
2300
|
NzDatePickerModule,
|
|
2252
2301
|
TranslateModule,
|
|
2253
2302
|
DateInputParserDirective,
|
|
2254
|
-
], template: "<div class=\"extend-wrapper\" [ngStyle]=\"{ display: displayInline ? 'inline' : null }\">\n @if (controlName) {\n <div [formGroup]=\"formData\">\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"
|
|
2303
|
+
], template: "<div class=\"extend-wrapper\" [ngStyle]=\"{ display: displayInline ? 'inline' : null }\">\n @if (controlName) {\n <div [formGroup]=\"formData\">\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"dynamicErrorTemplate\"\n >\n <nz-date-picker\n class=\"full-width\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [nzSize]=\"size\"\n [formControlName]=\"controlName\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n ></nz-date-picker>\n </nz-form-control>\n </nz-form-item>\n\n <ng-template #dynamicErrorTemplate let-control>\n <ng-container *ngFor=\"let error of errorMessages | keyvalue\">\n <ng-container *ngIf=\"control.hasError(error.key)\">\n {{ error.value }}\n </ng-container>\n </ng-container>\n </ng-template>\n </div>\n } @else {\n @if (label) {\n <nz-form-item>\n <nz-form-label\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? labelSpan : null\"\n [nzFlex]=\"labelFlex\"\n [nzLabelAlign]=\"labelAlign\"\n [nzRequired]=\"required\"\n [nzFor]=\"controlName\"\n nzNoColon\n nzLabelWrap\n >\n {{ label }}\n </nz-form-label>\n <nz-form-control\n [nzSpan]=\"layOutType == 'horizontal' && !labelFlex ? 24 - labelSpan : null\"\n [nzFlex]=\"inputFlex\"\n [ngClass]=\"{ 'full-width': layOutType == 'vertical' }\"\n [nzErrorTip]=\"errorMessage\"\n [nzValidateStatus]=\"errorMessage ? 'error' : ''\"\n >\n <nz-date-picker\n class=\"full-width\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [nzSize]=\"size\"\n [disabled]=\"disabled\"\n [nzDisabledDate]=\"disabledDate\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n [(ngModel)]=\"_ngModel\"\n (ngModelChange)=\"onNgModelChange($event)\"\n (blur)=\"onBlur()\"\n ></nz-date-picker>\n </nz-form-control>\n </nz-form-item>\n } @else {\n <nz-date-picker\n class=\"full-width\"\n [ngStyle]=\"{\n width: inputWidth,\n height: inputHeight,\n }\"\n [ngClass]=\"{\n 'border-bottom-only': borderBottomOnly,\n }\"\n [nzSize]=\"size\"\n [nzPlaceHolder]=\"placeHolder || ' '\"\n [nzFormat]=\"dateFormat\"\n [disabled]=\"disabled\"\n [(ngModel)]=\"_ngModel\"\n (ngModelChange)=\"onNgModelChange($event)\"\n ></nz-date-picker>\n }\n }\n</div>\n" }]
|
|
2255
2304
|
}], propDecorators: { dateFormat: [{
|
|
2256
2305
|
type: Input
|
|
2257
2306
|
}], layOutType: [{
|
|
@@ -2306,6 +2355,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImpor
|
|
|
2306
2355
|
type: Output
|
|
2307
2356
|
}], isTouched: [{
|
|
2308
2357
|
type: Input
|
|
2358
|
+
}], errorMessages: [{
|
|
2359
|
+
type: Input
|
|
2309
2360
|
}] } });
|
|
2310
2361
|
|
|
2311
2362
|
class ExtendDateRangePicker {
|