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

Incorrect minuteInterval time returned #862

Open
Agent57 opened this issue Oct 4, 2024 · 0 comments
Open

Incorrect minuteInterval time returned #862

Agent57 opened this issue Oct 4, 2024 · 0 comments

Comments

@Agent57
Copy link

Agent57 commented Oct 4, 2024

Describe the bug
This was previously raised as issue #666, but incorrectly dismissed as fixed in version 4.2.12

The problem is, that if you open the datetime picker and immediately press 'Confirm', without having altered any of the displayed date/time values, then the returned value will not be rounded to the interval time.

Expected behavior
If you're using the minuteInterval prop and press Confirm, then the returned value should always be the floored value as displayed in the datetime picker.

To Reproduce

import React, {useState} from 'react';
import {SafeAreaView, Text, TouchableOpacity, View} from 'react-native';
import DatePicker from 'react-native-date-picker';

export function TestScreen() {
  const [date, setDate] = useState<Date>();
  const [open, setOpen] = useState(false);

  return (
    <SafeAreaView
      style={{display: 'flex', flex: 1, justifyContent: 'center', alignItems: 'center'}}
    >
      <View>
       <TouchableOpacity
          onPress={() => setOpen(true)}
          style={{minWidth: '50%', backgroundColor: 'lightblue', padding: 8, borderRadius: 4}}
        >
          <Text style={{color: 'black', fontWeight: 'bold', fontSize: 20}}>
            {date?.toDateString()} - {date?.toLocaleTimeString()}
          </Text>
        </TouchableOpacity>
        <DatePicker
          modal
          mode={'datetime'}
          open={open}
          date={new Date()}
          minuteInterval={5}
          onConfirm={newDate => {
            setOpen(false);
            setDate(newDate);
          }}
          onCancel={() => {
            setOpen(false);
            setDate(undefined);
          }}
        />
      </View>
    </SafeAreaView>
  );
}

Smartphone
Only tested on Android
"react-native": "0.74.3",
"react-native-date-picker": "^5.0.7",

react-native-date-picker.webm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant