Skip to content

Make loading date value formatted consistent with user preference #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/util/blameFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -103,5 +111,6 @@ function parseBlameOutput(blameOut) {

// EXPORTS
module.exports = {
parseBlame: parseBlameOutput
parseBlame: parseBlameOutput,
formatDate: formatDate
};
7 changes: 5 additions & 2 deletions lib/views/blame-line-view.coffee
Original file line number Diff line number Diff line change
@@ -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'


Expand Down