From 574398344a42d5a8b07dd3ade1623b287cd80212 Mon Sep 17 00:00:00 2001 From: Tobias Peper Date: Sat, 12 Apr 2025 10:46:22 +0200 Subject: [PATCH] Aktueller Stand - Datumsberechnungen --- src/app/app.component.html | 2 +- src/app/app.component.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 4d6a2ed..1ca7739 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -22,7 +22,7 @@ - +
diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 117830c..3d3f09d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,6 +5,7 @@ import { ChartComponent } from './chart/chart.component'; import { RestService } from './rest.service'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; +import { endOfMonth, format, startOfMonth, subMonths } from 'date-fns'; @Component({ selector: 'app-root', @@ -48,7 +49,23 @@ export class AppComponent implements OnInit, OnChanges { return 'Unbekannt'; } } + + testFunction(): string { + let startThisMonth: Date = subMonths(startOfMonth(new Date()), 1); + let returnValue: string = ''; + for (let i = 0; i < 12; i++) { + let endThisMonth: Date = endOfMonth(startThisMonth); + returnValue += ' / ' + format(startThisMonth, 'dd.MM.yyyy HH:mm:ss') + + ' - ' + format(endThisMonth, 'dd.MM.yyyy HH:mm:ss') + + ' (' + startThisMonth.getTime() + ' - ' + endThisMonth.getTime() + ')
'; + startThisMonth = subMonths(startThisMonth, 1); + } + return returnValue; + } houseId: number | undefined = undefined; duration: number | undefined = undefined; + + startThisMonth: Date = startOfMonth(new Date()); + testDate: string = ''; }