catc/react-timekeeper

Ability to use minutes for value and onChange

lostpebble opened this issue · 5 comments

And potentially seconds (if that feature is added).

I find that when working with times in the day, it's easy to reason about it when just using minutes as the value- as in the total minutes past 00:00 in the day. Its a nice single value to pass around and can easily be converted to hours and minutes again for display.

I will be using the separated out hours and minutes for now, but just thought it was strange that pure minutes was not included from the get go too.

catc commented

To clarify, do you mean that if its 2:30am you get a value for 150 minutes (2 * 60 + 30)?

Yep, exactly.

Currently I've wrapped this logic around the component like this:

const [curMins, setCurMins] = useState(initialMinutes);

     <TimeKeeper
        time={{
          hour: Math.floor(curMins / 60),
          minute: curMins % 60,
        }}
        onChange={newTime => {
          setCurMins(newTime.hour * 60 + newTime.minute);
        }}
      />
catc commented

Shouldn't be too hard to add. I'll try to include it in the next feature release.

Can I contribute to this Issue??

catc commented

On second thought, I don't think it make sense to add this since it's pretty niche and can be handled by parent pretty easily. Closing for now.