diff --git a/goofy-client/apps/goofy/src/app/app.component.spec.ts b/goofy-client/apps/goofy/src/app/app.component.spec.ts index cf7103954ef2fae0cbd83e3966e11e5c6daa7ec6..a9e762566f1b23e26649560c4760f29c61fd6515 100644 --- a/goofy-client/apps/goofy/src/app/app.component.spec.ts +++ b/goofy-client/apps/goofy/src/app/app.component.spec.ts @@ -1,4 +1,6 @@ +import { registerLocaleData } from '@angular/common'; import { HttpClient } from '@angular/common/http'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ApiRootResource, ApiRootService } from '@goofy-client/api-root-shared'; @@ -13,6 +15,8 @@ import { createApiRootResource } from 'libs/api-root-shared/test/api-root'; import { BehaviorSubject, of } from 'rxjs'; import { AppComponent } from './app.component'; +registerLocaleData(localeDe); + describe('AppComponent', () => { let component: AppComponent; let fixture: ComponentFixture<AppComponent>; diff --git a/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.html b/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.html index 88d1c978fe67f3c491f0b7bd8ff88a027a7fb405..13b62833329db8345b263b3bf171aa350e2e60d8 100644 --- a/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.html +++ b/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.html @@ -3,7 +3,7 @@ class="plain-text"> <goofy-client-user-profile-in-kommentar-container [kommentar]="kommentar" data-test-id="kommentar-list-item-user-profile"></goofy-client-user-profile-in-kommentar-container> - <span data-test-id="kommentar-created-at">{{ kommentar.createdAt | date: 'dd.MM.yy HH:mm' }}</span> + <span data-test-id="kommentar-created-at">{{ kommentar.createdAt | formatDateWithTimePipe: false }}</span> <p>{{ kommentar.text }}</p> </button> diff --git a/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.spec.ts b/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.spec.ts index c31047b981180f7cee0a3f29f2179ba810946b2f..58df951e0bd2dea7a8f066a89dfbbf8f33e1ddf2 100644 --- a/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.spec.ts +++ b/goofy-client/libs/kommentar/src/lib/kommentar-list-in-vorgang-container/kommentar-list-in-vorgang/kommentar-list-item-in-vorgang/kommentar-list-item-in-vorgang.component.spec.ts @@ -1,11 +1,15 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { ConvertForDataTestPipe } from '@goofy-client/tech-shared'; +import { ConvertForDataTestPipe, FormatDateWithTimePipe } from '@goofy-client/tech-shared'; import { UserProfileInKommentarContainerComponent } from '@goofy-client/user-profile'; import { createKommentarResource } from 'libs/kommentar-shared/test/kommentar'; import { MockComponent } from 'ng-mocks'; import { KommentarFormComponent } from '../../kommentar-form/kommentar-form.component'; import { KommentarListItemInVorgangComponent } from './kommentar-list-item-in-vorgang.component'; +registerLocaleData(localeDe); + describe('KommentarListItemInVorgangComponent', () => { let component: KommentarListItemInVorgangComponent; let fixture: ComponentFixture<KommentarListItemInVorgangComponent>; @@ -15,6 +19,7 @@ describe('KommentarListItemInVorgangComponent', () => { declarations: [ KommentarListItemInVorgangComponent, ConvertForDataTestPipe, + FormatDateWithTimePipe, MockComponent(KommentarFormComponent), MockComponent(UserProfileInKommentarContainerComponent) ] diff --git a/goofy-client/libs/navigation/src/lib/build-info/build-info.component.html b/goofy-client/libs/navigation/src/lib/build-info/build-info.component.html index e676042ec8adfd97593e95c622145c1101f0e5e9..f4d9c6b1327f086add9d9d03a7b9abf49c72476b 100644 --- a/goofy-client/libs/navigation/src/lib/build-info/build-info.component.html +++ b/goofy-client/libs/navigation/src/lib/build-info/build-info.component.html @@ -1 +1 @@ -<p>Version: {{ apiRoot.version }} | BuildTime: {{ apiRoot.buildTime | date: "dd.MM.yy HH:mm:ss" }}</p> \ No newline at end of file +<p>Version: {{ apiRoot.version }} | BuildTime: {{ apiRoot.buildTime | formatDateWithTimePipe }}</p> \ No newline at end of file diff --git a/goofy-client/libs/navigation/src/lib/build-info/build-info.component.spec.ts b/goofy-client/libs/navigation/src/lib/build-info/build-info.component.spec.ts index fa9f152a0e2251001eb4adbede9642e1d4b976f5..3d07136ba984302b588530bea1d90759d65f71d8 100644 --- a/goofy-client/libs/navigation/src/lib/build-info/build-info.component.spec.ts +++ b/goofy-client/libs/navigation/src/lib/build-info/build-info.component.spec.ts @@ -1,20 +1,29 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormatDateWithTimePipe } from '@goofy-client/tech-shared'; +import { createApiRootResource } from 'libs/api-root-shared/test/api-root'; import { BuildInfoComponent } from './build-info.component'; +registerLocaleData(localeDe); + describe('BuildInfoComponent', () => { let component: BuildInfoComponent; let fixture: ComponentFixture<BuildInfoComponent>; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [BuildInfoComponent] + declarations: [ + BuildInfoComponent, + FormatDateWithTimePipe + ] }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(BuildInfoComponent); component = fixture.componentInstance; - component.apiRoot = { version: '1', buildTime: '2', javaVersion: '3', _links: null }; + component.apiRoot = createApiRootResource(); fixture.detectChanges(); }); diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html index 916e039acd800e3d667cb1dcde5756eb55a3e76f..7a6249fa21ebd09bfb2bd85e4feffa70845d1622 100644 --- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html +++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html @@ -4,5 +4,5 @@ <span class="overflow">{{ postfachMail.subject }}</span> </div> -<div class="date" data-test-id="mail-created-at">{{ postfachMail.createdAt | date: "dd.MM.yy HH:mm" }}</div> +<div class="date" data-test-id="mail-created-at">{{ postfachMail.createdAt | formatDateWithTimePipe: false }}</div> <div class="message overflow" data-test-id="mail-text">{{ postfachMail.mailBody }}</div> \ No newline at end of file diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts index 759556928968481b543943088f9cdb18c3263ba9..87b1ae6a7ade182f76bab13281484dc23b927af7 100644 --- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts +++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts @@ -1,8 +1,13 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatIcon } from '@angular/material/icon'; +import { FormatDateWithTimePipe } from '@goofy-client/tech-shared'; import { createPostfachMailResource } from '../../../../../../../postfach-shared/test/postfach'; import { IncommingMailComponent } from './incomming-mail.component'; +registerLocaleData(localeDe); + describe('IncommingMailComponent', () => { let component: IncommingMailComponent; let fixture: ComponentFixture<IncommingMailComponent>; @@ -11,10 +16,10 @@ describe('IncommingMailComponent', () => { await TestBed.configureTestingModule({ declarations: [ IncommingMailComponent, - MatIcon + MatIcon, + FormatDateWithTimePipe ] - }) - .compileComponents(); + }).compileComponents(); }); beforeEach(() => { diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html index 529d962f7fd04210cb472956a18dca33f7adc75a..acadd13da20da4584a738f19b5c51028dbe43e5b 100644 --- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html +++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html @@ -3,5 +3,5 @@ </goofy-client-user-profile-in-postfach-mail-container> <span class="overflow subject" data-test-id="mail-subject">{{ postfachMail.subject }}</span> -<div class="date" data-test-id="mail-created-at">{{ postfachMail.createdAt | date: "dd.MM.yy HH:mm" }}</div> +<div class="date" data-test-id="mail-created-at">{{ postfachMail.createdAt | formatDateWithTimePipe: false }}</div> <div class="message overflow" data-test-id="mail-text">{{ postfachMail.mailBody }}</div> \ No newline at end of file diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts index 6c0e75a1a6d673ed5b712ce8ee9922bf24b0c3a0..aca1a5935df282bd738f0143cfcaab9ad894997b 100644 --- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts +++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts @@ -1,10 +1,14 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { HasLinkPipe } from '@goofy-client/tech-shared'; +import { FormatDateWithTimePipe, HasLinkPipe } from '@goofy-client/tech-shared'; import { UserProfileInPostfachMailContainerComponent } from '@goofy-client/user-profile'; import { MockComponent } from 'ng-mocks'; import { createPostfachMailResource } from '../../../../../../../postfach-shared/test/postfach'; import { OutgoingMailComponent } from './outgoing-mail.component'; +registerLocaleData(localeDe); + describe('OutgoingMailComponent', () => { let component: OutgoingMailComponent; let fixture: ComponentFixture<OutgoingMailComponent>; @@ -14,6 +18,7 @@ describe('OutgoingMailComponent', () => { declarations: [ OutgoingMailComponent, HasLinkPipe, + FormatDateWithTimePipe, MockComponent(UserProfileInPostfachMailContainerComponent) ] }) diff --git a/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts b/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..9cec0f0821df0902eb9e6fb0306fd8d9e40c5828 --- /dev/null +++ b/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts @@ -0,0 +1,34 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; +import { formatFullDate, formatFullDateWithTimeAndDay, formatFullDateWithTimeWithoutSeconds, formatWithoutYear } from './date.util'; + +registerLocaleData(localeDe); + +describe('Date Util', () => { + + const dateToFormat: Date = new Date('1010-01-01:01:01:01'); + + it('formatFullDateWithTimeWithoutSeconds', () => { + const formattedDate: string = formatFullDateWithTimeWithoutSeconds(dateToFormat); + + expect(formattedDate).toEqual('01.01.10 01:01'); + }) + + it('formatFullDateWithTimeAndDay', () => { + const formattedDate: string = formatFullDateWithTimeAndDay(dateToFormat); + + expect(formattedDate).toEqual('Montag, 01.01.1010, 01:01:01'); + }) + + it('formatFullDate', () => { + const formattedDate: string = formatFullDate(dateToFormat); + + expect(formattedDate).toEqual('01.01.1010'); + }) + + it('formatWithoutYear', () => { + const formattedDate: string = formatWithoutYear(dateToFormat); + + expect(formattedDate).toEqual('1.Jan.'); + }) +}) \ No newline at end of file diff --git a/goofy-client/libs/tech-shared/src/lib/date.util.ts b/goofy-client/libs/tech-shared/src/lib/date.util.ts index 44e1672aaf01f9770dc2a62bf536ca8e10c49fb0..243da7d68598a2d013e1ea0d776f3499edfe4329 100644 --- a/goofy-client/libs/tech-shared/src/lib/date.util.ts +++ b/goofy-client/libs/tech-shared/src/lib/date.util.ts @@ -2,7 +2,7 @@ import { formatDate } from '@angular/common'; import { isNil } from 'lodash-es'; import * as moment from 'moment'; -export function format(date: Date | moment.Moment): string { +export function formatForDatabase(date: Date | moment.Moment): string { const dateFormat: string = 'YYYY-MM-DD'; if (isNil(date)) { @@ -15,22 +15,26 @@ export function format(date: Date | moment.Moment): string { } } -export function formatWithTimeAndDay(date: Date): string { - return formatDate(date, 'EEEE, dd.MM.y, H:mm:ss', 'de'); -} -export function formatWithTime(date: Date): string { - return formatDate(date, 'dd.MM.y, H:mm:ss', 'de'); + +export function formatFullDateWithTimeWithoutSeconds(date: Date): string { + return formatDate(date, 'dd.MM.yy HH:mm', 'de'); } -export function formatForThisYear(date: Date): string { - return formatDate(date, 'd.MMM', 'de'); +export function formatFullDateWithTimeAndDay(date: Date): string { + return formatDate(date, 'EEEE, dd.MM.yyyy, HH:mm:ss', 'de'); } -export function formatDMYDate(date: Date): string { +export function formatFullDate(date: Date): string { return formatDate(date, 'dd.MM.yyyy', 'de'); } +export function formatWithoutYear(date: Date): string { + return formatDate(date, 'd.MMM', 'de'); +} + + + export function isToday(date: Date): boolean { return moment().isSame(date, 'day'); } @@ -59,6 +63,8 @@ export function isThisYear(date: Date): boolean { return moment().isSame(date, 'year') } + + export function createFutureDate(todayPlusDays: number): Date { const date = new Date(); date.setDate(date.getDate() + todayPlusDays); diff --git a/goofy-client/libs/tech-shared/src/lib/pipe/format-date-with-time.pipe.ts b/goofy-client/libs/tech-shared/src/lib/pipe/format-date-with-time.pipe.ts index ff2511896ada85b3185c6e8faf6a2136fd1c378d..a278705ca8bd30b58550d08fa747d32a6b51fc41 100644 --- a/goofy-client/libs/tech-shared/src/lib/pipe/format-date-with-time.pipe.ts +++ b/goofy-client/libs/tech-shared/src/lib/pipe/format-date-with-time.pipe.ts @@ -1,11 +1,13 @@ import { Pipe, PipeTransform } from '@angular/core'; import { isNil } from 'lodash-es'; -import { formatWithTimeAndDay } from '../date.util'; +import { formatFullDateWithTimeAndDay, formatFullDateWithTimeWithoutSeconds } from '../date.util'; @Pipe({ name: 'formatDateWithTimePipe' }) export class FormatDateWithTimePipe implements PipeTransform { - transform(date: Date): string { + transform(date: Date, withSeconds: boolean = true): string { if (isNil(date)) return undefined; - return formatWithTimeAndDay(date); + return withSeconds + ? formatFullDateWithTimeAndDay(date) + : formatFullDateWithTimeWithoutSeconds(date); } } \ No newline at end of file diff --git a/goofy-client/libs/tech-shared/src/lib/pipe/format-list-date.pipe.ts b/goofy-client/libs/tech-shared/src/lib/pipe/format-list-date.pipe.ts index dbb515fe1feb2d406ae5576177d64e02fa70331c..ae1e7f4f2f915c25512b9cdd82d3b64347e5f0c6 100644 --- a/goofy-client/libs/tech-shared/src/lib/pipe/format-list-date.pipe.ts +++ b/goofy-client/libs/tech-shared/src/lib/pipe/format-list-date.pipe.ts @@ -1,9 +1,10 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { formatDMYDate, formatForThisYear, isDayAfterTomorrow, isDayBeforeYesterday, isThisYear, isToday, isTomorrow, isYesterday } from '../date.util'; +import { formatFullDate, formatWithoutYear, isDayAfterTomorrow, isDayBeforeYesterday, isThisYear, isToday, isTomorrow, isYesterday } from '../date.util'; +//TODO: rename @Pipe({ name: 'formatListDate' }) export class FormatListDatePipe implements PipeTransform { - transform(date: Date) { + transform(date: Date): string { if (isToday(date)) return 'Heute'; if (isYesterday(date)) return 'Gestern'; if (isDayBeforeYesterday(date)) return 'Vorgestern'; @@ -11,9 +12,9 @@ export class FormatListDatePipe implements PipeTransform { if (isDayAfterTomorrow(date)) return 'Übermorgen'; if (isThisYear(date)) { - return formatForThisYear(date) + return formatWithoutYear(date) } - return formatDMYDate(date); + return formatFullDate(date); } } \ No newline at end of file diff --git a/goofy-client/libs/wiedervorlage/src/lib/wiedervorlage-page-container/wiedervorlage-page/wiedervorlage-form/wiedervorlage.formservice.ts b/goofy-client/libs/wiedervorlage/src/lib/wiedervorlage-page-container/wiedervorlage-page/wiedervorlage-form/wiedervorlage.formservice.ts index 787bf584ae98df08b15b8c64e0322959aae15366..2421e3233fd8b3145ed8891c5565b0107ea44514 100644 --- a/goofy-client/libs/wiedervorlage/src/lib/wiedervorlage-page-container/wiedervorlage-page/wiedervorlage-form/wiedervorlage.formservice.ts +++ b/goofy-client/libs/wiedervorlage/src/lib/wiedervorlage-page-container/wiedervorlage-page/wiedervorlage-form/wiedervorlage.formservice.ts @@ -1,7 +1,7 @@ import { Injectable, OnDestroy } from '@angular/core'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { OzgFileListLinkRel, OzgFileListResource, OzgFileResource } from '@goofy-client/ozg-file-shared'; -import { AbstractFormService, createFutureDate, createStateResource, format, StateResource } from '@goofy-client/tech-shared'; +import { AbstractFormService, createFutureDate, createStateResource, formatForDatabase, StateResource } from '@goofy-client/tech-shared'; import { Wiedervorlage, WiedervorlageLinkRel, WiedervorlageResource, WiedervorlageService } from '@goofy-client/wiedervorlage-shared'; import { getEmbeddedResource, getUrl, hasLink } from '@ngxp/rest'; import { isNil, isNull } from 'lodash-es'; @@ -75,7 +75,7 @@ export class WiedervorlageFormService extends AbstractFormService implements OnD getValue(): Wiedervorlage { const formValue = super.getFormValue(); - return { ...formValue, frist: format(formValue.frist), attachments: this.attachments.value.resource.map(ozgFile => getUrl(ozgFile)) }; + return { ...formValue, frist: formatForDatabase(formValue.frist), attachments: this.attachments.value.resource.map(ozgFile => getUrl(ozgFile)) }; } public getAttachments(): Observable<StateResource<OzgFileResource[]>> {