capacitor-community / capacitor-community/date-picker

bug: "Failed to parse date" on iOS when providing min and max values

Open
#43 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
94
Forks
30
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When I provide values for the min and max values, the date and time picker does not show up on iOS. The same typescript code works perfectly well on Android.

**To Reproduce**
Steps to reproduce the behavior:
1. On iOS, tap the "Select Date and Time" button

![image](https://user-images.githubusercontent.com/11599005/116279976-c96c3680-a7ba-11eb-81f4-2b16859119c4.png)

2. The following "Failed to parse date" error shows up

![image](https://user-images.githubusercontent.com/11599005/116280164-fc162f00-a7ba-11eb-9102-5313b1f8ba42.png)

**Expected behavior**

The date picker should open instead, honoring the min and max dates provided upon instantiation.

**Smartphone (please complete the following information):**
- Device: iPhone X
- OS: iOS 14.4.2

**Additional context**

```typescript

// Note that minDate is shown in the template itself
get minDate(): string {
return DateTime.now().plus({ hours: 2 }).toFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
}

get maxDate(): string {
return DateTime.now().plus({ days: 6 }).toFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
}

...

async showPicker() {
const DatePicker: DatePickerPluginInterface = Plugins.DatePickerPlugin as any;
const options = {
min: this.minDate,
max: this.maxDate,
};
DatePicker.present(options).then(
(date) => (this.currentArrivalDateTime = date.value),
(err) => alert(err)
);
}
```

```html
{{ minDate }}

Preferred Arrival Time





{{ currentArrivalDateTime | date: "EEE - MMM d (h:mm a)" }}


Change

Select Time and Date
```

The same exact code works on Android. See screenshots below.

![image](https://user-images.githubusercontent.com/11599005/116280132-f1f43080-a7ba-11eb-99d1-845376af8eef.png)

![image](https://user-images.githubusercontent.com/11599005/116280209-0a644b00-a7bb-11eb-885d-a900a7e4588c.png)

![image](https://user-images.githubusercontent.com/11599005/116280256-13edb300-a7bb-11eb-8275-0f30655257fa.png)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue on iOS using the min and max date strings shown in the report, then inspect the plugin's iOS date-parsing path. Done means the picker opens with those bounds honored and the existing Android behavior remains unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift, typescript
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.