From 15f04b4cf1e2467109fba1073ac67257244f36f7 Mon Sep 17 00:00:00 2001 From: tanshu Date: Tue, 12 Jan 2021 12:08:08 +0530 Subject: [PATCH] Fix: Proper date handling --- .../case-detail/case-detail.component.ts | 43 +++++++++++++++---- otis/src/app/cases/cases.module.ts | 1 - otis/src/app/core/case.ts | 8 ++-- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/otis/src/app/cases/case-detail/case-detail.component.ts b/otis/src/app/cases/case-detail/case-detail.component.ts index 36b78e0..e5cbe14 100644 --- a/otis/src/app/cases/case-detail/case-detail.component.ts +++ b/otis/src/app/cases/case-detail/case-detail.component.ts @@ -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; diff --git a/otis/src/app/cases/cases.module.ts b/otis/src/app/cases/cases.module.ts index 3faf6ce..fdfa3f6 100644 --- a/otis/src/app/cases/cases.module.ts +++ b/otis/src/app/cases/cases.module.ts @@ -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', diff --git a/otis/src/app/core/case.ts b/otis/src/app/core/case.ts index a45c111..5c86eba 100644 --- a/otis/src/app/core/case.ts +++ b/otis/src/app/core/case.ts @@ -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;