mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Merge pull request #85 from jjanusch/feat/present-formatter
formatDate template helper error handling and fallback
This commit is contained in:
commit
041c609ff0
@ -23,10 +23,17 @@ Generic template helper definitions for HackMyResume / FluentCV.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Convert the input date to a specified format through Moment.js.
|
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
|
@method formatDate
|
||||||
*/
|
*/
|
||||||
formatDate: function(datetime, format) {
|
formatDate: function(datetime, format, fallback) {
|
||||||
return moment ? moment( datetime ).format( format ) : datetime;
|
if (moment) {
|
||||||
|
var momentDate = moment( datetime );
|
||||||
|
if (momentDate.isValid()) return momentDate.format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
return datetime || (typeof fallback == 'string' ? fallback : (fallback === true ? 'Present' : null));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user