Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
6c989a43
Commit
6c989a43
authored
May 06, 2016
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove some code duplication
parent
a57bc066
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
19 deletions
+31
-19
time.js
h/static/scripts/time.js
+31
-19
No files found.
h/static/scripts/time.js
View file @
6c989a43
...
...
@@ -42,31 +42,43 @@ function nHr(date, now) {
return
'{} hr'
.
replace
(
'{}'
,
Math
.
floor
(
delta
(
date
,
now
)
/
hour
));
}
// Cached DateTimeFormat instance, instantiating a DateTimeFormat is expensive.
var
dayAndMonthFormatter
;
// Cached DateTimeFormat instances,
// because instantiating a DateTimeFormat is expensive.
var
formatters
=
{};
function
dayAndMonth
(
date
)
{
if
(
!
dayAndMonthFormatter
)
{
dayAndMonthFormatter
=
new
Intl
.
DateTimeFormat
(
undefined
,
{
month
:
'short'
,
day
:
'2-digit'
,
});
/**
* Efficiently return `date` formatted with `options`.
*
* This is a wrapper for Intl.DateTimeFormat.format() that caches
* DateTimeFormat instances because they're expensive to create.
*
* @returns {string}
*
*/
function
format
(
date
,
options
)
{
var
key
=
JSON
.
stringify
(
options
);
var
formatter
=
formatters
[
key
];
if
(
!
formatter
)
{
formatter
=
formatters
[
key
]
=
new
Intl
.
DateTimeFormat
(
undefined
,
options
);
}
return
dayAndMonthFormatter
.
format
(
date
);
return
formatter
.
format
(
date
);
}
// Cached DateTimeFormat instance, instantiating a DateTimeFormat is expensive.
var
dayMonthAndYearFormatter
;
function
dayAndMonth
(
date
)
{
return
format
(
date
,
{
month
:
'short'
,
day
:
'2-digit'
,
});
}
function
dayAndMonthAndYear
(
date
)
{
if
(
!
dayMonthAndYearFormatter
)
{
dayMonthAndYearFormatter
=
new
Intl
.
DateTimeFormat
(
undefined
,
{
day
:
'2-digit'
,
month
:
'short'
,
year
:
'numeric'
});
}
return
dayMonthAndYearFormatter
.
format
(
date
);
return
format
(
date
,
{
day
:
'2-digit'
,
month
:
'short'
,
year
:
'numeric'
});
}
var
BREAKPOINTS
=
[
...
...
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