MCPcopy Create free account
hub / github.com/adobe/react-spectrum / IncompleteDate

Class IncompleteDate

packages/react-stately/src/datepicker/IncompleteDate.ts:25–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 * time. This enables the user to adjust the day period (e.g. am/pm) independently from the hour.
24 */
25export class IncompleteDate {
26 calendar: Calendar;
27 era: string | null;
28 year: number | null;
29 month: number | null;
30 day: number | null;
31 hour: number | null;
32 hourCycle: HourCycle;
33 dayPeriod: number | null;
34 minute: number | null;
35 second: number | null;
36 millisecond: number | null;
37 offset: number | null;
38
39 constructor(
40 calendar: Calendar,
41 hourCycle: HourCycle,
42 dateValue?: Partial<Omit<AnyDateTime, 'copy'>> | null
43 ) {
44 this.era = dateValue?.era ?? null;
45 this.calendar = calendar;
46 this.year = dateValue?.year ?? null;
47 this.month = dateValue?.month ?? null;
48 this.day = dateValue?.day ?? null;
49 this.hour = dateValue?.hour ?? null;
50 this.hourCycle = hourCycle;
51 this.dayPeriod = null;
52 this.minute = dateValue?.minute ?? null;
53 this.second = dateValue?.second ?? null;
54 this.millisecond = dateValue?.millisecond ?? null;
55 this.offset = 'offset' in (dateValue ?? {}) ? (dateValue as any).offset : null;
56
57 // Convert the hour from 24 hour time to the given hour cycle.
58 if (this.hour != null) {
59 let [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);
60 this.dayPeriod = dayPeriod;
61 this.hour = hour;
62 }
63 }
64
65 copy(): IncompleteDate {
66 let res = new IncompleteDate(this.calendar, this.hourCycle);
67 res.era = this.era;
68 res.year = this.year;
69 res.month = this.month;
70 res.day = this.day;
71 res.hour = this.hour;
72 res.dayPeriod = this.dayPeriod;
73 res.minute = this.minute;
74 res.second = this.second;
75 res.millisecond = this.millisecond;
76 res.offset = this.offset;
77 return res;
78 }
79
80 /** Checks whether all the specified segments have a value. */
81 isComplete(segments: DateSegmentType[]) {
82 return segments.every(segment => this[segment] != null);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected