@1500cloud/taitimestamp 中文文档教程
taitimestamp
用于将 TAI 时间戳操作到纳秒级的 JavaScript/TypeScript 库 精度(例如,用于表示 PTP 时间)。
根据 Apache 许可 获得许可并归还给 1500 Cloud 社区。
Installation
npm i --save @1500cloud/taitimestamp
或
yarn add @1500cloud/taitimestamp
Usage
例如,
import { now } from "@1500cloud/taitimestamp";
或
const { now } = require("@1500cloud/taitimestamp");
类型 TaiTimestamp
用于在 TypeScript 中表示此。 这是 正式一个对象,但请使用内置的帮助程序来转换其他 域。
now(): TaiTimestamp
返回表示当前日期的 TAI 时间戳的字符串。 这是 限于底层 JavaScript 平台的毫秒分辨率。
taiTimestampFromJsTime(number): TaiTimestamp
采用 JavaScript 时间戳(例如,new Date().getTime()
)并将其转换 到 TAI Timestamp 对象(限制为毫秒精度 JavaScript 日期对象)。
taiTimestampFromString(string): TaiTimestamp | null
这需要一个像 "123455.66"
这样的字符串,它代表一个小数 自 Unix 纪元以来的秒数并将其转换为对象。 (字符串是 用于保持精度)。
taiTimestampFromMediaTimestamp(string): TaiTimestamp | null
这需要一个像 "123455:678000000"
这样的字符串来表示时间 广播域(例如,NMOS API)并返回一个 TaiTimestamp 对象。
taiTimestampFromNanoseconds(BigInt): TaiTimestamp | null
这需要一个代表纳秒数的 BigInt 数字并返回 一个 TaiTimestamp 对象。
taiTimestampToString(TaiTimestamp): string
这会将 TaiTimestamp 对象转换为字符串表示形式。
taiTimestampToMediaTimestamp(TaiTimestamp): string
这会将 TaiTimestamp 对象转换为 TAI 时间的字符串表示形式 用于广播(例如,NMOS API)。
taiTimestampToNanoseconds(TaiTimestamp): BigInt
这将返回一个 BigInt 数字,表示中的纳秒数 Tai时间戳。
equals(TaiTimestamp, TaiTimestamp): boolean
这将比较两个时间戳对象并返回它们是否相等。
gt(TaiTimestamp, TaiTimestamp): boolean
这比较两个时间戳对象并返回第一个是否是 大于(晚于)第二个。
gte(TaiTimestamp, TaiTimestamp): boolean
这比较两个时间戳对象并返回第一个是否是 大于(晚于)或等于第二个。
lt(TaiTimestamp, TaiTimestamp): boolean
这比较两个时间戳对象并返回第一个是否是 比第二个少(早)。
lte(TaiTimestamp, TaiTimestamp): boolean
这比较两个时间戳对象并返回第一个是否是 小于(早于)或等于第二个。
add(TaiTimestamp, TaiTimestamp): TaiTimestamp
这会将两个 TaiTimestamp 相加并返回结果。 这只是真的 如果您将至少一个 TaiTimestamps 视为持续时间,则有意义, 因为将两个绝对时间加在一起并没有多大意义。
subtract(TaiTimestamp, TaiTimestamp): TaiTimestamp
这从第一个减去第二个 TaiTimestamp 并返回结果。 如果您至少想到其中一个,这才真正有意义 TaiTimestamps 作为持续时间,因为减去两个绝对时间并不真正 合理。
Changelog
这里使用语义版本控制。 请参阅 GitHub 发布页面 更改信息。
Contributing
欢迎以错误报告、错误修复或功能的形式做出贡献 改进! 如果您不确定要进行的更改,请打开 GitHub 上的一个问题首先要与维护者讨论。 请注意,通过 回馈这个项目你同意分配任何代码的版权 对 1500 Services Ltd 的修改。另请参阅我们的行为准则。
- Run unit tests:
yarn test
- Run a test watcher:
yarn dev
taitimestamp
A JavaScript/TypeScript library for manipulating TAI timestamps to nanosecond precision (e.g., for representing PTP time).
Licensed under the Apache License and given back to the community by 1500 Cloud.
Installation
npm i --save @1500cloud/taitimestamp
or
yarn add @1500cloud/taitimestamp
Usage
e.g.,
import { now } from "@1500cloud/taitimestamp";
or
const { now } = require("@1500cloud/taitimestamp");
The type TaiTimestamp
is used to represent this in TypeScript. This is officially an object, but please use the built-in helpers to convert other domains.
now(): TaiTimestamp
Returns a string representing a TAI Timestamp for the current date. This is limited to the millisecond resolution of the underlying JavaScript platform.
taiTimestampFromJsTime(number): TaiTimestamp
Takes a JavaScript timestamp (e.g., new Date().getTime()
) and converts it to a TAI Timestamp object (limited to the millisecond precision of a JavaScript date object).
taiTimestampFromString(string): TaiTimestamp | null
This takes a string like "123455.66"
which represents a fractional number of seconds since the Unix epoch and converts it into an object. (Strings are used to maintain precision).
taiTimestampFromMediaTimestamp(string): TaiTimestamp | null
This takes a string like "123455:678000000"
as used to represent time in the broadcasting domain (e.g., NMOS APIs) and returns a TaiTimestamp object.
taiTimestampFromNanoseconds(BigInt): TaiTimestamp | null
This takes a BigInt number representing the number of nanoseconds and returns a TaiTimestamp object.
taiTimestampToString(TaiTimestamp): string
This converts a TaiTimestamp object to a string representation.
taiTimestampToMediaTimestamp(TaiTimestamp): string
This converts a TaiTimestamp object to a string representation for TAI time as used in broadcasting (e.g., NMOS APIs).
taiTimestampToNanoseconds(TaiTimestamp): BigInt
This returns a BigInt number representing the number of nanoseconds in the TaiTimestamp.
equals(TaiTimestamp, TaiTimestamp): boolean
This compares two timestamp objects and returns if they are equal or not.
gt(TaiTimestamp, TaiTimestamp): boolean
This compares two timestamp objects and returns whether or not the first is greater (later) than the second.
gte(TaiTimestamp, TaiTimestamp): boolean
This compares two timestamp objects and returns whether or not the first is greater (later) than or equal to the second.
lt(TaiTimestamp, TaiTimestamp): boolean
This compares two timestamp objects and returns whether or not the first is less (earlier) than the second.
lte(TaiTimestamp, TaiTimestamp): boolean
This compares two timestamp objects and returns whether or not the first is less (earlier) than or equal to the second.
add(TaiTimestamp, TaiTimestamp): TaiTimestamp
This adds two TaiTimestamps together and returns the result. This only really makes sense if you think of at least one of the TaiTimestamps as a duration, as adding together two absolute times doesn't really make sense.
subtract(TaiTimestamp, TaiTimestamp): TaiTimestamp
This subtracts the second TaiTimestamp from the first and returns the result. This only really makes sense if you think of at least one of the TaiTimestamps as a duration, as subtracting two absolute times doesn't really make sense.
Changelog
Semantic versioning is in use here. Please see the GitHub releases page for change information.
Contributing
Contributions are welcomed in the form of bug reports, bug fixes or feature improvements! If you're unsure on the change you want to make, please open an issue on GitHub first to discuss with the maintainers. Please note that by contributing back to this project you agree to assign copyright of any code modifications to 1500 Services Ltd. Please also see our code of conduct.
- Run unit tests:
yarn test
- Run a test watcher:
yarn dev