mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Improve date handling.
This commit is contained in:
parent
8e806dc04f
commit
27c7a0264a
2
dist/core/abstract-resume.js
vendored
2
dist/core/abstract-resume.js
vendored
@ -29,7 +29,7 @@ Definition of the AbstractResume class.
|
|||||||
AbstractResume.prototype.duration = function(collKey, startKey, endKey, unit) {
|
AbstractResume.prototype.duration = function(collKey, startKey, endKey, unit) {
|
||||||
var firstDate, hist, lastDate, new_e;
|
var firstDate, hist, lastDate, new_e;
|
||||||
unit = unit || 'years';
|
unit = unit || 'years';
|
||||||
hist = hist || __.get(this, collKey);
|
hist = __.get(this, collKey);
|
||||||
if (!hist || !hist.length) {
|
if (!hist || !hist.length) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
30
dist/core/fluent-date.js
vendored
30
dist/core/fluent-date.js
vendored
@ -60,7 +60,7 @@ The HackMyResume date representation.
|
|||||||
module.exports = FluentDate;
|
module.exports = FluentDate;
|
||||||
|
|
||||||
FluentDate.fmt = function(dt, throws) {
|
FluentDate.fmt = function(dt, throws) {
|
||||||
var defTime, month, mt, parts, ref, temp;
|
var month, mt, parts, ref, temp;
|
||||||
throws = (throws === void 0 || throws === null) || throws;
|
throws = (throws === void 0 || throws === null) || throws;
|
||||||
if (typeof dt === 'string' || dt instanceof String) {
|
if (typeof dt === 'string' || dt instanceof String) {
|
||||||
dt = dt.toLowerCase().trim();
|
dt = dt.toLowerCase().trim();
|
||||||
@ -78,33 +78,7 @@ The HackMyResume date representation.
|
|||||||
} else if (/^\s*\d{4}\s*$/.test(dt)) {
|
} else if (/^\s*\d{4}\s*$/.test(dt)) {
|
||||||
return moment(dt, 'YYYY');
|
return moment(dt, 'YYYY');
|
||||||
} else if (/^\s*$/.test(dt)) {
|
} else if (/^\s*$/.test(dt)) {
|
||||||
defTime = {
|
return moment();
|
||||||
isNull: true,
|
|
||||||
isBefore: function(other) {
|
|
||||||
if (other && !other.isNull) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isAfter: function(other) {
|
|
||||||
if (other && !other.isNull) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
unix: function() {
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
format: function() {
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
diff: function() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return defTime;
|
|
||||||
} else {
|
} else {
|
||||||
mt = moment(dt);
|
mt = moment(dt);
|
||||||
if (mt.isValid()) {
|
if (mt.isValid()) {
|
||||||
|
1
dist/verbs/validate.js
vendored
1
dist/verbs/validate.js
vendored
@ -104,7 +104,6 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
shouldExit: true
|
shouldExit: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log('1111');
|
|
||||||
return ret;
|
return ret;
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ class AbstractResume
|
|||||||
###
|
###
|
||||||
duration: (collKey, startKey, endKey, unit) ->
|
duration: (collKey, startKey, endKey, unit) ->
|
||||||
unit = unit || 'years'
|
unit = unit || 'years'
|
||||||
hist = hist || __.get(this, collKey)
|
hist = __.get @, collKey
|
||||||
return 0 if !hist or !hist.length
|
return 0 if !hist or !hist.length
|
||||||
|
|
||||||
# BEGIN CODE DUPLICATION --> src/inspectors/gap-inspector.coffee (TODO)
|
# 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,
|
# 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
|
# where each element in the array is a start date or an end date of a
|
||||||
# job -- it doesn't matter which.
|
# job -- it doesn't matter which.
|
||||||
new_e = hist.map( ( job ) ->
|
new_e = hist.map ( job ) ->
|
||||||
obj = _.pick( job, [startKey, endKey] )
|
obj = _.pick( job, [startKey, endKey] )
|
||||||
# Synthesize an end date if this is a "current" gig
|
# Synthesize an end date if this is a "current" gig
|
||||||
obj[endKey] = 'current' if !_.has obj, endKey
|
obj[endKey] = 'current' if !_.has obj, endKey
|
||||||
if obj && (obj[startKey] || obj[endKey])
|
if obj && (obj[startKey] || obj[endKey])
|
||||||
obj = _.pairs( obj )
|
obj = _.pairs obj
|
||||||
obj[0][1] = FluentDate.fmt( obj[0][1] )
|
obj[0][1] = FluentDate.fmt( obj[0][1] )
|
||||||
if obj.length > 1
|
if obj.length > 1
|
||||||
obj[1][1] = FluentDate.fmt( obj[1][1] )
|
obj[1][1] = FluentDate.fmt( obj[1][1] )
|
||||||
return obj
|
obj
|
||||||
)
|
|
||||||
|
|
||||||
# Flatten the array, remove empties, and sort
|
# Flatten the array, remove empties, and sort
|
||||||
new_e = _.filter _.flatten( new_e, true ), (v) ->
|
new_e = _.filter _.flatten( new_e, true ), (v) ->
|
||||||
return v && v.length && v[0] && v[0].length
|
return v && v.length && v[0] && v[0].length
|
||||||
|
|
||||||
return 0 if !new_e or !new_e.length
|
return 0 if !new_e or !new_e.length
|
||||||
|
|
||||||
new_e = _.sortBy new_e, ( elem ) -> return elem[1].unix()
|
new_e = _.sortBy new_e, ( elem ) -> return elem[1].unix()
|
||||||
|
|
||||||
# END CODE DUPLICATION
|
# END CODE DUPLICATION
|
||||||
|
@ -59,16 +59,7 @@ FluentDate.fmt = ( dt, throws ) ->
|
|||||||
else if /^\s*\d{4}\s*$/.test(dt) # "2015"
|
else if /^\s*\d{4}\s*$/.test(dt) # "2015"
|
||||||
return moment dt, 'YYYY'
|
return moment dt, 'YYYY'
|
||||||
else if /^\s*$/.test(dt) # "", " "
|
else if /^\s*$/.test(dt) # "", " "
|
||||||
defTime =
|
return moment()
|
||||||
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
|
|
||||||
else
|
else
|
||||||
mt = moment dt
|
mt = moment dt
|
||||||
if mt.isValid()
|
if mt.isValid()
|
||||||
|
@ -85,8 +85,6 @@ validate = (sources, unused, opts) ->
|
|||||||
if opts.assert and !ret.isValid
|
if opts.assert and !ret.isValid
|
||||||
throw fluenterror: HMSTATUS.invalid, shouldExit: true
|
throw fluenterror: HMSTATUS.invalid, shouldExit: true
|
||||||
|
|
||||||
console.log '1111'
|
ret
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
, @
|
, @
|
||||||
|
81
test/scripts/test-dates.js
Normal file
81
test/scripts/test-dates.js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
@module test-dates.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
var chai = require('chai')
|
||||||
|
, expect = chai.expect
|
||||||
|
, should = chai.should()
|
||||||
|
, path = require('path')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, FRESHResume = require('../../dist/core/fresh-resume')
|
||||||
|
, FCMD = require( '../../dist/index')
|
||||||
|
, validator = require('is-my-json-valid')
|
||||||
|
, EXTEND = require('extend');
|
||||||
|
|
||||||
|
chai.config.includeStack = true;
|
||||||
|
|
||||||
|
var gig = {
|
||||||
|
employer: 'E1'
|
||||||
|
};
|
||||||
|
|
||||||
|
var r = {
|
||||||
|
name: 'John Doe',
|
||||||
|
meta: {
|
||||||
|
format: 'FRESH@0.6.0'
|
||||||
|
},
|
||||||
|
employment: {
|
||||||
|
history: [ null ]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var tests = [
|
||||||
|
// single job, concrete start, no end
|
||||||
|
[ { start: '2010-01-01' } , { val: 6, unit: 'year' } ],
|
||||||
|
[ { start: '2010-01' } , { val: 6, unit: 'year' } ],
|
||||||
|
[ { start: '2010' } , { val: 6, unit: 'year' } ],
|
||||||
|
|
||||||
|
// single job, concrete start, concrete end
|
||||||
|
[ { start: '2010-01-01', end: '2015-01-01' } , { val: 5, unit: 'year' } ],
|
||||||
|
[ { start: '2010-01', end: '2015-01' } , { val: 5, unit: 'year' } ],
|
||||||
|
[ { start: '2010', end: '2015' } , { val: 5, unit: 'year' } ],
|
||||||
|
|
||||||
|
// single job, falsy start, falsy end
|
||||||
|
[ { } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: null } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { end: null } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: undefined } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { end: undefined } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: null, end: null } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: '', end: '' } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: ' ', end: ' ' } , { val: 0, unit: 'year' } ],
|
||||||
|
[ { start: undefined, end: undefined } , { val: 0, unit: 'year' } ],
|
||||||
|
|
||||||
|
// two jobs (concrete start + end) -> ( concrete start )
|
||||||
|
[ { start: '2000-01', end: '2013-01' }, { start: '2013-01' }, { val: 16, unit: 'year' } ],
|
||||||
|
[ { start: '2000-01', end: '2013-01' }, { start: '2013-01', end: '' }, { val: 16, unit: 'year' } ],
|
||||||
|
[ { start: '2000-01', end: '2013-01' }, { start: '2013-01', end: null }, { val: 16, unit: 'year' } ],
|
||||||
|
[ { start: '2000-01', end: '2013-01' }, { start: '2013-01', end: 'current' }, { val: 16, unit: 'year' } ]
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
tests.forEach(function(t){
|
||||||
|
_.initial( t ).forEach(function(t){ t.employer = 'E1' });
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Testing DATES', function () {
|
||||||
|
|
||||||
|
tests.forEach( function(t) {
|
||||||
|
|
||||||
|
it( JSON.stringify( _.initial(t) ), function () {
|
||||||
|
r.employment.history = _.initial( t );
|
||||||
|
var rObj = new FRESHResume();
|
||||||
|
rObj.parseJSON( r );
|
||||||
|
var dur = rObj.duration();
|
||||||
|
expect( dur ).to.equal( _.last(t).val );
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user