@@ -15,6 +15,15 @@ export function parseGitBlamePorcelain(blame: string): {
15
15
return fields ;
16
16
}
17
17
18
+ export function formatTimeValue ( value : string ) {
19
+ const date = new Date ( parseInt ( value ) * 1000 ) ;
20
+
21
+ return {
22
+ dateString : date . toISOString ( ) ,
23
+ timeAgo : relativeTimePassed ( Date . now ( ) , date . getTime ( ) ) ,
24
+ } ;
25
+ }
26
+
18
27
export function relativeTimePassed ( now : number , past : number ) : string {
19
28
const msMinutes = 60 * 1000 ;
20
29
const msHours = msMinutes * 60 ;
@@ -50,13 +59,10 @@ export function relativeTimePassed(now: number, past: number): string {
50
59
}
51
60
52
61
export function formatMessage ( fields : Record < string , string > ) : string {
53
- const elapsed = relativeTimePassed (
54
- Date . now ( ) ,
55
- parseInt ( fields [ "author-time" ] ) * 1000
56
- ) ;
62
+ const { timeAgo } = formatTimeValue ( fields [ "author-time" ] ) ;
57
63
const isUncommitted = fields [ "author" ] === "Not Committed Yet" ;
58
64
const isUnsaved = fields [ "author" ] === "External file (--contents)" ;
59
- const defaultMessage = `${ fields . author } , ${ elapsed } • ${ fields . summary } ` ;
65
+ const defaultMessage = `${ fields . author } , ${ timeAgo } • ${ fields . summary } ` ;
60
66
61
67
if ( isUncommitted ) {
62
68
return "Not committed yet" ;
@@ -70,7 +76,15 @@ export function formatMessage(fields: Record<string, string>): string {
70
76
export function formatHoverMessage ( fields : Record < string , string > ) : string {
71
77
const header = "| Key | Value |\n| :-- | :-- |\n" ;
72
78
const message = Object . entries ( fields )
73
- . map ( ( [ k , v ] ) => `| ${ k } | \`${ v } \` |` )
79
+ . map ( ( [ k , v ] ) => {
80
+ if ( k === "author-time" || k === "committer-time" ) {
81
+ const { dateString, timeAgo } = formatTimeValue ( v ) ;
82
+
83
+ v = `${ dateString } (${ timeAgo } )` ;
84
+ }
85
+
86
+ return `| ${ k } | \`${ v } \` |` ; }
87
+ )
74
88
. join ( "\n" ) ;
75
89
return header + message ;
76
90
}
0 commit comments