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
6401db89
Commit
6401db89
authored
Nov 01, 2019
by
jakeburden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update usage of timeago.js
parent
21cb540a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
74 deletions
+63
-74
app/assets/javascripts/lib/utils/datetime_utility.js
app/assets/javascripts/lib/utils/datetime_utility.js
+63
-74
No files found.
app/assets/javascripts/lib/utils/datetime_utility.js
View file @
6401db89
import
$
from
'
jquery
'
;
import
_
from
'
underscore
'
;
import
timeago
from
'
timeago.js
'
;
import
*
as
timeago
from
'
timeago.js
'
;
import
dateFormat
from
'
dateformat
'
;
import
{
languageCode
,
s__
,
__
,
n__
}
from
'
../../locale
'
;
...
...
@@ -92,90 +92,79 @@ export const formatDate = (datetime, format = 'mmm d, yyyy h:MMtt Z') => {
*/
const
timeagoLanguageCode
=
languageCode
().
replace
(
/-/g
,
'
_
'
);
let
timeagoInstance
;
/**
*
Sets a timeago Instance
*
Registers timeago locales
*/
export
const
getTimeago
=
()
=>
{
if
(
!
timeagoInstance
)
{
const
memoizedLocaleRemaining
=
()
=>
{
const
cache
=
[];
const
timeAgoLocaleRemaining
=
[
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|right now
'
)],
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|%s seconds remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 minute ago
'
),
s__
(
'
Timeago|1 minute remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s minutes ago
'
),
s__
(
'
Timeago|%s minutes remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 hour ago
'
),
s__
(
'
Timeago|1 hour remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s hours ago
'
),
s__
(
'
Timeago|%s hours remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 day ago
'
),
s__
(
'
Timeago|1 day remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s days ago
'
),
s__
(
'
Timeago|%s days remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 week ago
'
),
s__
(
'
Timeago|1 week remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s weeks ago
'
),
s__
(
'
Timeago|%s weeks remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 month ago
'
),
s__
(
'
Timeago|1 month remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s months ago
'
),
s__
(
'
Timeago|%s months remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 year ago
'
),
s__
(
'
Timeago|1 year remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s years ago
'
),
s__
(
'
Timeago|%s years remaining
'
)],
];
return
(
number
,
index
)
=>
{
if
(
cache
[
index
])
{
return
cache
[
index
];
}
cache
[
index
]
=
timeAgoLocaleRemaining
[
index
]
&&
timeAgoLocaleRemaining
[
index
]();
return
cache
[
index
];
};
};
const
memoizedLocale
=
()
=>
{
const
cache
=
[];
const
timeAgoLocale
=
[
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|right now
'
)],
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|in %s seconds
'
)],
()
=>
[
s__
(
'
Timeago|1 minute ago
'
),
s__
(
'
Timeago|in 1 minute
'
)],
()
=>
[
s__
(
'
Timeago|%s minutes ago
'
),
s__
(
'
Timeago|in %s minutes
'
)],
()
=>
[
s__
(
'
Timeago|1 hour ago
'
),
s__
(
'
Timeago|in 1 hour
'
)],
()
=>
[
s__
(
'
Timeago|%s hours ago
'
),
s__
(
'
Timeago|in %s hours
'
)],
()
=>
[
s__
(
'
Timeago|1 day ago
'
),
s__
(
'
Timeago|in 1 day
'
)],
()
=>
[
s__
(
'
Timeago|%s days ago
'
),
s__
(
'
Timeago|in %s days
'
)],
()
=>
[
s__
(
'
Timeago|1 week ago
'
),
s__
(
'
Timeago|in 1 week
'
)],
()
=>
[
s__
(
'
Timeago|%s weeks ago
'
),
s__
(
'
Timeago|in %s weeks
'
)],
()
=>
[
s__
(
'
Timeago|1 month ago
'
),
s__
(
'
Timeago|in 1 month
'
)],
()
=>
[
s__
(
'
Timeago|%s months ago
'
),
s__
(
'
Timeago|in %s months
'
)],
()
=>
[
s__
(
'
Timeago|1 year ago
'
),
s__
(
'
Timeago|in 1 year
'
)],
()
=>
[
s__
(
'
Timeago|%s years ago
'
),
s__
(
'
Timeago|in %s years
'
)],
];
return
(
number
,
index
)
=>
{
if
(
cache
[
index
])
{
return
cache
[
index
];
}
cache
[
index
]
=
timeAgoLocale
[
index
]
&&
timeAgoLocale
[
index
]();
return
cache
[
index
];
};
};
timeago
.
register
(
timeagoLanguageCode
,
memoizedLocale
());
timeago
.
register
(
`
${
timeagoLanguageCode
}
-remaining`
,
memoizedLocaleRemaining
());
timeagoInstance
=
timeago
();
}
const
memoizedLocaleRemaining
=
()
=>
{
const
cache
=
[];
const
timeAgoLocaleRemaining
=
[
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|right now
'
)],
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|%s seconds remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 minute ago
'
),
s__
(
'
Timeago|1 minute remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s minutes ago
'
),
s__
(
'
Timeago|%s minutes remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 hour ago
'
),
s__
(
'
Timeago|1 hour remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s hours ago
'
),
s__
(
'
Timeago|%s hours remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 day ago
'
),
s__
(
'
Timeago|1 day remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s days ago
'
),
s__
(
'
Timeago|%s days remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 week ago
'
),
s__
(
'
Timeago|1 week remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s weeks ago
'
),
s__
(
'
Timeago|%s weeks remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 month ago
'
),
s__
(
'
Timeago|1 month remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s months ago
'
),
s__
(
'
Timeago|%s months remaining
'
)],
()
=>
[
s__
(
'
Timeago|1 year ago
'
),
s__
(
'
Timeago|1 year remaining
'
)],
()
=>
[
s__
(
'
Timeago|%s years ago
'
),
s__
(
'
Timeago|%s years remaining
'
)],
];
return
(
number
,
index
)
=>
{
if
(
cache
[
index
])
{
return
cache
[
index
];
}
cache
[
index
]
=
timeAgoLocaleRemaining
[
index
]
&&
timeAgoLocaleRemaining
[
index
]();
return
cache
[
index
];
};
};
const
memoizedLocale
=
()
=>
{
const
cache
=
[];
const
timeAgoLocale
=
[
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|right now
'
)],
()
=>
[
s__
(
'
Timeago|just now
'
),
s__
(
'
Timeago|in %s seconds
'
)],
()
=>
[
s__
(
'
Timeago|1 minute ago
'
),
s__
(
'
Timeago|in 1 minute
'
)],
()
=>
[
s__
(
'
Timeago|%s minutes ago
'
),
s__
(
'
Timeago|in %s minutes
'
)],
()
=>
[
s__
(
'
Timeago|1 hour ago
'
),
s__
(
'
Timeago|in 1 hour
'
)],
()
=>
[
s__
(
'
Timeago|%s hours ago
'
),
s__
(
'
Timeago|in %s hours
'
)],
()
=>
[
s__
(
'
Timeago|1 day ago
'
),
s__
(
'
Timeago|in 1 day
'
)],
()
=>
[
s__
(
'
Timeago|%s days ago
'
),
s__
(
'
Timeago|in %s days
'
)],
()
=>
[
s__
(
'
Timeago|1 week ago
'
),
s__
(
'
Timeago|in 1 week
'
)],
()
=>
[
s__
(
'
Timeago|%s weeks ago
'
),
s__
(
'
Timeago|in %s weeks
'
)],
()
=>
[
s__
(
'
Timeago|1 month ago
'
),
s__
(
'
Timeago|in 1 month
'
)],
()
=>
[
s__
(
'
Timeago|%s months ago
'
),
s__
(
'
Timeago|in %s months
'
)],
()
=>
[
s__
(
'
Timeago|1 year ago
'
),
s__
(
'
Timeago|in 1 year
'
)],
()
=>
[
s__
(
'
Timeago|%s years ago
'
),
s__
(
'
Timeago|in %s years
'
)],
];
return
timeagoInstance
;
return
(
number
,
index
)
=>
{
if
(
cache
[
index
])
{
return
cache
[
index
];
}
cache
[
index
]
=
timeAgoLocale
[
index
]
&&
timeAgoLocale
[
index
]();
return
cache
[
index
];
};
};
timeago
.
register
(
timeagoLanguageCode
,
memoizedLocale
());
timeago
.
register
(
`
${
timeagoLanguageCode
}
-remaining`
,
memoizedLocaleRemaining
());
/**
* For the given elements, sets a tooltip with a formatted date.
* @param {JQuery} $timeagoEls
* @param {Boolean} setTimeago
*/
export
const
localTimeAgo
=
(
$timeagoEls
,
setTimeago
=
true
)
=>
{
getTimeago
();
$timeagoEls
.
each
((
i
,
el
)
=>
{
$
(
el
).
text
(
timeago
Instance
.
format
(
$
(
el
).
attr
(
'
datetime
'
),
timeagoLanguageCode
));
$
(
el
).
text
(
timeago
.
format
(
$
(
el
).
attr
(
'
datetime
'
),
timeagoLanguageCode
));
});
if
(
!
setTimeago
)
{
...
...
@@ -207,7 +196,7 @@ export const timeFor = (time, expiredLabel) => {
if
(
new
Date
(
time
)
<
new
Date
())
{
return
expiredLabel
||
s__
(
'
Timeago|Past due
'
);
}
return
getTimeago
()
return
timeago
.
format
(
time
,
`
${
timeagoLanguageCode
}
-remaining`
)
.
trim
();
};
...
...
@@ -417,7 +406,7 @@ export const dayInQuarter = (date, quarter) =>
window
.
gl
=
window
.
gl
||
{};
window
.
gl
.
utils
=
{
...(
window
.
gl
.
utils
||
{}),
getT
imeago
,
t
imeago
,
localTimeAgo
,
};
...
...
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