Compare two different cart objects and get the messages of newest one

It's possible that we're comparing two carts that have the same server header date.
This means the changes only happened locally and the messages returned will be [].

@param {cartValue} [previousCartValue] - the previously loaded cart
@param {cartValue} [nextCartValue] - the new cart value
@returns {array} [nextCartMessages] - an array of messages about the state of the cart
function getNewMessages( previousCartValue, nextCartValue ) {
	previousCartValue = previousCartValue || {};
	nextCartValue = nextCartValue || {};
	const nextCartMessages = nextCartValue.messages || [];

	// If there is no previous cart then just return the messages for the new cart
	if (
		! previousCartValue ||
		! previousCartValue.client_metadata ||
		! nextCartValue.client_metadata
	) {
		return nextCartMessages;
	}

	const previousDate = previousCartValue.client_metadata.last_server_response_date;
	const nextDate = nextCartValue.client_metadata.last_server_response_date;
	const hasNewServerData = i18n.moment( nextDate ).isAfter( previousDate );

	return hasNewServerData ? nextCartMessages : [];
}