• 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

36.11
/projects/igniteui-angular/src/lib/calendar/common/model.ts
1
import { isDate } from "../../core/utils";
2

3
/* eslint-disable @typescript-eslint/consistent-type-definitions */
4
export type DayParameter = CalendarDay | Date;
5

6
export type CalendarRangeParams = {
7
    start: DayParameter;
8
    end: DayParameter | number;
9
    unit?: DayInterval;
10
};
11

12
type CalendarDayParams = {
13
    year: number;
14
    month: number;
15
    date?: number;
16
};
17

18
export type DayInterval = "year" | "quarter" | "month" | "week" | "day";
19

20
export const daysInWeek = 7;
2✔
21
const millisecondsInDay = 86400000;
2✔
22

23
export function toCalendarDay(date: DayParameter) {
UNCOV
24
    return isDate(date) ? CalendarDay.from(date) : date;
×
25
}
26

27
function checkRollover(original: CalendarDay, modified: CalendarDay) {
UNCOV
28
    return original.date !== modified.date
×
29
        ? modified.set({ date: 0 })
30
        : modified;
31
}
32

33
export class CalendarDay {
34
    private _date!: Date;
35

36
    /** Constructs and returns the current day. */
37
    public static get today() {
UNCOV
38
        return CalendarDay.from(new Date());
×
39
    }
40

41
    /** Constructs a new CalendarDay instance from a Date object. */
42
    public static from(date: Date) {
43
        return new CalendarDay({
16✔
44
            year: date.getFullYear(),
45
            month: date.getMonth(),
46
            date: date.getDate(),
47
        });
48
    }
49

50
    constructor(args: CalendarDayParams) {
51
        this._date = new Date(args.year, args.month, args.date ?? 1);
22!
52
    }
53

54
    /** Returns a copy of this instance. */
55
    public clone() {
56
        return CalendarDay.from(this._date);
12✔
57
    }
58

59
    /**
60
     * Returns a new instance with values replaced.
61
     */
62
    public set(args: Partial<CalendarDayParams>) {
UNCOV
63
        return new CalendarDay({
×
64
            year: args.year ?? this.year,
×
65
            month: args.month ?? this.month,
×
66
            date: args.date ?? this.date,
×
67
        });
68
    }
69

70
    public add(unit: DayInterval, value: number) {
71
        const result = this.clone();
12✔
72
        switch (unit) {
12!
73
            case "year":
UNCOV
74
                result._date.setFullYear(result.year + value);
×
UNCOV
75
                return checkRollover(this, result);
×
76
            case "quarter":
UNCOV
77
                result._date.setMonth(result.month + 3 * value);
×
UNCOV
78
                return checkRollover(this, result);
×
79
            case "month":
UNCOV
80
                result._date.setMonth(result.month + value);
×
UNCOV
81
                return checkRollover(this, result);
×
82
            case "week":
83
                result._date.setDate(result.date + 7 * value);
4✔
84
                return result;
4✔
85
            case "day":
86
                result._date.setDate(result.date + value);
8✔
87
                return result;
8✔
88
            default:
89
                throw new Error("Invalid interval");
×
90
        }
91
    }
92

93
    /** Returns the day of the week (Sunday = 0). */
94
    public get day() {
UNCOV
95
        return this._date.getDay();
×
96
    }
97

98
    /** Returns the full year. */
99
    public get year() {
UNCOV
100
        return this._date.getFullYear();
×
101
    }
102

103
    /** Returns the month. */
104
    public get month() {
UNCOV
105
        return this._date.getMonth();
×
106
    }
107

108
    /** Returns the date */
109
    public get date() {
110
        return this._date.getDate();
12✔
111
    }
112

113
    /** Returns the timestamp since epoch in milliseconds. */
114
    public get timestamp() {
UNCOV
115
        return this._date.getTime();
×
116
    }
117

118
    /** Returns the current week number. */
119
    public get week() {
UNCOV
120
        const firstDay = new CalendarDay({ year: this.year, month: 0 })
×
121
            .timestamp;
122
        const currentDay =
UNCOV
123
            (this.timestamp - firstDay + millisecondsInDay) / millisecondsInDay;
×
UNCOV
124
        return Math.ceil(currentDay / daysInWeek);
×
125
    }
126

127
    /** Returns the underlying native date instance. */
128
    public get native() {
129
        return new Date(this._date);
8✔
130
    }
131

132
    /**
133
     * Whether the current date is a weekend day.
134
     *
135
     * @remarks
136
     * This is naive, since it does not account for locale specifics.
137
     */
138
    public get weekend() {
UNCOV
139
        return this.day < 1 || this.day > 5;
×
140
    }
141

142
    public equalTo(value: DayParameter) {
UNCOV
143
        return this.timestamp === toCalendarDay(value).timestamp;
×
144
    }
145

146
    public greaterThan(value: DayParameter) {
UNCOV
147
        return this.timestamp > toCalendarDay(value).timestamp;
×
148
    }
149

150
    public lessThan(value: DayParameter) {
UNCOV
151
        return this.timestamp < toCalendarDay(value).timestamp;
×
152
    }
153

154
    public toString() {
UNCOV
155
        return `${this.native}`;
×
156
    }
157
}
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