Base solution for your next web application
Open Closed

moment _isUtc: true #8082


User avatar
0
murat.yuceer created

Hello,

I using zero with default utc settings (ClockProviders.Unspecified)

My Task entity store ReminderTime and in database its look like 2019-11-04 12:06:05 When api get this record its look like reminderTime: "2019-11-13T12:06:05"

But when i write to angular app => console.log(this.userTask.reminderTime); its look like bellow _isUTC field is true. Because of that when i call console.log(this.userTask.reminderTime.toDate()); function its write Wed Nov 13 2019 12:06:05 GMT+0300 (GMT+03:00) and bsDatepicker add 3 hours I confused its should _isUTC false right?

Moment {_isAMomentObject: true, _i: "2019-11-13T12:06:05", _f: "YYYY-MM-DDTHH:mm:ss", _isUTC: false, _pf: {…}, …} _a: (7) [2019, 10, 13, 12, 6, 5, 0] _d: Wed Nov 13 2019 15:06:05 GMT+0300 (GMT+03:00) {} _f: "YYYY-MM-DDTHH:mm:ss" _i: "2019-11-13T12:06:05" _isAMomentObject: true _isUTC: true _isValid: true _locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _dayOfMonthOrdinalParse: /\d{1,2}/, ordinal: ƒ, …} _offset: 0 _pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -1, charsLeftOver: 0, …} _z: null proto: Object


5 Answer(s)
  • User Avatar
    0
    murat.yuceer created

    I guess bsDatepicker bind moment wrong??

  • User Avatar
    0
    murat.yuceer created

    Actualy my problem is, when i save db is save correct but when i show form is show wrong hours (showing utc hours)

    bsDatepicker

    <input class="form-control m-input" type="datetime" bsDatepicker [bsConfig]="{ dateInputFormat: 'DD-MM-YYYY, HH:mm'}" [(ngModel)]="reminderTime" id="UserTask_ReminderTime" name="UserTask_ReminderTime">

    show function

    show(userTaskId?: string): void {
        this.reminderTime = null;
    
        if (!userTaskId) {
            this.userTask = new CreateOrEditUserTaskDto();
            this.userTask.id = userTaskId;
            this.userTask.state = TaskState.Open;
    
            this.active = true;
            this.modal.show();
        } else {
            this._userTasksServiceProxy.getUserTaskForEdit(userTaskId).subscribe(result => {
                this.userTask = result.userTask;
                if (this.userTask.reminderTime) {
                    this.reminderTime = this.userTask.reminderTime.toDate();
                }
    
                this.active = true;
                this.modal.show();
            });
        }
    }
    

    save function save(): void { this.saving = true;

        if (this.reminderTime) {
            if (!this.userTask.reminderTime) {
                this.userTask.reminderTime = moment(this.reminderTime, "DD-MM-YYYY, HH:mm");
            }
            else {
                this.userTask.reminderTime = moment(this.reminderTime, "DD-MM-YYYY, HH:mm");
            }
        }
        else {
            this.userTask.reminderTime = null;
        }
        this._userTasksServiceProxy.createOrEdit(this.userTask)
            .pipe(finalize(() => { this.saving = false; }))
            .subscribe(() => {
                this.notify.info(this.l('SavedSuccessfully'));
                this.close();
                this.modalSave.emit(null);
            });
    }
    
  • User Avatar
    1
    murat.yuceer created

    I fixed problem, bsDatepicker have bug on 5.20 versiyon i updated it 5.3 and problem resolved

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Do you also use datePickerMomentModifier in ypur input element ?

  • User Avatar
    0
    murat.yuceer created

    I created example for you understand what is bug

    this is correct result for current datetime (5.3.2) https://stackblitz.com/edit/angular-qbj9cv?file=app/ngx-bootstrap-demo.component.ts

    after change package.json "ngx-bootstrap": "5.3.2" to "ngx-bootstrap": "5.2.0" then you will see time wrong