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
fc4d0c15
Commit
fc4d0c15
authored
May 06, 2016
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fallback when Intl not defined
parent
9942a8a5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
time-test.js
h/static/scripts/test/time-test.js
+21
-0
time.js
h/static/scripts/time.js
+12
-6
No files found.
h/static/scripts/test/time-test.js
View file @
fc4d0c15
...
@@ -99,6 +99,27 @@ describe('time', function () {
...
@@ -99,6 +99,27 @@ describe('time', function () {
it
(
'creates correct fuzzy string for fixture '
+
i
,
it
(
'creates correct fuzzy string for fixture '
+
i
,
testFixture
(
f
));
testFixture
(
f
));
}
}
it
(
'falls back to simple strings for >24hrs ago'
,
function
()
{
// If window.Intl is not available then the date formatting for dates
// more than one day ago falls back to a simple date string.
window
.
Intl
=
undefined
;
var
d
=
new
Date
();
sandbox
.
clock
.
tick
(
day
*
2
*
1000
);
assert
.
equal
(
time
.
toFuzzyString
(
d
),
'Thu Jan 01 1970'
);
});
it
(
'falls back to simple strings for >1yr ago'
,
function
()
{
// If window.Intl is not available then the date formatting for dates
// more than one year ago falls back to a simple date string.
window
.
Intl
=
undefined
;
var
d
=
new
Date
();
sandbox
.
clock
.
tick
(
year
*
2
*
1000
);
assert
.
equal
(
time
.
toFuzzyString
(
d
),
'Thu Jan 01 1970'
);
});
});
});
describe
(
'.decayingInterval'
,
function
()
{
describe
(
'.decayingInterval'
,
function
()
{
...
...
h/static/scripts/time.js
View file @
fc4d0c15
...
@@ -56,14 +56,20 @@ var formatters = {};
...
@@ -56,14 +56,20 @@ var formatters = {};
*
*
*/
*/
function
format
(
date
,
options
)
{
function
format
(
date
,
options
)
{
if
(
typeof
Intl
!==
'undefined'
&&
Intl
.
DateTimeFormat
)
{
var
key
=
JSON
.
stringify
(
options
);
var
key
=
JSON
.
stringify
(
options
);
var
formatter
=
formatters
[
key
];
var
formatter
=
formatters
[
key
];
if
(
!
formatter
)
{
if
(
!
formatter
)
{
formatter
=
formatters
[
key
]
=
new
Intl
.
DateTimeFormat
(
undefined
,
options
);
formatter
=
formatters
[
key
]
=
new
Intl
.
DateTimeFormat
(
undefined
,
options
);
}
}
return
formatter
.
format
(
date
);
return
formatter
.
format
(
date
);
}
else
{
// IE < 11, Safari <= 9.0.
return
date
.
toDateString
();
}
}
}
function
dayAndMonth
(
date
)
{
function
dayAndMonth
(
date
)
{
...
...
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