Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
dde56a78
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dde56a78
编写于
8月 31, 2017
作者:
B
Bryce Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for custom daysPerWeek and hoursPerDay to prettyTime.parseSeconds.
上级
e5842838
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
88 addition
and
6 deletion
+88
-6
app/assets/javascripts/lib/utils/pretty_time.js
app/assets/javascripts/lib/utils/pretty_time.js
+7
-6
spec/javascripts/pretty_time_spec.js
spec/javascripts/pretty_time_spec.js
+81
-0
未找到文件。
app/assets/javascripts/lib/utils/pretty_time.js
浏览文件 @
dde56a78
...
...
@@ -2,19 +2,20 @@ import _ from 'underscore';
(()
=>
{
/*
* TODO: Make these methods more configurable (e.g.
parseSeconds timePeriodContstraints,
*
stringifyTime condensed or
non-condensed, abbreviateTimelengths)
* TODO: Make these methods more configurable (e.g.
stringifyTime condensed or
* non-condensed, abbreviateTimelengths)
* */
const
utils
=
window
.
gl
.
utils
=
gl
.
utils
||
{};
const
prettyTime
=
utils
.
prettyTime
=
{
/*
* Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # }
* Seconds can be negative or positive, zero or non-zero.
* Seconds can be negative or positive, zero or non-zero. Can be configured for any day
* or week length.
*/
parseSeconds
(
seconds
)
{
const
DAYS_PER_WEEK
=
5
;
const
HOURS_PER_DAY
=
8
;
parseSeconds
(
seconds
,
{
daysPerWeek
=
5
,
hoursPerDay
=
8
}
=
{}
)
{
const
DAYS_PER_WEEK
=
daysPerWeek
;
const
HOURS_PER_DAY
=
hoursPerDay
;
const
MINUTES_PER_HOUR
=
60
;
const
MINUTES_PER_WEEK
=
DAYS_PER_WEEK
*
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
const
MINUTES_PER_DAY
=
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
...
...
spec/javascripts/pretty_time_spec.js
浏览文件 @
dde56a78
...
...
@@ -76,6 +76,87 @@ import '~/lib/utils/pretty_time';
expect
(
aboveOneWeek
.
days
).
toBe
(
3
);
expect
(
aboveOneWeek
.
weeks
).
toBe
(
173
);
});
it
(
'
should correctly accept a custom param for hoursPerDay
'
,
function
()
{
const
parser
=
prettyTime
.
parseSeconds
;
const
config
=
{
hoursPerDay
:
24
};
const
aboveOneHour
=
parser
(
4800
,
config
);
expect
(
aboveOneHour
.
minutes
).
toBe
(
20
);
expect
(
aboveOneHour
.
hours
).
toBe
(
1
);
expect
(
aboveOneHour
.
days
).
toBe
(
0
);
expect
(
aboveOneHour
.
weeks
).
toBe
(
0
);
const
aboveOneDay
=
parser
(
110000
,
config
);
expect
(
aboveOneDay
.
minutes
).
toBe
(
33
);
expect
(
aboveOneDay
.
hours
).
toBe
(
6
);
expect
(
aboveOneDay
.
days
).
toBe
(
1
);
expect
(
aboveOneDay
.
weeks
).
toBe
(
0
);
const
aboveOneWeek
=
parser
(
25000000
,
config
);
expect
(
aboveOneWeek
.
minutes
).
toBe
(
26
);
expect
(
aboveOneWeek
.
hours
).
toBe
(
8
);
expect
(
aboveOneWeek
.
days
).
toBe
(
4
);
expect
(
aboveOneWeek
.
weeks
).
toBe
(
57
);
});
it
(
'
should correctly accept a custom param for daysPerWeek
'
,
function
()
{
const
parser
=
prettyTime
.
parseSeconds
;
const
config
=
{
daysPerWeek
:
7
};
const
aboveOneHour
=
parser
(
4800
,
config
);
expect
(
aboveOneHour
.
minutes
).
toBe
(
20
);
expect
(
aboveOneHour
.
hours
).
toBe
(
1
);
expect
(
aboveOneHour
.
days
).
toBe
(
0
);
expect
(
aboveOneHour
.
weeks
).
toBe
(
0
);
const
aboveOneDay
=
parser
(
110000
,
config
);
expect
(
aboveOneDay
.
minutes
).
toBe
(
33
);
expect
(
aboveOneDay
.
hours
).
toBe
(
6
);
expect
(
aboveOneDay
.
days
).
toBe
(
3
);
expect
(
aboveOneDay
.
weeks
).
toBe
(
0
);
const
aboveOneWeek
=
parser
(
25000000
,
config
);
expect
(
aboveOneWeek
.
minutes
).
toBe
(
26
);
expect
(
aboveOneWeek
.
hours
).
toBe
(
0
);
expect
(
aboveOneWeek
.
days
).
toBe
(
0
);
expect
(
aboveOneWeek
.
weeks
).
toBe
(
124
);
});
it
(
'
should correctly accept custom params for daysPerWeek and hoursPerDay
'
,
function
()
{
const
parser
=
prettyTime
.
parseSeconds
;
const
config
=
{
daysPerWeek
:
55
,
hoursPerDay
:
14
};
const
aboveOneHour
=
parser
(
4800
,
config
);
expect
(
aboveOneHour
.
minutes
).
toBe
(
20
);
expect
(
aboveOneHour
.
hours
).
toBe
(
1
);
expect
(
aboveOneHour
.
days
).
toBe
(
0
);
expect
(
aboveOneHour
.
weeks
).
toBe
(
0
);
const
aboveOneDay
=
parser
(
110000
,
config
);
expect
(
aboveOneDay
.
minutes
).
toBe
(
33
);
expect
(
aboveOneDay
.
hours
).
toBe
(
2
);
expect
(
aboveOneDay
.
days
).
toBe
(
2
);
expect
(
aboveOneDay
.
weeks
).
toBe
(
0
);
const
aboveOneWeek
=
parser
(
25000000
,
config
);
expect
(
aboveOneWeek
.
minutes
).
toBe
(
26
);
expect
(
aboveOneWeek
.
hours
).
toBe
(
0
);
expect
(
aboveOneWeek
.
days
).
toBe
(
1
);
expect
(
aboveOneWeek
.
weeks
).
toBe
(
9
);
});
});
describe
(
'
stringifyTime
'
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录