Commit b6577d15 authored by Sean Arnold's avatar Sean Arnold Committed by Phil Hughes

Format dates before creating timestamps

parent e50a6361
......@@ -175,6 +175,7 @@ export const localTimeAgo = ($timeagoEls, setTimeago = true) => {
function addTimeAgoTooltip() {
$timeagoEls.each((i, el) => {
// Recreate with custom template
el.setAttribute('title', formatDate(el.dateTime));
$(el).tooltip({
template:
'<div class="tooltip local-timeago" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
......
---
title: Fix timezones for popovers.
merge_request: 24942
author:
type: fixed
import { __, s__ } from '~/locale';
import $ from 'jquery';
import '~/commons/bootstrap';
import * as datetimeUtility from '~/lib/utils/datetime_utility';
describe('Date time utils', () => {
......@@ -563,3 +565,23 @@ describe('approximateDuration', () => {
expect(datetimeUtility.approximateDuration(seconds)).toBe(approximation);
});
});
describe('localTimeAgo', () => {
beforeEach(() => {
document.body.innerHTML = `<time title="some time" datetime="2020-02-18T22:22:32Z">1 hour ago</time>`;
});
it.each`
timeagoArg | title | dataOriginalTitle
${false} | ${'some time'} | ${null}
${true} | ${''} | ${'Feb 18, 2020 10:22pm GMT+0000'}
`('converts $seconds seconds to $approximation', ({ timeagoArg, title, dataOriginalTitle }) => {
const element = document.querySelector('time');
datetimeUtility.localTimeAgo($(element), timeagoArg);
jest.runAllTimers();
expect(element.getAttribute('data-original-title')).toBe(dataOriginalTitle);
expect(element.getAttribute('title')).toBe(title);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment