Initializes a new instance of the TimeWriter class optionally using the given configurations.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
This "overload" will always use TIME_SEGMENTS_COMMON as source for its time unit conversions.
An encapsulated nanosecond-based time.
When given, these configurations will override the those of the Locale and the
instance, for this specific countdown
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
An encapsulated nanosecond-based time.
Accepts any number of time units or array of time units (if repetitions are given, they will be singled out).
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
An encapsulated nanosecond-based time.
Accepts any number of time units or array of time units (if repetitions are given, they will be singled out).
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
An encapsulated nanosecond-based time.
When given, these configurations will override the those of the Locale and the
instance, for this specific countdown
. It does not change the object in any way whatsoever.
Accepts any number of time units or array of time units (if repetitions are given, they will be singled out).
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
An encapsulated nanosecond-based time.
When given, these configurations will override the those of the Locale and the
instance, for this specific countdown
. It does not change the object in any way whatsoever.
Accepts any number of time units or array of time units (if repetitions are given, they will be singled out).
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time length segmented into multiple units using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will produce explanations of time lengths much easier to understand than arbitrary fractions.
An encapsulated nanosecond-based time.
When given, these configurations will override the those of the Locale and the
instance, for this specific countdown
. It does not change the object in any way whatsoever.
Accepts any number of time units or array of time units (if repetitions are given, they will be singled out).
A string containing a synthetic representation of the given time through the use of multiple units of time.
Writes a time value using a Time object and, optionally, configurations that may override those of the Locale and the instance, for the duration of the method.
This will use the default time unit (which falls back to "nanoseconds") as both input (when time is numeric) and output time unit.
A numeric representation of a time value -or- an encapsulated nanosecond-based time.
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
An encapsulated nanosecond-based time.
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
An encapsulated nanosecond-based time.
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds". Accepts plurals and case variations.
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds". Accepts plurals and case variations.
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds".
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds". Accepts plurals and case variations.
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
A numeric representation of a time value.
Time unit from which the given time value will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds". Accepts plurals and case variations.
Time unit to which the given time will be converted. If this parameter is not passed, it fallbacks to the default time unit and ultimately to "nanoseconds". Accepts plurals and case variations.
When given, these configurations will override the those of the Locale and the
instance, for this specific write
. It does not change the object in any way whatsoever.
A string containing a synthetic representation of the given time.
Generated using TypeDoc
Time writers are objects used to synthesize time values into strings, i.e. write times using different lexical and numerical configurations. Write is used to express a single time value, using a single time unit; countdown is used to classify time values by segmenting them into parts with different time units.
These configurations are loaded in the following order:
Examples
Writing time using different units
First, import and initialize the appropriate objects:
EcmaScript 6:
import { Time, TimeWriter } from "timecount"; var time = new Time(1000); const timeWriter = new TimeWriter();
Older EcmaScripts:
var timecount = require("timecount"); var time = new timecount.Time(1000); var timeWriter = new timecount.TimeWriter();
Next, use the hypothetical
log
function to receive time outputs:1. Writing multiple time values
import { Time, TimeWriter } from "timecount"; const timeWriter = new TimeWriter(); // Writes the value of 90 minutes using hours: console.log(timerWriter.write(90, "minute", "hour")); // Result: 1.5 h // Writes the value of 90 minutes: console.log(timerWriter.write(90, "minute")); // Result: 90 min // Writes the value of a trillion nanoseconds in minutes: console.log(timerWriter.write(new Time(1000000000000), "minute"); // Result: 16.666666666666668 min // By default, timecount will use nanoseconds for input and output: console.log(timerWriter.write(1000000000000)); // Result: 1000000000000 ns
2. Customizing the time output
There are three places where the output of a time writer (TimeWriterSettings) can be configured, each one overriding the previous:
options
of the write method.const timecount = require("timecount"); const tw = new TimeWriter({ verbose: true }); tw.write(10, "second"); // Result: 10 seconds tw.write(10, "second", { spaceTimeUnit: false, verbose: false }); // Result: 10s tw.write(10, "day"); // Result: 10 days Locale.set("es"); tw.write(10, "day"); // Result: 10 días tw.settings.verbose = false; tw.write(10, "second"); // Result: 10 s