Fix: Proper date handling

This commit is contained in:
Amritanshu Agrawal 2021-01-12 12:08:08 +05:30
parent 0233e7145b
commit 15f04b4cf1
3 changed files with 38 additions and 14 deletions

View File

@ -1,8 +1,8 @@
import * as moment from 'moment';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { Observable } from 'rxjs';
import { distinctUntilChanged, startWith, switchMap } from 'rxjs/operators';
@ -112,16 +112,22 @@ export class CaseDetailComponent implements OnInit, AfterViewInit {
year: this.item.year,
title: this.item.title,
docketNumber: this.item.docketNumber,
receiptDate: moment(this.item.receiptDate, 'DD-MMM-YYYY').toDate(),
limitationDate: moment(this.item.limitationDate, 'DD-MMM-YYYY').toDate(),
filingDate: moment(this.item.filingDate, 'DD-MMM-YYYY').toDate(),
receiptDate: this.item.receiptDate
? moment(this.item.receiptDate, 'DD-MMM-YYYY').toDate()
: '',
limitationDate: this.item.limitationDate
? moment(this.item.limitationDate, 'DD-MMM-YYYY').toDate()
: '',
filingDate: this.item.filingDate ? moment(this.item.filingDate, 'DD-MMM-YYYY').toDate() : '',
appearOnBehalfOf: this.item.appearOnBehalfOf,
questionOfLaw: this.item.questionOfLaw,
aorName: this.item.aorName,
opposingCouncilAor: this.item.opposingCouncilAor,
opposingCouncilDetail: this.item.opposingCouncilDetail,
lowerCourtCaseNumber: this.item.lowerCourtCaseNumber,
dateOfImpugnedJudgement: moment(this.item.dateOfImpugnedJudgement, 'DD-MMM-YYYY').toDate(),
dateOfImpugnedJudgement: this.item.dateOfImpugnedJudgement
? moment(this.item.dateOfImpugnedJudgement, 'DD-MMM-YYYY').toDate()
: '',
briefDescription: this.item.briefDescription,
remarks: this.item.remarks,
slpCounter: this.item.slpCounter,
@ -197,16 +203,35 @@ export class CaseDetailComponent implements OnInit, AfterViewInit {
this.item.year = formModel.year;
this.item.title = formModel.title;
this.item.docketNumber = formModel.docketNumber;
this.item.receiptDate = formModel.receiptDate;
this.item.limitationDate = formModel.limitationDate;
this.item.filingDate = formModel.filingDate;
if (formModel.receiptDate === '') {
this.item.receiptDate = null;
} else {
this.item.receiptDate = moment(formModel.receiptDate).format('DD-MMM-YYYY');
}
if (formModel.limitationDate === '') {
this.item.limitationDate = null;
} else {
this.item.limitationDate = moment(formModel.limitationDate).format('DD-MMM-YYYY');
}
console.log(formModel.filingDate);
if (formModel.filingDate === '') {
this.item.filingDate = null;
} else {
this.item.filingDate = moment(formModel.filingDate).format('DD-MMM-YYYY');
}
this.item.appearOnBehalfOf = formModel.appearOnBehalfOf;
this.item.questionOfLaw = formModel.questionOfLaw;
this.item.aorName = formModel.aorName;
this.item.opposingCouncilAor = formModel.opposingCouncilAor;
this.item.opposingCouncilDetail = formModel.opposingCouncilDetail;
this.item.lowerCourtCaseNumber = formModel.lowerCourtCaseNumber;
this.item.dateOfImpugnedJudgement = formModel.dateOfImpugnedJudgement;
if (formModel.dateOfImpugnedJudgement === '') {
this.item.dateOfImpugnedJudgement = null;
} else {
this.item.dateOfImpugnedJudgement = moment(formModel.dateOfImpugnedJudgement).format(
'DD-MMM-YYYY',
);
}
this.item.briefDescription = formModel.briefDescription;
this.item.remarks = formModel.remarks;
this.item.slpCounter = formModel.slpCounter;

View File

@ -24,7 +24,6 @@ import { CaseDetailComponent } from './case-detail/case-detail.component';
import { CaseListComponent } from './case-list/case-list.component';
import { CasesRoutingModule } from './cases-routing.module';
export const MY_FORMATS = {
parse: {
dateInput: 'DD-MMM-YYYY',

View File

@ -14,16 +14,16 @@ export class Case {
year: string;
title: string;
docketNumber: string;
receiptDate: string;
limitationDate: string;
filingDate: string;
receiptDate: string | null;
limitationDate: string | null;
filingDate: string | null;
appearOnBehalfOf: string;
questionOfLaw: string;
aorName: string;
opposingCouncilAor: string;
opposingCouncilDetail: string;
lowerCourtCaseNumber: string;
dateOfImpugnedJudgement: string;
dateOfImpugnedJudgement: string | null;
briefDescription: string;
remarks: string;
slpCounter: string;