MCPcopy Index your code
hub / github.com/angular/components / parseInterval

Function parseInterval

src/material/timepicker/util.ts:45–75  ·  view source on GitHub ↗
(value: number | string | null)

Source from the content-addressed store, hash-verified

43
44/** Parses an interval value into seconds. */
45export function parseInterval(value: number | string | null): number | null {
46 let result: number;
47
48 if (value === null) {
49 return null;
50 } else if (typeof value === 'number') {
51 result = value;
52 } else {
53 if (value.trim().length === 0) {
54 return null;
55 }
56
57 const parsed = value.match(INTERVAL_PATTERN);
58 const amount = parsed ? parseFloat(parsed[1]) : null;
59 const unit = parsed?.[2]?.toLowerCase() || null;
60
61 if (!parsed || amount === null || isNaN(amount)) {
62 return null;
63 }
64
65 if (unit === 'h' || unit === 'hour' || unit === 'hours') {
66 result = amount * 3600;
67 } else if (unit === 'm' || unit === 'min' || unit === 'minute' || unit === 'minutes') {
68 result = amount * 60;
69 } else {
70 result = amount;
71 }
72 }
73
74 return result;
75}
76
77/**
78 * Generates the options to show in a timepicker.

Callers 2

MatTimepickerClass · 0.90
util.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…