Skip to content

Incorrect minuteInterval time returned #862

Open
@Agent57

Description

@Agent57

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions