Skip to content

Commit

Permalink
Allow overriding which format to use
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Jan 22, 2024
1 parent 1f131bd commit ac2aa3c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
8 changes: 3 additions & 5 deletions frontend/src/app/core/datetime/timezone.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import { Injectable } from '@angular/core';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import * as moment from 'moment-timezone';
import {
Moment,
} from 'moment';
import { Moment } from 'moment';

@Injectable({ providedIn: 'root' })
export class TimezoneService {
Expand Down Expand Up @@ -84,9 +82,9 @@ export class TimezoneService {
return this.parseDate(date, 'YYYY-MM-DD');
}

public formattedDate(date:string):string {
public formattedDate(date:string, format = this.getDateFormat()):string {
const d = this.parseDate(date);
return d.format(this.getDateFormat());
return d.format(format);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<display-field
*ngIf="!showAsInlineCard"
[resource]="workPackage"
[displayFieldOptions]="{ writable: false }"
[displayFieldOptions]="{ writable: false, dateFormat: 'MMM DD, YYYY' }"
[displayClass]="combinedDateDisplayField"
fieldName="dueDate"
class="op-wp-single-card--content-dates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ export class CombinedDateDisplayField extends DateDisplayField {
private createDateDisplayField(date:'dueDate'|'startDate'):HTMLElement {
const dateElement = document.createElement('span');
const dateDisplayField = new DateDisplayField(date, this.context);
const text = this.resource[date]
? this.timezoneService.formattedDate(this.resource[date])
: this.text.placeholder[date];

dateDisplayField.apply(this.resource, this.schema);
dateDisplayField.render(dateElement, text);
dateDisplayField.render(dateElement, dateDisplayField.valueString);

return dateElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
// See COPYRIGHT and LICENSE files for more details.
//++

import { Highlighting } from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';
import { HighlightableDisplayField } from 'core-app/shared/components/fields/display/field-types/highlightable-display-field.module';
import {
Highlighting,
} from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';
import {
HighlightableDisplayField,
} from 'core-app/shared/components/fields/display/field-types/highlightable-display-field.module';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
Expand Down Expand Up @@ -75,7 +79,7 @@ export class DateDisplayField extends HighlightableDisplayField {

public get valueString() {
if (this.value) {
return this.timezoneService.formattedDate(this.value);
return this.timezoneService.formattedDate(this.value, this.context.options.dateFormat);

Check failure on line 82 in frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts#L82 <@typescript-eslint/no-unsafe-argument>(https://typescript-eslint.io/rules/no-unsafe-argument)

Unsafe argument of type `any` assigned to a parameter of type `string`.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-argument","severity":2,"message":"Unsafe argument of type `any` assigned to a parameter of type `string`.","line":82,"column":49,"nodeType":"MemberExpression","messageId":"unsafeArgument","endLine":82,"endColumn":59}

Check failure on line 82 in frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts#L82 <@typescript-eslint/no-unsafe-argument>(https://typescript-eslint.io/rules/no-unsafe-argument)

Unsafe argument of type `any` assigned to a parameter of type `string`.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-argument","severity":2,"message":"Unsafe argument of type `any` assigned to a parameter of type `string`.","line":82,"column":61,"nodeType":"MemberExpression","messageId":"unsafeArgument","endLine":82,"endColumn":92}
}
return '';
}
Expand Down

0 comments on commit ac2aa3c

Please sign in to comment.