Timer

Timer

计时类

Constructor

new Timer(options)

Source:

构造函数

Parameters:
Name Type Description
options object

其他配置选项见Timer.options

Properties
Name Type Description
timeStamp number

剩余计时时间戳,毫秒单位,且毫秒数必须为1000单位,不能是1234这样,超出时会自动向下取整

Members

(static, readonly) options :object

Source:
Since:
  • 1.0.0
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

Source:
Since:
  • 1.0.0

实例初始配置项

Type:
  • object

(readonly) $status :string

Source:
Since:
  • 1.0.0

实例状态,可能处于以下状态:prepare=准备创段、processing=进行中、finished=已完成、stoped=暂停中

Type:
  • string

(readonly) $timeZoneTimeStamp :number

Source:
Since:
  • 1.0.0

当前地区的偏移时区时间戳

Type:
  • number

(readonly) $remainTimeStamp :number

Source:
Since:
  • 1.0.0

剩余计时时间戳

Type:
  • number

(readonly) $throughTimeStamp :number

Source:
Since:
  • 1.0.0

已经过的时间戳

Type:
  • number

(readonly) $startTimeStamp :number

Source:
Since:
  • 1.0.0

开始计时时间戳

Type:
  • number

(readonly) $stopTimeStamp :number

Source:
Since:
  • 1.0.0

暂停计时时间戳

Type:
  • number

(readonly) $endTimeStamp :number

Source:
Since:
  • 1.0.0

计时器开始计时起 => 计时器完成时的一轮周期计时时间戳

Type:
  • number

(readonly) $currentTimeStamp :number

Source:
Since:
  • 1.0.0

当前时间的时间戳,用于修正计时器在空间维度中出现异常流逝的时间戳

Type:
  • number

(readonly) $stopwatch :Array.<string>

Source:
Since:
  • 1.0.0

计时器每次记录的妙表功能

Type:
  • Array.<string>

(readonly) $timeStamp :number

Source:
Since:
  • 1.0.0

获取实例的计时时间戳配置项

Type:
  • number

(readonly) $format :string

Source:
Since:
  • 1.0.0

获取实例的日期时间格式化配置项

Type:
  • string

(readonly) $mode :string

Source:
Since:
  • 1.0.0

获取实例的计时模式配置项

Type:
  • string

(readonly) $datetime :string

Source:
Since:
  • 1.0.0

获取实例的日期时间字符串值

Type:
  • string

(readonly) $data :object

Source:
Since:
  • 1.1.0
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}

Source:
Since:
  • 1.0.0

计时器开始计时
计时器结束后进入resolved状态
若在未结束前中途造成暂停,会触发rejectd状态

Parameters:
Name Type Description
callback function

每秒执行的回调函数

Returns:
Type
Promise

record() → {Timer}

Source:
Since:
  • 1.1.0

秒表:记录触发该操作的计时结果,保存结果的值将根据当前实例的format格式化

Returns:
Type
Timer

stop() → {Timer}

Source:
Since:
  • 1.0.0

计时器停止

Returns:
Type
Timer

reset() → {Timer}

Source:
Since:
  • 1.0.0

计时器复位

Returns:
Type
Timer