Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bachelor 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mikkel Aas
bachelor 2022
Commits
c41baed5
Commit
c41baed5
authored
May 11, 2022
by
Mikkel Aas
Browse files
Options
Downloads
Patches
Plain Diff
added error handling
parent
fb7849ec
No related branches found
No related tags found
1 merge request
!88
Nav verifier extended
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils/dateUtils.ts
+22
-13
22 additions, 13 deletions
src/utils/dateUtils.ts
with
22 additions
and
13 deletions
src/utils/dateUtils.ts
+
22
−
13
View file @
c41baed5
...
...
@@ -6,13 +6,18 @@ import moment from 'moment';
* @param date2 the second date as a string
* @returns the absolute value of the year difference.
*/
export
function
computeYearsBetweenDates
(
date1
:
string
,
date2
:
string
):
number
{
export
function
computeYearsBetweenDates
(
date1
:
string
,
date2
:
string
):
number
|
Error
{
try
{
const
momentDate1
=
moment
(
date1
);
const
momentDate2
=
moment
(
date2
);
const
yearDiff
=
momentDate1
.
diff
(
momentDate2
,
'
years
'
);
return
Math
.
abs
(
yearDiff
);
}
catch
(
error
)
{
return
new
Error
(
'
unable to calculate amount of years
'
);
}
}
/**
...
...
@@ -21,11 +26,15 @@ export function computeYearsBetweenDates(date1: string, date2: string): number {
* @param date2 the second date as a string
* @returns the absolute value of the month difference.
*/
export
function
computeMonthsBetweenDates
(
date1
:
string
,
date2
:
string
):
number
{
export
function
computeMonthsBetweenDates
(
date1
:
string
,
date2
:
string
):
number
|
Error
{
try
{
const
momentDate1
=
moment
(
date1
);
const
momentDate2
=
moment
(
date2
);
const
monthDiff
=
momentDate1
.
diff
(
momentDate2
,
'
months
'
);
return
Math
.
abs
(
monthDiff
);
}
catch
(
error
)
{
return
new
Error
(
'
unable to calculate amount of months
'
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment