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

add minHour & minMinute props #3

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export default Example;

| Prop | Type | Description | Default |
| -------------- | -------- | ---------------------------------------------- | ------- |
| minHour | number | Minimum of hour | 0 |
| maxHour | number | Maximum of hour | 23 |
| minMinute | number | Minimum of minute | 0 |
| maxMinute | number | Maximum of minute | 59 |
| hourInterval | number | The interval at which hours can be selected. | 1 |
| minuteInterval | number | The interval at which minutes can be selected. | 1 |
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { StyleProp, ViewStyle } from "react-native";

declare module "react-native-24h-timepicker" {
export type TimePickerProps = {
minHour?: number;
maxHour?: number;
minMinute?: number;
maxMinute?: number;
hourInterval?: number;
minuteInterval?: number;
Expand Down
29 changes: 13 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,26 @@ class TimePicker extends Component {

getHourItems = () => {
const items = [];
const { maxHour, hourInterval, hourUnit } = this.props;
const interval = maxHour / hourInterval;
for (let i = 0; i <= interval; i++) {
const value = `${i * hourInterval}`;
const { minHour, maxHour, hourInterval, hourUnit } = this.props;
for (let i = minHour; i <= maxHour; i=i+hourInterval){
const value = `${i}`;
const item = (
<Picker.Item key={value} value={value} label={value + hourUnit} />
);
items.push(item);
items.push(item);
}
return items;
};

getMinuteItems = () => {
const items = [];
const { maxMinute, minuteInterval, minuteUnit } = this.props;
const interval = maxMinute / minuteInterval;
for (let i = 0; i <= interval; i++) {
const value = i * minuteInterval;
const new_value = value < 10 ? `0${value}` : `${value}`;
const { minMinute, maxMinute, minuteInterval, minuteUnit } = this.props;
for (let i = minMinute; i <= maxMinute; i=i+minuteInterval){
const value = value < 10 ? `0${i}` : `${i}`;
const item = (
<Picker.Item
key={value}
value={new_value}
label={new_value + minuteUnit}
/>
<Picker.Item key={value} value={value} label={value + minuteUnit} />
);
items.push(item);
items.push(item);
}
return items;
};
Expand Down Expand Up @@ -140,7 +133,9 @@ class TimePicker extends Component {
}

TimePicker.propTypes = {
minHour: PropTypes.number,
maxHour: PropTypes.number,
minMinute: PropTypes.number,
maxMinute: PropTypes.number,
hourInterval: PropTypes.number,
minuteInterval: PropTypes.number,
Expand All @@ -156,7 +151,9 @@ TimePicker.propTypes = {
};

TimePicker.defaultProps = {
minHour: 0,
maxHour: 23,
minMinute: 0,
maxMinute: 59,
hourInterval: 1,
minuteInterval: 1,
Expand Down