File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed
Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,6 @@ export default function useTimer(settings) {
5757 }
5858
5959 function handleExtraMilliSeconds ( secondsValue , extraMilliSeconds ) {
60- setSeconds ( Math . floor ( secondsValue ) + 1 ) ;
6160 intervalRef . current = setTimeout ( ( ) => {
6261 intervalRef . current = undefined ;
6362 setSeconds ( Time . getSecondsFromExpiry ( expiryTimestamp ) ) ;
@@ -69,10 +68,10 @@ export default function useTimer(settings) {
6968 if ( Validate . expiryTimestamp ( expiryTimestamp ) ) {
7069 const secondsValue = Time . getSecondsFromExpiry ( expiryTimestamp ) ;
7170 const extraMilliSeconds = ( ( secondsValue - Math . floor ( secondsValue ) ) * 1000 ) . toFixed ( 2 ) ;
71+ setSeconds ( secondsValue ) ;
7272 if ( extraMilliSeconds > 0 ) {
7373 handleExtraMilliSeconds ( secondsValue , extraMilliSeconds ) ;
7474 } else {
75- setSeconds ( secondsValue ) ;
7675 start ( ) ;
7776 }
7877 }
Original file line number Diff line number Diff line change 11export default class Time {
2- static getTimeFromSeconds ( totalSeconds ) {
2+ static getTimeFromSeconds ( secs ) {
3+ const totalSeconds = Math . ceil ( secs ) ;
34 const days = Math . floor ( totalSeconds / ( 60 * 60 * 24 ) ) ;
45 const hours = Math . floor ( ( totalSeconds % ( 60 * 60 * 24 ) ) / ( 60 * 60 ) ) ;
56 const minutes = Math . floor ( ( totalSeconds % ( 60 * 60 ) ) / 60 ) ;
@@ -16,9 +17,8 @@ export default class Time {
1617 static getSecondsFromExpiry ( expiry ) {
1718 const now = new Date ( ) . getTime ( ) ;
1819 const milliSecondsDistance = expiry - now ;
19- const roundedValue = Math . ceil ( ( milliSecondsDistance ) / 100 ) * 100 ;
20- if ( roundedValue > 0 ) {
21- return roundedValue / 1000 ;
20+ if ( milliSecondsDistance > 0 ) {
21+ return milliSecondsDistance / 1000 ;
2222 }
2323 return 0 ;
2424 }
You can’t perform that action at this time.
0 commit comments