/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const moment = require( 'moment' );

/**
 * Checks whether the "🆕" icon should be added next to the page title in menu.
 *
 * If the page has specified the `modified_at` property, we create a time period: <modified_at, modified_at+90d>.
 * When the documentation is being built, we check whether `now` is the period. If so, the new symbol will be displayed on the page.
 *
 * See #882.
 *
 * @protected
 * @param {Object} page
 * @return {Boolean}
 */
module.exports = function shouldDisplayNewIndicator( page ) {
	if ( !page.modified_at ) {
		return false;
	}

	const now = moment();
	const leftLimit = moment( page.modified_at ).set( { hour: 0, minute: 0, second: 0 } );
	const rightLimit = leftLimit.clone().add( { days: 60 } ).set( { hour: 23, minute: 59, second: 59 } );

	// Return `true` if order ot the date is equal: [ `leftLimit`, `now`, `rightLimit` ].
	return now.isAfter( leftLimit ) && now.isBefore( rightLimit );
};
