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

atinc / ngx-tethys / df6b162a-6409-4216-a048-95638a1cf8c3

11 Apr 2025 10:17AM UTC coverage: 90.237% (+0.001%) from 90.236%
df6b162a-6409-4216-a048-95638a1cf8c3

Pull #3335

circleci

wangyuan-ky
feat(time-picker): enhance time manipulation functions with timezone support
Pull Request #3335: feat(date-picker): add timezone support to date picker components and utilities #TINFR-1734

5610 of 6877 branches covered (81.58%)

Branch coverage included in aggregate %.

45 of 49 new or added lines in 12 files covered. (91.84%)

46 existing lines in 8 files now uncovered.

13365 of 14151 relevant lines covered (94.45%)

992.21 hits per line

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

85.51
/src/date-picker/lib/calendar/calendar-table.component.ts
1
import { Directive, EventEmitter, Input, OnChanges, OnInit, Output, Signal, SimpleChange, SimpleChanges, TemplateRef } from '@angular/core';
2
import { injectLocale, ThyDatePickerLocale } from 'ngx-tethys/i18n';
3
import { SafeAny } from 'ngx-tethys/types';
4
import { FunctionProp, isTemplateRef, TinyDate } from 'ngx-tethys/util';
5
import { DateBodyRow, DateCell } from '../date/types';
6

7
/**
8
 * @private
1✔
9
 */
10
@Directive()
244✔
11
export abstract class CalendarTable implements OnInit, OnChanges {
244✔
12
    locale: Signal<ThyDatePickerLocale> = injectLocale('datePicker');
244✔
13
    isTemplateRef = isTemplateRef;
244✔
14
    headRow: DateCell[] = [];
244✔
15
    bodyRows: DateBodyRow[] = [];
244✔
16
    MAX_ROW = 6;
244✔
17
    MAX_COL = 7;
244✔
18

244✔
19
    @Input() prefixCls: string = 'thy-calendar';
244✔
20
    @Input() value: TinyDate;
244✔
21
    @Input() activeDate: TinyDate = new TinyDate();
244✔
22
    @Input() showWeek: boolean = false;
244✔
23
    @Input() selectedValue: TinyDate[] = []; // Range ONLY
24
    @Input() hoverValue: TinyDate[] = []; // Range ONLY
25
    @Input() timeZone: string;
697!
26
    @Input() disabledDate?: (d: Date) => boolean;
697✔
27
    @Input() cellRender?: FunctionProp<TemplateRef<Date> | string>;
697✔
28
    @Input() fullCellRender?: FunctionProp<TemplateRef<Date> | string>;
29
    @Output() readonly valueChange = new EventEmitter<TinyDate>();
30

31
    @Output() readonly cellHover = new EventEmitter<TinyDate>(); // Emitted when hover on a day by mouse enter
590✔
32

33
    constructor() {}
34

1,820✔
35
    protected render(): void {
36
        if (this.activeDate) {
UNCOV
37
            this.headRow = this.makeHeadRow();
×
38
            this.bodyRows = this.makeBodyRows();
39
        }
40
    }
243✔
41

42
    trackByBodyRow(_index: number, item: DateBodyRow): SafeAny {
43
        return item.trackByIndex;
500!
UNCOV
44
    }
×
45

46
    trackByBodyColumn(_index: number, item: DateCell): SafeAny {
500✔
47
        return item.trackByIndex;
48
    }
49

50
    hasRangeValue(): boolean {
51
        return this.selectedValue?.length > 0 || this.hoverValue?.length > 0;
52
    }
53

442✔
54
    abstract makeHeadRow(): DateCell[];
55
    abstract makeBodyRows(): DateBodyRow[];
56

57
    ngOnInit(): void {
488✔
58
        this.render();
365✔
59
    }
365✔
60

365✔
61
    ngOnChanges(changes: SimpleChanges): void {
88✔
62
        if (changes.activeDate && !changes.activeDate.currentValue) {
63
            this.activeDate = new TinyDate();
UNCOV
64
        }
×
65

×
66
        if (
67
            changes.disabledDate ||
68
            changes.locale ||
69
            changes.showWeek ||
277✔
70
            this.isDateRealChange(changes.activeDate) ||
71
            this.isDateRealChange(changes.value) ||
72
            this.isDateRealChange(changes.selectedValue) ||
123✔
73
            this.isDateRealChange(changes.hoverValue)
74
        ) {
75
            this.render();
277✔
76
        }
77
    }
1✔
78

1✔
79
    private isDateRealChange(change: SimpleChange): boolean {
80
        if (change) {
81
            const previousValue: TinyDate | TinyDate[] = change.previousValue;
82
            const currentValue: TinyDate | TinyDate[] = change.currentValue;
83
            if (Array.isArray(currentValue)) {
84
                return (
85
                    !Array.isArray(previousValue) ||
86
                    currentValue.length !== previousValue.length ||
87
                    currentValue.some((value, index) => {
88
                        const previousCandyDate = previousValue[index];
89
                        return previousCandyDate instanceof TinyDate ? previousCandyDate.isSameDay(value) : previousCandyDate !== value;
90
                    })
91
                );
92
            } else {
93
                return !this.isSameDate(previousValue as TinyDate, currentValue);
1✔
94
            }
95
        }
96
        return false;
97
    }
98

99
    private isSameDate(left: TinyDate, right: TinyDate): boolean {
100
        return (!left && !right) || (left && right && right.isSameDay(left));
101
    }
102
}
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