From 3d1f589bc114b7dc66521315e9866e2bff7f2002 Mon Sep 17 00:00:00 2001 From: Josh Janusch Date: Fri, 1 Jan 2016 17:27:49 -0500 Subject: [PATCH] formatDate helper now will only use moment if date is valid. If it's not, will use the user inputted value or a fallback parameter, if it is provided --- src/eng/generic-helpers.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/eng/generic-helpers.js b/src/eng/generic-helpers.js index a5b1751..0a73877 100644 --- a/src/eng/generic-helpers.js +++ b/src/eng/generic-helpers.js @@ -23,10 +23,20 @@ Generic template helper definitions for HackMyResume / FluentCV. /** Convert the input date to a specified format through Moment.js. + If date is invalid, will return the time provided by the user, + or default to the fallback param or 'Present' if that is set to true @method formatDate */ - formatDate: function(datetime, format) { - return moment ? moment( datetime ).format( format ) : datetime; + formatDate: function(datetime, format, fallback) { + if (moment) { + var momentDate = moment( datetime ); + + if (momentDate.isValid()) { + return moment.format(format); + } + } + + return datetime || (typeof fallback == 'string' ? fallback : (fallback === true ? 'Present' : null)); }, /**