TimeDeltaQuantityString#

class astropy.time.TimeDeltaQuantityString(val1, val2, scale, precision, in_subfmt, out_subfmt, from_jd=False)[source]#

Bases: TimeDeltaFormat, TimeUnique

Time delta as a string with one or more Quantity components.

This format provides a human-readable multi-scale string representation of a time delta. It is convenient for applications like a configuration file or a command line option.

The format is specified as follows:

  • The string is a sequence of one or more components.

  • Each component is a number followed by an astropy unit of time.

  • For input, whitespace within the string is allowed but optional.

  • For output, there is a single space between components.

  • The allowed components are listed below.

  • The order (yr, d, hr, min, s) is fixed but individual components are optional.

The allowed input component units are shown below:

  • “yr”: years (365.25 days)

  • “d”: days (24 hours)

  • “hr”: hours (60 minutes)

  • “min”: minutes (60 seconds)

  • “s”: seconds

Note

These definitions correspond to physical units of time and are NOT calendar date intervals. Thus adding “1yr” to “2000-01-01 00:00:00” will give “2000-12-31 06:00:00” instead of “2001-01-01 00:00:00”.

The out_subfmt attribute specifies the components to be included in the string output. The default is "multi" which represents the time delta as "<days>d <hours>hr <minutes>min <seconds>s", where only non-zero components are included.

  • “multi”: multiple components, e.g. “2d 3hr 15min 5.6s”

  • “yr”: years

  • “d”: days

  • “hr”: hours

  • “min”: minutes

  • “s”: seconds

Examples

>>> from astropy.time import Time, TimeDelta
>>> import astropy.units as u
>>> print(TimeDelta("1yr"))
365d 6hr
>>> print(Time("2000-01-01") + TimeDelta("1yr"))
2000-12-31 06:00:00.000
>>> print(TimeDelta("+3.6d"))
3d 14hr 24min
>>> print(TimeDelta("-3.6d"))
-3d 14hr 24min
>>> print(TimeDelta("1yr 3.6d", out_subfmt="d"))
368.85d
>>> td = TimeDelta(40 * u.hr)
>>> print(td.to_value(format="quantity_str"))
1d 16hr
>>> print(td.to_value(format="quantity_str", subfmt="d"))
1.667d
>>> td.precision = 9
>>> print(td.to_value(format="quantity_str", subfmt="d"))
1.666666667d

Attributes Summary

in_subfmt

jd1

jd2

name

out_subfmt

precision

re_float

re_ydhms

scale

Time scale.

subfmts

value

Methods Summary

fill_value(subfmt)

Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.

fix_comp_vals_overflow(comp_vals)

get_multi_comps(jd1, jd2)

parse_string(timestr)

Read time from a single string

set_jds(val1, val2)

Parse the time strings contained in val1 and get jd1, jd2.

to_value([parent, out_subfmt])

Return time representation from internal jd1 and jd2 in specified out_subfmt.

Attributes Documentation

in_subfmt#
jd1#
jd2#
name = 'quantity_str'#
out_subfmt#
precision#
re_float = '(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?'#
re_ydhms = re.compile('^ \\s*\n        (?P<sign>[-+])? \\s*  # Optional sign\n        (?=[^-+\\s])  # At least one character which is not a sign or whitespace\n        ((?P<yr>(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?) \\s*, re.VERBOSE)#
scale#

Time scale.

subfmts = (('multi', None, None), ('yr', None, None), ('d', None, None), ('hr', None, None), ('min', None, None), ('s', None, None))#
value#

Methods Documentation

classmethod fill_value(subfmt)#

Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.

This is used as a fill value for masked arrays to ensure that any ERFA operations on the masked array will not fail due to the masked value.

static fix_comp_vals_overflow(comp_vals)[source]#
get_multi_comps(jd1, jd2)[source]#
parse_string(timestr)[source]#

Read time from a single string

set_jds(val1, val2)[source]#

Parse the time strings contained in val1 and get jd1, jd2.

to_value(parent=None, out_subfmt=None)[source]#

Return time representation from internal jd1 and jd2 in specified out_subfmt.

This is the base method that ignores parent and uses the value property to compute the output. This is done by temporarily setting self.out_subfmt and calling self.value. This is required for legacy Format subclasses prior to astropy 4.0 New code should instead implement the value functionality in to_value() and then make the value property be a simple call to self.to_value().

Parameters:
parentobject

Parent Time object associated with this TimeFormat object

out_subfmtstr or None

Output subformt (use existing self.out_subfmt if None)

Returns:
valuenumpy.array, numpy.ma.array

Array or masked array of formatted time representation values