Constructor
new Timer(options)
构造函数
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
object | 其他配置选项见Timer.options Properties
|
Members
(static, readonly) options :object
Properties:
Name | Type | Default | Description |
---|---|---|---|
name |
string |
'timer'
|
日志器命名空间 |
debug |
boolean |
false
|
调试模式 |
format |
string |
'mm:ss'
|
日期时间格式化字符串,支持使用字母占位符匹配对应的年月日时分秒:Y=年、M=月、D=日、h=时、m=分、s=秒、ms=毫秒,年和毫秒字母占位符可以使用1-4个,其他占位符可以使用1-2个,如果实际结果值长度大于占位符的长度,则显示值实际结果值,如果小于,则前置用0补足 |
mode |
string |
'-'
|
计时模式类型,可选值请参考 MODE_TYPE |
默认配置选项
Type:
- object
(readonly) $options :object
实例初始配置项
Type:
- object
(readonly) $status :string
实例状态,可能处于以下状态:prepare=准备创段、processing=进行中、finished=已完成、stoped=暂停中
Type:
- string
(readonly) $timeZoneTimeStamp :number
当前地区的偏移时区时间戳
Type:
- number
(readonly) $remainTimeStamp :number
剩余计时时间戳
Type:
- number
(readonly) $throughTimeStamp :number
已经过的时间戳
Type:
- number
(readonly) $startTimeStamp :number
开始计时时间戳
Type:
- number
(readonly) $stopTimeStamp :number
暂停计时时间戳
Type:
- number
(readonly) $endTimeStamp :number
计时器开始计时起 => 计时器完成时的一轮周期计时时间戳
Type:
- number
(readonly) $currentTimeStamp :number
当前时间的时间戳,用于修正计时器在空间维度中出现异常流逝的时间戳
Type:
- number
(readonly) $stopwatch :Array.<string>
计时器每次记录的妙表功能
Type:
- Array.<string>
(readonly) $timeStamp :number
获取实例的计时时间戳配置项
Type:
- number
(readonly) $format :string
获取实例的日期时间格式化配置项
Type:
- string
(readonly) $mode :string
获取实例的计时模式配置项
Type:
- string
(readonly) $datetime :string
获取实例的日期时间字符串值
Type:
- string
(readonly) $data :object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
year |
string |
<optional> |
剩余年数 |
month |
string |
<optional> |
剩余月数 |
date |
string |
<optional> |
剩余日数 |
hour |
string |
<optional> |
剩余时数 |
minute |
string |
<optional> |
剩余分数 |
second |
string |
<optional> |
剩余秒数 |
millisecond |
string |
<optional> |
剩余毫秒数 |
获取实例的日期时间数据片断
Type:
- object
Methods
(static) config(options) → {Timer}
- Source:
- Since:
- 1.0.0
- See:
更新默认配置选项
Parameters:
Name | Type | Description |
---|---|---|
options |
object | 其他配置选项见Timer.options |
Returns:
- Type
- Timer
(async) start(callback) → {Promise}
计时器开始计时
计时器结束后进入resolved状态
若在未结束前中途造成暂停,会触发rejectd状态
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | 每秒执行的回调函数 |
Returns:
- Type
- Promise
record() → {Timer}
秒表:记录触发该操作的计时结果,保存结果的值将根据当前实例的format格式化
Returns:
- Type
- Timer
stop() → {Timer}
计时器停止
Returns:
- Type
- Timer
reset() → {Timer}
计时器复位
Returns:
- Type
- Timer