UNPKG

2.08 kBJavaScriptView Raw
1(function() {
2 var FluentDate, _, lo;
3
4 FluentDate = require('../core/fluent-date');
5
6 _ = require('underscore');
7
8 lo = require('lodash');
9
10 module.exports = {
11 /**
12 Compute the total duration of the work history.
13 @returns The total duration of the sheet's work history, that is, the number
14 of years between the start date of the earliest job on the resume and the
15 *latest end date of all jobs in the work history*. This last condition is for
16 sheets that have overlapping jobs.
17 */
18 run: function(rez, collKey, startKey, endKey, unit) {
19 var firstDate, hist, lastDate, new_e;
20 unit = unit || 'years';
21 hist = lo.get(rez, collKey);
22 if (!hist || !hist.length) {
23 return 0;
24 }
25 // BEGIN CODE DUPLICATION --> src/inspectors/gap-inspector.coffee (TODO)
26
27 // Convert the candidate's employment history to an array of dates,
28 // where each element in the array is a start date or an end date of a
29 // job -- it doesn't matter which.
30 new_e = hist.map(function(job) {
31 var obj;
32 obj = _.pick(job, [startKey, endKey]);
33 if (!_.has(obj, endKey)) {
34 // Synthesize an end date if this is a "current" gig
35 obj[endKey] = 'current';
36 }
37 if (obj && (obj[startKey] || obj[endKey])) {
38 obj = _.pairs(obj);
39 obj[0][1] = FluentDate.fmt(obj[0][1]);
40 if (obj.length > 1) {
41 obj[1][1] = FluentDate.fmt(obj[1][1]);
42 }
43 }
44 return obj;
45 });
46 // Flatten the array, remove empties, and sort
47 new_e = _.filter(_.flatten(new_e, true), function(v) {
48 return v && v.length && v[0] && v[0].length;
49 });
50 if (!new_e || !new_e.length) {
51 return 0;
52 }
53 new_e = _.sortBy(new_e, function(elem) {
54 return elem[1].unix();
55 });
56 // END CODE DUPLICATION
57 firstDate = _.first(new_e)[1];
58 lastDate = _.last(new_e)[1];
59 return lastDate.diff(firstDate, unit);
60 }
61 };
62
63}).call(this);
64
65//# sourceMappingURL=duration-inspector.js.map