Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dade5a44
Commit
dade5a44
authored
May 28, 2019
by
Paul Gascou-Vaillancourt
Committed by
Phil Hughes
May 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw an error when formatDate's input is invalid
parent
ff7766b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
app/assets/javascripts/lib/utils/datetime_utility.js
app/assets/javascripts/lib/utils/datetime_utility.js
+6
-1
changelogs/unreleased/fix-format-date-safari-ff.yml
changelogs/unreleased/fix-format-date-safari-ff.yml
+5
-0
spec/frontend/lib/utils/datetime_utility_spec.js
spec/frontend/lib/utils/datetime_utility_spec.js
+21
-1
No files found.
app/assets/javascripts/lib/utils/datetime_utility.js
View file @
dade5a44
...
...
@@ -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.
...
...
changelogs/unreleased/fix-format-date-safari-ff.yml
0 → 100644
View file @
dade5a44
---
title
:
Throw an error when formatDate's input is invalid
merge_request
:
28713
author
:
type
:
fixed
spec/
javascripts
/lib/utils/datetime_utility_spec.js
→
spec/
frontend
/lib/utils/datetime_utility_spec.js
View file @
dade5a44
...
...
@@ -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
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment