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
ea3c62fb
Commit
ea3c62fb
authored
Jan 27, 2020
by
Miguel Rincon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update jsdocs of functions and improve parameter naming
parent
12c055a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
26 deletions
+36
-26
app/assets/javascripts/lib/utils/datetime_range.js
app/assets/javascripts/lib/utils/datetime_range.js
+36
-26
No files found.
app/assets/javascripts/lib/utils/datetime_range.js
View file @
ea3c62fb
...
@@ -32,20 +32,29 @@ function handleRangeDirection({ direction = 'before', anchor, before, after }) {
...
@@ -32,20 +32,29 @@ function handleRangeDirection({ direction = 'before', anchor, before, after }) {
};
};
}
}
function
convertFixedToFixed
(
range
)
{
/**
* Converts a fixed range to a fixed range
* @param {Object} fixedRange - A range with fixed start and end (e.g. From January 1st 2020 to January 31st 2020)
*/
function
convertFixedToFixed
(
fixedRange
)
{
//
return
{
return
{
startTime
:
new
Date
(
r
ange
.
startTime
).
toISOString
(),
startTime
:
new
Date
(
fixedR
ange
.
startTime
).
toISOString
(),
endTime
:
new
Date
(
r
ange
.
endTime
).
toISOString
(),
endTime
:
new
Date
(
fixedR
ange
.
endTime
).
toISOString
(),
};
};
}
}
function
convertAnchoredToFixed
(
range
)
{
/**
const
anchor
=
new
Date
(
range
.
anchor
);
* Converts an anchored range to a fixed range
* @param {Object} anchoredRange - A duration of time relative to an fixed point in time (2 minutes before January 1st, 1 day after)
*/
function
convertAnchoredToFixed
(
anchoredRange
)
{
const
anchor
=
new
Date
(
anchoredRange
.
anchor
);
const
{
startDate
,
endDate
}
=
handleRangeDirection
({
const
{
startDate
,
endDate
}
=
handleRangeDirection
({
before
:
dateMinusDuration
(
anchor
,
r
ange
.
duration
),
before
:
dateMinusDuration
(
anchor
,
anchoredR
ange
.
duration
),
after
:
datePlusDuration
(
anchor
,
r
ange
.
duration
),
after
:
datePlusDuration
(
anchor
,
anchoredR
ange
.
duration
),
direction
:
r
ange
.
direction
,
direction
:
anchoredR
ange
.
direction
,
anchor
,
anchor
,
});
});
...
@@ -55,24 +64,32 @@ function convertAnchoredToFixed(range) {
...
@@ -55,24 +64,32 @@ function convertAnchoredToFixed(range) {
};
};
}
}
function
convertRollingToFixed
(
range
)
{
/**
* Converts a rolling change to a fixed range
* @param {Object} rollingRange - a time range relative to now (Last 2 minutes, Next 2 days)
*/
function
convertRollingToFixed
(
rollingRange
)
{
const
now
=
new
Date
(
Date
.
now
());
const
now
=
new
Date
(
Date
.
now
());
return
convertAnchoredToFixed
({
return
convertAnchoredToFixed
({
duration
:
range
.
duration
,
duration
:
r
ollingR
ange
.
duration
,
direction
:
range
.
direction
,
direction
:
r
ollingR
ange
.
direction
,
anchor
:
now
.
toISOString
(),
anchor
:
now
.
toISOString
(),
});
});
}
}
function
convertOpenToFixed
(
range
)
{
/**
* Converts an open range to a fixed range
* @param {Object} openRange - a time range relative to an anchor (Before 1st of January, After 1st of January)
*/
function
convertOpenToFixed
(
openRange
)
{
const
now
=
new
Date
(
Date
.
now
());
const
now
=
new
Date
(
Date
.
now
());
const
anchor
=
new
Date
(
r
ange
.
anchor
);
const
anchor
=
new
Date
(
openR
ange
.
anchor
);
const
{
startDate
,
endDate
}
=
handleRangeDirection
({
const
{
startDate
,
endDate
}
=
handleRangeDirection
({
before
:
MINIMUM_DATE
,
before
:
MINIMUM_DATE
,
after
:
now
,
after
:
now
,
direction
:
r
ange
.
direction
,
direction
:
openR
ange
.
direction
,
anchor
,
anchor
,
});
});
...
@@ -126,24 +143,17 @@ export function getRangeType(range) {
...
@@ -126,24 +143,17 @@ export function getRangeType(range) {
*
*
* A a range of time can be understood as an arbitrary period
* A a range of time can be understood as an arbitrary period
* of time that can represent points in time relative to the
* of time that can represent points in time relative to the
* present moment. Some examples can be:
* present moment:
*
* -
* - From January 1st onwards
* -
* - Last 2 days
* - The next 2 days
* - Today so far
*
*
* The range of time can take different shapes according to
* The range of time can take different shapes according to
* the point of time and type of time range it represents.
* the point of time and type of time range it represents.
*
*
* The following types of ranges can be represented:
* The following types of ranges can be represented:
*
*
*
- Fixed Range: fixed start and ends
(e.g. From January 1st 2020 to January 31st 2020)
*
Fixed Range: A range with fixed start and end
(e.g. From January 1st 2020 to January 31st 2020)
*
- Anchored Range: a fixed points in time (2 minutes before January 1st, 1 day after
)
*
Anchored Range: A duration of time relative to an fixed point in time (2 minutes before January 1st, 1 day after
)
*
- Rolling Range: a
time range relative to now (Last 2 minutes, Next 2 days)
*
Rolling Range: A
time range relative to now (Last 2 minutes, Next 2 days)
*
- Open Range: a time range relative to now
(Before 1st of January, After 1st of January)
*
Open Range: A time range relative to an anchor
(Before 1st of January, After 1st of January)
*
*
* @param {Object} dateTimeRange - A Time Range representation
* @param {Object} dateTimeRange - A Time Range representation
* It contains the data needed to create a fixed time range plus
* It contains the data needed to create a fixed time range plus
...
...
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