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

adobe / spectrum-web-components / 12693741474

09 Jan 2025 04:03PM UTC coverage: 98.259% (+0.05%) from 98.206%
12693741474

Pull #5002

github

web-flow
Merge 3502508d0 into 5bf31e817
Pull Request #5002: feat: Calendar and DateTimePicker components

5677 of 5977 branches covered (94.98%)

Branch coverage included in aggregate %.

2878 of 2891 new or added lines in 26 files covered. (99.55%)

3 existing lines in 1 file now uncovered.

35918 of 36355 relevant lines covered (98.8%)

1123.79 hits per line

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

98.04
/packages/date-time-picker/src/segments/time/DayPeriodSegment.ts
1
/*
2✔
2
Copyright 2024 Adobe. All rights reserved.
2✔
3
This file is licensed to you under the Apache License, Version 2.0 (the "License");
2✔
4
you may not use this file except in compliance with the License. You may obtain a copy
2✔
5
of the License at http://www.apache.org/licenses/LICENSE-2.0
2✔
6

2✔
7
Unless required by applicable law or agreed to in writing, software distributed under
2✔
8
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
2✔
9
OF ANY KIND, either express or implied. See the License for the specific language
2✔
10
governing permissions and limitations under the License.
2✔
11
*/
2✔
12

2✔
13
import { DateFormatter, ZonedDateTime } from '@internationalized/date';
2✔
14
import { getDayPeriodModifier } from '../../helpers';
2✔
15
import { AM, PM, SegmentTypes } from '../../types';
2✔
16
import { EditableSegment } from '../EditableSegment';
2✔
17

2✔
18
export class DayPeriodSegment extends EditableSegment {
2✔
19
    public minValue: typeof AM = AM;
2✔
20
    public maxValue: typeof PM = PM;
2✔
21
    public value?: typeof AM | typeof PM;
2✔
22
    private localizedMinValue: string = 'AM';
2✔
23
    private localizedMaxValue: string = 'PM';
2✔
24

2✔
25
    constructor(formatted: string, label: string) {
2✔
26
        super(SegmentTypes.DayPeriod, formatted, label);
484✔
27
    }
484✔
28

484✔
29
    private toggleAmPm(): void {
484✔
30
        if (this.value === AM) this.value = PM;
2✔
31
        else this.value = AM;
5✔
32
    }
3✔
33

3✔
34
    public override increment(): void {
5✔
35
        if (this.value === undefined) this.value = this.minValue;
2✔
36
        else this.toggleAmPm();
23✔
37
    }
2✔
38

2✔
39
    public override decrement(): void {
2✔
40
        if (this.value === undefined) this.value = this.maxValue;
2✔
41
        else this.toggleAmPm();
5✔
42
    }
3✔
43

3✔
44
    public override setValueFromDate(currentDate: ZonedDateTime): void {
2✔
45
        this.value = getDayPeriodModifier(currentDate.hour);
108✔
46
    }
108✔
47

108✔
48
    public override handleInput(eventData: string): void {
108✔
49
        const charTypedIn = eventData.toLowerCase();
2✔
50
        const isCharFromAM = this.localizedMinValue
8✔
51
            .toLowerCase()
8✔
52
            .includes(charTypedIn);
8✔
53
        const isCharFromPM = this.localizedMaxValue
8✔
54
            .toLowerCase()
8✔
55
            .includes(charTypedIn);
8✔
56

8✔
57
        if (isCharFromAM && isCharFromPM) return;
8✔
58

8✔
59
        if (isCharFromAM) this.value = AM;
8✔
60
        if (isCharFromPM) this.value = PM;
8✔
61
        return;
3✔
62
    }
3✔
63

3✔
64
    public setLocalizedLimits(dateFormatter: DateFormatter): void {
2✔
65
        const amDate = new Date(0, 0, 0, this.minValue, 0);
484✔
66
        const pmDate = new Date(0, 0, 0, this.maxValue, 0);
484✔
67

484✔
68
        const [am, pm] = [amDate, pmDate].map(
484✔
69
            this.getDayPeriodFromDate.bind(this, dateFormatter)
484✔
70
        );
484✔
71

484✔
72
        if (am) this.localizedMinValue = am;
484✔
73
        if (pm) this.localizedMaxValue = pm;
484✔
74
    }
484✔
75

484✔
76
    private getDayPeriodFromDate(
484✔
77
        dateFormatter: DateFormatter,
968✔
78
        date: Date
968✔
79
    ): string | undefined {
968✔
80
        return dateFormatter
968✔
81
            .formatToParts(date)
968✔
82
            .find((part) => part.type === this.type)?.value;
968✔
83
    }
968!
NEW
84
}
×
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