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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

56.36
/projects/igniteui-angular/src/lib/time-picker/time-picker.pipes.ts
1
import { Pipe, PipeTransform, Inject } from '@angular/core';
2
import { DatePipe } from '@angular/common';
3
import { IGX_TIME_PICKER_COMPONENT, IgxTimePickerBase } from './time-picker.common';
4
import { DatePart } from '../directives/date-time-editor/public_api';
5
import { DateTimeUtil } from '../date-common/util/date-time.util';
6

7
const ITEMS_COUNT = 7;
2✔
8

9
@Pipe({
10
    name: 'timeFormatPipe',
11
    standalone: true
12
})
13
export class TimeFormatPipe implements PipeTransform {
2✔
UNCOV
14
    constructor(@Inject(IGX_TIME_PICKER_COMPONENT) private timePicker: IgxTimePickerBase) { }
×
15

16
    public transform(value: Date): string {
UNCOV
17
        const format = this.timePicker.appliedFormat.replace('tt', 'aa');
×
UNCOV
18
        const datePipe = new DatePipe(this.timePicker.locale);
×
UNCOV
19
        return datePipe.transform(value, format);
×
20
    }
21
}
22

23
@Pipe({
24
    name: 'timeItemPipe',
25
    standalone: true
26
})
27
export class TimeItemPipe implements PipeTransform {
2✔
28
    constructor(@Inject(IGX_TIME_PICKER_COMPONENT) private timePicker: IgxTimePickerBase) { }
4✔
29

30
    public transform(_collection: any[], timePart: string, selectedDate: Date, min: Date, max: Date) {
31
        let list;
32
        let part;
33
        switch (timePart) {
4!
34
            case 'hour':
35
                list = this.generateHours(min, max);
2✔
36
                const hours = this.timePicker.isTwelveHourFormat ? this.toTwelveHourFormat(selectedDate.getHours())
2!
37
                    : selectedDate.getHours();
38
                list = this.scrollListItem(hours, list);
2✔
39
                part = DatePart.Hours;
2✔
40
                break;
2✔
41
            case 'minutes':
42
                list = this.generateMinutes(selectedDate, min, max);
2✔
43
                list = this.scrollListItem(selectedDate.getMinutes(), list);
2✔
44
                part = DatePart.Minutes;
2✔
45
                break;
2✔
46
            case 'seconds':
UNCOV
47
                list = this.generateSeconds(selectedDate, min, max);
×
UNCOV
48
                list = this.scrollListItem(selectedDate.getSeconds(), list);
×
UNCOV
49
                part = DatePart.Seconds;
×
UNCOV
50
                break;
×
51
            case 'ampm':
UNCOV
52
                const selectedAmPm = this.timePicker.getPartValue(selectedDate, 'ampm');
×
UNCOV
53
                list = this.generateAmPm(min, max, selectedAmPm);
×
UNCOV
54
                list = this.scrollListItem(selectedAmPm, list);
×
UNCOV
55
                part = DatePart.AmPm;
×
UNCOV
56
                break;
×
57
        }
58
        return this.getListView(list, part);
4✔
59
    }
60

61
    private getListView(view: any, dateType: DatePart): any {
62
        for (let i = 0; i < view.length; i++) {
4✔
63
            view[i] = this.getItemView(view[i], dateType);
28✔
64
        }
65
        return view;
4✔
66
    }
67

68
    private getItemView(item: any, dateType: DatePart): string {
69
        if (item === null) {
28!
UNCOV
70
            item = '';
×
71
        } else if (dateType && typeof (item) !== 'string') {
28✔
72
            const leadZeroHour = (item < 10 && (this.timePicker.appliedFormat?.indexOf('hh') !== -1
28!
73
                || this.timePicker.appliedFormat?.indexOf('HH') !== -1));
74
            const leadZeroMinute = (item < 10 && this.timePicker.appliedFormat?.indexOf('mm') !== -1);
28✔
75
            const leadZeroSeconds = (item < 10 && this.timePicker.appliedFormat?.indexOf('ss') !== -1);
28✔
76

77
            const leadZero = {
28✔
78
                hours: leadZeroHour,
79
                minutes: leadZeroMinute,
80
                seconds: leadZeroSeconds
81
            }[dateType];
82

83
            item = (leadZero) ? '0' + item : `${item}`;
28✔
84
        }
85
        return item;
28✔
86
    }
87

88
    private scrollListItem(item: number | string, items: any[]): any[] {
89
        const itemsCount = items.length;
4✔
90
        let view;
91
        if (items) {
4✔
92
            const index = items.indexOf(item);
4✔
93
            if (index < 3) {
4!
94
                view = items.slice(itemsCount - (3 - index), itemsCount);
4✔
95
                view = view.concat(items.slice(0, index + 4));
4✔
UNCOV
96
            } else if (index + 4 > itemsCount) {
×
UNCOV
97
                view = items.slice(index - 3, itemsCount);
×
UNCOV
98
                view = view.concat(items.slice(0, index + 4 - itemsCount));
×
99
            } else {
UNCOV
100
                view = items.slice(index - 3, index + 4);
×
101
            }
102
        }
103
        return view;
4✔
104
    }
105

106
    private generateHours(min: Date, max: Date): any[] {
107
        const hourItems = [];
2✔
108
        let hoursCount = this.timePicker.isTwelveHourFormat ? 13 : 24;
2!
109
        hoursCount /= this.timePicker.itemsDelta.hours;
2✔
110
        const minHours = min.getHours();
2✔
111
        const maxHours = max.getHours();
2✔
112

113
        if (hoursCount > 1) {
2!
114
            for (let hourIndex = 0; hourIndex < 24; hourIndex++) {
2✔
115
                let hours = hourIndex * this.timePicker.itemsDelta.hours;
48✔
116
                if (hours >= minHours && hours <= maxHours) {
48✔
117
                    hours = this.timePicker.isTwelveHourFormat ? this.toTwelveHourFormat(hours) : hours;
48!
118
                    if (!hourItems.find((element => element === hours))) {
288✔
119
                        hourItems.push(hours);
24✔
120
                    }
121
                }
122
            }
123
        } else {
124
            hourItems.push(0);
×
125
        }
126

127
        if (hourItems.length < ITEMS_COUNT || hoursCount < ITEMS_COUNT || !this.timePicker.spinLoop) {
2!
UNCOV
128
            const index = !this.timePicker.spinLoop || (hourItems.length < ITEMS_COUNT && hoursCount < ITEMS_COUNT) ? 6 : 3;
×
UNCOV
129
            for (let i = 0; i < index; i++) {
×
UNCOV
130
                hourItems.push(null);
×
131
            }
132
        }
133

134
        return hourItems;
2✔
135
    }
136

137
    private generateMinutes(time: Date, min: Date, max: Date): any[] {
138
        const minuteItems = [];
2✔
139
        const minuteItemsCount = 60 / this.timePicker.itemsDelta.minutes;
2✔
140
        time = new Date(time);
2✔
141

142
        for (let i = 0; i < minuteItemsCount; i++) {
2✔
143
            const minutes = i * this.timePicker.itemsDelta.minutes;
120✔
144
            time.setMinutes(minutes);
120✔
145
            if (time >= min && time <= max) {
120✔
146
                minuteItems.push(i * this.timePicker.itemsDelta.minutes);
120✔
147
            }
148
        }
149

150
        if (minuteItems.length < ITEMS_COUNT || minuteItemsCount < ITEMS_COUNT || !this.timePicker.spinLoop) {
2!
UNCOV
151
            const index = !this.timePicker.spinLoop || (minuteItems.length < ITEMS_COUNT && minuteItemsCount < ITEMS_COUNT) ? 6 : 3;
×
UNCOV
152
            for (let i = 0; i < index; i++) {
×
UNCOV
153
                minuteItems.push(null);
×
154
            }
155
        }
156

157
        return minuteItems;
2✔
158
    }
159

160
    private generateSeconds(time: Date, min: Date, max: Date): any[] {
UNCOV
161
        const secondsItems = [];
×
UNCOV
162
        const secondsItemsCount = 60 / this.timePicker.itemsDelta.seconds;
×
UNCOV
163
        time = new Date(time);
×
164

UNCOV
165
        for (let i = 0; i < secondsItemsCount; i++) {
×
UNCOV
166
            const seconds = i * this.timePicker.itemsDelta.seconds;
×
UNCOV
167
            time.setSeconds(seconds);
×
UNCOV
168
            if (time.getTime() >= min.getTime()
×
169
                && time.getTime() <= max.getTime()) {
UNCOV
170
                secondsItems.push(i * this.timePicker.itemsDelta.seconds);
×
171
            }
172
        }
173

UNCOV
174
        if (secondsItems.length < ITEMS_COUNT || secondsItemsCount < ITEMS_COUNT || !this.timePicker.spinLoop) {
×
UNCOV
175
            const index = !this.timePicker.spinLoop || (secondsItems.length < ITEMS_COUNT && secondsItemsCount < ITEMS_COUNT) ? 6 : 3;
×
UNCOV
176
            for (let i = 0; i < index; i++) {
×
UNCOV
177
                secondsItems.push(null);
×
178
            }
179
        }
180

UNCOV
181
        return secondsItems;
×
182
    }
183

184
    private generateAmPm(min: Date, max: Date, selectedAmPm: string): any[] {
UNCOV
185
        const ampmItems = [];
×
UNCOV
186
        const minHour = min.getHours();
×
UNCOV
187
        const maxHour = max.getHours();
×
188

UNCOV
189
        if (minHour < 12) {
×
UNCOV
190
            ampmItems.push(DateTimeUtil.getAmPmValue(selectedAmPm.length, true));
×
191
        }
192

UNCOV
193
        if (minHour >= 12 || maxHour >= 12) {
×
UNCOV
194
            ampmItems.push(DateTimeUtil.getAmPmValue(selectedAmPm.length, false));
×
195
        }
196

UNCOV
197
        for (let i = 0; i < 5; i++) {
×
UNCOV
198
            ampmItems.push(null);
×
199
        }
200

UNCOV
201
        return ampmItems;
×
202
    }
203

204
    private toTwelveHourFormat(hour: number): number {
205
        if (hour > 12) {
50✔
206
            hour -= 12;
22✔
207
        } else if (hour === 0) {
28✔
208
            hour = 12;
4✔
209
        }
210

211
        return hour;
50✔
212
    }
213
}
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