File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Expand file tree Collapse file tree 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';
33import ActionRunStatus from ' ./ActionRunStatus.vue' ;
44import {createApp } from ' vue' ;
55import {toggleElem } from ' ../utils/dom.js' ;
6- import {getCurrentLocale } from ' ../utils.js' ;
6+ import {formatDatetime } from ' ../utils/time .js' ;
77import {renderAnsi } from ' ../render/ansi.js' ;
88import {POST , DELETE } from ' ../modules/fetch.js' ;
99
@@ -167,7 +167,7 @@ const sfc = {
167167 const logTimeStamp = document .createElement (' span' );
168168 logTimeStamp .className = ' log-time-stamp' ;
169169 const date = new Date (parseFloat (line .timestamp * 1000 ));
170- const timeStamp = date . toLocaleString ( getCurrentLocale (), {timeZoneName : ' short ' } );
170+ const timeStamp = formatDatetime (date );
171171 logTimeStamp .textContent = timeStamp;
172172 toggleElem (logTimeStamp, this .timeVisible [' log-time-stamp' ]);
173173 // for "Show seconds"
Original file line number Diff line number Diff line change 11import tippy , { followCursor } from 'tippy.js' ;
22import { isDocumentFragmentOrElementNode } from '../utils/dom.js' ;
3+ import { formatDatetime } from '../utils/time.js' ;
34
45const visibleInstances = new Set ( ) ;
56
@@ -93,8 +94,15 @@ function attachTooltip(target, content = null) {
9394}
9495
9596function switchTitleToTooltip ( target ) {
96- const title = target . getAttribute ( 'title' ) ;
97+ let title = target . getAttribute ( 'title' ) ;
9798 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+ }
98106 target . setAttribute ( 'data-tooltip-content' , title ) ;
99107 target . setAttribute ( 'aria-label' , title ) ;
100108 // keep the attribute, in case there are some other "[title]" selectors
Original file line number Diff line number Diff line change 11import dayjs from 'dayjs' ;
2+ import { getCurrentLocale } from '../utils.js' ;
23
34// Returns an array of millisecond-timestamps of start-of-week days (Sundays)
45export function startDaysBetween ( startDate , endDate ) {
@@ -44,3 +45,23 @@ export function fillEmptyStartDaysWithZeroes(startDays, data) {
4445
4546 return Object . values ( result ) ;
4647}
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