0 ? '▼ ' : '' ) ) . number_format_i18n( abs( $diff ), 1 ); break; default: if ( 0.0 === $prev ) { $text = $cur > 0 ? __( 'new', 'turtlereport' ) : '±0%'; } else { $pct = $diff / $prev * 100; $text = self::sign( $pct ) . number_format_i18n( abs( $pct ), abs( $pct ) < 10 ? 1 : 0 ) . '%'; } } if ( abs( $diff ) < 0.0001 ) { $color = self::FLAT; $text = __( 'No change', 'turtlereport' ); } else { $good = $lower ? $diff < 0 : $diff > 0; $color = $good ? self::GOOD : self::BAD; } return array( 'text' => $text, 'color' => $color, ); } /** * Sign character for a number. * * @param float $n Number. * @return string */ private static function sign( $n ) { if ( $n > 0 ) { return '+'; } return $n < 0 ? '−' : '±'; } /** * A date range in the site's language, e.g. "1 Sept 2026 – 30 Sept 2026". * * @param string $s Start date. * @param string $e End date. * @return string */ public static function range( $s, $e ) { $fmt = (string) get_option( 'date_format', 'j M Y' ); return wp_date( $fmt, strtotime( $s . ' 12:00:00 UTC' ), new \DateTimeZone( 'UTC' ) ) . ' – ' . wp_date( $fmt, strtotime( $e . ' 12:00:00 UTC' ), new \DateTimeZone( 'UTC' ) ); } }