• 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

85.37
/packages/date-time-picker/src/segments/modifiers/SegmentsModifier.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 { EditableSegmentType, SegmentType, SegmentTypes } from '../../types';
2✔
15
import { DateTimeSegments } from '../DateTimeSegments';
2✔
16
import { type EditableSegment } from '../EditableSegment';
2✔
17
import { SegmentsFormatter } from '../SegmentsFormatter';
2✔
18

2✔
19
export interface SegmentsModifierParams {
2✔
20
    dateFormatter: DateFormatter;
2✔
21
    segments: DateTimeSegments;
2✔
22
    currentDate: ZonedDateTime;
2✔
23
}
2✔
24

2✔
25
export abstract class SegmentsModifier {
2✔
26
    protected segments: DateTimeSegments;
2✔
27
    protected dateFormatter: DateFormatter;
2✔
28
    protected currentDate: ZonedDateTime;
2✔
29

2✔
30
    constructor(params: SegmentsModifierParams) {
2✔
31
        const { dateFormatter, segments, currentDate } = params;
2✔
32
        this.segments = new DateTimeSegments(segments.all);
763✔
33
        this.dateFormatter = dateFormatter;
763✔
34
        this.currentDate = currentDate;
763✔
35
    }
763✔
36

763✔
37
    public modify(segmentType: EditableSegmentType): DateTimeSegments {
763✔
38
        const segment = this.segments.getByType(segmentType);
2✔
39
        if (!segment) return this.segments;
763!
NEW
40

×
41
        this.modifySegment(segment);
763✔
42

763✔
43
        this.updateSegmentsLimits(segmentType);
763✔
44

763✔
45
        const segmentsFormatter = new SegmentsFormatter(
763✔
46
            this.dateFormatter,
763✔
47
            this.currentDate
763✔
48
        );
763✔
49
        this.segments = segmentsFormatter.format(this.segments);
763✔
50

763✔
51
        return this.segments;
763✔
52
    }
763✔
53

763✔
54
    private updateSegmentsLimits(modifiedSegmentType: SegmentType): void {
2✔
55
        const changedYear = modifiedSegmentType === SegmentTypes.Year;
763✔
56
        const changedMonth = modifiedSegmentType === SegmentTypes.Month;
763✔
57

763✔
58
        const year = this.segments.year;
763✔
59
        const month = this.segments.month;
763✔
60
        const day = this.segments.day;
763✔
61

763✔
62
        if (changedYear) {
763✔
63
            month?.setLimits(this.currentDate);
763✔
64
            day?.setLimits(this.currentDate, month?.value, year?.value);
150!
NEW
65
        }
×
NEW
66

×
NEW
67
        if (changedMonth)
×
68
            day?.setLimits(this.currentDate, month?.value, year?.value);
763!
NEW
69
    }
×
NEW
70

×
NEW
71
    protected abstract modifySegment(segment: EditableSegment): void;
×
NEW
72
}
×
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