mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-24 17:30:10 +00:00
Introduce "date" helper.
This commit is contained in:
parent
255a518565
commit
7c36ff8331
26
dist/helpers/generic-helpers.js
vendored
26
dist/helpers/generic-helpers.js
vendored
@ -57,6 +57,30 @@ Generic template helper definitions for HackMyResume / FluentCV.
|
||||
return datetime || (typeof fallback === 'string' ? fallback : (fallback === true ? 'Present' : null));
|
||||
},
|
||||
|
||||
/** Display a formatted date. */
|
||||
date: function(dateValue, dateFormat, dateDefault) {
|
||||
var dateValueMoment, dateValueSafe, reserved;
|
||||
if (arguments.length < 4 || !dateDefault || !String.is(dateDefault)) {
|
||||
dateDefault = 'Current';
|
||||
}
|
||||
if (arguments.length < 3 || !dateFormat || !String.is(dateFormat)) {
|
||||
dateFormat = 'YYYY-MM';
|
||||
}
|
||||
if (!dateValue) {
|
||||
return dateDefault;
|
||||
}
|
||||
reserved = ['current', 'present', 'now'];
|
||||
dateValueSafe = dateValue.trim().toLowerCase();
|
||||
if (_.contains(reserved, dateValueSafe)) {
|
||||
return dateValue;
|
||||
}
|
||||
dateValueMoment = moment(dateValue, dateFormat);
|
||||
if (dateValueMoment.isValid()) {
|
||||
return dateValueMoment.format(dateFormat);
|
||||
}
|
||||
return dateValue;
|
||||
},
|
||||
|
||||
/**
|
||||
Given a resume sub-object with a start/end date, format a representation of
|
||||
the date range.
|
||||
@ -580,7 +604,7 @@ Generic template helper definitions for HackMyResume / FluentCV.
|
||||
dateFrom = dateTemp.format(fmt);
|
||||
}
|
||||
if (_.contains(reserved, dateBTrim)) {
|
||||
dateTo = fallback || 'Current';
|
||||
dateTo = fallback || 'Present';
|
||||
} else {
|
||||
dateTemp = FluentDate.fmt(dateB);
|
||||
dateTo = dateTemp.format(fmt);
|
||||
|
@ -47,6 +47,20 @@ GenericHelpers = module.exports =
|
||||
|
||||
|
||||
|
||||
###* Display a formatted date. ###
|
||||
date: (dateValue, dateFormat, dateDefault) ->
|
||||
dateDefault = 'Current' if arguments.length < 4 or !dateDefault or !String.is dateDefault
|
||||
dateFormat = 'YYYY-MM' if arguments.length < 3 or !dateFormat or !String.is dateFormat
|
||||
return dateDefault if !dateValue
|
||||
reserved = ['current', 'present', 'now'];
|
||||
dateValueSafe = dateValue.trim().toLowerCase();
|
||||
return dateValue if _.contains reserved, dateValueSafe
|
||||
dateValueMoment = moment dateValue, dateFormat
|
||||
return dateValueMoment.format dateFormat if dateValueMoment.isValid()
|
||||
dateValue
|
||||
|
||||
|
||||
|
||||
###*
|
||||
Given a resume sub-object with a start/end date, format a representation of
|
||||
the date range.
|
||||
@ -542,7 +556,7 @@ _fromTo = ( dateA, dateB, fmt, sep, fallback ) ->
|
||||
dateFrom = dateTemp.format( fmt )
|
||||
|
||||
if _.contains( reserved, dateBTrim )
|
||||
dateTo = fallback || 'Current'
|
||||
dateTo = fallback || 'Present'
|
||||
else
|
||||
dateTemp = FluentDate.fmt( dateB )
|
||||
dateTo = dateTemp.format( fmt )
|
||||
|
Loading…
Reference in New Issue
Block a user