TimeDelta class¶
This page explains the TimeDelta
class.
What class is this?¶
The TimeDelta
class treats a time delta between two DateTime
instances.
Basic usage¶
Subtraction between two DateTime
instances returns this class’s instance.
import apysc as ap
ap.Stage()
datetime_1: ap.DateTime = ap.DateTime(2022, 12, 7)
datetime_2: ap.DateTime = ap.DateTime(2022, 12, 5)
timedelta_: ap.TimeDelta = datetime_1 - datetime_2
A TimeDelta
instance has each interface, such as the days
’ property or total_seconds
’ method, as follows:
import apysc as ap
ap.Stage()
datetime_1: ap.DateTime = ap.DateTime(2022, 12, 7)
datetime_2: ap.DateTime = ap.DateTime(2022, 12, 5)
timedelta_: ap.TimeDelta = datetime_1 - datetime_2
days: ap.Int = timedelta_.days
assert days == 2
total_seconds: ap.Number = timedelta_.total_seconds()
assert total_seconds == 60 * 60 * 24 * 2
days property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get days in the duration.
[Returns]
days
: IntDays value. This interface ignores a fraction.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> datetime_1: ap.DateTime = ap.DateTime(2022, 12, 7)
>>> datetime_2: ap.DateTime = ap.DateTime(2022, 12, 5)
>>> timedelta_: ap.TimeDelta = datetime_1 - datetime_2
>>> timedelta_.days
Int(2)
[References]
total_seconds method API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] total_seconds(self) -> apysc._type.number.Number
[Interface summary]
Get the total seconds in the duration.
[Returns]
total_seconds
: NumberTotal seconds in the duration.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> datetime_1: ap.DateTime = ap.DateTime(2022, 12, 7)
>>> datetime_2: ap.DateTime = ap.DateTime(2022, 12, 6)
>>> timedelta_: ap.TimeDelta = datetime_1 - datetime_2
>>> timedelta_.total_seconds()
Number(86400.0)
[References]