Commit 3092b308 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents f14948f8 2cc6e6ff
......@@ -79,7 +79,12 @@ export const getDayName = date =>
* @param {date} datetime
* @returns {String}
*/
export const formatDate = datetime => dateFormat(datetime, 'mmm d, yyyy h:MMtt Z');
export const formatDate = datetime => {
if (_.isString(datetime) && datetime.match(/\d+-\d+\d+ /)) {
throw new Error('Invalid date');
}
return dateFormat(datetime, 'mmm d, yyyy h:MMtt Z');
};
/**
* Timeago uses underscores instead of dashes to separate language from country code.
......
---
title: Throw an error when formatDate's input is invalid
merge_request: 28713
author:
type: fixed
......@@ -65,6 +65,26 @@ describe('Date time utils', () => {
});
});
describe('formatDate', () => {
it('should format date properly', () => {
const formattedDate = datetimeUtility.formatDate(new Date('07/23/2016'));
expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
});
it('should format ISO date properly', () => {
const formattedDate = datetimeUtility.formatDate('2016-07-23T00:00:00.559Z');
expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
});
it('should throw an error if date is invalid', () => {
expect(() => {
datetimeUtility.formatDate('2016-07-23 00:00:00 UTC');
}).toThrow(new Error('Invalid date'));
});
});
describe('get day difference', () => {
it('should return 7', () => {
const firstDay = new Date('07/01/2016');
......@@ -380,7 +400,7 @@ describe('prettyTime methods', () => {
describe('calculateRemainingMilliseconds', () => {
beforeEach(() => {
spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime());
jest.spyOn(Date, 'now').mockImplementation(() => new Date('2063-04-04T00:42:00Z').getTime());
});
it('calculates the remaining time for a given end date', () => {
......
......@@ -685,10 +685,10 @@
eslint-plugin-promise "^4.1.1"
eslint-plugin-vue "^5.0.0"
"@gitlab/svgs@^1.62.0":
version "1.62.0"
resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-1.62.0.tgz#7072220b7c3aeb31d49b770888ff923b31e44e39"
integrity sha512-xBmIidLfJZ3N9OJTsrtphsCbmenGm25AJe6s9Hsm9ikuSJ9FLBbwDJBORw95CSmajB0GdgbkPoTOWbIh1V9KgA==
"@gitlab/svgs@^1.63.0":
version "1.63.0"
resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-1.63.0.tgz#9dd544026d203e4ce6efed72b05db68f710c4d49"
integrity sha512-YztrReFTg31B7v5wtUC5j15KHNcMebtW+kACytEU42XomMaIwk4USIbygqWlq0VRHA2VHJrHApfJHIjxiCCQcA==
"@gitlab/ui@^3.10.0":
version "3.10.0"
......
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