-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathsignature.js
More file actions
38 lines (30 loc) · 1.02 KB
/
signature.js
File metadata and controls
38 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var NodeGit = require("../");
var Signature = NodeGit.Signature;
const toPaddedDoubleDigitString = (number) => {
if (number < 10) {
return `0${number}`;
}
return `${number}`;
};
/**
* Standard string representation of an author.
* @param {Boolean} withTime Whether or not to include timestamp
* @return {String} Representation of the author.
*/
Signature.prototype.toString = function(withTime) {
const name = this.name().toString();
const email = this.email().toString();
let stringifiedSignature = `${name} <${email}>`;
if (!withTime) {
return stringifiedSignature;
}
const when = this.when();
const offset = when.offset();
const offsetMagnitude = Math.abs(offset);
const time = when.time();
const sign = (offset < 0 || when.sign() === "-") ? "-" : "+";
const hours = toPaddedDoubleDigitString(Math.floor(offsetMagnitude / 60));
const minutes = toPaddedDoubleDigitString(offsetMagnitude % 60);
stringifiedSignature += ` ${time} ${sign}${hours}${minutes}`;
return stringifiedSignature;
};