1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 12:27:08 +01:00

Improve date handling.

This commit is contained in:
hacksalot
2016-01-30 20:06:04 -05:00
parent 8e806dc04f
commit 27c7a0264a
7 changed files with 90 additions and 50 deletions

View File

@ -19,7 +19,7 @@ class AbstractResume
###
duration: (collKey, startKey, endKey, unit) ->
unit = unit || 'years'
hist = hist || __.get(this, collKey)
hist = __.get @, collKey
return 0 if !hist or !hist.length
# BEGIN CODE DUPLICATION --> src/inspectors/gap-inspector.coffee (TODO)
@ -27,24 +27,21 @@ class AbstractResume
# Convert the candidate's employment history to an array of dates,
# where each element in the array is a start date or an end date of a
# job -- it doesn't matter which.
new_e = hist.map( ( job ) ->
new_e = hist.map ( job ) ->
obj = _.pick( job, [startKey, endKey] )
# Synthesize an end date if this is a "current" gig
obj[endKey] = 'current' if !_.has obj, endKey
if obj && (obj[startKey] || obj[endKey])
obj = _.pairs( obj )
obj = _.pairs obj
obj[0][1] = FluentDate.fmt( obj[0][1] )
if obj.length > 1
obj[1][1] = FluentDate.fmt( obj[1][1] )
return obj
)
obj
# Flatten the array, remove empties, and sort
new_e = _.filter _.flatten( new_e, true ), (v) ->
return v && v.length && v[0] && v[0].length
return 0 if !new_e or !new_e.length
new_e = _.sortBy new_e, ( elem ) -> return elem[1].unix()
# END CODE DUPLICATION

View File

@ -59,16 +59,7 @@ FluentDate.fmt = ( dt, throws ) ->
else if /^\s*\d{4}\s*$/.test(dt) # "2015"
return moment dt, 'YYYY'
else if /^\s*$/.test(dt) # "", " "
defTime =
isNull: true
isBefore: ( other ) ->
if other and !other.isNull then true else false
isAfter: ( other ) ->
if other and !other.isNull then false else false
unix: () -> 0
format: () -> ''
diff: () -> 0
return defTime
return moment()
else
mt = moment dt
if mt.isValid()

View File

@ -85,8 +85,6 @@ validate = (sources, unused, opts) ->
if opts.assert and !ret.isValid
throw fluenterror: HMSTATUS.invalid, shouldExit: true
console.log '1111'
return ret
ret
, @