= 2000; } /** * Today on the site's clock, Y-m-d. * * @return string */ public static function today() { return wp_date( 'Y-m-d' ); } /** * A day N days before today on the site's clock, Y-m-d. * * @param int $days How many days back. * @return string */ public static function days_ago( $days ) { return wp_date( 'Y-m-d', time() - max( 0, (int) $days ) * DAY_IN_SECONDS ); } /** * The UTC bounds of a range of the site's days, inclusive: from the first * second of `from` to the last second of `to`. An empty or invalid end is open. * * @param mixed $from First day (Y-m-d) or ''. * @param mixed $to Last day (Y-m-d) or ''. * @return string[] Two 'Y-m-d H:i:s' UTC times. */ public static function utc_range( $from, $to ) { $zone = wp_timezone(); $utc = new \DateTimeZone( 'UTC' ); $start = '1970-01-01 00:00:00'; $end = '9999-12-31 23:59:59'; if ( self::is_day( $from ) ) { $start = ( new \DateTimeImmutable( $from . ' 00:00:00', $zone ) )->setTimezone( $utc )->format( 'Y-m-d H:i:s' ); } if ( self::is_day( $to ) ) { $end = ( new \DateTimeImmutable( $to . ' 23:59:59', $zone ) )->setTimezone( $utc )->format( 'Y-m-d H:i:s' ); } return array( $start, $end ); } }