• Resolved airdrummer

    (@airdrummer)


    the widget displays _8_days for an event to be held @ 3pm in a week (7 days from today) right up until 3pm today:-\

    please improve your automatic time units to fix this misleading round-off error: 7days + 6 hours == 7.25 days but != 8 days; or add a days+hours option.

    in the meantime, i have worked around this bug by setting the event’s time to 3am, so i won’t have to unbork the time for 6 days;-}

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter airdrummer

    (@airdrummer)

    fixed it:
    line 538 in plugins/jetpack/modules/widgets/milestone/class-milestone-widget.php
    change
    return (int) ( $seconds / 60 / 60 / 24 + 1 );
    to
    return (int) ( $seconds / 60 / 60 / 24 + 0.5 );

    Plugin Contributor Stef (a11n)

    (@erania-pinnera)

    Hi there,

    I’m glad to hear you sorted this out by yourself 🙂

    In case you need more help from us, please share your site URL next time so we’ll be able to take a look at it.

    For now, I make this as solved. Cheers!

    Thread Starter airdrummer

    (@airdrummer)

    ah, but will u fix it so i don’t have to patch it in the next update?

    protected function get_interval_in_units( $seconds, $units ) {
    	switch ( $units ) {
    		case 'years':
    			$years    = $seconds / YEAR_IN_SECONDS;
    			$decimals = abs( round( $years, 1 ) - round( $years ) ) > 0 ? 1 : 0;
    			return number_format_i18n( $years, $decimals );
    		case 'months':
    			return (int) ( $seconds / 60 / 60 / 24 / 30 + 0.5);
    		case 'days':
    			return (int) ( $seconds / 60 / 60 / 24 + 0.5 );
    		case 'hours':
    			return (int) ( $seconds / 60 / 60 + 0.5);
    		case 'minutes':
    			return (int) ( $seconds / 60 + 0.5 );
    		default:
    			return $seconds;
    	}
    }

    (also note that all other units are cast to integer; above contains my patch for simple 1/2 rounding instead of rounding up; added roundings noted by lack of space after 0.5)

    • This reply was modified 5 years, 2 months ago by airdrummer.
    Plugin Contributor Dan (a11n)

    (@drawmyface)

    Thanks @airdrummer I’ve submitted this to our developers on Github so you can follow along there for any updates:
    https://github.com/Automattic/jetpack/issues/18449

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘milestone widget countdown days inaccurate’ is closed to new replies.