Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): Support yearAndMonth #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"projectOwner": "capacitor-community",
"repoType": "github",
"repoHost": "https://github.com",
"files": [
"README.md"
],
"files": ["README.md"],
"imageSize": 75,
"commit": true,
"commitConvention": "angular",
Expand All @@ -16,31 +14,30 @@
"name": "Stew",
"avatar_url": "https://avatars1.githubusercontent.com/u/719763?v=4",
"profile": "https://twitter.com/StewanSilva",
"contributions": [
"code",
"doc"
]
"contributions": ["code", "doc"]
},
{
"login": "danielprrazevedo",
"name": "Daniel Pereira",
"avatar_url": "https://avatars2.githubusercontent.com/u/20153661?v=4",
"profile": "https://github.com/danielprrazevedo",
"contributions": [
"code",
"doc",
"maintenance"
]
"contributions": ["code", "doc", "maintenance"]
},
{
"login": "carolineoliva",
"name": "Caroline Oliva",
"avatar_url": "https://avatars1.githubusercontent.com/u/4886893?v=4",
"profile": "https://github.com/carolineoliva",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "oliveryasuna",
"name": "Oliver Yasuna",
"avatar_url": "https://avatars.githubusercontent.com/u/17092333?v=4",
"profile": "https://github.com/oliveryasuna",
"contributions": ["code"]
}
],
"contributorsPerLine": 7
}

17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="https://www.npmjs.com/package/@capacitor-community/date-picker"><img src="https://img.shields.io/npm/dw/@capacitor-community/date-picker?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/date-picker"><img src="https://img.shields.io/npm/v/@capacitor-community/date-picker?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors"><img src="https://img.shields.io/badge/all%20contributors-3-orange?style=flat-square" /></a>
<a href="#contributors"><img src="https://img.shields.io/badge/all%20contributors-4-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</p>

Expand Down Expand Up @@ -301,14 +301,17 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://twitter.com/StewanSilva"><img src="https://avatars1.githubusercontent.com/u/719763?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Stew</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=stewwan" title="Code">💻</a> <a href="https://github.com/capacitor-community/date-picker/commits?author=stewwan" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/danielprrazevedo"><img src="https://avatars2.githubusercontent.com/u/20153661?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Daniel Pereira</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=danielprrazevedo" title="Code">💻</a> <a href="https://github.com/capacitor-community/date-picker/commits?author=danielprrazevedo" title="Documentation">📖</a> <a href="#maintenance-danielprrazevedo" title="Maintenance">🚧</a></td>
<td align="center"><a href="https://github.com/carolineoliva"><img src="https://avatars1.githubusercontent.com/u/4886893?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Caroline Oliva</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=carolineoliva" title="Code">💻</a></td>
</tr>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/StewanSilva"><img src="https://avatars1.githubusercontent.com/u/719763?v=4?s=75" width="75px;" alt="Stew"/><br /><sub><b>Stew</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=stewwan" title="Code">💻</a> <a href="https://github.com/capacitor-community/date-picker/commits?author=stewwan" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/danielprrazevedo"><img src="https://avatars2.githubusercontent.com/u/20153661?v=4?s=75" width="75px;" alt="Daniel Pereira"/><br /><sub><b>Daniel Pereira</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=danielprrazevedo" title="Code">💻</a> <a href="https://github.com/capacitor-community/date-picker/commits?author=danielprrazevedo" title="Documentation">📖</a> <a href="#maintenance-danielprrazevedo" title="Maintenance">🚧</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/carolineoliva"><img src="https://avatars1.githubusercontent.com/u/4886893?v=4?s=75" width="75px;" alt="Caroline Oliva"/><br /><sub><b>Caroline Oliva</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=carolineoliva" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/oliveryasuna"><img src="https://avatars.githubusercontent.com/u/17092333?v=4?s=75" width="75px;" alt="Oliver Yasuna"/><br /><sub><b>Oliver Yasuna</b></sub></a><br /><a href="https://github.com/capacitor-community/date-picker/commits?author=oliveryasuna" title="Code">💻</a></td>
</tr>
</tbody>
</table>

<!-- markdownlint-enable -->
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
Expand Down
12 changes: 11 additions & 1 deletion example/src/app/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class HomePage implements OnInit {
value: 'dateAndTime',
label: 'Date and Time',
},
{
value: 'yearAndMonth',
label: 'Year and Month',
},
];

async ngOnInit(): Promise<void> {
Expand Down Expand Up @@ -131,7 +135,13 @@ export class HomePage implements OnInit {
options.ios.style = this.wheels ? 'wheels' : null;
}
console.log(options);
return DatePicker.present(options);
const result = DatePicker.present(options);

result.then(({value: string}): void => {
alert(`Value: ${string}`);
});

return result;
}

async platformIs(
Expand Down
9 changes: 9 additions & 0 deletions ios/Plugin/DatePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public class DatePicker {
picker.datePickerMode = UIDatePicker.Mode.dateAndTime
} else if options.mode == "date" || options.mode == "dateAndTime" {
picker.datePickerMode = UIDatePicker.Mode.date
} else if options.mode == "yearAndMonth" {
if #available(iOS 17.4, *) {
picker.datePickerMode = UIDatePicker.Mode.yearAndMonth
} else {
picker.datePickerMode = UIDatePicker.Mode.date
picker.datePickerMode = UIDatePicker.Mode.init(rawValue: 4269) ?? UIDatePicker.Mode.date
}
} else {
picker.datePickerMode = UIDatePicker.Mode.time
}
Expand Down Expand Up @@ -259,6 +266,8 @@ public class DatePicker {
format = options.is24h || is24h ? "HH:mm" : "hh:mm a"
} else if self.options.mode == "date" {
format = "E, MMM d, yyyy"
} else if options.mode == "yearAndMonth" {
format = "MMM yyyy"
}
return Parse.dateToString(date: date, format: format, locale: locale)
}
Expand Down
5 changes: 3 additions & 2 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type DatePickerMode = 'time' | 'date' | 'dateAndTime' | 'countDownTimer';
export type DatePickerMode = 'time' | 'date' | 'dateAndTime' | 'countDownTimer' | 'yearAndMonth';
export type DatePickerTheme = 'light' | 'dark' | string;
export type DatePickerIosStyle = 'wheels' | 'inline';

Expand Down Expand Up @@ -26,7 +26,8 @@ export interface DatePickerBaseOptions {
* @type {DatePickerMode}
* @default "dateAndTime"
*
* @description Datepicker mode
* @description Datepicker mode.
* `yearAndMonth` is only available for iOS.
*/
mode?: DatePickerMode;
/**
Expand Down