diff --git a/assets/src/components/form/model/base/test/build-options.js b/assets/src/components/form/model/base/test/build-options.js index d171f53aaec..61d442d13aa 100644 --- a/assets/src/components/form/model/base/test/build-options.js +++ b/assets/src/components/form/model/base/test/build-options.js @@ -1,10 +1,18 @@ +/** + * Internal imports + */ import buildOptions from '../build-options'; -import moment from 'moment-timezone'; +import { prettyDateFromDateTime } from '../../../../../data/model/datetime/formatter'; + +/** + * External imports + */ import { DATE_TIME_FORMAT_SITE, TIME_FORMAT_SITE, } from '@eventespresso/helpers'; -import { prettyDateFromDateTime } from '../../../../../data/model/datetime/formatter'; +import { ServerDateTime as DateTime, Duration } from '@eventespresso/value-objects'; +import { DateTimeFactory } from '@test/fixtures'; describe( 'buildOptions()', () => { const testResponse = [ @@ -83,29 +91,30 @@ describe( 'buildOptions()', () => { ); } ); it( 'returns expected values for options using default optionsEntityMap for DatetimeSelect', () => { - const testLocalMoment = moment( '2018-12-24 05:00:00' ).local(); - const dateTimeResponse = [ + const testDate = DateTime.fromISO( '2019-01-23T19:20:03.531Z' ); + const testEndDate = testDate.plus( Duration.fromObject( + { [ Duration.UNIT_HOURS ]: 1 } ) + ); + const testDateTime = DateTimeFactory.createNew( { - DTT_ID: 30, DTT_name: 'DateTime 1', - DTT_EVT_start: moment( testLocalMoment ).format(), - DTT_EVT_end: moment( testLocalMoment ).add( 1, 'h' ).format(), - }, - ]; + DTT_EVT_start: testDate, + DTT_EVT_end: testEndDate, + } + ); + const response = [ testDateTime ]; const expectedLabel = 'DateTime 1' + ' (' + - moment( testLocalMoment ).format( DATE_TIME_FORMAT_SITE ) + + testDate.toFormat( DATE_TIME_FORMAT_SITE ) + ' - ' + - moment( testLocalMoment ).add( 1, 'h' ).format( TIME_FORMAT_SITE ) + + testEndDate.toFormat( TIME_FORMAT_SITE ) + ')'; - expect( buildOptions( dateTimeResponse, datetimeOptionsEntityMap ) ).toEqual( + expect( buildOptions( response, datetimeOptionsEntityMap ) ).toEqual( [ { - value: 30, + value: testDateTime.DTT_ID, label: expectedLabel, }, ] ); } ); } ); - -// location: assets/src/components/form/select/test/build-options.js diff --git a/assets/src/components/form/model/base/test/model-select.js b/assets/src/components/form/model/base/test/model-select.js index 34e1ee8b582..845329d4d6c 100644 --- a/assets/src/components/form/model/base/test/model-select.js +++ b/assets/src/components/form/model/base/test/model-select.js @@ -59,5 +59,3 @@ describe( 'ModelSelect props check', () => { expect( wrapper.childAt( 0 ).text() ).toEqual( 'Label for Select' ); } ); } ); - -// location: assets/src/components/form/select/test/model-select.js diff --git a/assets/src/data/model/datetime/formatter.js b/assets/src/data/model/datetime/formatter.js index a3ab7a25f01..9a8d837861d 100644 --- a/assets/src/data/model/datetime/formatter.js +++ b/assets/src/data/model/datetime/formatter.js @@ -2,17 +2,18 @@ * Internal imports */ import * as baseFormatter from '../base-date-formatter'; + +/** + * External imports + */ +import { forOwn, pullAt } from 'lodash'; import { TIME_FORMAT_SITE, DATE_TIME_FORMAT_SITE, allDateTimesAsString, SEPARATOR_SPACE_DASH_SPACE, } from '@eventespresso/helpers'; - -/** - * External imports - */ -import { forOwn, pullAt } from 'lodash'; +import { isModelEntityOfModel } from '@eventespresso/validators'; /** * Array of fields that have date information @@ -62,51 +63,41 @@ forOwn( baseFormatter, ( implementation, functionName ) => { * This will account for if both start and end are in the same day and simply * use time for the end part. * - * @param { Object } DateTimeEntity + * @param { BaseEntity } DateTimeEntity * @return { string } A formatted string representing the provided * DateTimeEntity. */ -export const prettyDateFromDateTime = ( DateTimeEntity = {} ) => { +export const prettyDateFromDateTime = ( DateTimeEntity ) => { let content = ''; - DateTimeEntity = formatters.convertEntityDatesToMoment( DateTimeEntity ); - if ( DateTimeEntity.DTT_EVT_start && DateTimeEntity.DTT_EVT_end ) { - if ( DateTimeEntity.DTT_EVT_start.local().format( 'md' ) === - DateTimeEntity.DTT_EVT_end.local().format( 'md' ) ) { + if ( isModelEntityOfModel( DateTimeEntity, 'datetime' ) ) { + if ( DateTimeEntity.DTT_EVT_start.hasSame( + DateTimeEntity.DTT_EVT_end, + 'day' + ) ) { content += allDateTimesAsString( SEPARATOR_SPACE_DASH_SPACE, - DateTimeEntity.DTT_EVT_start.format( + DateTimeEntity.DTT_EVT_start.toFormat( DATE_TIME_FORMAT_SITE ), - DateTimeEntity.DTT_EVT_end.format( + DateTimeEntity.DTT_EVT_end.toFormat( TIME_FORMAT_SITE ), ); } else { content += allDateTimesAsString( SEPARATOR_SPACE_DASH_SPACE, - DateTimeEntity.DTT_EVT_start.format( + DateTimeEntity.DTT_EVT_start.toFormat( DATE_TIME_FORMAT_SITE ), - DateTimeEntity.DTT_EVT_end.format( + DateTimeEntity.DTT_EVT_end.toFormat( DATE_TIME_FORMAT_SITE ), ); } - } else { - if ( DateTimeEntity.DTT_EVT_start ) { - content += DateTimeEntity.DTT_EVT_start.format( - DATE_TIME_FORMAT_SITE - ); - } - if ( DateTimeEntity.DTT_EVT_end ) { - content += DateTimeEntity.DTT_EVT_end.format( - DATE_TIME_FORMAT_SITE - ); - } + content = DateTimeEntity.DTT_name ? + `${ DateTimeEntity.DTT_name } (${ content })` : + content; } - content = DateTimeEntity.DTT_name ? - `${ DateTimeEntity.DTT_name } (${ content })` : - content; return content; }; diff --git a/assets/src/data/model/datetime/test/formatter.js b/assets/src/data/model/datetime/test/formatter.js index f0391879fcb..1f06ad63a51 100644 --- a/assets/src/data/model/datetime/test/formatter.js +++ b/assets/src/data/model/datetime/test/formatter.js @@ -1,4 +1,11 @@ +/** + * Internal imports + */ import formatters, { prettyDateFromDateTime } from '../formatter'; + +/** + * External imports + */ import moment from 'moment-timezone'; import { DATE_TIME_FORMAT_MYSQL, @@ -6,6 +13,11 @@ import { DATE_TIME_FORMAT_SITE, TIME_FORMAT_SITE, } from '@eventespresso/helpers'; +import { + ServerDateTime as DateTime, + Duration, +} from '@eventespresso/value-objects'; +import { DateTimeFactory } from '@test/fixtures'; const { formatDatesOnEntities, @@ -391,43 +403,53 @@ describe( 'convertEntitiesDatesToMoment()', () => { } ); describe( 'prettyDateFromDateTime', () => { + const testDate = DateTime.fromISO( '2019-01-23T19:20:03.531Z' ); + const getDateTimeEntity = ( + name, + start, + end + ) => name ? DateTimeFactory.createNew( + { + DTT_name: name, + DTT_EVT_start: start, + DTT_EVT_end: end, + } + ) : + DateTimeFactory.createNew( { DTT_EVT_start: start, DTT_EVT_end: end } ); it( 'returns expected value for no arguments passed in', () => { expect( prettyDateFromDateTime() ).toEqual( '' ); } ); it( 'returns expected value when DTT_name is present and start date and' + ' end date are on different days', () => { - expect( prettyDateFromDateTime( testEntities[ 3 ] ) ).toEqual( - 'Test Date D' + ' (' + moment( testLocalMoment ) - .format( DATE_TIME_FORMAT_SITE ) + - ' - ' + moment( testLocalMoment ) - .add( 1, 'd' ) - .format( DATE_TIME_FORMAT_SITE ) + ')', + const endDate = testDate.plus( + Duration.fromObject( { [ Duration.UNIT_DAYS ]: 2 } ) + ); + expect( prettyDateFromDateTime( + getDateTimeEntity( + 'Test Date D', + testDate, + endDate, + ) + ) ).toEqual( + 'Test Date D' + ' (' + testDate.toFormat( DATE_TIME_FORMAT_SITE ) + + ' - ' + endDate.toFormat( DATE_TIME_FORMAT_SITE ) + ')', ); }, ); it( 'returns expected value when DTT_name is not present and start date' + ' and end date are on the same day', () => { - expect( prettyDateFromDateTime( testEntities[ 2 ] ) ).toEqual( - moment( testLocalMoment ).format( DATE_TIME_FORMAT_SITE ) + - ' - ' + moment( testLocalMoment ).add( 1, 'h' ) - .format( TIME_FORMAT_SITE ), + const endDate = testDate.plus( + Duration.fromObject( { [ Duration.UNIT_HOURS ]: 1 } ) ); - }, - ); - it( 'returns expected value when DTT_name is not present and start date' + - ' is not present', () => { - expect( prettyDateFromDateTime( testEntities[ 5 ] ) ).toEqual( - 'Test Date F' + ' (' + moment( testLocalMoment ) - .format( DATE_TIME_FORMAT_SITE ) + ')' - ); - } ); - it( 'returns expected value when DTT_name is present and end date' + - ' is not present', () => { - expect( prettyDateFromDateTime( testEntities[ 4 ] ) ).toEqual( - 'Test Date E' + ' (' + moment( testLocalMoment ) - .format( DATE_TIME_FORMAT_SITE ) + ')' + expect( prettyDateFromDateTime( getDateTimeEntity( + '', + testDate, + endDate, + ) ) ).toEqual( + testDate.toFormat( DATE_TIME_FORMAT_SITE ) + + ' - ' + endDate.toFormat( TIME_FORMAT_SITE ), ); } ); } ); diff --git a/espresso.php b/espresso.php index 8c23fa0ab41..fe10ae1e047 100644 --- a/espresso.php +++ b/espresso.php @@ -3,7 +3,7 @@ Plugin Name:Event Espresso Plugin URI: http://eventespresso.com/pricing/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link Description: Manage events, sell tickets, and receive payments from your WordPress website. Reduce event administration time, cut-out ticketing fees, and own your customer data. | Extensions | Sales | Support - Version: 4.9.78.rc.000 + Version: 4.9.78.rc.001 Author: Event Espresso Author URI: http://eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link License: GPLv2 @@ -102,7 +102,7 @@ function espresso_minimum_php_version_error() */ function espresso_version() { - return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.000'); + return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.001'); } /**