Files
doneit-web/src/app/services/date.service.ts
T

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-08-31 16:32:16 +01:00
import { Injectable } from '@angular/core';
2024-02-29 09:40:51 +01:00
import { EventList } from '../models/agenda/AgendaEventList';
2021-08-31 16:32:16 +01:00
@Injectable({
providedIn: 'root'
})
export class DateService {
constructor() { }
deferenceBetweenDays(start: any, end: any) {
const diffTime = Math.abs(end - start);
2024-02-29 09:40:51 +01:00
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
2021-08-31 16:32:16 +01:00
}
notSameDate(start: any, end: any): boolean {
return new Date(start).toLocaleDateString() != new Date(end).toLocaleDateString()
}
isSameDate(start: any, end: any): boolean {
return !this.notSameDate(start, end)
}
EventEndDateTreatment({startTime, endTime}) {
const startTimeSamp = new Date(startTime).toLocaleDateString()
const endTimeSamp = new Date(endTime).toLocaleDateString()
const endMinutes = new Date(endTime).getMinutes()
2024-02-29 09:40:51 +01:00
const endHours = new Date(endTime).getHours()
2021-08-31 16:32:16 +01:00
if (startTimeSamp < endTimeSamp && (endMinutes + endHours) == 0) {
endTime = new Date(endTime);
return new Date(endTime)
} else {
return new Date(endTime)
}
}
2021-09-03 12:19:21 +01:00
getDay(date) {
return (((new Date (date)).getDate())).toString().padStart(2,'0')
}
2024-02-29 09:40:51 +01:00
2024-05-30 12:03:30 +01:00
fixDate(res: EventList): any {
2024-02-29 09:40:51 +01:00
if(res.IsAllDayEvent && this.deferenceBetweenDays(new Date(res.StartDate), new Date(res.EndDate)) >= 1) {
const date = new Date(res.EndDate);
date.setDate(date.getDate() -1);
2024-02-29 22:29:00 +01:00
const _date = String(date.getDate()).padStart(2,'0');
const month = String(date.getMonth() + 1).padStart(2,'0');
2024-02-29 09:40:51 +01:00
const fullYear = date.getFullYear();
const formattedDate = `${fullYear}-${month}-${_date} 23:59`;
res.EndDate = formattedDate
}
return res as any
}
2021-08-31 16:32:16 +01:00
}