File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -56,10 +56,25 @@ export default function useTimer(settings) {
5656 setExpiryTimestamp ( newExpiryTimestamp ) ;
5757 }
5858
59- useEffect ( ( ) => {
60- if ( Validate . expiryTimestamp ( expiryTimestamp ) ) {
59+ function handleExtraMilliSeconds ( secondsValue , extraMilliSeconds ) {
60+ setSeconds ( Math . floor ( secondsValue ) + 1 ) ;
61+ intervalRef . current = setTimeout ( ( ) => {
62+ intervalRef . current = undefined ;
6163 setSeconds ( Time . getSecondsFromExpiry ( expiryTimestamp ) ) ;
6264 start ( ) ;
65+ } , extraMilliSeconds ) ;
66+ }
67+
68+ useEffect ( ( ) => {
69+ if ( Validate . expiryTimestamp ( expiryTimestamp ) ) {
70+ const secondsValue = Time . getSecondsFromExpiry ( expiryTimestamp ) ;
71+ const extraMilliSeconds = ( ( secondsValue - Math . floor ( secondsValue ) ) * 1000 ) . toFixed ( 2 ) ;
72+ if ( extraMilliSeconds > 0 ) {
73+ handleExtraMilliSeconds ( secondsValue , extraMilliSeconds ) ;
74+ } else {
75+ setSeconds ( secondsValue ) ;
76+ start ( ) ;
77+ }
6378 }
6479 return clearIntervalRef ;
6580 } , [ expiryTimestamp ] ) ;
Original file line number Diff line number Diff line change @@ -16,8 +16,9 @@ export default class Time {
1616 static getSecondsFromExpiry ( expiry ) {
1717 const now = new Date ( ) . getTime ( ) ;
1818 const milliSecondsDistance = expiry - now ;
19- if ( milliSecondsDistance > 0 ) {
20- return Math . floor ( milliSecondsDistance / 1000 ) ;
19+ const roundedValue = Math . ceil ( ( milliSecondsDistance ) / 100 ) * 100 ;
20+ if ( roundedValue > 0 ) {
21+ return roundedValue / 1000 ;
2122 }
2223 return 0 ;
2324 }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ module.exports = {
3333 devServer : {
3434 contentBase : path . join ( __dirname , 'dev-dist' ) ,
3535 compress : true ,
36- port : 9000
36+ port : 9000 ,
37+ disableHostCheck : true
3738 }
3839}
You can’t perform that action at this time.
0 commit comments