Skip to content

Commit 8c63a12

Browse files
committed
Modernize op-date-time component, fix type safety
1 parent 8abad75 commit 8c63a12

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

frontend/src/app/shared/components/date/op-date-time.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
// See COPYRIGHT and LICENSE files for more details.
2727
//++
2828

29-
import { Component, Input } from '@angular/core';
29+
import { Component, Input, OnInit, inject } from '@angular/core';
3030
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
31+
import { toDateTime } from 'core-app/shared/helpers/date-time-helpers';
32+
import { type DateTime } from 'luxon';
3133

3234
@Component({
3335
selector: 'op-date-time',
@@ -40,19 +42,18 @@ import { TimezoneService } from 'core-app/core/datetime/timezone.service';
4042
`,
4143
standalone: false,
4244
})
43-
export class OpDateTimeComponent {
44-
@Input('dateTimeValue') dateTimeValue:any;
45+
export class OpDateTimeComponent implements OnInit {
46+
readonly timezoneService = inject(TimezoneService);
4547

46-
public date:any;
48+
@Input({ transform: toDateTime }) dateTimeValue:DateTime;
4749

48-
public time:any;
50+
public date:string;
4951

50-
constructor(readonly timezoneService:TimezoneService) {
51-
}
52+
public time:string;
5253

5354
ngOnInit() {
54-
const c = this.timezoneService.formattedDatetimeComponents(this.dateTimeValue);
55-
this.date = c[0];
56-
this.time = c[1];
55+
const [date, time] = this.timezoneService.formattedDatetimeComponents(this.dateTimeValue);
56+
this.date = date;
57+
this.time = time;
5758
}
5859
}

modules/github_integration/frontend/module/pull-request/pull-request.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { PullRequestComponent } from "./pull-request.component";
55
import { OpIconComponent } from 'core-app/shared/components/icon/icon.component';
66
import { IGithubCheckRunResource, IGithubPullRequest, IGithubUserResource } from '../state/github-pull-request.model';
77
import { PullRequestStateComponent } from './pull-request-state.component';
8+
import { DateTime } from 'luxon';
89

910
@Component({
1011
selector: 'op-date-time',
1112
template: ``,
1213
standalone: false,
1314
})
1415
class OpDateTimeComponent {
15-
@Input('dateTimeValue') dateTimeValue:any;
16+
@Input('dateTimeValue') dateTimeValue:DateTime;
1617
}
1718

1819
describe('PullRequestComponent', () => {

0 commit comments

Comments
 (0)