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

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

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

2.61
/src/time-picker/time-picker.utils.ts
1
import { coerceNumberProperty } from '@angular/cdk/coercion';
2
import { TinyDate } from 'ngx-tethys/util';
3
import { Time, TimePickerComponentState } from './inner/inner-time-picker.class';
1✔
4

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

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

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

19
    if (typeof value === 'string') {
UNCOV
20
        return isValidDate(new TinyDate(value)?.nativeDate);
×
UNCOV
21
    }
×
22

UNCOV
23
    return true;
×
UNCOV
24
}
×
25

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

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

35
    return true;
UNCOV
36
}
×
UNCOV
37

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

×
UNCOV
44
    return hour;
×
UNCOV
45
}
×
46

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

UNCOV
53
    return minute;
×
UNCOV
54
}
×
55

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

×
62
    return seconds;
×
63
}
UNCOV
64

×
UNCOV
65
export function parseTime(value: string | Date, timeZone?: string): Date {
×
UNCOV
66
    if (typeof value === 'string') {
×
UNCOV
67
        return new TinyDate(value, timeZone)?.nativeDate;
×
UNCOV
68
    } else if (value instanceof TinyDate) {
×
UNCOV
69
        return value?.nativeDate;
×
70
    } else {
×
71
        return new TinyDate(value, timeZone)?.nativeDate;
72
    }
UNCOV
73
}
×
UNCOV
74

×
75
export function changeTime(value: Date, diff: Time, timeZone?: string): Date {
UNCOV
76
    if (!value) {
×
UNCOV
77
        return changeTime(createDate(new TinyDate(undefined, timeZone)?.nativeDate, 0, 0, 0), diff, timeZone);
×
78
    }
UNCOV
79

×
80
    let hour = value.getHours();
81
    let minutes = value.getMinutes();
UNCOV
82
    let seconds = value.getSeconds();
×
UNCOV
83

×
UNCOV
84
    if (diff.hour) {
×
UNCOV
85
        hour = (hour + coerceNumberProperty(diff.hour)) % hoursPerDay;
×
UNCOV
86
        if (hour < 0) {
×
87
            hour += hoursPerDay;
UNCOV
88
        }
×
UNCOV
89
    }
×
UNCOV
90

×
91
    if (diff.minute) {
92
        minutes = minutes + coerceNumberProperty(diff.minute);
×
93
    }
UNCOV
94

×
UNCOV
95
    if (diff.seconds) {
×
96
        seconds = seconds + coerceNumberProperty(diff.seconds);
UNCOV
97
    }
×
98

99
    return createDate(value, hour, minutes, seconds, timeZone);
UNCOV
100
}
×
101

102
export function setTime(value: Date, opts: Time, timeZone?: string): Date {
UNCOV
103
    let hour = parseHours(opts.hour);
×
UNCOV
104
    const minute = parseMinutes(opts.minute);
×
UNCOV
105
    const seconds = parseSeconds(opts.seconds) || 0;
×
106

UNCOV
107
    if (opts.isPM && hour !== 12) {
×
108
        hour += hoursPerDayHalf;
109
    }
UNCOV
110

×
111
    if (!value) {
112
        if (!isNaN(hour) && !isNaN(minute)) {
UNCOV
113
            return createDate(new TinyDate(undefined, timeZone)?.nativeDate, hour, minute, seconds, timeZone);
×
114
        }
115

UNCOV
116
        return value;
×
117
    }
118

UNCOV
119
    if (isNaN(hour) || isNaN(minute)) {
×
UNCOV
120
        return value;
×
121
    }
×
122

UNCOV
123
    return createDate(value, hour, minute, seconds, timeZone);
×
UNCOV
124
}
×
125

UNCOV
126
export function createDate(value: Date, hours: number, minutes: number, seconds: number, timeZone?: string): Date {
×
127
    return new TinyDate(value, timeZone).setHours(hours).setMinutes(minutes).setSeconds(seconds).nativeDate;
128
}
×
UNCOV
129

×
130
export function padNumber(value: number): string {
131
    const _value = value.toString();
132
    if (_value.length > 1) {
133
        return _value;
134
    }
135

136
    return `0${_value}`;
137
}
138

139
export function isHourInputValid(hours: string, isPM: boolean): boolean {
140
    return !isNaN(parseHours(hours, isPM));
141
}
142

143
export function isMinuteInputValid(minutes: string): boolean {
144
    return !isNaN(parseMinutes(minutes));
145
}
146

147
export function isSecondInputValid(seconds: string): boolean {
148
    return !isNaN(parseSeconds(seconds));
149
}
150

151
export function isInputLimitValid(diff: Time, max: Date, min: Date, timeZone?: string): boolean {
152
    const newDate = setTime(new TinyDate(undefined, timeZone)?.nativeDate, diff, timeZone);
153

154
    if (max && newDate > max) {
155
        return false;
156
    }
157

158
    if (min && newDate < min) {
159
        return false;
160
    }
161

162
    return true;
163
}
164

165
export function isInputValid(hours: string, minutes = '0', seconds = '0', isPM: boolean): boolean {
166
    return isHourInputValid(hours, isPM) && isMinuteInputValid(minutes) && isSecondInputValid(seconds);
167
}
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