Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Dec 14, 2023
1 parent d5f9221 commit e48ba51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DatetimeComponent extends AbstractDatetimeComponent {
}

public update(): void {
const fullDateTime = this.luxonDateTime.toFormat("yyyy-MM-dd HH:mm:ss.SSS");
const fullDateTime = this.luxonDateTime.toFormat("yyyy-MM-dd HH:mm:ss");
const timezoneName = this.longTimezone();

// we do not place the timezoneName in brackets as the ngx-bootstrap tooltip
Expand Down
29 changes: 15 additions & 14 deletions src/app/components/shared/datetime/duration/duration.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Component, Input } from "@angular/core";
import { isInstantiated } from "@helpers/isInstantiated/isInstantiated";
import { HumanizeDurationOptions, toRelative } from "@interfaces/apiInterfaces";
import { toRelative } from "@interfaces/apiInterfaces";
import { Duration } from "luxon";
import { AbstractDatetimeComponent } from "../abstract-datetime.component";

@Component({
selector: "baw-duration",
templateUrl: "../abstract-datetime.component.html",
})
export class DurationComponent
extends AbstractDatetimeComponent
{
export class DurationComponent extends AbstractDatetimeComponent {
public constructor() {
super();
}
Expand Down Expand Up @@ -38,25 +36,28 @@ export class DurationComponent
return "";
}

// we use isInstantiated() to check if the humanized attribute is set
// because seconds are the smallest unit we want to emit in the text
// we round the duration to the nearest second
// however, we still retain the original duration object as we emit fractional seconds in the
// tooltip and rawDateTime
const durationSeconds = Math.round(this.value.seconds);
const roundedDuration = this.value
.set({ seconds: durationSeconds })
.rescale();

// we use isInstantiated() to check if the humanized attribute is set eg. <baw-duration humanized>
// and we also check that it is not set to false
// by allowing boolean values, we support reactive formats (e.g. [humanized]="isHumanized")
if (isInstantiated(this.humanized) && this.humanized !== false) {
const relativeOptions: HumanizeDurationOptions = {
return toRelative(roundedDuration, {
largest: 2,
round: true,
};

return toRelative(this.value, relativeOptions);
});
} else if (isInstantiated(this.iso8601) && this.iso8601 !== false) {
const seconds = Math.round(this.value.seconds);
const roundedDuration = this.value.set({ seconds });
return roundedDuration.rescale().toISO();
return roundedDuration.toISO();
}

// if not format operator is supplied, the component will default to sexagesimal format
const seconds = Math.round(this.value.seconds);
const roundedDuration = this.value.set({ seconds });
return roundedDuration.toFormat("hh:mm:ss");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class RelativeTimeComponent extends AbstractDatetimeComponent {

this.tooltipValue = `${formattedStartDate} ${timezoneInformation}`;
this.rawDateTime = this.durationValue.toISO();

this.formattedValue = toRelative(this.durationValue, {
largest: 2,
round: true,
Expand Down

0 comments on commit e48ba51

Please sign in to comment.