Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ed3-format-default
Project
Project
Details
Activity
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Evgeny
ed3-format-default
Commits
929968c8
Commit
929968c8
authored
Aug 14, 2016
by
Evgeny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Date formatting now takes time as raw number in milliseconds
parent
3abc26c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
index.js
index.js
+6
-5
test_format.js
test/test_format.js
+12
-9
No files found.
index.js
View file @
929968c8
...
...
@@ -6,7 +6,12 @@ export default function format(v, type='', str=''){
return
basicFormat
(
v
);
}
type
=
toStandard
(
type
);
if
(
type
===
'DateTime'
){
if
(
!
(
v
instanceof
Date
)){
v
=
new
Date
(
v
);
}
}
const
result
=
dataFormatter
.
format
(
v
.
toString
(),
type
,
str
);
...
...
@@ -52,7 +57,3 @@ export function basicFormat(x){
return
x
.
toLocaleString
();
// for proper decimal separator
};
function
toStandard
(
type
){
return
type
[
0
].
toUpperCase
()
+
type
.
slice
(
1
);
}
test/test_format.js
View file @
929968c8
...
...
@@ -13,12 +13,12 @@ describe('format', ()=>{
it
(
'should do number formatting'
,
function
(){
const
str
=
'#,#0.00'
;
expect
(
format
(
0
,
'
n
umber'
,
str
)).
to
.
be
(
'0,00'
);
expect
(
format
(
1
,
'
n
umber'
,
str
)).
to
.
be
(
'1,00'
);
expect
(
format
(
-
1
,
'
n
umber'
,
str
)).
to
.
be
(
'-1,00'
);
expect
(
format
(
1
e10
,
'
n
umber'
,
str
)).
to
.
be
(
'10 000 000 000,00'
);
expect
(
format
(
1.1234
,
'
n
umber'
,
str
)).
to
.
be
(
'1,12'
);
expect
(
format
(
1.1289
,
'
n
umber'
,
str
)).
to
.
be
(
'1,13'
);
expect
(
format
(
0
,
'
N
umber'
,
str
)).
to
.
be
(
'0,00'
);
expect
(
format
(
1
,
'
N
umber'
,
str
)).
to
.
be
(
'1,00'
);
expect
(
format
(
-
1
,
'
N
umber'
,
str
)).
to
.
be
(
'-1,00'
);
expect
(
format
(
1
e10
,
'
N
umber'
,
str
)).
to
.
be
(
'10 000 000 000,00'
);
expect
(
format
(
1.1234
,
'
N
umber'
,
str
)).
to
.
be
(
'1,12'
);
expect
(
format
(
1.1289
,
'
N
umber'
,
str
)).
to
.
be
(
'1,13'
);
});
it
(
'should do currency formatting'
,
function
(){
...
...
@@ -33,15 +33,18 @@ describe('format', ()=>{
it
(
'should do date formatting'
,
()
=>
{
let
d
=
new
Date
(
2016
,
0
,
1
,
0
,
0
,
0
,
0
);
expect
(
format
(
d
,
'DateTime'
,
'yyyy-mm-dd'
)).
to
.
be
(
'2016-01-01'
);
d
=
new
Date
(
2016
,
0
,
1
,
1
,
0
,
0
,
0
);
expect
(
format
(
d
,
'DateTime'
,
'hh:mm'
)).
to
.
be
(
'01:00'
);
d
=
new
Date
(
2016
,
0
,
1
,
1
,
59
,
0
,
0
);
expect
(
format
(
d
,
'DateTime'
,
'hh:mm'
)).
to
.
be
(
'01:59'
);
});
it
(
'should do date formatting when number is given'
,
()
=>
{
expect
(
format
(
0
,
'DateTime'
,
'yyyy-mm-dd'
)).
to
.
be
(
'1970-01-01'
);
expect
(
format
(
1000
*
60
*
60
*
24
,
'DateTime'
,
'yyyy-mm-dd'
)).
to
.
be
(
'1970-01-02'
);
});
});
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