diff --git a/lib/util/blameFormatter.js b/lib/util/blameFormatter.js index 49cb148..7bf4b5d 100644 --- a/lib/util/blameFormatter.js +++ b/lib/util/blameFormatter.js @@ -22,6 +22,15 @@ function parseCommitter(line) { return line.match(committerMatcher)[1]; } +/** + * Formats a date according to the user's preferred format string. + * @param {object} date - a moment date object + */ +function formatDate(date) { + var formatString = atom.config.get('git-blame.dateFormatString'); + return date.format(formatString); +} + /** * Parses the commit date from blame data for a line of code. * @@ -32,8 +41,7 @@ function parseDate(line) { var dateMatcher = /^committer-time\s(.*)$/m; var dateStamp = line.match(dateMatcher)[1]; - var formatString = atom.config.get('git-blame.dateFormatString'); - return moment.unix(dateStamp).format(formatString); + return formatDate(moment.unix(dateStamp)); } /** @@ -103,5 +111,6 @@ function parseBlameOutput(blameOut) { // EXPORTS module.exports = { - parseBlame: parseBlameOutput + parseBlame: parseBlameOutput, + formatDate: formatDate }; diff --git a/lib/views/blame-line-view.coffee b/lib/views/blame-line-view.coffee index 0777ae7..87256e3 100644 --- a/lib/views/blame-line-view.coffee +++ b/lib/views/blame-line-view.coffee @@ -1,15 +1,18 @@ {$, React, Reactionary} = require 'atom' -RP = React.PropTypes {div, span, a} = Reactionary +RP = React.PropTypes +moment = require 'moment' +{formatDate} = require '../util/blameFormatter' HASH_LENGTH = 7 # github uses this length BLANK_HASH = '-'.repeat(HASH_LENGTH) +DEFAULT_DATE = formatDate moment("2000-01-01T13:17:00 Z") renderLoading = -> div className: 'blame-line loading', span className: 'hash', BLANK_HASH - span className: 'date', '1337-01-01' + span className: 'date', DEFAULT_DATE span className: 'committer', 'Loading'