react-countdown-clock icon indicating copy to clipboard operation
react-countdown-clock copied to clipboard

When it comes to second, unable to maintain the time format as (xx:xx)

Open krishnakumar-g opened this issue 8 years ago • 2 comments
trafficstars

I have specified the value of 'timeFormat' props as 'hms'. For value greater than 60 seconds, it maintains the time format as (xx:xx). But, when the time is 60 seconds or less it omits the format(xx:xx) and shows only the seconds as (60, 59...1). There should be some default props to disable this.

  _formattedTime: ->
    decimals = (@_seconds <= 9.9 && @props.showMilliseconds) ? 1 : 0

    if @props.timeFormat == 'hms'
      hours   = parseInt( @_seconds / 3600 ) % 24
      minutes = parseInt( @_seconds / 60 ) % 60
      seconds = (@_seconds % 60).toFixed(decimals)

In the 'formattedTime' function, if showMilliseconds = false && enableStrictFormat = true, then we can avoid 'toFixed(decimals)' to maintain the format.

I need this functionality, so please do the needful.

Thanks in advance. KrishnaKumar G

krishnakumar-g avatar Dec 21 '16 10:12 krishnakumar-g

Hi,

Yes it was a stylistic choice to drop hours and minutes as they become exhausted. I'm not sure what you mean in regards to preventing toFixed on the seconds (feel free to do a PR). I would have thought it's the construction of the time timeParts array that needs some additional conditionals to prevent us dropping hours/minutes.

      timeParts = []
      timeParts.push hours if hours > 0
      timeParts.push minutes if minutes > 0
      timeParts.push seconds

It needs a little thought about how to handle durations with and without hours/minutes. I'm of the feeling that it's the initial duration which defines the time format and then you want an option to maintain that throughout the countdown.

Thanks, Hugh

pughpugh avatar Dec 21 '16 11:12 pughpugh

Yes, I want to maintain the same format(xx:xx) throughout the countdown.

Current behavior: for 3 minutes, it is showing as (03:00), but for 1 minute, it is showing as (60), and for 30 seconds it is showing as (30)

Expected behavior: for 3 minutes - (03:00) for 1 minute - (01:00) for 30 seconds - (00:30) for 1 second - (00:01)

This is what I am looking for.

Thanks.

krishnakumar-g avatar Dec 21 '16 12:12 krishnakumar-g