Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-wheel-picker-android

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-wheel-picker-android - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

.eslintrc.json

205

DatePicker.js

@@ -1,31 +0,32 @@

import React from 'react'
import React from 'react';
import {
View,
StyleSheet
} from 'react-native'
import WheelPicker from './WheelPicker'
StyleSheet,
} from 'react-native';
import WheelPicker from './WheelPicker';
import moment from 'moment';
class DatePicker extends React.Component {
constructor(props){
super(props)
this.selectedDate = this.props.initDate ? new Date(this.props.initDate) : new Date()
let time12format = hourTo12Format(this.selectedDate.getHours())
let time24format = this.selectedDate.getHours()
constructor(props) {
super(props);
this.selectedDate = this.props.initDate ? new Date(this.props.initDate) : new Date();
const time12format = hourTo12Format(this.selectedDate.getHours());
const time24format = this.selectedDate.getHours();
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var millisBetween = this.selectedDate.getTime() - new Date().getTime();
const millisecondsPerDay = 1000 * 60 * 60 * 24;
const millisBetween = this.selectedDate.getTime() - new Date().getTime();
let millisBetweenStartDate, daysStartDate
let millisBetweenStartDate,
daysStartDate;
if (this.props.startDate) {
millisBetweenStartDate = new Date(this.props.startDate).getTime() - new Date().getTime()
daysStartDate = millisBetweenStartDate / millisecondsPerDay
millisBetweenStartDate = new Date(this.props.startDate).getTime() - new Date().getTime();
daysStartDate = millisBetweenStartDate / millisecondsPerDay;
}
var days = millisBetween / millisecondsPerDay;
this.daysAfterSelectedDate = Math.round(daysStartDate)
this.initDayInex = this.props.startDate ? Math.round(days) - Math.round(daysStartDate) : Math.round(days)
this.initHourInex = this.props.format24 ? time24format : time12format[0] - 1
this.initMinuteInex = Math.round(this.selectedDate.getMinutes() / 5)
this.initAmInex = time12format[1] === 'AM' ? 0 : 1
const days = millisBetween / millisecondsPerDay;
this.daysAfterSelectedDate = Math.round(daysStartDate);
this.initDayInex = this.props.startDate ? Math.round(days) - Math.round(daysStartDate) : Math.round(days);
this.initHourInex = this.props.format24 ? time24format : time12format[0] - 1;
this.initMinuteInex = Math.round(this.selectedDate.getMinutes() / 5);
this.initAmInex = time12format[1] === 'AM' ? 0 : 1;
}

@@ -43,5 +44,5 @@

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onDaySelected(data)}
onItemSelected={data => this.onDaySelected(data)}
selectedItemPosition={this.initDayInex}
/>
/>
<WheelPicker

@@ -55,5 +56,5 @@ style={styles.wheelPicker}

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onHourSelected(data)}
onItemSelected={data => this.onHourSelected(data)}
selectedItemPosition={this.initHourInex}
/>
/>
<WheelPicker

@@ -67,11 +68,11 @@ style={styles.wheelPicker}

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onMinuteSelected(data)}
onItemSelected={data => this.onMinuteSelected(data)}
selectedItemPosition={this.initMinuteInex}
/>
/>
{this.renderAm()}
</View>
)
);
}
renderAm(){
renderAm() {
if (!this.props.format24) {

@@ -86,50 +87,50 @@ return (

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onAmSelected(data)}
onItemSelected={data => this.onAmSelected(data)}
selectedItemPosition={this.initAmInex}
/>
)
/>
);
}
}
onDaySelected(event){
let hours = this.selectedDate.getHours()
let minutes = this.selectedDate.getMinutes()
onDaySelected(event) {
const hours = this.selectedDate.getHours();
const minutes = this.selectedDate.getMinutes();
if (event.data === 'Today') {
this.selectedDate = new Date()
this.selectedDate = new Date();
} else {
this.selectedDate = increaseDateByDays(new Date(), this.props.startDate ? this.daysAfterSelectedDate + event.position : event.position)
this.selectedDate = increaseDateByDays(new Date(), this.props.startDate ? this.daysAfterSelectedDate + event.position : event.position);
}
this.selectedDate.setHours(hours)
this.selectedDate.setMinutes(minutes)
this.onDateSelected()
this.selectedDate.setHours(hours);
this.selectedDate.setMinutes(minutes);
this.onDateSelected();
}
onHourSelected(event){
onHourSelected(event) {
if (this.props.format24) {
this.selectedDate.setHours(event.data)
this.selectedDate.setHours(event.data);
} else {
let time12format = hourTo12Format(this.selectedDate.getHours())
let newTime12Format = event.data + ' ' + time12format[1]
let selectedHour24format = hourTo24Format(newTime12Format)
this.selectedDate.setHours(selectedHour24format)
const time12format = hourTo12Format(this.selectedDate.getHours());
const newTime12Format = `${event.data} ${time12format[1]}`;
const selectedHour24format = hourTo24Format(newTime12Format);
this.selectedDate.setHours(selectedHour24format);
}
this.onDateSelected()
this.onDateSelected();
}
onMinuteSelected(event){
this.selectedDate.setMinutes(event.data)
this.onDateSelected()
onMinuteSelected(event) {
this.selectedDate.setMinutes(event.data);
this.onDateSelected();
}
onAmSelected(event){
let time12format = hourTo12Format(this.selectedDate.getHours())
let newTime12Format = time12format[0] + ' ' + event.data
let selectedHour24format = hourTo24Format(newTime12Format)
this.selectedDate.setHours(selectedHour24format)
this.onDateSelected()
onAmSelected(event) {
const time12format = hourTo12Format(this.selectedDate.getHours());
const newTime12Format = `${time12format[0]} ${event.data}`;
const selectedHour24format = hourTo24Format(newTime12Format);
this.selectedDate.setHours(selectedHour24format);
this.onDateSelected();
}
onDateSelected(){
onDateSelected() {
if (this.props.onDateSelected) {
this.props.onDateSelected(this.selectedDate)
this.props.onDateSelected(this.selectedDate);
}

@@ -149,5 +150,5 @@ }

format24: React.PropTypes.bool,
}
};
var styles = StyleSheet.create({
let styles = StyleSheet.create({
container: {

@@ -161,3 +162,3 @@ flex: 1,

width: null,
flex:1,
flex: 1,
},

@@ -167,3 +168,3 @@ dateWheelPicker: {

width: null,
flex:3,
flex: 3,
},

@@ -179,23 +180,23 @@ });

function hourTo12Format(hour) {
let currDate = new Date()
currDate.setHours(hour)
return dateTo12Hour(currDate.toISOString())
const currDate = new Date();
currDate.setHours(hour);
return dateTo12Hour(currDate.toISOString());
}
const dateTo12Hour = dateString => {
let localDate = new Date(dateString);
const dateTo12Hour = (dateString) => {
const localDate = new Date(dateString);
let hour = localDate.getHours();
if (hour === 12 ) {
return [('12'),('PM')];
} if (hour === 0 ) {
return [('12'),('AM')];
if (hour === 12) {
return [('12'), ('PM')];
} if (hour === 0) {
return [('12'), ('AM')];
}
let afterMidday = hour % 12 === hour;
const afterMidday = hour % 12 === hour;
hour = afterMidday ? hour : hour % 12;
let amPm = afterMidday ? 'AM' : 'PM';
return [(hour.toString()),(amPm)];
}
const amPm = afterMidday ? 'AM' : 'PM';
return [(hour.toString()), (amPm)];
};
function increaseDateByDays(date, numOfDays) {
let nextDate = new Date(date.valueOf());
const nextDate = new Date(date.valueOf());
nextDate.setDate(nextDate.getDate() + numOfDays);

@@ -206,44 +207,44 @@ return nextDate;

const PickerDateArray = (startDate, daysCount) => {
startDate = startDate ? new Date(startDate) : new Date()
daysCount = daysCount ? daysCount : 365
let arr = []
for (var i = 0; i < daysCount; i++) {
if (i === 0 && startDate.getDate() === new Date().getDate() ) {
arr.push('Today')
startDate = startDate ? new Date(startDate) : new Date();
daysCount = daysCount ? daysCount : 365;
const arr = [];
for (let i = 0; i < daysCount; i++) {
if (i === 0 && startDate.getDate() === new Date().getDate()) {
arr.push('Today');
} else {
arr.push(formatDatePicker(new Date(new Date().setDate(startDate.getDate() + i))))
arr.push(formatDatePicker(new Date(new Date().setDate(startDate.getDate() + i))));
}
}
return arr
}
return arr;
};
function formatDatePicker(date) {
let strDate = moment(date).format('ddd MMM D');
const strDate = moment(date).format('ddd MMM D');
return strDate;
}
function getHoursArray(){
let arr = []
for (var i = 1; i < 13; i++) {
arr.push(i)
function getHoursArray() {
const arr = [];
for (let i = 1; i < 13; i++) {
arr.push(i);
}
return arr
return arr;
}
function getFiveMinutesArray(){
let arr = []
arr.push('00')
arr.push('05')
for (var i = 10; i < 60; i = i + 5) {
arr.push('' + i)
function getFiveMinutesArray() {
const arr = [];
arr.push('00');
arr.push('05');
for (let i = 10; i < 60; i += 5) {
arr.push(`${i}`);
}
return arr
return arr;
}
function getAmArray(){
let arr = []
arr.push('AM')
arr.push('PM')
return arr
function getAmArray() {
const arr = [];
arr.push('AM');
arr.push('PM');
return arr;
}
module.exports = DatePicker;

@@ -10,2 +10,2 @@ import WheelPicker from './WheelPicker';

DatePicker,
}
};
{
"name": "react-native-wheel-picker-android",
"version": "0.1.4",
"version": "0.1.5",
"description": "Simple Wheel Picker for Android to use with react-native",

@@ -24,4 +24,22 @@ "main": "index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
"fix": "eslint --fix",
"lint": "eslint .",
"test": "ava"
},
"devDependencies": {
"ava": "^0.17.0",
"react": "~15.3.0",
"react-native": "^0.34.0",
"react-dom": "^15.3.1",
"react-addons-test-utils": "^15.3.1",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"pre-commit": "^1.2.2"
},
"pre-commit": [
"test"
]
}

@@ -1,19 +0,32 @@

import React from 'react'
import React from 'react';
import {
View,
StyleSheet
} from 'react-native'
import WheelPicker from './WheelPicker'
StyleSheet,
} from 'react-native';
import WheelPicker from './WheelPicker';
import moment from 'moment';
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
flexDirection: 'row',
},
wheelPicker: {
height: 150,
width: null,
flex: 1,
},
});
class TimePicker extends React.Component {
constructor(props){
super(props)
this.selectedDate = this.props.initDate ? new Date(this.props.initDate) : new Date()
let time12format = hourTo12Format(this.selectedDate.getHours())
this.hours = this.props.hours ? this.props.hours : getHoursArray()
this.minutes = this.props.minutes ? this.props.minutes : getFiveMinutesArray()
this.initHourInex = time12format[0] - 1
this.initMinuteInex = Math.round(this.selectedDate.getMinutes() / 5)
this.initAmInex = time12format[1] === 'AM' ? 0 : 1
constructor(props) {
super(props);
this.selectedDate = this.props.initDate ? new Date(this.props.initDate) : new Date();
const time12format = hourTo12Format(this.selectedDate.getHours());
this.hours = this.props.hours ? this.props.hours : getHoursArray();
this.minutes = this.props.minutes ? this.props.minutes : getFiveMinutesArray();
this.initHourInex = time12format[0] - 1;
this.initMinuteInex = Math.round(this.selectedDate.getMinutes() / 5);
this.initAmInex = time12format[1] === 'AM' ? 0 : 1;
}

@@ -32,5 +45,5 @@

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onHourSelected(data)}
onItemSelected={data => this.onHourSelected(data)}
selectedItemPosition={this.initHourInex}
/>
/>
<WheelPicker

@@ -44,5 +57,5 @@ style={styles.wheelPicker}

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onMinuteSelected(data)}
onItemSelected={data => this.onMinuteSelected(data)}
selectedItemPosition={this.initMinuteInex}
/>
/>
<WheelPicker

@@ -55,33 +68,33 @@ style={styles.wheelPicker}

selectedItemTextColor={'black'}
onItemSelected={(data)=> this.onAmSelected(data)}
onItemSelected={data => this.onAmSelected(data)}
selectedItemPosition={this.initAmInex}
/>
/>
</View>
)
);
}
onHourSelected(event){
let time12format = hourTo12Format(this.selectedDate.getHours())
let newTime12Format = event.data + ' ' + time12format[1]
let selectedHour24format = hourTo24Format(newTime12Format)
this.selectedDate.setHours(selectedHour24format)
this.onDateSelected()
onHourSelected(event) {
const time12format = hourTo12Format(this.selectedDate.getHours());
const newTime12Format = `${event.data} ${time12format[1]}`;
const selectedHour24format = hourTo24Format(newTime12Format);
this.selectedDate.setHours(selectedHour24format);
this.onDateSelected();
}
onMinuteSelected(event){
this.selectedDate.setMinutes(event.data)
this.onDateSelected()
onMinuteSelected(event) {
this.selectedDate.setMinutes(event.data);
this.onDateSelected();
}
onAmSelected(event){
let time12format = hourTo12Format(this.selectedDate.getHours())
let newTime12Format = time12format[0] + ' ' + event.data
let selectedHour24format = hourTo24Format(newTime12Format)
this.selectedDate.setHours(selectedHour24format)
this.onDateSelected()
onAmSelected(event) {
const time12format = hourTo12Format(this.selectedDate.getHours());
const newTime12Format = `${time12format[0]} ${event.data}`;
const selectedHour24format = hourTo24Format(newTime12Format);
this.selectedDate.setHours(selectedHour24format);
this.onDateSelected();
}
onDateSelected(){
onDateSelected() {
if (this.props.onDateSelected) {
this.props.onDateSelected(this.selectedDate)
this.props.onDateSelected(this.selectedDate);
}

@@ -97,17 +110,4 @@ }

minutes: React.PropTypes.array,
}
};
var styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
flexDirection: 'row',
},
wheelPicker: {
height: 150,
width: null,
flex:1,
},
});
// it takes in format '12 AM' and return 24 format

@@ -120,45 +120,45 @@ function hourTo24Format(hour) {

function hourTo12Format(hour) {
let currDate = new Date()
currDate.setHours(hour)
return dateTo12Hour(currDate.toISOString())
const currDate = new Date();
currDate.setHours(hour);
return dateTo12Hour(currDate.toISOString());
}
const dateTo12Hour = dateString => {
let localDate = new Date(dateString);
const dateTo12Hour = (dateString) => {
const localDate = new Date(dateString);
let hour = localDate.getHours();
if (hour === 12 ) {
return [('12'),('PM')];
} if (hour === 0 ) {
return [('12'),('AM')];
if (hour === 12) {
return [('12'), ('PM')];
} if (hour === 0) {
return [('12'), ('AM')];
}
let afterMidday = hour % 12 === hour;
const afterMidday = hour % 12 === hour;
hour = afterMidday ? hour : hour % 12;
let amPm = afterMidday ? 'AM' : 'PM';
return [(hour.toString()),(amPm)];
}
const amPm = afterMidday ? 'AM' : 'PM';
return [(hour.toString()), (amPm)];
};
function getHoursArray(){
let arr = []
for (var i = 1; i < 13; i++) {
arr.push(i)
function getHoursArray() {
const arr = [];
for (let i = 1; i < 13; i++) {
arr.push(i);
}
return arr
return arr;
}
function getFiveMinutesArray(){
let arr = []
arr.push('00')
arr.push('05')
for (var i = 10; i < 60; i = i + 5) {
arr.push('' + i)
function getFiveMinutesArray() {
const arr = [];
arr.push('00');
arr.push('05');
for (let i = 10; i < 60; i += 5) {
arr.push(`${i}`);
}
return arr
return arr;
}
function getAmArray(){
let arr = []
arr.push('AM')
arr.push('PM')
return arr
function getAmArray() {
const arr = [];
arr.push('AM');
arr.push('PM');
return arr;
}
module.exports = TimePicker;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc