• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.68
/src/time-picker/time-picker.utils.ts
1
import { Time, TimePickerComponentState } from './inner/inner-time-picker.class';
2
import { coerceNumberValue } from 'ngx-tethys/util';
1✔
3

1✔
4
const hoursPerDay = 24;
1✔
5
const hoursPerDayHalf = 12;
1✔
6
const minutesPerHour = 60;
7
const secondsPerMinute = 60;
×
8

×
9
export function isValidDate(value?: string | Date): boolean {
10
    if (!value) {
×
11
        return false;
×
12
    }
13

×
14
    if (value instanceof Date && isNaN(value.getHours())) {
×
15
        return false;
16
    }
×
17

18
    if (typeof value === 'string') {
19
        return isValidDate(new Date(value));
×
20
    }
×
21

22
    return true;
×
23
}
×
24

25
export function isValidLimit(controls: TimePickerComponentState, newDate: Date): boolean {
×
26
    if (controls.min && newDate < controls.min) {
27
        return false;
×
28
    }
×
29

×
30
    if (controls.max && newDate > controls.max) {
×
31
        return false;
32
    }
×
33

34
    return true;
35
}
×
36

×
37
export function parseHours(value: string | number, isPM = false): number {
×
38
    const hour = coerceNumberValue(value);
39
    if (isNaN(hour) || hour < 0 || hour > (isPM ? hoursPerDayHalf : hoursPerDay)) {
×
40
        return NaN;
41
    }
42

×
43
    return hour;
×
44
}
×
45

46
export function parseMinutes(value: string | number): number {
×
47
    const minute = coerceNumberValue(value);
48
    if (isNaN(minute) || minute < 0 || minute > minutesPerHour) {
49
        return NaN;
×
50
    }
×
51

52
    return minute;
×
53
}
54

55
export function parseSeconds(value: string | number): number {
×
56
    const seconds = coerceNumberValue(value);
×
57
    if (isNaN(seconds) || seconds < 0 || seconds > secondsPerMinute) {
58
        return NaN;
×
59
    }
×
60

×
61
    return seconds;
×
62
}
×
63

×
64
export function parseTime(value: string | Date): Date {
×
65
    if (typeof value === 'string') {
66
        return new Date(value);
67
    }
×
68

×
69
    return value;
70
}
×
71

×
72
export function changeTime(value: Date, diff: Time): Date {
73
    if (!value) {
×
74
        return changeTime(createDate(new Date(), 0, 0, 0), diff);
75
    }
76

×
77
    let hour = value.getHours();
×
78
    let minutes = value.getMinutes();
×
79
    let seconds = value.getSeconds();
×
80

×
81
    if (diff.hour) {
82
        hour = (hour + coerceNumberValue(diff.hour)) % hoursPerDay;
×
83
        if (hour < 0) {
×
84
            hour += hoursPerDay;
×
85
        }
86
    }
×
87

88
    if (diff.minute) {
×
89
        minutes = minutes + coerceNumberValue(diff.minute);
×
90
    }
91

×
92
    if (diff.seconds) {
93
        seconds = seconds + coerceNumberValue(diff.seconds);
94
    }
×
95

96
    return createDate(value, hour, minutes, seconds);
97
}
×
98

×
99
export function setTime(value: Date, opts: Time): Date {
×
100
    let hour = parseHours(opts.hour);
101
    const minute = parseMinutes(opts.minute);
×
102
    const seconds = parseSeconds(opts.seconds) || 0;
103

104
    if (opts.isPM && hour !== 12) {
×
105
        hour += hoursPerDayHalf;
106
    }
107

×
108
    if (!value) {
109
        if (!isNaN(hour) && !isNaN(minute)) {
110
            return createDate(new Date(), hour, minute, seconds);
×
111
        }
112

113
        return value;
×
114
    }
×
115

×
116
    if (isNaN(hour) || isNaN(minute)) {
117
        return value;
×
118
    }
×
119

120
    return createDate(value, hour, minute, seconds);
×
121
}
122

×
123
export function createDate(value: Date, hours: number, minutes: number, seconds: number): Date {
×
124
    return new Date(value.getFullYear(), value.getMonth(), value.getDate(), hours, minutes, seconds, value.getMilliseconds());
125
}
126

127
export function padNumber(value: number): string {
128
    const _value = value.toString();
129
    if (_value.length > 1) {
130
        return _value;
131
    }
132

133
    return `0${_value}`;
134
}
135

136
export function isHourInputValid(hours: string, isPM: boolean): boolean {
137
    return !isNaN(parseHours(hours, isPM));
138
}
139

140
export function isMinuteInputValid(minutes: string): boolean {
141
    return !isNaN(parseMinutes(minutes));
142
}
143

144
export function isSecondInputValid(seconds: string): boolean {
145
    return !isNaN(parseSeconds(seconds));
146
}
147

148
export function isInputLimitValid(diff: Time, max: Date, min: Date): boolean {
149
    const newDate = setTime(new Date(), diff);
150

151
    if (max && newDate > max) {
152
        return false;
153
    }
154

155
    if (min && newDate < min) {
156
        return false;
157
    }
158

159
    return true;
160
}
161

162
export function isInputValid(hours: string, minutes = '0', seconds = '0', isPM: boolean): boolean {
163
    return isHourInputValid(hours, isPM) && isMinuteInputValid(minutes) && isSecondInputValid(seconds);
164
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc