From 9b18afd9c3520b48bcc4d98d22f0dc1f3151e6ed Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:25:21 +0200 Subject: [PATCH] Fix date handling in time zone other than UTC --- apps/api/src/app/user/user.service.ts | 2 +- ...reate-or-update-access-dialog.component.ts | 25 ++++++++++++++----- .../create-or-update-access-dialog.html | 2 +- libs/common/src/lib/dtos/create-access.dto.ts | 4 +-- libs/common/src/lib/dtos/update-access.dto.ts | 9 +++---- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index ac997a874..082aeb779 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -138,7 +138,7 @@ export class UserService { user: true }, orderBy: { alias: 'asc' }, - where: { expiresAt: { gt: new Date() }, granteeUserId: id } + where: { granteeUserId: id } }), this.prismaService.account.findMany({ include: { platform: true }, diff --git a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts index 1757d20f8..d8bb3dab1 100644 --- a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts +++ b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts @@ -52,7 +52,7 @@ import { import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; import { MatSelectModule } from '@angular/material/select'; -import { addYears, endOfDay, isBefore, startOfDay } from 'date-fns'; +import { addYears, endOfDay, isBefore, isValid, startOfDay } from 'date-fns'; import { StatusCodes } from 'http-status-codes'; import { EMPTY, catchError } from 'rxjs'; @@ -84,6 +84,7 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { public tags: Filter[] = []; protected accessForm: FormGroup; + protected minExpiresAt: Date; protected readonly mode: 'create' | 'update'; protected readonly today = startOfDay(new Date()); @@ -153,9 +154,10 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { ] }); - if (access?.expiresAt && isBefore(new Date(access.expiresAt), this.today)) { - this.accessForm.get('expiresAt')?.markAsTouched(); - } + this.minExpiresAt = + access?.expiresAt && isBefore(new Date(access.expiresAt), this.today) + ? startOfDay(new Date(access.expiresAt)) + : this.today; this.assetClasses = getAssetClassFilters(); @@ -223,9 +225,20 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { } private buildExpiresAt() { - const expiresAt = this.accessForm.get('expiresAt')?.value as Date; + const expiresAtControl = this.accessForm.get('expiresAt'); + const expiresAtOfAccess = this.data.access?.expiresAt; + + if ( + this.mode === 'update' && + !expiresAtControl?.dirty && + expiresAtOfAccess + ) { + return new Date(expiresAtOfAccess).toISOString(); + } + + const expiresAt = expiresAtControl?.value as Date; - return endOfDay(expiresAt).toISOString(); + return isValid(expiresAt) ? endOfDay(expiresAt).toISOString() : ''; } private buildFilters(): Filter[] { diff --git a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html index ba5b9661e..a802b2291 100644 --- a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html +++ b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html @@ -52,7 +52,7 @@ formControlName="expiresAt" matInput [matDatepicker]="expiresAt" - [min]="today" + [min]="minExpiresAt" />