| 79 | } |
| 80 | |
| 81 | function segmentBounds( |
| 82 | type: 'year' | 'month' | 'day', |
| 83 | ctx: { year: number; month: number }, |
| 84 | minDate: Date | undefined, |
| 85 | maxDate: Date | undefined |
| 86 | ): { min: number; max: number } { |
| 87 | const minP = minDate |
| 88 | ? { |
| 89 | year: minDate.getUTCFullYear(), |
| 90 | month: minDate.getUTCMonth() + 1, |
| 91 | day: minDate.getUTCDate(), |
| 92 | } |
| 93 | : null; |
| 94 | const maxP = maxDate |
| 95 | ? { |
| 96 | year: maxDate.getUTCFullYear(), |
| 97 | month: maxDate.getUTCMonth() + 1, |
| 98 | day: maxDate.getUTCDate(), |
| 99 | } |
| 100 | : null; |
| 101 | |
| 102 | if (type === 'year') { |
| 103 | return { min: minP?.year ?? 1, max: maxP?.year ?? 9999 }; |
| 104 | } |
| 105 | if (type === 'month') { |
| 106 | return { |
| 107 | min: minP && ctx.year === minP.year ? minP.month : 1, |
| 108 | max: maxP && ctx.year === maxP.year ? maxP.month : 12, |
| 109 | }; |
| 110 | } |
| 111 | return { |
| 112 | min: minP && ctx.year === minP.year && ctx.month === minP.month ? minP.day : 1, |
| 113 | max: |
| 114 | maxP && ctx.year === maxP.year && ctx.month === maxP.month |
| 115 | ? maxP.day |
| 116 | : daysInMonth(ctx.year, ctx.month), |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | export interface DateOptions extends PromptOptions<Date, DatePrompt> { |
| 121 | format?: DateFormat; |