Commit 8d10edca authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '35613-refactor-secondstomilliseconds-to-make-this-available-for-importing' into 'master'

Refactor secondsToMilliseconds to make this available for importing

Closes #35613

See merge request gitlab-org/gitlab!19703
parents 925315e1 5e47dec7
......@@ -541,7 +541,7 @@ export const stringifyTime = (timeObject, fullNameFormat = false) => {
* The result cannot become negative.
*
* @param endDate date string that the time difference is calculated for
* @return {number} number of milliseconds remaining until the given date
* @return {Number} number of milliseconds remaining until the given date
*/
export const calculateRemainingMilliseconds = endDate => {
const remainingMilliseconds = new Date(endDate).getTime() - Date.now();
......@@ -552,7 +552,7 @@ export const calculateRemainingMilliseconds = endDate => {
* Subtracts a given number of days from a given date and returns the new date.
*
* @param {Date} date the date that we will substract days from
* @param {number} daysInPast number of days that are subtracted from a given date
* @param {Number} daysInPast number of days that are subtracted from a given date
* @returns {Date} Date in past as Date object
*/
export const getDateInPast = (date, daysInPast) =>
......@@ -594,3 +594,11 @@ export const getDatesInRange = (d1, d2, formatter = x => x) => {
return range.map(formatter);
};
/**
* Converts the supplied number of seconds to milliseconds.
*
* @param {Number} seconds
* @return {Number} number of milliseconds
*/
export const secondsToMilliseconds = seconds => seconds * 1000;
import dateformat from 'dateformat';
import { secondsIn, dateTimePickerRegex, dateFormats } from './constants';
const secondsToMilliseconds = seconds => seconds * 1000;
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
export const getTimeDiff = timeWindow => {
const end = Math.floor(Date.now() / 1000); // convert milliseconds to seconds
......
<script>
import { GlButton, GlLink, GlProgressBar } from '@gitlab/ui';
import { __ } from '~/locale';
import { formatTime } from '~/lib/utils/datetime_utility';
import { formatTime, secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import Icon from '~/vue_shared/components/icon.vue';
export default {
......@@ -31,7 +31,7 @@ export default {
return Math.round((this.report.success_count / this.report.total_count) * 100) || 0;
},
formattedDuration() {
return formatTime(this.report.total_time * 1000);
return formatTime(secondsToMilliseconds(this.report.total_time));
},
progressBarVariant() {
if (this.successPercentage < 33) {
......
import { TestStatus } from '~/pipelines/constants';
import { formatTime } from '~/lib/utils/datetime_utility';
import { formatTime, secondsToMilliseconds } from '~/lib/utils/datetime_utility';
function iconForTestStatus(status) {
switch (status) {
......@@ -12,7 +12,7 @@ function iconForTestStatus(status) {
}
}
export const formattedTime = timeInSeconds => formatTime(timeInSeconds * 1000);
export const formattedTime = timeInSeconds => formatTime(secondsToMilliseconds(timeInSeconds));
export const addIconStatus = testCase => ({
...testCase,
......
......@@ -474,3 +474,11 @@ describe('getDatesInRange', () => {
});
});
});
describe('secondsToMilliseconds', () => {
it('converts seconds to milliseconds correctly', () => {
expect(datetimeUtility.secondsToMilliseconds(0)).toBe(0);
expect(datetimeUtility.secondsToMilliseconds(60)).toBe(60000);
expect(datetimeUtility.secondsToMilliseconds(123)).toBe(123000);
});
});
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