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
Show 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) {
...
@@ -42,31 +42,43 @@ function nHr(date, now) {
return
'{} hr'
.
replace
(
'{}'
,
Math
.
floor
(
delta
(
date
,
now
)
/
hour
));
return
'{} hr'
.
replace
(
'{}'
,
Math
.
floor
(
delta
(
date
,
now
)
/
hour
));
}
}
// Cached DateTimeFormat instance, instantiating a DateTimeFormat is expensive.
// Cached DateTimeFormat instances,
var
dayAndMonthFormatter
;
// because instantiating a DateTimeFormat is expensive.
var
formatters
=
{};
/**
* 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
formatter
.
format
(
date
);
}
function
dayAndMonth
(
date
)
{
function
dayAndMonth
(
date
)
{
if
(
!
dayAndMonthFormatter
)
{
return
format
(
date
,
{
dayAndMonthFormatter
=
new
Intl
.
DateTimeFormat
(
undefined
,
{
month
:
'short'
,
month
:
'short'
,
day
:
'2-digit'
,
day
:
'2-digit'
,
});
});
}
return
dayAndMonthFormatter
.
format
(
date
);
}
}
// Cached DateTimeFormat instance, instantiating a DateTimeFormat is expensive.
var
dayMonthAndYearFormatter
;
function
dayAndMonthAndYear
(
date
)
{
function
dayAndMonthAndYear
(
date
)
{
if
(
!
dayMonthAndYearFormatter
)
{
return
format
(
date
,
{
dayMonthAndYearFormatter
=
new
Intl
.
DateTimeFormat
(
undefined
,
{
day
:
'2-digit'
,
day
:
'2-digit'
,
month
:
'short'
,
month
:
'short'
,
year
:
'numeric'
year
:
'numeric'
});
});
}
return
dayMonthAndYearFormatter
.
format
(
date
);
}
}
var
BREAKPOINTS
=
[
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