File tree 3 files changed +32
-3
lines changed
3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import {SvgIcon} from '../svg.js';
3
3
import ActionRunStatus from ' ./ActionRunStatus.vue' ;
4
4
import {createApp } from ' vue' ;
5
5
import {toggleElem } from ' ../utils/dom.js' ;
6
- import {getCurrentLocale } from ' ../utils.js' ;
6
+ import {formatDatetime } from ' ../utils/time .js' ;
7
7
import {renderAnsi } from ' ../render/ansi.js' ;
8
8
import {POST , DELETE } from ' ../modules/fetch.js' ;
9
9
@@ -167,7 +167,7 @@ const sfc = {
167
167
const logTimeStamp = document .createElement (' span' );
168
168
logTimeStamp .className = ' log-time-stamp' ;
169
169
const date = new Date (parseFloat (line .timestamp * 1000 ));
170
- const timeStamp = date . toLocaleString ( getCurrentLocale (), {timeZoneName : ' short ' } );
170
+ const timeStamp = formatDatetime (date );
171
171
logTimeStamp .textContent = timeStamp;
172
172
toggleElem (logTimeStamp, this .timeVisible [' log-time-stamp' ]);
173
173
// for "Show seconds"
Original file line number Diff line number Diff line change 1
1
import tippy , { followCursor } from 'tippy.js' ;
2
2
import { isDocumentFragmentOrElementNode } from '../utils/dom.js' ;
3
+ import { formatDatetime } from '../utils/time.js' ;
3
4
4
5
const visibleInstances = new Set ( ) ;
5
6
@@ -93,8 +94,15 @@ function attachTooltip(target, content = null) {
93
94
}
94
95
95
96
function switchTitleToTooltip ( target ) {
96
- const title = target . getAttribute ( 'title' ) ;
97
+ let title = target . getAttribute ( 'title' ) ;
97
98
if ( title ) {
99
+ // apply custom formatting to relative-time's tooltips
100
+ if ( target . tagName . toLowerCase ( ) === 'relative-time' ) {
101
+ const datetime = target . getAttribute ( 'datetime' ) ;
102
+ if ( datetime ) {
103
+ title = formatDatetime ( new Date ( datetime ) ) ;
104
+ }
105
+ }
98
106
target . setAttribute ( 'data-tooltip-content' , title ) ;
99
107
target . setAttribute ( 'aria-label' , title ) ;
100
108
// keep the attribute, in case there are some other "[title]" selectors
Original file line number Diff line number Diff line change 1
1
import dayjs from 'dayjs' ;
2
+ import { getCurrentLocale } from '../utils.js' ;
2
3
3
4
// Returns an array of millisecond-timestamps of start-of-week days (Sundays)
4
5
export function startDaysBetween ( startDate , endDate ) {
@@ -44,3 +45,23 @@ export function fillEmptyStartDaysWithZeroes(startDays, data) {
44
45
45
46
return Object . values ( result ) ;
46
47
}
48
+
49
+ let dateFormat ;
50
+
51
+ // format a Date object to document's locale, but with 24h format from user's current locale because this
52
+ // option is a personal preference of the user, not something that the document's locale should dictate.
53
+ export function formatDatetime ( date ) {
54
+ if ( ! dateFormat ) {
55
+ // TODO: replace `hour12` with `Intl.Locale.prototype.getHourCycles` once there is broad browser support
56
+ dateFormat = new Intl . DateTimeFormat ( getCurrentLocale ( ) , {
57
+ day : 'numeric' ,
58
+ month : 'short' ,
59
+ year : 'numeric' ,
60
+ hour : 'numeric' ,
61
+ hour12 : ! Number . isInteger ( Number ( new Intl . DateTimeFormat ( [ ] , { hour : 'numeric' } ) . format ( ) ) ) ,
62
+ minute : '2-digit' ,
63
+ timeZoneName : 'short' ,
64
+ } ) ;
65
+ }
66
+ return dateFormat . format ( date ) ;
67
+ }
You can’t perform that action at this time.
0 commit comments