Example #1
0
const getIsInactive = ( state ) => {
	const startDateMoment = selectors.getRSVPStartDateMoment( state );
	const startTime = selectors.getRSVPStartTimeNoSeconds( state );
	const endDateMoment = selectors.getRSVPEndDateMoment( state );
	const endTime = selectors.getRSVPEndTimeNoSeconds( state );

	if ( ! startDateMoment || ! endDateMoment ) {
		return false;
	}

	const startMoment = momentUtil.setTimeInSeconds(
		startDateMoment.clone(),
		time.toSeconds( startTime, time.TIME_FORMAT_HH_MM ),
	);
	const endMoment = momentUtil.setTimeInSeconds(
		endDateMoment.clone(),
		time.toSeconds( endTime, time.TIME_FORMAT_HH_MM ),
	);
	const currentMoment = moment();

	return ! ( currentMoment.isAfter( startMoment ) && currentMoment.isBefore( endMoment ) );
};
Example #2
0
	test( 'roundTime', () => {
		expect( time.roundTime( '01:23:54.423', time.TIME_FORMAT_HH_MM_SS_SSS ) )
			.toEqual( '01:00:00.000' );
		expect( time.roundTime( '14:46:13.042', time.TIME_FORMAT_HH_MM_SS_SSS ) )
			.toEqual( '14:30:00.000' );
		expect( time.roundTime( '01:23:54', time.TIME_FORMAT_HH_MM_SS ) )
			.toEqual( '01:00:00' );
		expect( time.roundTime( '14:46:13', time.TIME_FORMAT_HH_MM_SS ) )
			.toEqual( '14:30:00' );
		expect( time.roundTime( '01:23', time.TIME_FORMAT_HH_MM ) )
			.toEqual( '01:00' );
		expect( time.roundTime( '14:46', time.TIME_FORMAT_HH_MM ) )
			.toEqual( '14:30' );
		expect( time.roundTime( '23:54.423', time.TIME_FORMAT_MM_SS_SSS ) )
			.toEqual( '00:00.000' );
		expect( time.roundTime( '46:13.042', time.TIME_FORMAT_MM_SS_SSS ) )
			.toEqual( '30:00.000' );
		expect( time.roundTime( '23:54', time.TIME_FORMAT_MM_SS ) )
			.toEqual( '00:00' );
		expect( time.roundTime( '46:13', time.TIME_FORMAT_MM_SS ) )
			.toEqual( '30:00' );
	} );
Example #3
0
	test( 'fromMilliseconds() test', () => {
		// Basic functionality
		expect( time.fromMilliseconds( 75000 ) ).toEqual( '01:15' );
		expect( time.fromMilliseconds( 442800000 ) ).toEqual( '123:00:00' );
		expect( time.fromMilliseconds( 90576 ) ).toEqual( '01:30.576' );
		expect( time.fromMilliseconds( -157250 ) ).toEqual( '-02:37.250' );

		// Output formatting
		expect( time.fromMilliseconds( 38000, 'mm:ss.sss' ) ).toEqual( '00:38.000' );
		expect( time.fromMilliseconds( 0, 'hh:mm:ss' ) ).toEqual( '00:00:00' );
		expect( time.fromMilliseconds( 3600000, 'mm:ss' ) ).toEqual( '01:00:00' );
		expect( time.fromMilliseconds( 4500000, 'hh:mm' ) ).toEqual( '01:15' );
		expect( time.fromMilliseconds( -9900000, 'hh:mm' ) ).toEqual( '-02:45' );

		// Input validation
		expect( () => time.fromMilliseconds( null ) ).toThrowErrorMatchingSnapshot();
		expect( () => time.fromMilliseconds('text') ).toThrowErrorMatchingSnapshot();
		expect( () => time.fromMilliseconds(0, 'mm:hh:ss') ).toThrowErrorMatchingSnapshot();
	} );
Example #4
0
	test( 'toSeconds() test', () => {
		// Basic functionality
		expect( time.toSeconds( '01:05:17' ) ).toEqual( 3917 );
		expect( time.toSeconds( '137:00:00.0' ) ).toEqual( 493200 );
		expect( time.toSeconds( '00:10.230' ) ).toEqual( 10 );
		expect( time.toSeconds( '00:00:07.10845' ) ).toEqual( 7 );
		expect( time.toSeconds( '-02:07:12' ) ).toEqual( -7632 );
		expect( time.toSeconds( '02:00' ) ).toEqual( 120 );
		expect( time.toSeconds( '02:00', 'hh:mm' ) ).toEqual( 7200 );
		expect( time.toSeconds( '-04:35', 'hh:mm' ) ).toEqual( -16500 );
		expect( time.toSeconds( '00:00:07.10845', 'hh:mm' ) ).toEqual( 7 );

		// Input validation
		expect( () => time.toSeconds( '13:05:02:11' ) ).toThrowErrorMatchingSnapshot();
		expect( () => time.toSeconds( '153' ) ).toThrowErrorMatchingSnapshot();
		expect( () => time.toSeconds( null ) ).toThrowErrorMatchingSnapshot();
		expect( () => time.toSeconds( '00:62' ) ).toThrowErrorMatchingSnapshot();
		expect( () => time.toSeconds( '01:30', 'mm:hh:ss' ) ).toThrowErrorMatchingSnapshot();
	} );
Example #5
0
	const getItems = () => {
		const items = [];

		const startSeconds = timeUtil.toSeconds( start, timeUtil.TIME_FORMAT_HH_MM );
		const endSeconds = timeUtil.toSeconds( end, timeUtil.TIME_FORMAT_HH_MM );

		const currentMoment = moment( current, momentUtil.TIME_FORMAT );

		for ( let time = startSeconds; time <= endSeconds; time += step ) {
			let isCurrent = false;
			if ( currentMoment.isValid() ) {
				const currentTime = momentUtil.toTime24Hr( currentMoment );
				isCurrent = time === timeUtil.toSeconds( currentTime, timeUtil.TIME_FORMAT_HH_MM );
			}

			items.push( {
				value: time,
				text: formatLabel( time ),
				isCurrent,
			} );
		}

		return items;
	};
Example #6
0
	test( 'symmetrical conversion test', () => {
		/*
		 * fromMilliseconds() and toMilliseconds() for all formats
		 */

		// 90000ms = 1m 30s
		expect( time.toMilliseconds( time.fromMilliseconds( 90000, 'mm:ss' ), 'mm:ss' ) ).toEqual( 90000 );
		expect( time.toMilliseconds( time.fromMilliseconds( 90000, 'mm:ss.sss' ), 'mm:ss.sss' ) ).toEqual( 90000 );
		expect( time.toMilliseconds( time.fromMilliseconds( 90000, 'hh:mm' ), 'hh:mm' ) ).toEqual( 90000 );
		expect( time.toMilliseconds( time.fromMilliseconds( 90000, 'hh:mm:ss' ), 'hh:mm:ss' ) ).toEqual( 90000 );
		expect( time.toMilliseconds( time.fromMilliseconds( 90000, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss' ) ).toEqual( 90000 );

		// 7517245ms = 2h 5m 17.245s
		expect( time.toMilliseconds( time.fromMilliseconds( 7517245, 'mm:ss' ), 'mm:ss' ) ).toEqual( 7517245 );
		expect( time.toMilliseconds( time.fromMilliseconds( 7517245, 'mm:ss.sss' ), 'mm:ss.sss' ) ).toEqual( 7517245 );
		expect( time.toMilliseconds( time.fromMilliseconds( 7517245, 'hh:mm' ), 'hh:mm' ) ).toEqual( 7517245 );
		expect( time.toMilliseconds( time.fromMilliseconds( 7517245, 'hh:mm:ss' ), 'hh:mm:ss' ) ).toEqual( 7517245 );
		expect( time.toMilliseconds( time.fromMilliseconds( 7517245, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss' ) ).toEqual( 7517245 );

		// -10800000ms = -3h
		expect( time.toMilliseconds( time.fromMilliseconds( -10800000, 'mm:ss' ), 'mm:ss' ) ).toEqual( -10800000 );
		expect( time.toMilliseconds( time.fromMilliseconds( -10800000, 'mm:ss.sss' ), 'mm:ss.sss' ) ).toEqual( -10800000 );
		expect( time.toMilliseconds( time.fromMilliseconds( -10800000, 'hh:mm' ), 'hh:mm' ) ).toEqual( -10800000 );
		expect( time.toMilliseconds( time.fromMilliseconds( -10800000, 'hh:mm:ss' ), 'hh:mm:ss' ) ).toEqual( -10800000 );
		expect( time.toMilliseconds( time.fromMilliseconds( -10800000, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss' ) ).toEqual( -10800000 );

		/*
		 * fromSeconds() and toMilliseconds() for all formats
		 */

		// 930s = 15m 30s
		expect( time.toSeconds( time.fromSeconds( 930, 'mm:ss' ), 'mm:ss') ).toEqual( 930 );
		expect( time.toSeconds( time.fromSeconds( 930, 'mm:ss.sss' ), 'mm:ss.sss') ).toEqual( 930 );
		expect( time.toSeconds( time.fromSeconds( 930, 'hh:mm' ), 'hh:mm') ).toEqual( 930 );
		expect( time.toSeconds( time.fromSeconds( 930, 'hh:mm:ss' ), 'hh:mm:ss') ).toEqual( 930 );
		expect( time.toSeconds( time.fromSeconds( 930, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss') ).toEqual( 930 );

		// 4850s = 1h 20m 50s
		expect( time.toSeconds( time.fromSeconds( 4850, 'mm:ss' ), 'mm:ss') ).toEqual( 4850 );
		expect( time.toSeconds( time.fromSeconds( 4850, 'mm:ss.sss' ), 'mm:ss.sss') ).toEqual( 4850 );
		expect( time.toSeconds( time.fromSeconds( 4850, 'hh:mm' ), 'hh:mm') ).toEqual( 4850 );
		expect( time.toSeconds( time.fromSeconds( 4850, 'hh:mm:ss' ), 'hh:mm:ss') ).toEqual( 4850 );
		expect( time.toSeconds( time.fromSeconds( 4850, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss') ).toEqual( 4850 );

		// -300s = -5m
		expect( time.toSeconds( time.fromSeconds( -300, 'mm:ss' ), 'mm:ss') ).toEqual( -300 );
		expect( time.toSeconds( time.fromSeconds( -300, 'mm:ss.sss' ), 'mm:ss.sss') ).toEqual( -300 );
		expect( time.toSeconds( time.fromSeconds( -300, 'hh:mm' ), 'hh:mm') ).toEqual( -300 );
		expect( time.toSeconds( time.fromSeconds( -300, 'hh:mm:ss' ), 'hh:mm:ss') ).toEqual( -300 );
		expect( time.toSeconds( time.fromSeconds( -300, 'hh:mm:ss.sss' ), 'hh:mm:ss.sss') ).toEqual( -300 );
	} );
Example #7
0
		expect( () => time.toSeconds( '01:30', 'mm:hh:ss' ) ).toThrowErrorMatchingSnapshot();
Example #8
0
		expect( () => time.toSeconds( '00:62' ) ).toThrowErrorMatchingSnapshot();
Example #9
0
		expect( () => time.toSeconds( null ) ).toThrowErrorMatchingSnapshot();
Example #10
0
		expect( () => time.toSeconds( '13:05:02:11' ) ).toThrowErrorMatchingSnapshot();
Example #11
0
		expect( () => time.toMilliseconds( '153' ) ).toThrowErrorMatchingSnapshot();
Example #12
0
		expect( () => time.fromSeconds( 0, 'mm:hh:ss' ) ).toThrowErrorMatchingSnapshot();
Example #13
0
		expect( () => time.fromSeconds( 'text' ) ).toThrowErrorMatchingSnapshot();
Example #14
0
		expect( () => time.fromMilliseconds( null ) ).toThrowErrorMatchingSnapshot();