Jump to content

Using concrete dates instead of relative ones in admin


creativejay
 Share

Recommended Posts

You can use a hook to replace all relative time strings in admin with a specific date format. Add the following to /site/templates/admin.php, at the top after the namespace declaration:

$wire->addHookBefore('WireDateTime::relativeTimeStr', function(HookEvent $event) {
	$timestamp = $event->arguments(0);
	// If given a date string, convert it to a timestamp
	if(!ctype_digit("$timestamp")) $timestamp = strtotime($timestamp);
	$event->replace = true;
	// Set your preferred date format below
	$event->return = date('Y-m-d H:i:s', $timestamp);
});

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

15 hours ago, adrian said:

Just one thing to consider - it may result in some weirdness when both actual and relative versions are shown together

Depending on how much mixing of relative and absolute dates occur on a single page, it might be possible to avoid those scenarios by excluding specific processes and/or URL segments, e.g.

if($page->process != 'ProcessPageEdit') {
	$wire->addHookBefore('WireDateTime::relativeTimeStr', function(HookEvent $event) {
		$timestamp = $event->arguments(0);
		// If given a date string, convert it to a timestamp
		if(!ctype_digit("$timestamp")) $timestamp = strtotime($timestamp);
		$event->replace = true;
		// Set your preferred date format below
		$event->return = date('Y-m-d H:i:s', $timestamp);
	});
}

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...