charlyghislaindotcom/src/app/app.component.ts
cghislai e0a0f26560
Some checks failed
charlyghislain/charlyghislaindotcom/pipeline/head There was a failure building this commit
Migrate moment to luxon
2022-04-18 01:06:06 +02:00

43 lines
1.2 KiB
TypeScript

import {Component, OnInit} from '@angular/core';
import {BuildInfoService} from './build-info.service';
import {Observable, of} from 'rxjs';
import {catchError, defaultIfEmpty, filter, map, publishReplay, refCount} from 'rxjs/operators';
import {BuildInfo} from './build-info';
import {DateTime} from 'luxon';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
buildDate: Observable<string>;
buildCommit: Observable<string>;
constructor(private buildinfoService: BuildInfoService) {
const buildInfo = this.buildinfoService.getBuildInfo()
.pipe(
catchError(e => of(<BuildInfo>{date: null, commit: null})),
publishReplay(1), refCount(),
);
this.buildDate = buildInfo.pipe(
map(info => info.date),
map(date => this.parseDate(date)),
);
this.buildCommit = buildInfo.pipe(
map(info => info.commit),
filter(commit => commit != null),
defaultIfEmpty('HEAD'),
);
}
ngOnInit(): void {
}
private parseDate(dateString: string) {
const parsedDateString = dateString == null ? undefined : DateTime.fromISO(dateString).toISODate();
return parsedDateString;
}
}