All files / src/variables/types time.ts

90% Statements 9/10
100% Branches 0/0
50% Functions 1/2
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  1x 1x   1x 1x     2x 2x 2x 2x 2x              
import { DateAndTimeUtils } from "@templates/utils/dateAndTime";
import { encode } from "html-entities";
import { CustomVariable } from "./base";
 
export class TimeCustomVariable extends CustomVariable {
    static definitionName = "time";
 
    public processInput(input: string, dateAndTimeUtils: DateAndTimeUtils): string {
        const [hours, minutes] = input.split(":");
        const now = new Date();
        now.setHours(Number.parseInt(hours));
        now.setMinutes(Number.parseInt(minutes));
        return dateAndTimeUtils.formatMsToLocal(now.getTime(), dateAndTimeUtils.getTimeFormat());
    }
 
    protected inputHTML(): string {
        return `<input name="${encode(this.name)}" type="time" aria-label="${encode(this.label)}"></input>`;
    }
}