RED-4243: Fixed dates difference

This commit is contained in:
Adina Țeudan 2022-06-20 18:39:09 +03:00
parent cd698f9eb6
commit 12f501a001
3 changed files with 9 additions and 11 deletions

View File

@ -18,6 +18,7 @@ import { TrashService } from '@services/entity-services/trash.service';
import { ArchivedDossiersService } from '@services/dossiers/archived-dossiers.service';
import { DossierStatesMapService } from '@services/entity-services/dossier-states-map.service';
import dayjs from 'dayjs';
import { dateWithoutTime } from '@utils/functions';
@Component({
selector: 'redaction-edit-dossier-general-info',
@ -110,7 +111,7 @@ export class EditDossierGeneralInfoComponent implements OnInit, EditDossierSecti
async save(): EditDossierSaveResult {
let dueDate;
if (this.hasDueDate) {
dueDate = dayjs(this.form.get('dueDate').value).set('h', 0).set('m', 0).set('s', 0);
dueDate = dateWithoutTime(dayjs(this.form.get('dueDate').value));
}
const dossier = {
...this.dossier,

View File

@ -3,6 +3,7 @@ import { DossierStats, IDossier } from '@red/domain';
import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service';
import { List } from '@iqser/common-ui';
import dayjs from 'dayjs';
import { dateWithoutTime } from '@utils/functions';
const DUE_DATE_WARN_DAYS = 14;
@ -36,7 +37,7 @@ export class DossierNameColumnComponent {
}
private get _dueDateDaysDiff(): number {
return dayjs(this.dossier.dueDate).get('date') - dayjs().get('date');
return dayjs(this.dossier.dueDate).diff(dateWithoutTime(dayjs()), 'day');
}
getDossierTemplateNameFor(dossierTemplateId: string): string {

View File

@ -1,12 +1,6 @@
import type { List } from '@iqser/common-ui';
import type { AnnotationWrapper } from '@models/file/annotation.wrapper';
export function groupBy(xs: List<unknown>, key: string) {
return xs.reduce((rv, x) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
}
import { Dayjs } from 'dayjs';
export function hexToRgb(hex: string) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
@ -24,7 +18,7 @@ export function getFirstRelevantTextPart(text: string, direction: 'FORWARD' | 'B
let accumulator = '';
const breakChars = [':', ' '];
const handle = i => {
const handle = (i: number) => {
const char = text[i];
if (breakChars.indexOf(char) >= 0) {
spaceCount += 1;
@ -69,7 +63,7 @@ export function toNumber(str: string) {
}
}
export function removeBraces(str: any): string {
export function removeBraces(str: string): string {
return str.replace(/[{}]/g, '');
}
@ -100,3 +94,5 @@ export const byId = (id: string) => (annotation: AnnotationWrapper) => annotatio
export function getLast<T>(list: List<T>) {
return list[list.length - 1];
}
export const dateWithoutTime = (date: Dayjs) => date.set('h', 0).set('m', 0).set('s', 0).set('ms', 0);