# Time 1.0.3+

# TeslaCloud.TIme

# Flags

Флаг Значение Описание
ALL 0x3F
SECONDS 0x1 Display seconds in results.
MINUTES 0x2 Display minutes in results.
HOURS 0x4 Display hours in results.
DAYS 0x8 Display days in results.
MONTHS 0x10 Display months in results..
YEARS 0x20 Display years in results.
NO_ZEROS 0x800 Removing zeros from results.
NO_FIRST_ZEROS 0x1000 Removing insignificant zeros from results.

# Properties

Constant Value
FORMAT_STR

# timeToObject

Converts time in seconds to years, months, days, hours, minutes and seconds.

timeToObject(time, flags = this.ALL)

# Arguments

Argument Type Default value Description
time int Time to convert (in seconds).
flags int this.ALL | this.NO_FIRST_ZEROS See Flags.

# Examples

# Simple conversion
console.log(
    TeslaCloud.Time.timeToObject(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
    )
);

/*
Object<TeslaCloud.DateInterval>
{
    years: 3,
    months: 1,
    days: 0,
    hours: 14,
    minutes: 37,
    seconds: 13,
    invert: false
}
*/
# Retrieving only certain values
const TCT = TeslaCloud.Time;
console.log(
    TCT.timeToObject(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        TCT.DAYS | TCT.HOURS | TCT.MINUTES
    )
);

/*
Object<TeslaCloud.DateInterval>
{
    years: 0,
    months: 0,
    days: 1125,
    hours: 14,
    minutes: 37,
    seconds: 0,
    invert: false
}
*/

# timeToString

Converts a time to a string.

timeToString(time, format = this.FORMAT_STR, flags = this.ALL | this.NO_FIRST_ZEROS)

# Arguments

Argument Type Default value Description
time int Time to convert (in seconds).
format string this.FORMAT_STR Output format.
The following placeholders are available:
⋅ {seconds}, {minutes}, {hours}, {days}, {months}, {years} — values returned by the timeToObject method
⋅ {seconds_phrased}, {minutes_phrased}, {hours_phrased}, {days_phrased}, {months_phrased}, {years_phrased} — phrases for these values.
flags int this.ALL | this.NO_FIRST_ZEROS See Flags.

# Examples

# Simple conversion
console.log(
    TeslaCloud.Time.timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
    )
);

// 3 years 1 month 0 days 14 hours 37 minutes 13 seconds
# Removing all zeros from results
const TCT = TeslaCloud.Time;
console.log(
    TCT.timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400,
        TCT.FORMAT_STR,
        TCT.ALL | TCT.NO_ZEROS
    )
);

// 1 month 14 hours 37 minutes 13 seconds
# Retrieving only certain values
const TCT = TeslaCloud.Time;
console.log(
    TCT.timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        TCT.FORMAT_STR,
        TCT.DAYS | TCT.HOURS | TCT.MINUTES
    )
);

// 1 125 days 14 hours 37 minutes
# Custom format
const TCT = TeslaCloud.Time;
console.log(
    TCT.timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        '{hours}:{minutes}:{seconds}',
        TCT.HOURS | TCT.MINUTES | TCT.SECONDS
    )
);

// 27014:37:13

# diff

Returns the difference between two dates.

diff(one, two, absolute = false)

# Arguments

Argument Type Default value Description
one Date|int|string string
two Date|int|string i string
absolute bool false If true, the interval will be forced to be converted to an absolute value.

# Return values

Returns a TeslaCloud.DateInterval object that represents the difference between the two dates.

# Examples

const TCT = TeslaCloud.Time;

console.log(
    TCT.diff(Date.now(), 'January 19, 2038 03:14:08 UTC')
);

/*
Object<TeslaCloud.DateInterval>
{
    years: 13,
    months: 11,
    days: 8,
    hours: 4,
    minutes: 14,
    seconds: 2,
    invert: false
}
*/

console.log(
    TCT.diff(Date.now(), 'October 7, 2005')
);

/*
Object<TeslaCloud.DateInterval>
{
    years: 18,
    months: 4,
    days: 4,
    hours: 3,
    minutes: 3,
    seconds: 49,
    invert: true
}
*/

# TeslaCloud.DateInterval

Represents the difference between the two dates

# Properties

Property Description
years Number of years.
months Number of months.
days Number of days.
hours Number of hours.
minutes Number of minutes.
seconds Number of seconds.
invert If true, the interval represents a negative time period, otherwise false.

# isZero

Returns true if all values of the object are zero, otherwise false.

# TeslaCloud.Countdown (tc-countdown)

# Parameters

Parameter Default value Description
to Time for countdown.
format TeslaCloud.Time.FORMAT_STR Interval display format.
formatNegative Negative interval display format.
allowNegative true If false, countdown will stop when the interval value is zero. The value of the endText parameter will be displayed instead of the interval.
If true, countdown will continue if the interval value is negative. The format from the formatNegative parameter will be used to display the interval.
endText The text that will be displayed when the interval value is zero. If not specified, the inner HTML of the element for which the handler was initialized will be used.

# Examples

<xf:js src="TC/ComponentLibrary/time.js" addon="TC/ComponentLibrary" min="1" />

<dl class="pairs pairs--spaced">
    <dt>Countdown to January 19, 2038 03:14:08 UTC</dt>
    <dd>
        <span data-xf-init="tc-countdown"
              data-to="January 19, 2038 03:14:08 UTC">Initialization...</span>
    </dd>
</dl>

<dl class="pairs pairs--spaced">
    <dt>Countdown to October 7, 2005</dt>
    <dd>
        <span data-xf-init="tc-countdown"
              data-to="10.07.2005">Initialization...</span>
    </dd>
</dl>

<dl class="pairs pairs--spaced">
    <dt>Countdown to January 19, 2038 03:14:08 UTC with custom format</dt>
    <dd>
        <span data-xf-init="tc-countdown"
              data-to="January 19, 2038 03:14:08 UTC"
              data-format="The Epochalipse will come in {$xf.tcTime.FORMAT_STR}"
              data-format-negative="The Epochalpse came {{ phrase('tc_clib_x_ago', {'time': $xf.tcTime.FORMAT_STR}) }}">Initialization...</span>
    </dd>
</dl>

<dl class="pairs pairs--spaced">
    <dt>Countdown to January 1, 2025 without negative interval</dt>
    <dd>
        <span data-xf-init="tc-countdown"
              data-to="January 1, 2025"
              data-allow-negative="false"
              data-end-text="The countdown is over">Initialization...</span>
    </dd>
</dl>Pluralization [!badge variant="info" text="1.0.3+"]Pluralization [!badge variant="info" text="1.0.3+"]